Jump to content

I need help making a character who loses sanity from killing bugs


Recommended Posts

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!

05d7133413c0cae0135633f056e042a7.png

crash log

Edited by Massimell
to add pic
Link to comment
Share on other sites

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

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
 Share

×
  • Create New...