• Player:GiveAmmo() Function not working .? nothing happens
    10 replies, posted
hello everyone ! actually my addon work better and better, i like to add some new features ... today i'm blocked on a weird step the feature give to a player 3 clips of his actual weapon ( for example an ak with a clip size of 30 , the ammo button will give 90 bullets ) the button in the menu works so this is not the problem , when i click it he launch the function :) here the code : ClientSIde Script : [CODE] function SendToServerSpawnAmmo() local actualweaponAmmoId = ply:GetActiveWeapon():GetPrimaryAmmoType() local clipsize = ply:GetActiveWeapon():GetMaxClip1() net.Start( "giveAMMO" ) net.WriteString( actualweaponAmmoId ) net.WriteInt( clipsize, 32 ) net.SendToServer() end [/CODE] ServerSide Script : [CODE]-- this is called when the player click on a ammo -- util.AddNetworkString( "giveAMMO" ) net.Receive( "giveAMMO", function(ln, pl) local ammo = net.ReadString() local clipsize = net.ReadInt( 32 ) print (ammo.. " <- type | Size -> ".. clipsize ) -- <= Debug infos :) pl:GiveAmmo( clipsize*3 , ammo , true ) end)[/CODE] the weird thing there nothing happend, no error but no result no ammo added [B] !! But the print show exactly what i want to know ..... !![/B] [CODE]1 <- type | size -> 18[/CODE] what is the problem ? :weeb: :ninja: :trumpet: :s::neat:
You did actually RUN the SendToServerSpawnAmmo function, didn't you? [editline]23rd June 2016[/editline] Also, have you defined ply? I know you said you had no errors, but you never know
[QUOTE=MPan1;50573908] Also, have you defined ply? I know you said you had no errors, but you never know[/QUOTE] the pl variable in the net.receive() is the player :)
I meant in the clientside code Wait, I didn't read the bit where you said it prints the right stuff, nevermind
Try setting the pl:GiveAmmo( clipsize*3 , ammo , [B]false[/B] ) and see if it actually gives you any kind of ammo.
:snip: automerge
nothing haapens again with the false Bool :/ debug info print : [CODE] 4 <- type | Size -> 45 (smg) 5 <- type | Size -> 6 (357) [/CODE]
MAYBE it has to do with you writing a number(returned by ply:GetActiveWeapon():GetPrimaryAmmoType()) to net.WriteString()
I just tested your code, and you need to do [CODE] pl:GiveAmmo( clipsize*3 , tonumber(ammo), true ) [/CODE] [editline]23rd June 2016[/editline] GiveAmmo needs either a string or a number, and if it's a string, it has to be an ammo type string, not a string containing a number.
Yeah, it does. Just replace the writeString with writeInt [B]Edited:[/B] Hey, kinda did the same results, but different ways lol
[QUOTE=MPan1;50574003]I just tested your code, and you need to do [CODE] pl:GiveAmmo( clipsize*3 , tonumber(ammo), true ) [/CODE] [editline]23rd June 2016[/editline] GiveAmmo needs either a string or a number, and if it's a string, it has to be an ammo type string, not a string containing a number.[/QUOTE] Absolutly right, it works now ! Thanks mate ! :goodjob::dance::trumpet::toot:
Sorry, you need to Log In to post a reply to this thread.