I couldn't really think of a more informative title, sorry.
Anyways, I have been coding a weapon selection system for TTT, my problem though, is that I need the arguments from concommands to associate with a hook.
I'll show you what I mean:
[CODE]
function GivePrimSpawn( ply, cmd, args )
if args[1] == "weapon_ttt_m16" then
ply:Give("weapon_ttt_m16")
ply:GiveAmmo(40, "Pistol")
elseif args[1] == "weapon_ttt_aug" then
ply:Give("weapon_ttt_aug")
ply:GiveAmmo(40, "Pistol")
elseif args[1] == "weapon_ttt_p90" then
ply:Give("weapon_ttt_p90")
ply:GiveAmmo(60, "SMG1")
elseif args[1] == "weapon_zm_mac10" then
ply:Give("weapon_zm_mac10")
ply:GiveAmmo(60, "SGM1")
elseif args[1] == "weapon_zm_scout" then
ply:Give("weapon_zm_scout")
ply:GiveAmmo(20, "357")
elseif args[1] == "weapon_ttt_sg550" then
ply:Give("weapon_ttt_sg550")
ply:GiveAmmo(20, "357")
elseif args[1] == "weapon_ttt_hunting" then
ply:Give("weapon_ttt_hunting")
ply:GiveAmmo(28, "Buckshot")
elseif args[1] == "weapon_ttt_pump" then
ply:Give("weapon_ttt_pump")
ply:GiveAmmo(28, "Buckshot")
elseif args[1] == "weapon_sm_sledge" then
ply:Give("weapon_zm_sledge")
ply:GiveAmmo(150, "AirboatGun")
end
end
function GiveSecSpawn( ply, cmd, args )
if args[1] == "weapon_zm_revolver" then
ply:Give("weapon_zm_revolver")
ply:GiveAmmo(34, "AlyxGun")
elseif args[1] == "weapon_zm_pistol" then
ply:Give("weapon_zm_pistol")
ply:GiveAmmo(40, "Pistol")
elseif args[1] == "weapon_ttt_glock" then
ply:Give("weapon_ttt_glock")
ply:GiveAmmo(40, "Pistol")
elseif args[1] == "weapon_ttt_p228" then
ply:Give("weapon_ttt_p228")
ply:GiveAmmo(40, "Pistol")
end
end
concommand.Add("selectedPrim", GivePrimSpawn) --So obviously, as you can see here I don't want the concommand directly linked with the function, but when it isn't it doesn't know the arguments it needs to use.
concommand.Add("selectedSec", GiveSecSpawn)
hook.Add("PlayerSpawn", "SpawnWithPrimWeapon", GivePrimSpawn)
hook.Add("PlayerSpawn", "SpawnWithSecWeapon", GiveSecSpawn)
[/CODE]
What you want to do is to create a convar instead of concommand and get the value of that convar in your hooks.
Thanks for the response, I'll give it a try now.
[editline]25th June 2013[/editline]
Thank you so much, Robot!
Works flawlessly. Posting the changes here, incase anyone would like to use/reference from it:
Added this to the client side file:
[code]
CreateClientConVar("prim_weapon", "nothing", true, true)
CreateClientConVar("sec_weapon", "nothing", true true)
[/code]
Server side file:
[code]
function GivePrimSpawn( ply )
local pwep = ply:GetInfo("prim_weapon")
if pwep == "weapon_ttt_m16" then
ply:Give("weapon_ttt_m16")
ply:GiveAmmo(40, "Pistol")
elseif pwep == "weapon_ttt_aug" then
ply:Give("weapon_ttt_aug")
ply:GiveAmmo(40, "Pistol")
elseif pwep == "weapon_ttt_p90" then
ply:Give("weapon_ttt_p90")
ply:GiveAmmo(60, "SMG1")
elseif pwep == "weapon_zm_mac10" then
ply:Give("weapon_zm_mac10")
ply:GiveAmmo(60, "SGM1")
elseif pwep == "weapon_zm_scout" then
ply:Give("weapon_zm_scout")
ply:GiveAmmo(20, "357")
elseif pwep == "weapon_ttt_sg550" then
ply:Give("weapon_ttt_sg550")
ply:GiveAmmo(20, "357")
elseif pwep == "weapon_ttt_hunting" then
ply:Give("weapon_ttt_hunting")
ply:GiveAmmo(28, "Buckshot")
elseif pwep == "weapon_ttt_pump" then
ply:Give("weapon_ttt_pump")
ply:GiveAmmo(28, "Buckshot")
elseif pwep == "weapon_sm_sledge" then
ply:Give("weapon_zm_sledge")
ply:GiveAmmo(150, "AirboatGun")
end
end
function GiveSecSpawn( ply )
local swep = ply:GetInfo("sec_weapon")
if swep == "weapon_zm_revolver" then
ply:Give("weapon_zm_revolver")
ply:GiveAmmo(34, "AlyxGun")
elseif swep == "weapon_zm_pistol" then
ply:Give("weapon_zm_pistol")
ply:GiveAmmo(40, "Pistol")
elseif swep == "weapon_ttt_glock" then
ply:Give("weapon_ttt_glock")
ply:GiveAmmo(40, "Pistol")
elseif swep == "weapon_ttt_p228" then
ply:Give("weapon_ttt_p228")
ply:GiveAmmo(40, "Pistol")
end
end
hook.Add("PlayerSpawn", "SpawnWithPrimWeapon", GivePrimSpawn)
hook.Add("PlayerSpawn", "SpawnWithSecWeapon", GiveSecSpawn)
[/code]
Sorry, you need to Log In to post a reply to this thread.