[lua]
function SetSpawn( ply, _, args)
if !args[1] then
ply.SpawnPoint = ply:GetPos() elseif
args[1] == "all" then
for k,v in pairs(player.GetAll) do
v.SpawnPoint = ply:GetPos()
end
elseif
args[1] and args[1] != "all" and type(args[1]) == string then
for k, v in pairs(player.GetAll) do
if (string.find( v:Nick(), args[1] )) then
v.SpawnPoint = ply:GetPos()
end
end
end
end
concommand.Add("setspawn",SetSpawn)
[/lua]
Why does this not want to work. Does not set your spawn, you simply spawn at the default spawn after you use it.
Some help and an example of some working code for this would be very nice, it's suposed to make a console command that lets you set your and others spawnpoints. If you don't specify who to set it for it does it for you and can set everyones spawn to a specific point if you use "all" as an argument.
Expedition/gamemode/init.lua:403: bad argument #1 to 'pairs' (table expected, got function)
error when setspawn all is used.
It's because you're putting () after .SpawnPoint
[QUOTE=Nori;19907317]It's because you're putting () after .SpawnPoint[/QUOTE]
Well I no longer get an error, but it just doesn't set your spawn point.
The parameters for a console command are (player, command, args). Even if you're not using one you need to have it in there so that the later ones can be in the right place. Change function SetSpawn( ply, args) to function SetSpawn(ply, _, args), that way you can actually use args.
[QUOTE=fishface60;19913544]The parameters for a console command are (player, command, args). Even if you're not using one you need to have it in there so that the later ones can be in the right place. Change function SetSpawn( ply, args) to function SetSpawn(ply, _, args), that way you can actually use args.[/QUOTE]
Alright... Did that. Only problem now is that it still does nothing. Doesn't set my spawn. And then there's this.
Expedition/gamemode/init.lua:403: bad argument #1 to 'pairs' (table expected, got function)
Got that when I typed setspawn all in the console. What is wrong here?
player.GetAll is a function, so call it.
player.GetAll()
[QUOTE=|FlapJack|;19920109]player.GetAll is a function, so call it.
player.GetAll()[/QUOTE]
Well that fixed my error, and thank you for that, but the problem of it not actauly setting your spawn still remains.
Can we see the code for your PlayerSpawn hook?
[QUOTE=MegaJohnny;19921022]Can we see the code for your PlayerSpawn hook?[/QUOTE]
[code]
function GM:PlayerSpawn( ply )
local ent = ents.Create( "artifact" )
ent:Spawn()
ent:SetPos( ply:GetPos() + Vector(0, 0, 75 ) )
ent:Activate()
if ply:Team() != TEAM_ZOMBIE then
PowerDecayRate = 1
else
PowerDecayRate = 0 end
self.BaseClass:PlayerSpawn( ply )
if ply:Team() != TEAM_ZOMBIE then
ply:Give( "pocket" )
end
ply:SetNWInt( "flashlight_power", 100 )
ply:StripWeapons()
if ply:Team() == TEAM_SCIENTIST then
SetArcModel( ply )
ply:SetGravity( 1 )
ply:SetMaxHealth( 75, true )
ply:SetRunSpeed( 300 )
ply:SetWalkSpeed( 225 )
ply:Give( "gmod_tool" )
ply:Give( "weapon_physgun" )
ply:Give( "weapon_physcannon" )
end
if ply:Team() == TEAM_ZOMBIE then
local Random = math.Round(math.random( 1, 8 ))
if Random == 1 then ply.SpawnPoint = Vector (8838,10522,-13312)
elseif Random == 2 then ply.SpawnPoint = Vector (8828,11091,-13312)
elseif Random == 3 then ply.SpawnPoint = Vector (9117,12515,-13312)
elseif Random == 4 then ply.SpawnPoint = Vector (9052,12955,-13440)
elseif Random == 5 then ply.SpawnPoint = Vector (11141,10305,-13312)
elseif Random == 6 then ply.SpawnPoint = Vector (10388,10563,-13312)
elseif Random == 7 then ply.SpawnPoint = Vector (9307,11959,-13440)
elseif Random == 8 then ply.SpawnPoint = Vector (9340,13218,-13440) end
ply:SetModel( "models/player/classic.mdl" )
ply:SetGravity( 0.75 )
ply:SetMaxHealth( 200, true )
ply:SetRunSpeed( 350 )
ply:SetWalkSpeed( 250 )
ply:Give( "weapon_crowbar" )
end
if ply:Team() == TEAM_SOLDIER then
local model
if MRandom == 1 then model = "models/player/group03/male_01.mdl"
elseif MRandom == 2 then model = "models/player/group03/male_02.mdl"
elseif MRandom == 3 then model = "models/player/group03/male_03.mdl"
elseif MRandom == 4 then model = "models/player/group03/male_04.mdl"
elseif MRandom == 5 then model = "models/player/group03/male_05.mdl"
elseif MRandom == 6 then model = "models/player/group03/male_06.mdl"
elseif MRandom == 7 then model = "models/player/group03/male_07.mdl"
elseif MRandom == 8 then model = "models/player/group03/male_08.mdl"
elseif MRandom == 9 then model = "models/player/Group03/male_09.mdl" end
ply:SetModel( model )
ply:SetGravity( 1 )
ply:SetMaxHealth( 135, true )
ply:SetRunSpeed( 280 )
ply:SetWalkSpeed( 225 )
ply:Give( "weapon_m4" )
ply:Give( "weapon_fiveseven" )
ply:Give( "weapon_frag" )
ply:GiveAmmo( -2, "grenade", true )
ply:Give( "weapon_physcannon" )
end
if ply:Team() == TEAM_SUPPLIER then
ply:SetModel( "models/player/breen.mdl" )
ply:SetGravity( 1 )
ply:SetMaxHealth( 100, true )
ply:SetRunSpeed( 250 )
ply:SetWalkSpeed( 200 )
ply:Give( "weapon_physcannon" )
ply:Give( "weapon_physgun" )
ply:Give( "gmod_tool" )
end
end
[/code]
Here you go,
And what does that have to do with it?
I can't see anywhere in that function with ply:SetPos(ply.SpawnPoint) or something to that effect...
[QUOTE=MegaJohnny;19924582]I can't see anywhere in that function with ply:SetPos(ply.SpawnPoint) or something to that effect...[/QUOTE]
As far as I know the engine does that automaticly. I have some custom spawn points for a certain class, and it works fine with just ply.SpawnPoint = Vector
Are you sure about that? When I look at player in the wiki, hit ctrl+F and type in spawn nothing comes up. When I search spawnpoint on the wiki all I get is mapping for some gamemode.
I just realized that I have to call the SetSpawn in the playerspawn hook. It all makes sense now. And also, can I hook my setspawn function to the PlayerSpawn hook and still have it work as a console command?
Sorry, you need to Log In to post a reply to this thread.