View unanswered posts | View active topics It is currently Sun Jan 12, 2025 5:50 am



Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
 help!!!! hurting something that something follows 
Author Message
User avatar

Joined: Sat Mar 20, 2010 4:51 pm
Posts: 30
Reply with quote
Post 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?


Sat Mar 20, 2010 5:00 pm
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: help!!!! hurting something that something follows
try using grabobject.ID rather than just grabobject


Sat Mar 20, 2010 5:29 pm
Profile
User avatar

Joined: Sat Mar 20, 2010 4:51 pm
Posts: 30
Reply with quote
Post 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);


Sun Mar 21, 2010 12:28 am
Profile
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: help!!!! hurting something that something follows
Sure would be nice to have the whole script, so we know what each thing is..


Sun Mar 21, 2010 3:53 am
Profile WWW
User avatar

Joined: Sat Mar 20, 2010 4:51 pm
Posts: 30
Reply with quote
Post 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


Sun Mar 21, 2010 4:01 am
Profile
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post 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
You need to verify that targetA is an actor before accessing the Health variable.


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.


Sun Mar 21, 2010 11:18 am
Profile
User avatar

Joined: Sat Mar 20, 2010 4:51 pm
Posts: 30
Reply with quote
Post Re: help!!!! hurting something that something follows
ooookay so how exactly do i do that?


Sun Mar 21, 2010 4:32 pm
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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


Sun Mar 21, 2010 4:55 pm
Profile
User avatar

Joined: Sat Mar 20, 2010 4:51 pm
Posts: 30
Reply with quote
Post 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


Sun Mar 21, 2010 7:34 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post 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;


Mon Mar 22, 2010 4:14 am
Profile
User avatar

Joined: Sat Mar 20, 2010 4:51 pm
Posts: 30
Reply with quote
Post Re: help!!!! hurting something that something follows
ok i dont get an error from that but the target's health doesnt go down


Tue Mar 23, 2010 3:32 am
Profile
User avatar

Joined: Sat Mar 20, 2010 4:51 pm
Posts: 30
Reply with quote
Post Re: help!!!! hurting something that something follows
bump for help?


Tue Mar 30, 2010 2:40 am
Profile
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post 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


Tue Mar 30, 2010 8:27 am
Profile
User avatar

Joined: Sat Mar 20, 2010 4:51 pm
Posts: 30
Reply with quote
Post 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


Tue Mar 30, 2010 8:31 pm
Profile
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post 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
If this does not work you are probably resetting self.LifeTimer somewhere else.


Tue Mar 30, 2010 8:55 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 16 posts ]  Go to page 1, 2  Next

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.078s | 15 Queries | GZIP : Off ]