After several searches, I’ve been able to put together bits and pieces of generic entity code. This is what I have gathered:
init.lua:
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include('shared.lua')
function ENT:Initialize()
self:SetModel("models/Items/Flare.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:Touch( ply )
if ( ply:IsValid() and ply:IsPlayer() ) then
Msg("Taco")
self.Entity:Remove()
end
end
cl_init.lua:
include("shared.lua")
function ENT:Initialize()
end
function ENT:Draw()
self.Entity:DrawModel()
end
In my gamemode code, I have this item spawn. Currently, it just … floats (whereas other entities drop to the ground). Also, I added the ENT:Touch hoping this would work for simulating a player ‘picking up’ an item. Right now, the player just walks through the item, nothing happens.
I don’t know anything about scripting entities and I’ve found no tutorials on the subject. Any thoughts on making this work?
Changing ply to hitEnt shouldn’t change anything. I should be able to use whatever name I want there…
Attempted both suggestions, absolutely no change.
Edit:
Ok, think it had something to do with the model… somehow. I changed it to a large prop and suddenly it works. It drops to the ground and the touch works. Any idea why?
Edit2:
It has to just be that some models can’t have physics applied to them… and it will somehow cause the whole script to not work. I changed it to
models/props_junk/garbage_takeoutcarton001a.mdl
A small chinese take-out carton, works fine. Doesn’t fit in with my game AT ALL, but… it’s the best I can do, apparently.