Spawning entity on gamemode spawn

So basicly, i have been trying to spawn a entity called “Jobotronic” (a entity i made myself) when the gamemode is spawned and stuff. So the entity will show up before any other player does.

I have been lurking on this for hours, giving no cake.
Wiki tells me to use the **[Gamemode.InitPostEntity

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Gamemode.InitPostEntity)** But that makes the players viewmodel and much else shit fuck up. I tried the GM:Initizialise, that makes garrysmod crash.

I dont know what else todo :frowning:

I might know a hacky way todo it:
I assign a global Boolean to a entity thats already on the map, a cubemap or something at the GM:initialize, ii set the boolean to true. Then at GM:PlayerInitSpawn i check if that boolean is true, if then, spawn the entity and when its spawned, set the bool to False, this way it wont make a new entity each time a player spawns.
Though, i just came up with that nothing is spawned at Initialize according to wiki.

Help!

InitPostEntity is what you’re looking for. Post your code: it’s probably something in there that’s making “shit fuck up.”

init.lua:
[lua]
function GM:InitPostEntity( )
Entity=ents.Create(“jobotronic”)
Entity:SetPos(Vector(0,0,0))
Entity:Spawn()
end
[/lua]
And i know its not the Entity thats not working, i tried exact same code with just a default entity and it gives same bug.

The bug is that, when i spawn, i cant see my Viewmodel, and i KNOW to fully that i should have the gravity gun and the camera because i get them if i comment out that part. The HUD is normal. Though, when i get killed by something, you should usualy see yourself on a red tinted window, i see the red tint, not my self though.

Edit: I cant use gm_spawnswep to give me any swep neither. Gives me the error:



] gm_spawnswep gmod_tool
sandbox\gamemode\commands.lua:638: attempt to call field 'GetStored' (a nil value)


local ent = ents.Create(myent)

By calling it Entity, you deleted an important function used by sandbox to give you SWeps and other scripts too.

You should try using N++ and the GLua plugin when you make Lua scripts. This helps you avoid errors like this, as it will highlight words that are used for functions or libraries or such.

Nope, still same problem.

Edit:
That made me get some insane walking bugs instead, like i were held back by a spring or something.

Edit2:
That sandbox error when typing gm_giveswep is still showing up.

And you changed the variable name?

Yes.
Guess i shall show you guys the involved files.
gamemode/init.lua:
[lua]
function GM:PlayerLoadout(ply)
ply:Give(“weapon_physcannon”)
ply:Give(“gmod_camera”)
–ply:Give() wtb hands
end
function GM:PlayerInitialSpawn(ply)
ply:SetTeam(ply:GetNWInt(“job”))
ply:SetNWBool(“Jobotronic”,false)
gamemode.Call(“PlayerLoadout”, ply)
end
function GM:PlayerSpawn(ply)
end
function GM:ShowHelp(ply)
local Premoney = ply:GetNWInt(“money”)
ply:SetNWInt(“money”,Premoney+100)
end
function GM:InitPostEntity( )
local ent=ents.Create(“jobotronic”)
ent:SetPos(Vector(0,0,0))
ent:Spawn()
end
[/lua]

entities/entities/jobotronic/init.lua:
[lua]
AddCSLuaFile(“cl_init.lua”)
AddCSLuaFile(“shared.lua”)

include(“shared.lua”)

function ENT:Initialize()
self:SetModel(“models/props_wasteland/laundry_dryer002.mdl”)
self:PhysicsInit( SOLID_VPHYSICS ) – Make us work with physics,
self:SetMoveType( MOVETYPE_VPHYSICS ) --after all, gmod is a physics
self:SetSolid( SOLID_VPHYSICS )
end

function ENT:Use(activator,caller)
activator:SetNWBool(“Jobotronic”,true)
activator:ChatPrint(“Cake”)
end
[/lua]

gamemode/cl_jobotronic.lua: (The menu that should popup when you click E on the jobotronic), I have already comment this part and thers no diffrence. Though, i would like to know if there would be any better way to check if the player just clicked the jobotronic than having a global variable if he is in it or not.
[lua]
function Jobotronicmenu()
local pl=LocalPlayer()
if pl:GetNWBool(“Jobotronic”)==false then return end
pl:ChatPrint(“You come this far!”)
local Mainpanel = vgui.Create( “DFrame” )
Mainpanel:SetPos(ScrW()/2-256,ScrH()/2-256) --Formula for getting it in teh middle
Mainpanel:SetSize( 512, 512 )
Mainpanel:SetTitle( “Job-O-Tronic” )
Mainpanel:SetVisible( true )
Mainpanel:SetDraggable( false )
Mainpanel:ShowCloseButton( false )
Mainpanel:MakePopup()

local Closebutton = vgui.Create( "DButton",Mainpanel)
	Closebutton:SetPos(ScrW()/2+206,ScrH()/2+241)
	Closebutton:SetSize( 50, 15 )
	Closebutton:SetText("Close")
	Closebutton.DoClick = function( Closebutton )
		pl:SetNWBool("Jobotronic",false)
		Mainpanel.Close()			
	end

end
[/lua]

Dont think anymore should be needed to show.