Server code not working


function give_ammo(ply)
    ply:Give("weapon_frag")//possibly need this before giving grenade ammo
    ply:GiveAmmo(999,"weapon_grenade")
    ply:GiveAmmo(999,"AR2")
    ply:GiveAmmo(999,"AR2AltFire")
    ply:GiveAmmo(999,"Pistol")
    ply:GiveAmmo(999,"SMG1")
    ply:GiveAmmo(999,"357")
    ply:GiveAmmo(999,"XBowBolt")
    ply:GiveAmmo(999,"Buckshot")
    ply:GiveAmmo(999,"RPG_Round")
    ply:GiveAmmo(999,"SMG1_Grenade")
    ply:GiveAmmo(999,"weapon_grenade")
end

function message_everyone()
    for i, ply in pairs(player.GetAll()) do
        ply:SendHint("Welcome! :D Have some st00f")
        //give_ammo(ply)
        ply:PrintMessage( HUD_PRINTTALK, "Zantier's pet server gives you some ammo." )
    end
end

hook.Add( "PlayerSpawn", "playerRespawnAmmo", give_ammo )

message_everyone()

Path:
C:\Program Files\Steam\steamapps\Zantier\garrysmod\garrysmod\ addons\Zantier\lua\autorun\server\server_test.lua

It’s meant to print those messages to each player, and then give everyone ammo each time they spawn, but it isn’t working.

I have a valid info.txt in my addons folder.

I’m a right n00b at lua, so any help is appreciated, even if it’s random unrelated information xD.

Many things wrong there. This should be in Newbie Questions too.


(User was banned for this post ("This isn't helpful; backseat moderation" - mahalis))

Im still pretty noobish at lua, but workin my way there. What errors do you get? (preferably the first one, always fix the first one first. (like with C++) clearing up the first error may solve all the following errors.

It doesn’t seem to give any errors… it just doesn’t do anything

I will fix in a bit, do you want it to be every spawn or just first spawn?

I want it to give ammo on every spawn, and send the messages on first spawn/load

Place in lua/autorun/server/yourfile.lua

Here is the lua don’t modify it and nothing in any file needs changing it works fine.

Your ammo might show low but its actually 999!
[lua]function give_ammo(pl)
timer.Simple(2, function()
pl:GiveAmmo( 999, “Pistol”, true )
pl:GiveAmmo( 999, “SMG1”, true )
pl:GiveAmmo( 999, “grenade”, true )
pl:GiveAmmo( 999, “Buckshot”, true )
pl:GiveAmmo( 999, “357”, true )
pl:GiveAmmo( 999, “XBowBolt”, true )
pl:GiveAmmo( 999, “AR2AltFire”, true )
pl:GiveAmmo( 999, “AR2”, true )
pl:GiveAmmo( 999, “RPG_Round”, true )
pl:GiveAmmo( 999, “SMG1_Grenade”, true )

pl:SendHint("Welcome! :D Have some st00f", 5)
pl:PrintMessage( HUD_PRINTTALK, "Zantier's pet server gives you some ammo." )
end)

end
hook.Add( “PlayerSpawn”, “playerRespawnAmmo”, give_ammo)
[/lua]

Thanks!

SendHint doesn’t seem to be doing anything, and when I tried replacing GiveAmmo with SetAmmo, that didn’t do anything…

The code works fine ill get SendHint working its GiveAmmo not SetAmmo -.- and your ammo will show as low but you have 999 ammo, because i tested first!
[lua]
function give_ammo(pl)
timer.Simple(2, function()
pl:GiveAmmo( 999, “Pistol”, true )
pl:GiveAmmo( 999, “SMG1”, true )
pl:GiveAmmo( 999, “grenade”, true )
pl:GiveAmmo( 999, “Buckshot”, true )
pl:GiveAmmo( 999, “357”, true )
pl:GiveAmmo( 999, “XBowBolt”, true )
pl:GiveAmmo( 999, “AR2AltFire”, true )
pl:GiveAmmo( 999, “AR2”, true )
pl:GiveAmmo( 999, “RPG_Round”, true )
pl:GiveAmmo( 999, “SMG1_Grenade”, true )

for k,v in pairs(player.GetAll()) do
v:SendHint( "Welcome! :D Have some st00f!",5)
end
pl:PrintMessage( HUD_PRINTTALK, "Zantier's pet server gives you some ammo." )
end)

end
hook.Add( “PlayerSpawn”, “playerRespawnAmmo”, give_ammo)
[/lua]

Why would you send the hint to every player?

[lua]
function give_ammo(pl)
timer.Simple(2, function()
pl:GiveAmmo( 999, “Pistol”, true )
pl:GiveAmmo( 999, “SMG1”, true )
pl:GiveAmmo( 999, “grenade”, true )
pl:GiveAmmo( 999, “Buckshot”, true )
pl:GiveAmmo( 999, “357”, true )
pl:GiveAmmo( 999, “XBowBolt”, true )
pl:GiveAmmo( 999, “AR2AltFire”, true )
pl:GiveAmmo( 999, “AR2”, true )
pl:GiveAmmo( 999, “RPG_Round”, true )
pl:GiveAmmo( 999, “SMG1_Grenade”, true )

pl:SendLua[[GAMEMODE:AddNotify( "Welcome! :D Have some st00f", NOTIFY_HINT, 20 )]]
pl:PrintMessage( HUD_PRINTTALK, "Zantier's pet server gives you some ammo." )
end)

end
hook.Add( “PlayerSpawn”, “playerRespawnAmmo”, give_ammo)
[/lua]

Thanks octogon. I only want the hint to appear the first time you spawn though, if you know how to.

I would prefer to be able to use SetAmmo, that’s all… is there a reason why SendHint and SetAmmo don’t work? Like does a certain convar have to be a certain value, or are they just broken?

[lua]function HazSomeAmmo(pl)

timer.Simple(0.5, function() 

pl:GiveAmmo( 999,	"Pistol", 		true )
pl:GiveAmmo( 999,	"SMG1", 		true )
pl:GiveAmmo( 999,	"grenade", 		true )
pl:GiveAmmo( 999,	"Buckshot", 	true )
pl:GiveAmmo( 999,	"357", 			true )
pl:GiveAmmo( 999,	"XBowBolt", 	true )
pl:GiveAmmo( 999,	"AR2AltFire", 	true )
pl:GiveAmmo( 999,	"AR2", 			true )
pl:GiveAmmo( 999,	"RPG_Round",	true )
    pl:GiveAmmo( 999,	"SMG1_Grenade",	true )

end)

end

hook.Add( “PlayerSpawn”, “HaveSomeAmmo”, HazSomeAmmo)

function HazANotify(pl)
pl:SendLua[[GAMEMODE:AddNotify( “Welcome! :smiley: Have some st00f”, NOTIFY_HINT, 20 )]]
pl:PrintMessage( HUD_PRINTTALK, “The server requests you to have ammo. Enjoy.” )
end

hook.Add( “PlayerInitialSpawn”, “HaveANotify”, HazANotify)
[/lua]

Read boy read :D, he didn’t say he wanted PrintMessage only shown 1 time.

Well I did in my initial request, and it’s hardly a change to the code structure, so it’s no problem ^^. Thanks you 2!

EDIT:If anybody has an answer to my previous post, then please respond, otherwise this thread is done :slight_smile:

Are you thick? Why would you want a message to be printed every time you spawn?

You’re dumb, He said,

He never quote’d the PrintMessage…

Use logic. Would you want someone to get a message every time they spawn?

Rage more somewhere else.

What are you talking about? He is correct in my opinion.