NSKuber

Exercise 6 No Helper

Mar 31st, 2021 (edited)
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.73 KB | None | 0 0
  1. RunHandled(WaitForever,
  2.  
  3. OnEvery(CustomEvent("EntitySpawned")),
  4. function(payload)
  5.   --payload : CEntitySpawnedScriptEvent
  6.   if not IsDeleted(payload) then
  7.     local entity = payload:GetSpawnedEntity()
  8.     if (entity:GetClassName() == "CPlayerPuppetEntity") then
  9.       while not IsDeleted(entity) do
  10.         entity:SetHealth(entity:GetHealth() + 1)
  11.         Wait(CustomEvent("OnStep"))
  12.       end
  13.     end
  14.   end
  15. end)
  16.  
  17. Note that here I have to check if the entity is not deleted *right* as it spawns, as it sometimes happens that by the time the event is caught, the entity is already deleted.
  18. I also have to check if it is the entity of the desired type to handle only those entities which I want to (in this case, player puppets).
  19.  
Add Comment
Please, Sign In to add comment