I cannot seem to get ply:Give to work in my gamemode's init.lua. Here's my code.
[code] function GM:PlayerLoadout(ply)
ply:StripWeapons()
if ply:Team() == 1 then
ply:StripWeapons()
ply:Give("weapon_physgun")
ply:Give("gmod_tool")
ply:Give("gmod_camera")
elseif ply:Team() == 2 then
ply:StripWeapons()
ply:Give("weapon_physcannon")
ply:Give("weapon_pistol")
ply:Give("weapon_357")
ply:Give("weapon_crowbar")
ply:Give("weapon_smg1")
ply:Give("weapon_ar2")
ply:Give("weapon_frag")
ply:Give("weapon_rpg")
ply:Give("weapon_crossbow")
ply:Give("weapon_shotgun")
ply:Give("gmod_camera")
end
end
function team_1( ply )
ply:Spawn()
ply:SetTeam( 1 )
end
function team_2( ply )
ply:Spawn()
ply:SetTeam( 2 )
end[/code]
What's wrong?
[editline]02:59AM[/editline]
Someone please help
Have you tried adding a "return true" in the Loadout function like it says to do on the Wiki?
If you did and it still didn't work you could always do something like this.
[lua]
function NewGamemode_Loadout(ply)
if(ply:IsValid()) then
if(ply:Team() == 1) then
print("PlyT1")
ply:Give("weapon_crowbar")
else
print("PlyT2")
ply:Give("weapon_pistol")
end
end
end
function GM:PlayerSpawn(ply)
NewGamemode_Loadout(ply)
end
[/lua]
Are you even spawning? What is team_1 hooked to?
[QUOTE=Kunit;24255974]Have you tried adding a "return true" in the Loadout function like it says to do on the Wiki?
If you did and it still didn't work you could always do something like this.
[lua]
function NewGamemode_Loadout(ply)
if(ply:IsValid()) then
if(ply:Team() == 1) then
print("PlyT1")
ply:Give("weapon_crowbar")
else
print("PlyT2")
ply:Give("weapon_pistol")
end
end
end
function GM:PlayerSpawn(ply)
NewGamemode_Loadout(ply)
end
[/lua][/QUOTE]
Yes, and yes to the next poster. I'll add the whole code
[lua] AddCSLuaFile( "cl_init.lua" ) //Tell the server that the client need to download cl_init.lua
AddCSLuaFile( "shared.lua" ) //Tell the server that the client need to download shared.lua
include( 'shared.lua' ) //Tell the server to load shared.lua
function GM:PlayerInitialSpawn( pl ) --"When the player first joins the server and spawns" function
pl:ConCommand( "team_menu" ) --Run the console command when the player first spawns
end
function buildMode(ply)
ply:StripWeapons()
ply:Give("weapon_physgun")
ply:Give("gmod_tool")
ply:Give("gmod_camera")
end
function fightMode(ply)
ply:StripWeapons()
ply:Give("weapon_physcannon")
ply:Give("weapon_pistol")
ply:Give("weapon_357")
ply:Give("weapon_crowbar")
ply:Give("weapon_smg1")
ply:Give("weapon_ar2")
ply:Give("weapon_frag")
ply:Give("weapon_rpg")
ply:Give("weapon_crossbow")
ply:Give("weapon_shotgun")
ply:Give("gmod_camera")
end
function GM:PlayerLoadout(ply)
if ply:Team() == 1 then
buildMode()
elseif ply:Team() == 2 then
fightMode()
end
end
function team_1( ply )
ply:Spawn()
ply:SetTeam( 1 )
end
function team_2( pl )
pl:Spawn()
pl:SetTeam( 2 ) --Make the player join team 2
end
concommand.Add( "team_1", team_1 ) --Add the command to set the players team to team 1
concommand.Add( "team_2", team_2 ) --Add the command to set the players team to team 2
[/lua]
[editline]12:28PM[/editline]
When I try to spawn, it doesn't even attempt to give me the weapons, but gives me the following console errors:
Attempted to create unknown entity type gmod_tool!
NULL Ent in GiveNamedItem!
Attempted to create unknown entity type gmod_camera!
NULL Ent in GiveNamedItem!
If your Deriving from base then they are invalided.
[QUOTE=Cubar;24261484]If your Deriving from base then they are invalided.[/QUOTE]
Ok, thanks, but how do I fix this?
[QUOTE=PopcornColonel;24261630]Ok, thanks, but how do I fix this?[/QUOTE]
In shared.lua DeriveGamemode("sandbox")
Or you can just copy the entities in sandbox/ to your gamemode.
[QUOTE=Cubar;24261643]In shared.lua DeriveGamemode("sandbox")
Or you can just copy the entities in sandbox/ to your gamemode.[/QUOTE]
I've already tried deriving the gamemode from sandbox, but all it does it mess up the scoreboard and [b]still[/b] not give me the weapons.
Then simply remove Camera and the toolgun and try again.
Sorry, you need to Log In to post a reply to this thread.