Data Realms Fan Forums http://45.55.195.193/ |
|
help!!!! hurting something that something follows http://45.55.195.193/viewtopic.php?f=73&t=18194 |
Page 1 of 2 |
Author: | roflcopterz [ Sat Mar 20, 2010 5:00 pm ] |
Post subject: | help!!!! hurting something that something follows |
Code: local targetA = MovableMan:GetMOFromID(grabobject); if self.LifeTimer:IsPastSimMS(500) and self.stick == 0 then self:GibThis(); end this dont work but everything else does. it says "attampt to index global 'targetA' (a nil value)", help? |
Author: | Grif [ Sat Mar 20, 2010 5:29 pm ] |
Post subject: | Re: help!!!! hurting something that something follows |
try using grabobject.ID rather than just grabobject |
Author: | roflcopterz [ Sun Mar 21, 2010 12:28 am ] |
Post subject: | Re: help!!!! hurting something that something follows |
now it says "attempt to index local 'grabobject' (a number value) on this line: Code: local targetA = MovableMan:GetMOFromID(grabobject.ID); |
Author: | Geti [ Sun Mar 21, 2010 3:53 am ] |
Post subject: | Re: help!!!! hurting something that something follows |
Sure would be nice to have the whole script, so we know what each thing is.. |
Author: | roflcopterz [ Sun Mar 21, 2010 4:01 am ] |
Post subject: | Re: help!!!! hurting something that something follows |
Code: function Create(self) self.stick = 0; -- 0 is no stick, 1 is to MO, 2 is to ground self.parent = nil; self.target = nil; self.targetclass = nil; self.stickpositionX = 0; self.stickpositionY = 0; self.stickrotation = 0; self.fireglow = CreateAEmitter("Flames","LOL.rte"); self.fireglow.Pos = self.Pos; MovableMan:AddParticle(self.fireglow); self.LifeTimer = Timer(); local curdist = 80; for actor in MovableMan.Actors do local avgx = actor.Pos.X - self.Pos.X; local avgy = actor.Pos.Y - self.Pos.Y; local dist = math.sqrt(avgx ^ 2 + avgy ^ 2); if dist < curdist and actor:HasObject("Flame Thrower") then self.parent = actor; self.parentid = self.parent.ID; end end end function Update(self) if MovableMan:IsParticle(self.fireglow) then self.fireglow.ToDelete = false; self.fireglow.ToSettle = false; self.fireglow.Pos = self.Pos; self.fireglow.Vel = self.Vel; end if not(MovableMan:IsActor(self.parent)) and self.parentid == 255 then self.ToDelete = true; self.LifeTime = 0; end if MovableMan:IsActor(self.parent) and self.stick == 0 then local grabobject = SceneMan:CastMORay(self.Pos,Vector(self.Vel.X,self.Vel.Y):SetMagnitude(5),self.parent.ID,0,true,0); local terrcheck = Vector(0,0); if grabobject ~= 255 and grabobject ~= self.ID then self.target = MovableMan:GetMOFromID(grabobject); -- local targetA = MovableMan:GetMOFromID(grabobject.ID); -- self.targetclass = self.target.ClassName; self.stick = 1; self.stickpositionX = self.Pos.X-self.target.Pos.X; self.stickpositionY = self.Pos.Y-self.target.Pos.Y; self.stickrotation = self.target.RotAngle; self.LifeTimer:Reset(); elseif SceneMan:CastStrengthRay(self.Pos,Vector(self.Vel.X,self.Vel.Y):SetMagnitude(10),0,terrcheck,0,0,true) then self.Vel = Vector(0,0); self.PinStrength = 1000; self.Pos = terrcheck; self.stick = 2; self.LifeTimer:Reset(); end end if self.stick == 1 and self.targetclass == self.target.ClassName then self.Pos = self.target.Pos + Vector(self.stickpositionX,self.stickpositionY):RadRotate(self.target.RotAngle+self.stickrotation); self.Vel = self.target.Vel; end -- if self.LifeTimer:IsPastSimMS(50) and (self.stick == 1) then targetA.Health = targetA.Health - 5; end -- if self.LifeTimer:IsPastSimMS(500) and self.stick == 0 then self:GibThis(); end end function Destroy(self) if MovableMan:IsParticle(self.fireglow) then self.fireglow.ToDelete = true; self.fireglow.LifeTime = 0; end end |
Author: | Abdul Alhazred [ Sun Mar 21, 2010 11:18 am ] |
Post subject: | Re: help!!!! hurting something that something follows |
Since grabobject is a number (the MOID), grabobject.ID will cause an error. The real problem is probably this: Code: if self.LifeTimer:IsPastSimMS(50) and (self.stick == 1) then targetA.Health = targetA.Health - 5 end One more thing; I recommend calculating distance between two objects (e.g. self.stickposition) using SceneMan:ShortestDistance to make sure the weapon works at the seam of maps that wrap. |
Author: | roflcopterz [ Sun Mar 21, 2010 4:32 pm ] |
Post subject: | Re: help!!!! hurting something that something follows |
ooookay so how exactly do i do that? |
Author: | Grif [ Sun Mar 21, 2010 4:55 pm ] |
Post subject: | Re: help!!!! hurting something that something follows |
Lua code comments don't work the way you think they do, if that's what you're attempting to do with the -- before and after certain blocks of code. Further, just check if MovableMan:IsActor(targetA) == true |
Author: | roflcopterz [ Sun Mar 21, 2010 7:34 pm ] |
Post subject: | Re: help!!!! hurting something that something follows |
no i did the comments to find the lines more easily. so you're saying do this? Code: if MovableMan:IsActor(targetA) == true and self.LifeTimer:IsPastSimMS(50) and (self.stick == 1) then targetA.Health = targetA.Health - 5; end |
Author: | CaveCricket48 [ Mon Mar 22, 2010 4:14 am ] |
Post subject: | Re: help!!!! hurting something that something follows |
And then replace Code: targetA.Health = targetA.Health - 5; with Code: ToActor(targetA).Health = ToActor(targetA).Health - 5; |
Author: | roflcopterz [ Tue Mar 23, 2010 3:32 am ] |
Post subject: | Re: help!!!! hurting something that something follows |
ok i dont get an error from that but the target's health doesnt go down |
Author: | roflcopterz [ Tue Mar 30, 2010 2:40 am ] |
Post subject: | Re: help!!!! hurting something that something follows |
bump for help? |
Author: | Abdul Alhazred [ Tue Mar 30, 2010 8:27 am ] |
Post subject: | Re: help!!!! hurting something that something follows |
The indentation of your code makes it hard to read but targetA is a local variable. You should probably work with self.target instead. One other thing that could cause you problems it the LifeTimer. If you constantly reset it, the code that reduce health will never run. You can test this by changing this code Code: if MovableMan:IsActor(targetA) == true and self.LifeTimer:IsPastSimMS(50) and (self.stick == 1) then targetA.Health = targetA.Health - 5; end to this Code: if self.stick == 1 and MovableMan:IsActor(self.target) then self.target.Health = self.target.Health - 1 end Just like CaveCricket said self.target has to be an Actor pointer so you should probably try replacing this Code: self.target = MovableMan:GetMOFromID(grabobject) with this Code: self.target = MovableMan:GetMOFromID(grabobject) if self.target.ID == self.target.RootID then -- target is an actor self.target = ToActor(self.target) else self.target = ToActor(MovableMan:GetMOFromID(self.target.RootID)) end |
Author: | roflcopterz [ Tue Mar 30, 2010 8:31 pm ] |
Post subject: | Re: help!!!! hurting something that something follows |
perfect but it hurts things too fast how do i make it hurt things slowly? like 1hp a second or something |
Author: | Abdul Alhazred [ Tue Mar 30, 2010 8:55 pm ] |
Post subject: | Re: help!!!! hurting something that something follows |
Try this: Code: if self.stick == 1 and self.LifeTimer:IsPastSimMS(100) and MovableMan:IsActor(self.target) then -- 1pt every 100ms self.LifeTimer:Reset() self.target.Health = self.target.Health - 1 end |
Page 1 of 2 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |