View unanswered posts | View active topics It is currently Sun Jul 21, 2019 1:31 am



Reply to topic  [ 5 posts ] 
 Strange Errors 
Author Message
User avatar

Joined: Fri Aug 19, 2011 4:02 pm
Posts: 40
Reply with quote
Post Strange Errors
I want to create gun that marks the targeted actor and makesa his head flash.
This is the first time the lua console gave up on me, it does not display any function names but just random characters.
Image

this scrip is on the HDFirearm itself:
Code:
function Create(self)
   print("create...");
   self.weaponRange = 500;
   self.alliedTeam = -2;
   self.owner = MovableMan:GetMOFromID(self.RootID);   --Parent Actor
   if MovableMan:IsActor(self.owner) then
      self.alliedTeam = ToActor(self.owner).Team;         --Parent Team
   end
   
   print("created succesfully");
   print("own team = " .. self.alliedTeam);
end




function Update(self)
   print("update...");
   print("1");
   local raycast = SceneMan:CastMORay(ToHDFirearm(self).MuzzlePos,Vector(self.weaponRange,0):RadRotate(ToActor(self.owner):GetAimAngle(true)),self.owner.ID,0,false,2);
   print("2");
   if raycast ~= 255 then
      print("raycast");
      print(raycast);   
      local raycast2 = MovableMan:GetMOFromID(MovableMan:GetMOFromID(raycast).RootID);
      if raycast2.ClassName == "AHuman" then
         print("raycast2");
         print(raycast2);
         print("toactor head");
         ToActor(raycast2).Head:FlashWhite(100);
      end
   end
end


The error must be in the SceneMan:CastMORay(...) function.
Probbably something simple im am just overlooking here.


Tue Sep 20, 2011 5:44 pm
Profile WWW
Data Realms Elite
Data Realms Elite
User avatar

Joined: Tue May 25, 2010 8:27 pm
Posts: 4521
Location: Constant motion
Reply with quote
Post Re: Strange Errors
The5 wrote:
Vector(self.weaponRange,0):RadRotate(ToActor(self.owner):GetAimAngle(true))

I'm pretty sure you're overloading the colon there, seems to be what the error is describing. Try setting it to variables, like:
Code:
self.ActorAim = ToActor(self.owner):GetAimAngle(true);
self.RangeVector = Vector(self.weaponRange,0);
local raycast = SceneMan:CastMORay(ToHDFirearm(self).MuzzlePos,self.RangeVector:RadRotate(self.ActorAim),self.owner.ID,0,false,2);

No promises that that's the only thing up with it though.


Tue Sep 20, 2011 5:58 pm
Profile
User avatar

Joined: Fri Aug 19, 2011 4:02 pm
Posts: 40
Reply with quote
Post Re: Strange Errors
On the projectile of this head-homing weapon i got a similar piece of code, that works.

Code:
local raycast = SceneMan:CastMORay(ToHDFirearm(gun).MuzzlePos,Vector(self.weaponRange,0):RadRotate(ToActor(owner):GetAimAngle(true)),owner.ID,0,false,2);


The only difference is, that "gun" was defined before (since the script is on the projectile, not the gun).
Code:
local gun = MovableMan:GetMOFromID(i)

Same for owner
Code:
local owner = MovableMan:GetMOFromID(gun.RootID)



Comparison:
Working:
local raycast =
SceneMan:CastMORay(ToHDFirearm(gun).MuzzlePos,Vector(self.weaponRange,0):RadRotate(ToActor(owner):GetAimAngle(true)),owner.ID,0,false,2);
Not-Working:
local raycast =
SceneMan:CastMORay(ToHDFirearm(self).MuzzlePos,Vector(self.weaponRange,0):RadRotate(ToActor(self.owner):GetAimAngle(true)),self.owner.ID,0,false,2);


Could be that "self" doeas not contain the data I expect it to contain.


Tue Sep 20, 2011 6:26 pm
Profile WWW
User avatar

Joined: Fri Aug 19, 2011 4:02 pm
Posts: 40
Reply with quote
Post Re: Strange Errors
Ok got it to work:

Code:
ToHDFirearm(self.gun)
ToActor(self.owner)

dind't work so I used
Code:
self.gun = MovableMan:GetMOFromID(self.ID);
self.owner = MovableMan:GetMOFromID(self.RootID);



EDIT:
Hmm it randomly fails, sometimes it works, sometiems it spams errors?


EDIT2:
The problem seems to occur when I buy a character with another weapon in the hand and the Head-homing-gun in the inventory. Once I switch to it the errors flow in. When I buy a actor with only that gun initially equiped everything works fine.

EDIT3:
The problem seems to be that the create block won't work correctly when the gun is in a inventory (not in the hand) when spawning!
Code:
function Create(self)
   self.weaponRange =   500;
   
   self.alliedTeam = -2;
   
   self.gun = MovableMan:GetMOFromID(self.ID);
   
   self.owner = MovableMan:GetMOFromID(self.RootID);   --Parent Actor
   
   if MovableMan:IsActor(self.owner) then
      self.alliedTeam = ToActor(self.owner).Team;         --Parent Team
   end
   
end


Tue Sep 20, 2011 6:41 pm
Profile WWW
User avatar

Joined: Wed Feb 17, 2010 12:07 am
Posts: 1545
Location: That small peaceful place called Hell.
Reply with quote
Post Re: Strange Errors
Why are you giving a separate pointer to the scripted object?

Code:
function Create(self)
   self.weaponRange =   500
   self.alliedTeam = -1
   
   if MovableMan:IsActor(self.owner) then
      self.alliedTeam = self.owner.Team        --Parent Team
   else                                                                            -- this owner part should be in the function Update() call by the way.
      self.owner = MovableMan:GetMOFromID(self.RootID)  --Parent Actor
   end
   

end


Try that instead.


Wed Sep 21, 2011 1:28 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: GopdirH


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.017s | 14 Queries | GZIP : Off ]