MegaNerdX Posted December 28, 2018 Share Posted December 28, 2018 (edited) I need help making a character that loses sanity from attacking insects and eating and using stuff like butterfly wings and spider glands. I have this code so far but it crashes the game. local function inst:(ListenForEvent("onattackother", function(inst, data) if data.target.prefab == "dragonfly" then inst.components.sanity:DoDelta(-30) end end) local function inst:(ListenForEvent("onattackother", function(inst, data) if data.target.prefab == "bee" then inst.components.sanity:DoDelta(-20) end end) local function onkill(inst, data) if data.cause == inst and data.target.prefab == "beequeen" then inst.components.sanity:DoDelta(-100) end end I would really appreciate if somebody could help! crash log Edited December 28, 2018 by Massimell to add pic Link to comment Share on other sites More sharing options...
Ultroman Posted December 29, 2018 Share Posted December 29, 2018 Your syntax is all over the place. Sorry to say, just being objective. A function like ListenForEvent is supposed to just be called on the entity you want to listen to an event on. This is usually done in the initialization function, or fn(), of the entity, and is done like this: inst:ListenForEvent("onattackother", function(inst, data) if data.target.prefab == "dragonfly" then inst.components.sanity:DoDelta(-30) end end) inst:ListenForEvent("onattackother", function(inst, data) if data.target.prefab == "bee" then inst.components.sanity:DoDelta(-20) end end) I would recommend taking at least the LUA Crash Course before continuing. It will make your life as a modder much easier. Link to comment Share on other sites More sharing options...
MegaNerdX Posted December 29, 2018 Author Share Posted December 29, 2018 thank you! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now