Why won't PlayerInitialSpawn fire?

I am trying to fire the command sb_start when a player joins a server but it just won’t work. I am making my own gamemode (mostly just for fun) and I have tried both hooking it and the normal way. Here is what I have tried:


function onplyinit( ply )  // When spawning after joining the sever
	self.BaseClass:PlayerInitialSpawn(ply) 
	CheckSpecialCharacters( ply ) //Is he defined in the specialchars.lua file? If yes, then he gets those values, and it stops here.
	if ply:IsAdmin() then //Is the connecting player admin?
		sb_team2( ply ) //If he is then set his team to team 2.
	else // If he isn't admin then,
	joining( ply ) //Call the function joining (found near the bottom of this file)
	RunConsoleCommand( "sb_start" )	 //Run the console command defined in cl_init.lua. 
	RunConsoleCommand( "testvgui" )	 //Run the console command defined in cl_init.lua. 
	end //Close the if
	return "";
end //close the function
hook.Add("PlayerInitialSpawn", "yesnobox", onplyinit) 

and this:


function GM:PlayerInitialSpawn( ply )  // When spawning after joining the sever
	self.BaseClass:PlayerInitialSpawn(ply) 
	CheckSpecialCharacters( ply ) //Is he defined in the specialchars.lua file? If yes, then he gets those values, and it stops here.
	if ply:IsAdmin() then //Is the connecting player admin?
		sb_team2( ply ) //If he is then set his team to team 2.
	else // If he isn't admin then,
	joining( ply ) //Call the function joining (found near the bottom of this file)
	RunConsoleCommand( "sb_start" )	 //Run the console command defined in cl_init.lua. 
	RunConsoleCommand( "testvgui" )	 //Run the console command defined in cl_init.lua. 
	end //Close the if
	return "";
end //close the function

I have searched everywhere and I am out of ideas.

The function RunConsoleCommand() is a client only thing. Usually to run concommands on a player from the server you would use ply:ConCommand, but apparently that broke in the update, so you have to use:


ply:SendLua("RunConsoleCommand(\"sb_start\")")

Like that.

Unfortunately that doesn’t seem to be working. ply:ConCommand doesn’t work either as you suspected.

[editline]11:02AM[/editline]

I was able to get it working, but in a different fashion:

in cl_int.lua I put:


hook.Add("InitPostEntity", "GetLocalPlayer", function()
   CL = LocalPlayer()
   datastream.StreamToServer( "incomingPlayerData", CL);
end)

which sends the player data to the server once he is done loading.

In init.lua I put this:


function acceptInitalSpawn ( ply, handler, id, encoded, decoded )
	ply:PrintMessage( HUD_PRINTTALK, "Welcofdasfsdme back, " .. ply:Nick() .. "
You connected under the IP: " .. ply:IPAddress() )
	ply:SendLua("RunConsoleCommand(\"sb_start\")")
	--print(ply,handler,id, encoded,decoded);
	return true;
end
datastream.Hook( "incomingPlayerData", acceptInitalSpawn );


which accepts the client and runs sb_start.

is it just not doing anything or are you getting some sort of error?


that is the most bastardized system i have ever seen…

InitPostEntity on client, use that and run the console commands there

also do not return anything in PlayerIntitalSpawn

@SeveredSkull
it just isn’t doing anything.

@Bang Train
I know it isn’t the best system, but it works. This is just the beginning. I will need to run some server side things before the the client runs sb_start.

are you sure the function isnt running?

add a print at the top of the function before any code is ran

check the lua error log, may be a syntax error or something

okay i put the print in and I saw it. so i guess it is running.

where is the lua error log?

garrysmod/garrysmod

lua_errors_server.txt

make sure you have lua_log_sv 1 on the server

I get this but I don’t think it is related:


Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
-- Error SENDING CLIENTSIDE file -------------------------
- File Not Found: cl_init.lua
----------------------------------------------------------
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)
Couldn't include file 'entities/base_wire_entity/init.lua' (File not found)


nope

so just add add a ton of prints and trace the code

I forgot to mention that if I type sb_start in the console it works just as it should. Which means cl_init.lua is being loaded because that console command is defined there.

[editline]11:43AM[/editline]

I just put used ConCommand and it worked.


function GM:PlayerInitialSpawn( ply )  -- When spawning after joining the sever
	self.BaseClass:PlayerInitialSpawn(ply) 
	CheckSpecialCharacters( ply ) --Is he defined in the specialchars.lua file? If yes, then he gets those values, and it stops here.
	if ply:IsAdmin() then --Is the connecting player admin?
		sb_team2( ply ) --If he is then set his team to team 2.
	else -- If he isn't admin then,
		joining( ply ) --Call the function joining (found near the bottom of this file)
		ply:ConCommand("testvgui")
		ply:ConCommand("sb_start")
	end --Close the if
end --close the function


Did you get that code from a tutorial on the Wiki?

yeah i did.

I followed that tutorial too, and I had the same problem.

well i got it to work like this (i removed non-essential things)


function GM:PlayerInitialSpawn( ply ) 
	self.BaseClass:PlayerInitialSpawn(ply) 
	timer.Simple(1, ply.ConCommand, ply, "team_menu")
end