Permanent Weapons

Im trying to make a permanent weapons addon, but I’m having a lot of trouble with it.

I want to make it so I can make a list of steamids and then list the weapon each steamid would get, here’s what I have so far.


ply:Give ( "weapon_crossbow" )
	if ply:SteamID()=="STEAM_0:1:80092425" then
		return true
	end
	
	return false
end


Any bit of help would be great. Thanks!

Use tables!

local table = { [ “steamidhere” ] = “weapon_crossbow” }

then you can simply do this: if ( table[ ply:SteamID() ] ) then ply:Give( table[ ply:SteamID() ] ) end

I tried doing it on a file and it’s still not working. Is this the right format?


local table = { [ "STEAM_0:1:80092425" ] = "weapon_crossbow" }

 if ( table[ ply:SteamID() ] ) then ply:Give( table[ ply:SteamID() ] ) end

Yes, just make sure you’re running the code in a PlayerInitialSpawn hook. Keep the table defined outside of the hook.

Okay, Im trying this, but it’s still not working. And I’m running it serverside.


function GM:PlayerInitialSpawn( ply )
local table = { [ "STEAM_0:1:80092425" ] = "weapon_crossbow" }
 if ( table[ ply:SteamID() ] ) then ply:Give( table[ ply:SteamID() ] ) end

:speechless:



local permanentWeapons = { [ "STEAM_0:1:80092425" ] = "weapon_crossbow" }

local function xd( ply )

	timer.Simple( 2, function()

		if ( permanentWeapons[ ply:SteamID() ] ) then ply:Give( permanentWeapons[ ply:SteamID() ] ) end

	end )

end
hook.Add( "PlayerInitialSpawn", "xdd", xd )


It works, but it doesnt give me the weapon back when I die, anyway to fix that?

I saw the PlayerInitialSpawn couldnt I just change that to GM:PlayerSpawn?

[editline]28th December 2016[/editline]

Okay…Ive got it fixed to spawn with everytime…but now I can’t do multiple weapons or steamIDs because it just reads the bottom one(Grappling Gun)


local permanentWeapons = { 
[ "STEAM_0:1:80092425" ] = "weapon_crossbow",
[ "STEAM_0:1:80092425" ] = "realistic_hook"
 }


local function xd( ply )

	timer.Simple( 2, function()

		if ( permanentWeapons[ ply:SteamID() ] ) then ply:Give( permanentWeapons[ ply:SteamID() ] ) end

	end )

end
hook.Add( "PlayerSpawn", "xdd", xd )


You can loop through a sub-table of weapons like this:


local ID = ply:SteamID()

if (permanentWeapons[ID]) then
   if (istable(permanentWeapons[ID])) then
      for _, v in ipairs(permanentWeapons[ID]) do
         ply:Give(v)
      end
   else
      ply:Give(permanentWeapons[ID])
   end
end

So would I just add that to the code? Like this?


local permanentWeapons = { 
[ "STEAM_0:1:80092425" ] = "weapon_crossbow",
[ "STEAM_0:1:80092425" ] = "realistic_hook",
 }


local function xd( ply )

	timer.Simple( 0, function()

		if ( permanentWeapons[ ply:SteamID() ] ) then ply:Give( permanentWeapons[ ply:SteamID() ] ) end

	end )

end
hook.Add( "PlayerSpawn", "xdd", xd )

local ID = ply:SteamID()

if (permanentWeapons[ID]) then
   if (istable(permanentWeapons[ID])) then
      for _, v in ipairs(permanentWeapons[ID]) do
         ply:Give(v)
      end
   else
      ply:Give(permanentWeapons[ID])
   end
end


[editline]28th December 2016[/editline]

It works… but I cant let one steamID have multiple weapons, anyway to fix that?

To make it work, I just changed the second SteamID

You have to think with tables, change weapon_crissbow by a table containing all weapons, then when you do the give part, just iterate inside it and give all values to player

so how would that actually work? I dont know how to make a table for every weapon. If I try duplicating a table, then it wouldn’t work.

{ your, weapons, here }