Need Some Help on a Server Autorun Script

So I want my server to automatically run a script which puts an anger core in an area of the map and changes it’s physical properties to no gravity and super bouncy.

My GLua vocabulary is really limited, so I only know how to do this in concept.

Any help is great. :slight_smile:

Here’s some code to help you help me.

From the physprop.lua:


construct.SetPhysProp( self:GetOwner(), Ent, Bone, nil,  { GravityToggle = gravity, Material = material } ) 

And a snip for spawning entities which I just found:


local ent = ents.Create( "npc_alyx" )
if ( !ent:IsValid() ) then return end
 
ent:SetPos( tr.HitPos )
ent:Spawn()
ent:Activate()

[lua]
hook.Add(“InitPostEntity”, “Angercoreplacement”, function()
local ent = vgui.Create(“INSERTANGERCORECLASSNAMEHERE”)
ent:SetPos(Vector(0,0,0)) // Where should it be?
ent:SetAngles(Angle(0,0,0)) // What angle?
ent:Spawn()
ent:Activate()
construct.SetPhysProp( nil, ent, 0, nil, { GravityToggle = false, Material = “super_bouncy” } )
end)
[/lua]
Untested, but should work. Stick it in “autorun/server”, and the entity should spawn on map spawn.

That should be ents.Create not vgui.Create
And I think the anger core is a prop, not a SENT, in which case you’d use the following instead the line in Donkie’s code that starts with "local ent = ":
[lua]
local ent = ents.Create(“prop_physics”)
ent:SetModel(“models/path/to/anger/core/model.mdl”)
[/lua]

There’s an anger core scripted entity which acts like the one in portal.

[editline]28th January 2011[/editline]

Also, I’ve tested it and it’s working, of course it’s ents.Create not vgui.Create, obviously your habits kicked in.

I’m currently tweaking the position and adding a “setvelocity” command because the prop won’t move otherwise. But thanks, small things (like putting the entire code into a hook) I wouldn’t have ever gotten.

[editline]28th January 2011[/editline]

Alright, I’m having one final problem.


hook.Add("InitPostEntity", "Angercoreplacement", function()
    local ent = ents.Create("sent_angercore")
        ent:SetPos(Vector(-589, -2075, -610)) // Where should it be?
        ent:SetAngles(Angle(0,0,0)) // What angle?
        ent:Spawn()
		ent:Activate()
		ent.getPhysicsObject:SetVelocity(ent:GetForward()*300)
		construct.SetPhysProp( nil, ent, 0, nil,  { GravityToggle = false, Material = "super_bouncy" } )
end)

I’m trying to set the velocity so it doesn’t stay stationary in the air. But with the above code I just find it sitting on the ground, as it if ignored the construct.SetPhysProp code. If you move the SetVelocity line beneath the construct.SetPhysProp, it won’t do anything.

Any tips?

Try waking it.
Also, it’s ent:GetPhysicsObject():