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:
[CODE]
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 [/CODE]
cl_init.lua:
[CODE]
include("shared.lua")
function ENT:Initialize()
end
function ENT:Draw()
self.Entity:DrawModel()
end[/CODE]
shared.lua
[CODE]ENT.Type = "anim"
ENT.Base = "base_entity"
ENT.PrintName = ""
ENT.Author = ""
ENT.Contact = ""
ENT.Spawnable = true
ENT.AdminSpawnable = false
ENT.RenderGroup = RENDERGROUP_OPAQUE
AddCSLuaFile( "shared.lua" )
/*---------------------------------------------------------
Name: Initialize
---------------------------------------------------------*/
function ENT:Initialize()
end[/CODE]
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?
Thanks
You're not activating the entity. Also, self.Entity is deprecated, use self.
Looks quite neat for a first entity. Well done!
[QUOTE=Overv;22724423]Also, self.Entity is deprecated, use self.[/QUOTE]
Will do.
[editline]01:02PM[/editline]
[QUOTE=XenonDice;22724508]Looks quite neat for a first entity. Well done![/QUOTE]
Well, I can hardly take any credit for it. I stole code from different posts to try and put this together. Thanks, tho
[editline]01:05PM[/editline]
[QUOTE=Overv;22724423]You're not activating the entity. [/QUOTE]
This is my code in the gamemode script that spawns the item
[CODE] local Drop = ents.Create("test")
Drop:SetPos(NPCPos + Vector (0,0,SpawnHeight))
Drop:Spawn()
Drop:Activate() [/CODE]
It is activated there, is that enough?
So far, adding activate to the entity lua has had no effect. It still floats and nothing happens when I walk through it.
For touch change ply to hitEnt, the floating thing happens to my stuff too but it normally drops once I touch it.
If it still floats in the air and has no collision after changing that then try removing
[code]
local phys = self:GetPhysicsObject()
if phys:IsValid() then phys:Wake() end[/code]
Thats the only other thing I could think of.
[QUOTE=DocDoomsday;22744294]For touch change ply to hitEnt, the floating thing happens to my stuff too but it normally drops once I touch it.
If it still floats in the air and has no collision after changing that then try removing
[code]
local phys = self:GetPhysicsObject()
if phys:IsValid() then phys:Wake() end[/code]Thats the only other thing I could think of.[/QUOTE]
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.
Sorry, you need to Log In to post a reply to this thread.