Hey does any one know how to get a entity to move when spawned? I asked this question a while back but I forgot how. :frown:
That is a bit of a vague question.
**[Entity.SetPos
http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Entity.SetPos)**
**[Entity.SetVelocity
http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Entity.SetVelocity)**
**[Entity.GetPhysicsObject
http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Entity.GetPhysicsObject)**
**[PhysObj.ApplyForceCenter
http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=PhysObj.ApplyForceCenter)**
**[PhysObj.SetVelocity
http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=PhysObj.SetVelocity)**
The barrel never stops rolling. Take a look at the code
[editline]01:59PM[/editline]
:ninja:
So should this work?
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include('shared.lua')
function ENT:Initialize()
self:SetModel("models/1-UP.mdl")
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
local phys = self:GetPhysicsObject()
if phys:IsValid() then phys:Wake() end
end
function ENT:SpawnFunction(ply, tr)
if ( !tr.Hit ) then return end
local ent = ents.Create("ent_1up")
ent:EmitSound(table.Random(spawnsounds), 100, 100)
ent:SetPos(tr.HitPos + tr.HitNormal * 16)
ent:Spawn()
ent:Activate()
trace.Entity:SetVelocity(=ENT:GetForward() * 500 + Vector(0,1000,0))
ent:SetVelocity(self:GetForward() * 500 + Vector(0, 1000, 0))
return ent
end
ents.Create("prop_physics")
--phys:SetVelocity(Vector(0,10,0))
spawnsounds={
"1upsounds/powerup.wav"
}
usesounds={
"1upsounds/1-up.wav"
}
function ENT:Use( activator, caller )
self.Entity:Remove()
if ( activator:IsPlayer() ) then
local health = activator:Health()
activator:SetHealth( 100 )
self:EmitSound(table.Random(usesounds), 100, 100)
end
end
Sorry for all the unnecessary parts of code. Using someone elses code. So I’m not going to release it unless I have there permission.
I dont know, lol. I’m not that good at Lua yet.
Remove this
trace.Entity:SetVelocity(=ENT:GetForward() * 500 + Vector(0,1000,0))
And this
ents.Create("prop_physics")
Ok 1 more problem and it should work. When I try to spawn it I get this.
Attempted to create unknown entity type ent_1up!
entities/1up/init.lua:18: Tried to use a NULL entity!
Any help?
Current code?
Yes… all of it… we need it for… purposes :smug:
Nah, just post the code you have so far that has any thing to do with the entity you are trying to spawn.
So here is cl_init.
include("shared.lua")
function ENT:Initialize()
end
function ENT:Draw()
self.Entity:DrawModel()
end
And here is init.
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include('shared.lua')
function ENT:Initialize()
self:SetModel("models/1-UP.mdl")
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
local phys = self:GetPhysicsObject()
if phys:IsValid() then phys:Wake() end
end
function ENT:SpawnFunction(ply, tr)
if ( !tr.Hit ) then return end
local ent = ents.Create("ent_1up")
ent:EmitSound(table.Random(spawnsounds), 100, 100)
ent:SetPos(tr.HitPos + tr.HitNormal * 16)
ent:Spawn()
ent:Activate()
ent:SetVelocity(self:GetForward() * 500 + Vector(0, 1000, 0))
return ent
end
--phys:SetVelocity(Vector(0,10,0))
spawnsounds={
"1upsounds/powerup.wav"
}
usesounds={
"1upsounds/1-up.wav"
}
function ENT:Use( activator, caller )
self.Entity:Remove()
if ( activator:IsPlayer() ) then
local health = activator:Health()
activator:SetHealth( 100 )
self:EmitSound(table.Random(usesounds), 100, 100)
end
end
Whoops. Forgot shared.
ENT.Type = "anim"
ENT.Base = "base_gmodentity"
ENT.PrintName = "1-UP"
ENT.Author = "Mat"
ENT.Contact = "Imakejets@hotmail.com"
ENT.Information = "A 1-UP mushroom!"
ENT.Category = "Mario"
ENT.Spawnable = true
ENT.AdminSpawnable = false
you dont have a shared.lua?
I forgot about it. :buddy:
Try making it emit a sound after you spawn it (or in the ENT:Initialize() hook)
[lua]ents.Create(“1up”)[/lua]
I put that in cl_init right? Also Disseminate, it already makes a noise when it spawns.
You need to replace this
[lua]local ent = ents.Create(“ent_1up”)[/lua]
with this
[lua]local ent = ents.Create(“1up”)[/lua]
because ‘1up’ is the folder that your entity is in.
Alright last error (hopefully).
**
entities/1up/init.lua:24: attempt to call method ‘GetForward’ (a nil value)
**
When I spawn it I get the error model.
The only code that has changed is init.
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include('shared.lua')
function ENT:Initialize()
self:SetModel("models/1-UP.mdl")
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
local phys = self:GetPhysicsObject()
if phys:IsValid() then phys:Wake() end
end
function ENT:SpawnFunction(ply, tr)
if ( !tr.Hit ) then return end
local ent = ents.Create("1up")
ent:EmitSound(table.Random(spawnsounds), 100, 100)
ent:SetPos(tr.HitPos + tr.HitNormal * 16)
ent:Spawn()
ent:Activate()
ent:SetVelocity(self:GetForward() * 500 + Vector(0, 1000, 0))
return ent
end
--phys:SetVelocity(Vector(0,10,0))
spawnsounds={
"1upsounds/powerup.wav"
}
usesounds={
"1upsounds/1-up.wav"
}
function ENT:Use( activator, caller )
self.Entity:Remove()
if ( activator:IsPlayer() ) then
local health = activator:Health()
activator:SetHealth( 100 )
self:EmitSound(table.Random(usesounds), 100, 100)
end
end
self:GetForward() should be ent:GetForward()
[editline]05:51PM[/editline]
I think.
One last error.
**
CMaterial::DrawElements: No bound shader
**
New init code.
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include('shared.lua')
function ENT:Initialize()
self:SetModel("models/1-UP.mdl")
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
local phys = self:GetPhysicsObject()
if phys:IsValid() then phys:Wake() end
end
function ENT:SpawnFunction(ply, tr)
if ( !tr.Hit ) then return end
local ent = ents.Create("1up")
ent:EmitSound(table.Random(spawnsounds), 100, 100)
ent:SetPos(tr.HitPos + tr.HitNormal * 16)
ent:Spawn()
ent:Activate()
ent:SetVelocity(ent:GetForward() * 500 + Vector(0, 1000, 0))
return ent
end
--phys:SetVelocity(Vector(0,10,0))
spawnsounds={
"1upsounds/powerup.wav"
}
usesounds={
"1upsounds/1-up.wav"
}
function ENT:Use( activator, caller )
self.Entity:Remove()
if ( activator:IsPlayer() ) then
local health = activator:Health()
activator:SetHealth( 100 )
self:EmitSound(table.Random(usesounds), 100, 100)
end
end
Any one? Thought that would auto merge…