• [GMOD HELP] Find one entity in sphere
    3 replies, posted
I have created a code where it will play a reloading shout when reloading a gun and friendly NPCs or players are nearby. It works, but the only issue is that it will play the sound a number of times according to the number of NPCs nearby. So it will play 3 times if 3 NPCs are nearby. Here is part of my code: [Lua] [GMOD] Lua GTA 5 Reloading Gun Sounds Code Is there a way I can make it only play 1 time if there are multiple npcs nearby? I know its probably a simple solution that I just can't figure out.
Use the break keyword in your for- loop. It will "break" the loop and allow code after the for- loop to continue to execute as if the loop has finished. You can also use return keyword to completely prevent everything after the return keyword from executing in the current function scope.
Thanks! It worked fine when I did this: if e:IsNPC() and e:Classify() == CLASS_PLAYER then if event == PLAYERANIMEVENT_RELOAD then ply:EmitSound(Sound("michael_reloading/reload"..math.random(1,12)..".wav"),volume,pitch)  return end end I knew it was something simple. I'm just a newbie to lua and never really understood exactly what 'return' did even though I've seen it all the time in other code. Thanks for the quick response!
cool
Sorry, you need to Log In to post a reply to this thread.