nicknightyx Posted March 6, 2018 Share Posted March 6, 2018 (edited) Hi there, I want to monitor the value change of a variable, say "inst.gcp = 0 or 1". How can I push event when the value of "inst.gcp" changes so that I could listen for event in the character.lua? Would someone please tell me how to do push event? I tried put on the code, it doesn't crash but it doesn't work either. This is my code Spoiler [modmain.lua] function combat(inst) inst.writing = false local x,y,z = inst.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x,y,z, 1, {"_writeable"}) for k,v in pairs(ents) do inst.writing = true end if not inst.writing and not inst.combat and inst.components.hunger.current > 1 then -- if not inst.combat and not inst.components.hunger.current == 0 and inst.gcp_c == 0 then -- if not inst.combat and not inst.components.hunger.current == 0 then inst.combat = true inst.components.talker:Say("Combat: On") inst.components.combat.damagemultiplier = 1 + (inst.strength-100)/800 inst.components.health:SetAbsorptionAmount((inst.strength-100)/(inst.strength+100)) inst.components.locomotor.externalspeedmultiplier = (inst.speed-100)/(inst.speed^0.85+400)*3+1 --TUNING.WILSON_WALK_SPEED inst.components.hunger.hungerrate = TUNING.WILSON_HUNGER_RATE *(0.5 + (inst.strength-100)/(inst.strength^0.9+1000) + (inst.speed-100)/(inst.speed^0.9+1000) + (inst.vitality-100)/(inst.vitality^0.9+1000)) -- inst:PushEvent("press_combat") -- elseif not inst.combat and inst.components.hunger.current == 0 then -- inst.components.talker:Say("Too hungry to do any fighting right now.") elseif not inst.writing and inst.combat then inst.combat = false inst.components.talker:Say("Combat: Off") inst.components.combat.damagemultiplier = 1 inst.components.health:SetAbsorptionAmount(0) inst.components.locomotor.externalspeedmultiplier = 1 inst.components.hunger.hungerrate = TUNING.WILSON_HUNGER_RATE * 0.5inst.gcp = inst.gcp + 1 end inst:PushEvent("gcpdelta") end AddModRPCHandler("hisoka", "combat", combat) Spoiler [character.lua] local master_postinit = function(inst) inst:ListenForEvent("gpcdelta",function() inst.components.talker:Say("Did I succeed?") end) end Would someone care to answer? Really appreciate it. Regards, Nick Edited March 7, 2018 by nicknightyx Link to comment https://forums.kleientertainment.com/forums/topic/88368-solved-how-to-write-pushevent/ 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