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.
[CODE]ply:Give ( "weapon_crossbow" )
if ply:SteamID()=="STEAM_0:1:80092425" then
return true
end
return false
end
[/CODE]
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
[QUOTE=Invule;51592203]Use tables!
local table = { [ "steamidhere" ] = "weapon_crossbow" }
then you can simply do this: if ( table[ ply:SteamID() ] ) then ply:Give( table[ ply:SteamID() ] ) end[/QUOTE]
I tried doing it on a file and it's still not working. Is this the right format?
[CODE]local table = { [ "STEAM_0:1:80092425" ] = "weapon_crossbow" }
if ( table[ ply:SteamID() ] ) then ply:Give( table[ ply:SteamID() ] ) end[/CODE]
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.
[CODE]function GM:PlayerInitialSpawn( ply )
local table = { [ "STEAM_0:1:80092425" ] = "weapon_crossbow" }
if ( table[ ply:SteamID() ] ) then ply:Give( table[ ply:SteamID() ] ) end[/CODE]
:speechless:
[code]
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 )
[/code]
[QUOTE=Invule;51592381]:speechless:
[code]
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 )
[/code][/QUOTE]
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)
[CODE]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 )
[/CODE]
You can loop through a sub-table of weapons like this:
[code]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[/code]
So would I just add that to the code? Like this?
[CODE]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
[/CODE]
[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.
[url]http://lua-users.org/wiki/TablesTutorial[/url]
{ your, weapons, here }
Sorry, you need to Log In to post a reply to this thread.