I have a SENT such that when you press E on it, it disappears and gives you a weapon.
However, if you already HAVE the weapon, it just disappears when you press E on it (and is wasted).
I have an idea. Somehow I should be able to use Player:GetWeapons() to check if the activating person already has the weapon, and if that is the case, then the SENT will do nothing.
I can very easily place the entire code block in an if/then statement, but I don't know how I would make the conditional part.
I want to do something like:
If the weapon the entity has to give is not already in the activator's inventory, then execute the code block. Otherwise, don't execute the code block.
Can anyone help?
[lua]if ply:HasWeapon("weapon_namehere") then return end[/lua]
It's that easy. Goes at the top of the use function for your entity.
[QUOTE=T3h raps13r;24309185][lua]if ply:HasWeapon("weapon_namehere") then return end[/lua]
It's that easy. Goes at the top of the use function for your entity.[/QUOTE]
Wow... thank you very much. I did not know there was such a function. As you can tell, I'm a super lua n00b. Lol.
[lua]/*---------------------------------------------------------
Name: Use
---------------------------------------------------------*/
function ENT:Use(activator, caller)
if (activator:HasWeapon("weapon_jack_m9")) then
return end
else
if (activator:IsPlayer()) then
//self.Entity:EmitSound("BaseCombatCharacter.AmmoPickup")
// Give the collecting player some SWEPZORZ ftw lol w00t
activator:Give("weapon_jack_m9")
self.Entity:Remove()
end
end
end[/lua]
Um... my notepadd++ with gmod plugin is not taking the right "end" at the end of its function.. the function is ending too early... I looked at the format of if,then,else,end statements and i dont know why its doing this...
I don't think you need the end on line 7.
i will try that
[QUOTE=iRzilla;24326756]Stops the rest of the function from running.[/QUOTE]
???
That's not what gmod wiki says: [url]http://wiki.garrysmod.com/?title=Return[/url]
Ah. I see. Thank you.
Sorry, you need to Log In to post a reply to this thread.