• Need help for give a swep
    7 replies, posted
I make a script for creating a weapon: a gun license! All is good, the swep a spawnable in the windows "weapons/Other", but I want this swep is automatically given when a player get a license by a mayor or by a job. And I won't, the gun license weapon is stripped when the mayor revoked the license! So I write this and i put this in : [I]/garrysmod/addons/MyAddons/lua/autorun/server/sv_givelisence.lua[/I] [CODE]function GiveLisence( ply ) if hasLicense == true then ply:Give("gunlisence") else if hasLicense == false then ply:StripWeapon("gunlisence") end end end[/CODE] And the sweep doesn't have problems, but she has not given when we do /givelisence :/ Did my ideas are possibles ? Could you help me ?
Where do you set hasLicense?
I don't set this variable and I'm not sure she is really functional... :weeb: I'm have to set the variable or there is one define ? I found this but i'm not sure [CODE]if LocalPlayer():getDarkRPVar("HasGunlicense") then[/CODE] So I make this [CODE] local function GiveLisence( ply ) if LocalPlayer():getDarkRPVar("HasGunlicense") then ply:Give("gunlisence") else ply:StripWeapon("gunlisence") end end function GiveLisence()[/CODE] But not working again... I think, i put it in the bad folder :/
Up ?!? Nobody now how to do this ?
Can you show us your code? Because i don't know what are you trying to do with that function GiveLisence() after you defined it in a local enviroment
Have you made the SWEP yet?
[QUOTE=BremFM;51533588]Have you made the SWEP yet?[/QUOTE] Yes i made the swep who called : "gunlisence". It is textured and functionnal but i wan't to give it when somebody got a gun license... [QUOTE=gonzalolog;51533278]Can you show us your code? Because i don't know what are you trying to do with that function GiveLisence() after you defined it in a local enviroment[/QUOTE] I don't now how to call the function and where, that's why I need help...
[QUOTE=Ezotose;51533780]I don't now how to call the function and where, that's why I need help...[/QUOTE] It looks like you've already got a half decent understanding of what you're doing, so you'll probably learn best if I just drop you some code [code] function SWEP:PrimaryAttack() if not self:CanPrimaryAttack() then return end if not IsValid( self:GetOwner() ) then return end local ply = self:GetOwner() local trace = ply:GetEyeTrace() local target = trace.Entity if not IsValid( target ) then return end if not target:IsPlayer() then return end GiveLisence( ply ) self:SetNextPrimaryFire( CurTime() + 1 ) end [/code] Untested, but it should work. If you have any problems, you can add me on Steam using the icon below my name, good luck!
Sorry, you need to Log In to post a reply to this thread.