Jump to content

Recommended Posts

For a creature mod I wanted to add some functions when it is mounted and then dismounted. The rider component pushes the events "mounted" and "dismounted" but I don't know how to properly listen for these. I can see that the code for wolfgang is able to use these same events but that isn't working for me. I've tried looking through the forums but can't understand what I need to do for my case. I'm not sure if I need to be adding something in modmain or the prefab and what exactly to put to make it work.

Any help is appreciated.

 

The events are pushed for the player who mounted/dismounted, you can see this because the player has the rider component and the one who has a component is always called "self.inst" within the component and the line is
self.inst:PushEvent("mounted", { target = target })

So now you now that you have to listen for this event at the player.
and the "data" is simply the table {...} you see in the line where the event is pushed. So data for mounted is {target=target}, which means with data.target you will get the target. dismount has not data, because when it is pusehd you see no table like this in the code: "self.inst:PushEvent("dismount")".
So all you need is:

AddPlayerPostInit(function(inst)
    inst:ListenForEvent("mounted",function(inst,data)
       -- you can use inst == the player and you can use data.target == the thing the player mounted
    end)
    inst:ListenForEvent("dismounted",function(inst) -- no data send for dismount
       -- you can use inst == the player
    end)
end)

if you only want this to run for your custom character, then put the ListenForEvent stuff into your master post init, instead of using AddPlayerPostInit.

So you see within rider you mostly have information about the player.
If you want more information about the ridden creature, you may look at ridable.lua instead. Use the explanation above and try to use it with events within rideable.lua

Edited by Serpens

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...