• DarkRP specified lua code question
    11 replies, posted
Hello, I just wanted to create an addon, which contains a SWEP for a weapon license, like a ID card and it’s working. Now I want a code, which can find out, who gets the license and cancels it and instead of giving the player normal license icon over the head, it should give the player the SWEP. Thanks for your answers!
Or maybe a bit more simple question... How can I get the player, the player who is writing /givelicense is looking at?
You can check the "HasGunlicense" DarkRPVar, but there is no hook for when a player receives a license.
So but how Im able to get the player, the player who writes a message is looking at?
Player/GetEyeTrace
So I looked at few examples with GetEyeTrace, also on your link, but it wasn’t very helpful because there were only examples to get the entity’s the player is looking on... Can somebody write me a little example code so I can understand that, how to find the player, the player who writes something looks at? Or is Entity such a player like entity == player?
The player would be the entity, if that's what was being looked at.
Ok good, but how can the player now get the SWEP?
heh, I tried your things but now I have another problem... When a player writes /givelicense in the chat, HE gets the SWEP. This is my code: hook.Add( "PlayerSay", "PlayerSayGivelicense", function( ply, text, team ) if ( string.lower( text ) == "/givelicense" ) then if Entity( 1 ):GetEyeTrace().Entity then return Entity( 1 ):Give( "weapon_weaponlicense" ) Entity.ChatPrint( "You recieved a weapon license!" )     end     end end ) But the player, he looks on should get the SWEP... How can I do this?
Don't use Entity(1). The PlayerSay hook gives you a ply variable which is a reference to the player who said something. Use ply:GetEyeTrace().Entity to get a reference to the player they're looking at. Use ply:GetEyeTrace().Entity:Give(..) to give a weapon to the player who the chatter is looking at.
Thanks, I‘ll try it out tomorrow
Sorry, you need to Log In to post a reply to this thread.