InspectorDave Posted August 16, 2017 Share Posted August 16, 2017 Hello, so, I've been working with this particular mod for a very long time now (more than months). Everything is fine, I don't have any errors or anything, the only problem, is that i don't know how to make a light that turns off slowly. Bassically, "onatack", my item starts emiting a light, and after 5 seconds, it turns off. If I hit only once, it works perfectly. Now, the thing is, if I atack a lot, instead of staying on for 5 seconds and then turning off, it will start flashing. This is because the action of turning off from the first hit won't be cancelled. This is the part of the code where i'm stuck: local function updatelight(inst) if inst.light then if inst.light:IsValid() then inst.light:Remove() end inst.light = nil end end local function onattack(inst, owner, weapon, attacker, target) if inst.light == nil or not inst.light:IsValid() then inst.light = SpawnPrefab("lightspearlight") end inst.light.entity:SetParent(owner.entity) inst:DoTaskInTime(0, updatelight) end I tryed to find a way to cancel the "updatelight" function so it won't start flashing, but i haven't found it. Please help (Sorry for my broken english) Link to comment Share on other sites More sharing options...
ZupaleX Posted August 16, 2017 Share Posted August 16, 2017 store your task as a "member" of your inst inst.turnofflighttask = inst:DoTaskInTime(5, [...]) and in your onattack check if that task exists if inst.turnofflighttask ~= nil then inst.turnofflighttask:Cancel() inst.turnofflighttask = nil end before applying the task again. Link to comment Share on other sites More sharing options...
InspectorDave Posted August 17, 2017 Author Share Posted August 17, 2017 THANK YOU SO MUCH. YOU ARE TRUE HERO. REALLY DUDE THANKS. I CAN'T THANK YOU ENOUGH. Really, thanks. The mod should be finished by friday now, thank you gain. 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