How do I make it so a certain player gets a weapon when they spawn?

So, I have a player that wants to pay for a permanent weapon. How do I make a player spawn with this weapon: m9k_l85
I couldn’t find any addons that’d do this for me, so I’m just going to post this here.

GM:PlayerInitialSpawn,

Player:SteamID64 to check they’re the right player, and

Player:Give to give them the weapon

Why PlayerInitialSpawn and not PlayerSpawn?

It really depends, if this guy wants InitialSpawn or everytime they spawn…

Oh and make a lua folder in autorun call it something like weaponsonspawn.lua
and inside put this:
for the STEAMID part put his community ID!


function PlayerSpawn(ply)
    if (ply:SteamID64() == AwesomeJacob) then
         ply:Give( "m9k_l85" )
    end 
end


and if this dont work then, who knows.

If you used PlayerSpawn it’d give them the weapon whenever they respawned, the OP can use that if he wants

[editline]28th July 2016[/editline]

That wouldn’t work since you never ran PlayerSpawn and you never defined AwesomeJacob or ply.

This would though:



hook.Add( 'PlayerInitialSpawn', 'blah', function( ply )
    if ply:SteamID64() == 'some_id' then
        ply:Give( 'm9k_l85' )
    end
end )


That’s not how hooks work…
[lua]hook.Add( “PlayerSpawn”, “GibWeaponsPlz”, function( ply )
if ply:SteamID() == “STEAM_0:00000000” then
ply:Give( “weapon_id_here” )
end
end )[/lua]

[editline]Blublub[/editline]
Dat ninja edit tho :v:

That worked. Thanks

I am re-opening this thread.
If I make multiple Lua files with this code in it, then only one of the files will work. How do I make it so I can add more people/weapons?

There’s no reason to make multiple files, you can easily do it all in the same file with less clutter.

I would use something like this:


local playerList =
{
    ["STEAM_0:00000000"] = true,
    ["STEAM_0:00000001"] = true,
    ["STEAM_0:00000002"] = true
}

hook.Add( "PlayerSpawn", "GibWeaponsPlz", function( ply )
    if playerList[ ply:SteamID() ] then
        ply:Give( "weapon_id_he" )
    end
end )


If you want different weapons, you could do something like this:


local playerList =
{
    ["STEAM_0:00000000"] = "some_weapon_id",
    ["STEAM_0:00000001"] = "another_weapon_id",
    ["STEAM_0:00000002"] = "one_more_weapon_id"
}

hook.Add( "PlayerSpawn", "GibWeaponsPlz", function( ply )
    if playerList[ ply:SteamID() ] then
         ply:Give( playerList[ ply:SteamID() ] )
    end
end )


Didn’t I already answer your question 2 days ago? You locked the thread before anyone could see why it wouldn’t work for you.
http://forum.facepunch.com/showthread.php?t=1528483&p=50786995#post50786995

Hmm, your code is basically the same as mine. Hopefully he doesn’t say “This doesn’t work for me” and close the thread again :v: