View unanswered posts | View active topics It is currently Tue Mar 19, 2024 7:46 am



Reply to topic  [ 2 posts ] 
 Need some lua to actor (LaserHead) 
Author Message
User avatar

Joined: Fri Apr 15, 2016 1:09 pm
Posts: 29
Location: Donetsk People's Republic
Reply with quote
Post Need some lua to actor (LaserHead)
I need lua for the actor, are follows:
Actor would have a laser sight, as Techion nanorifle, where you look, there is laser, it better to be from the head and not from body.

Experimental code:
Code:
dofile("Base.rte/Constants.lua")
require("Actors/AI/NativeHumanAI")
function Create(self)
   self.AI = NativeHumanAI:Create(self);
   self.laserTimer = Timer();
   self.laserLength = 800;
   self.laserSpaceCheck = 5; -- For optimization purposes. Smaller value means a more accurate but slower check.
   self.laserDensity = math.ceil(self.laserLength/self.laserSpaceCheck);
end
function Update(self)
   if self.laserTimer:IsPastSimMS(50) then
      self.laserTimer:Reset();
      if self:GetController():IsState(Controller.AIM_SHARP) and self:IsPlayerControlled() == true then
         local roughLandPos = self.EyePos + Vector(self.laserLength,0):RadRotate(self):GetAimAngle(true);
         for i = 0, self.laserDensity do
            local checkPos = self.EyePos + Vector(self.laserSpaceCheck*i,0):GetAimAngle(true);
            if SceneMan.SceneWrapsX == true then
               if checkPos.X > SceneMan.SceneWidth then
                  checkPos = Vector(checkPos.X - SceneMan.SceneWidth,checkPos.Y);
               elseif checkPos.X < 0 then
                  checkPos = Vector(SceneMan.SceneWidth + checkPos.X,checkPos.Y);
               end
            end
            local terrCheck = SceneMan:GetTerrMatter(checkPos.X,checkPos.Y);
            if terrCheck == 0 then
               local moCheck = SceneMan:GetMOIDPixel(checkPos.X,checkPos.Y);
               if moCheck ~= rte.NoMOID and MovableMan:GetMOFromID(moCheck).Team ~= self.Team then
                  roughLandPos = checkPos;
                  break;
               end
            else
               roughLandPos = checkPos;
               break;
            end
         end
         local checkRoughLandPos = roughLandPos + Vector(self.laserSpaceCheck*-1,0):RadRotate(self):GetAimAngle(true);
         for i = 0, self.laserSpaceCheck do
            local checkPos = checkRoughLandPos + Vector(i,0):GetAimAngle(true);
            if SceneMan.SceneWrapsX == true then
               if checkPos.X > SceneMan.SceneWidth then
                  checkPos = Vector(checkPos.X - SceneMan.SceneWidth,checkPos.Y);
               elseif checkPos.X < 0 then
                  checkPos = Vector(SceneMan.SceneWidth + checkPos.X,checkPos.Y);
               end
            end
            local terrCheck = SceneMan:GetTerrMatter(checkPos.X,checkPos.Y);
            if terrCheck == 0 then
               local moCheck = SceneMan:GetMOIDPixel(checkPos.X,checkPos.Y);
               if moCheck ~= 255 then
                  break;
               end
            else
               break;
            end
            roughLandPos = checkPos;
         end
         local laserPar = CreateMOPixel("Nanorifle Laser Sight Glow");
         laserPar.Pos = roughLandPos;
         MovableMan:AddParticle(laserPar);
      end
   end
end
function UpdateAI(self)
   self.AI:Update(self)
end


Does not work. In the console error:
ERROR: no overload of 'Vector: RadRotate' matched the arguments (Vector, AHuman)
candidates are:
Vector: RadRotate (custom [float])

Is nothing said for me.


Mon Jul 18, 2016 2:29 pm
Profile

Joined: Mon Jul 11, 2016 5:06 am
Posts: 8
Reply with quote
Post Re: Need some lua to actor (LaserHead)
Hi there.

Look carefully at lines 14 and 36. Looks like you misplaced a parenthesis, instead of putting a ')' after last self, put it right at the end of the line before ';'. Otherwise you're trying to pass self (a reference to the actor and unexpected argument type) to the function RadRotate and then calling GetAimAngle on the return value.


Mon Jul 18, 2016 11:05 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.390s | 15 Queries | GZIP : Off ]