• ENT:Use 8x Loop?
    9 replies, posted
function ENT:Use( activator, caller ) if activator:Team() == TEAM_MAYOR then activator:SetHealth( 100 ) activator:SetArmor( 100 ) activator:ChatPrint("Successfully given 100 HP and Armor!") else activator:ChatPrint( "You do not have the key!" ) self:EmitSound("doors/door_lock_1.wav") end end This is my code. For some unknown reason it is looping the output four times! It works perfectly fine apart from this, it will play the sound eight times and print the chat eight times! Does anybody know why this might be or how I can stop it doing that? https://i.imgur.com/Zx6ZTMf.jpg (p.s this addon is fully custom, the model and the broken code were made by me)
You need an antispam var. Basically this then you reset the var when the use is done. local antispam = false function ENT:Use(a, c)     antispam = true end
Thanks for the quick response! I tried this to no avail! It still repeats no matter how I lay it out! local antispam = false function ENT:Use( activator, caller ) if !antispam then if activator:CivilProtection then activator:SetHealth( 100 ) activator:SetArmor( 25 ) self:EmitSound("items/battery_pickup.wav") else activator:ChatPrint( "You do not have the key!" ) self:EmitSound("doors/door_lock_1.wav") end antispam = true end end   Although I am not sure if this is just me being a bit special or not... have I done it right?
Did you set the use type using https://wiki.garrysmod.com/page/Entity/SetUseType ?
I added that in with self:SetUseType( SIMPLE_USE ) but nothing changes!
Try this local antispam = false function ENT:Use( caller, caller )     if !antispam then         if caller:CivilProtection then             caller:SetHealth( 100 )             caller:SetArmor( 25 )             self:EmitSound("items/battery_pickup.wav")         else             caller:ChatPrint( "You do not have the key!" )             self:EmitSound("doors/door_lock_1.wav")         end antispam = true timer.Simple(1, function() antispam = false end)     end end
Did you add that to the use function or to the initialize function?
I put that in just as you did and still no luck! It is repeating it no matter what I do! I put it in the Initialize.
Might sound stupid, but are you sure you are editing the right file (not a copied file)? Are you re-spawning the ent or changing map when you update the code? I just quickly made a simple ent that prints to chat, and after setting UseType it only prints once.
I uh... I was editing the wrong file... It's never a good idea to try do things at 2am. Thanks for the help guys.
Sorry, you need to Log In to post a reply to this thread.