Hello world,
Yesterday, I try to make a SENT but the hook "ENT:Use()" doesn't called :/
Gmod Wiki Page : [b][url=wiki.garrysmod.com/?title=ENT.Use]ENT.Use [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
And my SENT luas :
[u][b]cl_init.lua[/b][/u]
[lua]
include("shared.lua")
[/lua]
[u][b]init.lua[/b][/u]
[lua]
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
local actPlayer = nil;
function ENT:SpawnFunction( ply, tr )
if ( !tr.Hit ) then return end
local ent = ents.Create("prop_physics");
ent:SetPos( tr.HitPos + tr.HitNormal * 16 );
ent:SetModel("models/props/metal_box.mdl");
ent:Spawn();
ent:SetUseType(SIMPLE_USE);
ent:Activate();
return ent;
end
function ENT:Use( activator, caller )
Msg("Active : "..activator:GetName().."\n");
if ( activator:IsPlayer() and actPlayer == nil ) then
actPlayer = activator;
Msg("Debug\n");
end
if( activator == actPlayer ) then
actPlayer = nil;
end
end
function ENT:Think()
if(actPlayer != nil) then
local pos = actPlayer:GetPos()+actPlayer:GetUp()*50+actPlayer:GetForward()*100
self.Entity:SetPos(pos);
end
end
[/lua]
[u][b]shared.lua[/b][/u]
[lua]
ENT.Type = "anim"
ENT.PrintName = "Portal Cube"
ENT.Author = "Wamilou"
ENT.Contact = "wamilou@hotmail.fr"
ENT.Purpose = "The cube of portal 1"
ENT.Instructions = "Play with this as on portal 1"
ENT.Category = "Portal Mod Entities"
ENT.Spawnable = true
ENT.AdminSpawnable = true
[/lua]
Could you help me please ?
[highlight](User was banned for this post ("Wrong section" - mahalis))[/highlight]
You ain't giving it any physics, thus there's nothing to press use on.
How can I make this please ?
By initiating it's physics through ENT:Initialize(),
I'm surprised you aren't using this.
function ENT:Initialize()
if phys:IsValid() then
phys:Wake()
end
Not near all the code that's in this function, look up ENT:Initialize and see what you learn from that.
Double post? Dunno how I managed that.
It does'nt work !
[lua]
Msg("-*-*- Init cube -*-*-\n");
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
ENT.Type = "anim"
local actPlayer = nil;
function ENT:Initialize()
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("prop_physics");
ent:SetPos( tr.HitPos + tr.HitNormal * 16 );
ent:SetModel("models/props/metal_box.mdl");
ent:Spawn();
ent:SetUseType(SIMPLE_USE);
ent:Activate();
local phys = ent:GetPhysicsObject();
if(phys:IsValid()) then
phys:Wake();
end
return ent;
end
function ENT:Use( activator, caller )
Msg("Active : OK\n");
end
[/lua]
Could you help please ?
I read the page of ENT:Initialize() but it don't work :/
Right now you're just making a prop_physics in the SpawnFunction, and not doing anything with it.
You need to make it spawn the SEnt instead.
[b]init.lua[/b]
[code]
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
local actPlayer = nil;
function ENT:SpawnFunction( ply, tr )
if ( !tr.Hit ) then return end
local SpawnPos = tr.HitPos + tr.HitNormal * 32
local ent = ents.Create( 'ent_broken' )
ent:SetPos( SpawnPos )
ent:Spawn()
ent:Activate()
return ent
end
function ENT:Initialize()
self:SetModel( 'models/props/metal_box.mdl' )
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
self:SetUseType(SIMPLE_USE)
local Phys = self:GetPhysicsObject()
if Phys:IsValid() then
Phys:Wake()
end
end
function ENT:Use( activator, caller )
Msg("Active : "..activator:GetName().."\n");
if ( activator:IsPlayer() and actPlayer == nil ) then
actPlayer = activator;
Msg("Debug\n");
end
if( activator == actPlayer ) then
actPlayer = nil;
end
end
function ENT:Think()
if(actPlayer != nil) then
local pos = actPlayer:GetPos()+actPlayer:GetUp()*50+actPlayer:GetForward()*100
self.Entity:SetPos(pos);
end
end
[/code]
Replace line 14's ent_broken with your classname.
No work.
It return in console :
prop at 663 -42 31 missing modelname
Can you help me please ?
[QUOTE=wamilou;25356152]No work.
It return in console :
prop at 663 -42 31 missing modelname
Can you help me please ?[/QUOTE]
Are you sure that you copied all the code?
That error should only come up if you're still making a prop_physics instead of your entity's classname.
Can you post your code?
[lua]
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
local actPlayer = nil;
function ENT:SpawnFunction( ply, tr )
if ( !tr.Hit ) then return end
local SpawnPos = tr.HitPos + tr.HitNormal * 32
local ent = ents.Create( 'prop_physics' )
ent:SetPos( SpawnPos )
ent:Spawn()
ent:Activate()
return ent
end
function ENT:Initialize()
self:SetModel( 'models/props/metal_box.mdl' )
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
self:SetUseType(SIMPLE_USE)
local Phys = self:GetPhysicsObject()
if Phys:IsValid() then
Phys:Wake()
end
end
function ENT:Use( activator, caller )
Msg("Active : "..activator:GetName().."\n");
if ( activator:IsPlayer() and actPlayer == nil ) then
actPlayer = activator;
Msg("Debug\n");
end
if( activator == actPlayer ) then
actPlayer = nil;
end
end
function ENT:Think()
if(actPlayer != nil) then
local pos = actPlayer:GetPos()+actPlayer:GetUp()*50+actPlayer:GetForward()*100
self.Entity:SetPos(pos);
end
end
[/lua]
ents.Create, shouldn't that contain the name of your entity you're making, not prop_physics, also use [NOPARSE][CODE][/CODE][/NOPARSE] tags.
Replace prop_physics with your entity's classname
Here's how to find it.
[img]http://i.imgur.com/n06Ru.png[/img]
Of course yours is different than mine.
Is metal_box.mdl really a vanilla model?
[QUOTE=ralle105;25357107]Is metal_box.mdl really a vanilla model?[/QUOTE]
Yeah, it's the companion cube.
Really descriptive name. :v:
Outta be love_box.mdl then:saddowns::h:
It works, thanks :D
Hmmm...I make a portal mod for gmod :)
In all honesty I don't think you're going to be able to, you're struggling with a simple entity like this one...
^^ lol
Sorry, you need to Log In to post a reply to this thread.