Hello, I decided to make a thread since it gets a bit too complex just for the thread.
Anyways here are my TWO problems I need help with. I don't understand why it isn't working (Even though I don't understand much lua beyond the tutorials on the wiki :P)
1: This code is a part of the gunlab init.lua for DarkRP. Anyway, it isn't erroring but isn't printing into the console either. I believe it was saying it couldn't dispatch the user message.
[LUA]function ENT:OnTakeDamage(dmg)
self.damage = self.damage - dmg:GetDamage()
if (self.damage <= 0) then
self.Entity:Destruct()
self.Entity:Remove()
end
if self:GetPhysicsAttacker():IsPlayer() then
Msg(self:GetPhysicsAttacker():Nick().." Destroyed a Gun Lab! \n")
end
end[/lua]
2: This piece of code is for a different project but isn't responding how it should either. To me its saying if that model is within the 10 units (V) then it should set its own model to the drum. I'm guessing it's just some annoying typo.
[LUA]function ENT:Think()
local entityfound = ents.FindInSphere(Vector(0,0,0),10)
for k,v in pairs(entityfound) do
if v:GetModel() == "models/labware/beaker1.mdl" then
self:SetModel("models/props_c17/oildrum001.mdl")
end
end
end[/LUA]
For your first problem:
[b][url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index8221.html?title=ENT.OnTakeDamage]ENT.OnTakeDamage [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
[quote=Wiki]
Appears that this hook will not run unless it takes physics damage.
[/quote]
Add self:TakePhysicsDamage(dmg) to the top.
Second problem:
You're originating from the vector 0,0,0. Are you sure it's not supposed to be self:GetPos()? Also, you should add something to disable the loop once it's been turned into an oildrum.
I changed it like so but I still get the 'Couldn't dispatch user message'?
[LUA]function ENT:OnTakeDamage(dmg)
self.damage = self.damage - dmg:GetDamage()
if (self.damage <= 0) then
self.Entity:Destruct()
self.Entity:Remove()
end
self:TakePhysicsDamage(dmg)
if self:GetPhysicsAttacker():IsPlayer() then
Msg(self:GetPhysicsAttacker():Nick().." Destroyed a Gun Lab! \n")
end
end[/LUA]
Could this be just a problem on my end?
2nd: Has been fixed. I am a dumb ass. I thought it meant 0, 0, 0 from the middle of the prop. Obviously it was global :V
Can you post the full error? And you're not using usermessages in any of that code, either it's unrelated or it's caused by the ENT.Destruct code that you haven't shown us.
There are no errors in the console
[LUA]function ENT:Destruct()
local vPoint = self.Entity:GetPos()
local effectdata = EffectData()
effectdata:SetStart(vPoint)
effectdata:SetOrigin(vPoint)
effectdata:SetScale(1)
util.Effect("Explosion", effectdata)
end[/LUA]
Well, then the usermessage dispatch error seem completely unrelated to anything in your entity code.
But you'd probably want to change
[lua]self:GetPhysicsAttacker()[/lua] to [lua]dmg:GetAttacker()[/lua]
anyway.
That seemed to work lol. I knew it would be stupid small mistakes like that but I guess I have to learn from somewhere :\
Might be worth telling me how to assign a value that lua understands :P
[LUA]function OnPaint()
cam.Start3D( self:GetPos() + ang:Up() * 8);
draw.RoundedBox( 8, 50, 50, 100, 100, Color( 255, 255, 255 ) );
cam.End3D();
end
hook.Add( "HUDPaint", "OnPaint", OnPaint );[/LUA]
Obviously 'self' is a nill value. What do I write so lua knows what 'self' means..?
Try replacing self with LocalPlayer() if thats what you're going for
Mm but i need it to stay above the entity even when its moving hence why i thought self would work. Because its getting the global vector of the ent
Sorry, you need to Log In to post a reply to this thread.