WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Need help in how to write this simple script to lua (https://www.wowinterface.com/forums/showthread.php?t=58910)

Googles 08-28-21 11:54 PM

Need help in how to write this simple script to lua
 
Hello.

So basically I have this script in a macro that I have to click everytime I logon. I just want help writing it in an .lua file so it automatically activates on logon. I have tried reading a few guides but could not get it to work.

The script is
  • /run C_NamePlate.SetNamePlateFriendlySize(60, 60)

I have made an addon with a .toc and everything but I'm not sure what to write exactly in the .lua file for the code to work properly. I have tried
  • C_NamePlate.SetNamePlateFriendlySize(60, 60)
  • SetNamePlateFriendlySize(60, 60)
  • local EventFrame = CreateFrame("Frame")
    EventFrame:RegisterEvent("PLAYER_LOGIN")
    EventFrame:SetScript("OnEvent", function(self,event,...)
    C_NamePlate.SetNamePlateFriendlySize(60, 60)
    end)

But none of them seemed to work for me. I have absolutely zero knowledge in coding and I've tried reading a few guides but with no success. If anyone can help I'd be thankful. Cheers

briskman3000 08-29-21 03:54 AM

In your addon file, you would need to create a function that has that script inside of it, and then trigger than function to run on player login.

Something similar to this should work

Lua Code:
  1. local setnameplateframe = CreateFrame("Frame", setnameplateframe)
  2.  
  3. local function setnameplatesize(self, event, ...)
  4.      C_NamePlate.SetNamePlateFriendlySize(60, 60)
  5. end
  6.  
  7. setnameplateframe:RegisterEvent("PLAYER_LOGIN")
  8. setnameplateframe:SetScript("OnEvent", setnameplatesize)

I have not tested this code and can not guarantee that it works.

Googles 08-29-21 06:42 AM

Quote:

Originally Posted by briskman3000 (Post 339766)
In your addon file, you would need to create a function that has that script inside of it, and then trigger than function to run on player login.

Something similar to this should work

Lua Code:
  1. local setnameplateframe = CreateFrame("Frame", setnameplateframe)
  2.  
  3. local function setnameplatesize(self, event, ...)
  4.      C_NamePlate.SetNamePlateFriendlySize(60, 60)
  5. end
  6.  
  7. setnameplateframe:RegisterEvent("PLAYER_LOGIN")
  8. setnameplateframe:SetScript("OnEvent", setnameplatesize)

I have not tested this code and can not guarantee that it works.

Worked perfectly thanks a lot!


All times are GMT -6. The time now is 12:20 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI