The Gold Road Chapter – which includes the Scribing system – and Update 42 is now available to test on the PTS! You can read the latest patch notes here: https://forums.elderscrollsonline.com/en/discussion/656454/

Need help for a simple mod

FunkyPizzaMan
FunkyPizzaMan
Soul Shriven
Hi everyone !
I need help writing a mod in lua. (I don't know how to write in lua ..).

I followed a few tutorials and I manage to get this mod working (it's not mine) but I wanted to add some features.
So this is the mod
CombatWarning= {}
CombatWarning.name = "CombatWarning"

function CombatWarning:Initialize()
   CombatWarning.inCombat = IsUnitInCombat("player")
   end

function CombatWarning.OnAddOnLoaded(event, addonName)
   if addonName == CombatWarning.name then
    CombatWarning:Initialize()
  end
end
EVENT_MANAGER:RegisterForEvent(CombatWarning.name, EVENT_ADD_ON_LOADED, CombatWarning.OnAddOnLoaded)
EVENT_MANAGER:RegisterForEvent(CombatWarning.name, EVENT_PLAYER_COMBAT_STATE, CombatWarning.OnPlayerCombatState)

function CombatWarning.OnPlayerCombatState(event, inCombat)
  if inCombat ~= CombatWarning.inCombat then
    CombatWarning.inCombat = inCombat
    if inCombat then
      d("Entering combat.")
    else
      d("Exiting combat.")
    end
  end
end

And I would like to add this function EVENT_MOUNTED_STATE_CHANGED (integereventCode, boolmounted) so that when the player get on or off his mount a message appears in the chatbox. I tried doing it like the player combat state function but it's not working ..

Anyone can help me ?
  • katkat42
    katkat42
    ✭✭✭
    @FunkyPizzaMan Sure, let's take a look. It should work similarly to the combat state alerter. What code do you have, and in what way is it not working?
    Stonehenge ROCKS!
  • FunkyPizzaMan
    FunkyPizzaMan
    Soul Shriven
    Well, I need to change the first function (initialisation)
    I supposed I'd write:
    function CombatWarnig:Initialize()
      self.Mounted = IsUnitMounted("player")
      
      EVENT_MANAGER:RegisterForEvent(self.name, EVENT_MOUNTED_STATE_CHANGED, self.OnMountedState)
    end
    

    But how do I know what write instead of "IsUnitInCombat" and "XXXX.OnPlayerCombatState" ?
    Edited by FunkyPizzaMan on February 22, 2015 12:11PM
  • katkat42
    katkat42
    ✭✭✭
    Well, I need to change the first function (initialisation)
    I supposed I'd write:
    function CombatWarnig:Initialize()
      self.Mounted = IsUnitMounted("player")
      
      EVENT_MANAGER:RegisterForEvent(self.name, EVENT_MOUNTED_STATE_CHANGED, self.OnMountedState)
    end
    

    But how do I know what write instead of "IsUnitInCombat" and "XXXX.OnPlayerCombatState" ?

    Well, the last argument of EVENT_MANAGER:RegisterForEvent() is the function that executes when the event fires, in this case when your mounted state changes. And this is the description of the event: EVENT_MOUNTED_STATE_CHANGED (integer eventCode, bool mounted)

    Those two items in parentheses are the arguments passed to your event handler function. The first is the event code; it tells you which event caused your function to execute (so you can use the same function for more than one event); the second tells you whether your character is now mounted (true for mounted; false for on foot).

    The combat state changed event is very similar; its description would look like this: EVENT_PLAYER_COMBAT_STATE (int eventCode, bool inCombat). Now look at the callback function in the original, OnPlayerCombatState. Can you see the similarities? Does this give you any clues?
    Stonehenge ROCKS!
Sign In or Register to comment.