Data Realms Fan Forums
http://45.55.195.193/

Quick Actor Switching Script Needed *More help needed
http://45.55.195.193/viewtopic.php?f=73&t=16239
Page 1 of 2

Author:  CaveCricket48 [ Sun Aug 16, 2009 12:03 am ]
Post subject:  Quick Actor Switching Script Needed *More help needed

Unfortunately, my Lua skills are not good enough to do this. I need a script that is attached to an actor, and when that said actor is created, the player of its team switches control to it. Thanks.

Edit: scroll all the way down to see the problem.

Author:  Grif [ Sun Aug 16, 2009 12:52 am ]
Post subject:  Re: Quick Actor Switching Script Needed

ActivityMan:GetActivity():SwitchToActor(self,Activity.PLAYER_1,self.Team);

Author:  CaveCricket48 [ Sun Aug 16, 2009 1:20 am ]
Post subject:  Re: Quick Actor Switching Script Needed

Simply putting the Lua line in a Lua file doesn't work, so I tried this:
Code:
function Create(self)
self.ActivityMan:GetActivity():SwitchToActor(self,Activity.PLAYER_1,self.Team);
end
end
end


And got this:
Attachment:
Error.bmp [14.24 KiB]
Not downloaded yet

Author:  Grif [ Sun Aug 16, 2009 1:23 am ]
Post subject:  Re: Quick Actor Switching Script Needed

Why did you put three ends?

function Create(self) needs one end.

Any logical statement (if, for, while) needs an end.

Function calls, variable changes, etc, do not need ends.

You put more ends than there are even lines of "real" code.

Author:  Mind [ Sun Aug 16, 2009 1:24 am ]
Post subject:  Re: Quick Actor Switching Script Needed

function Create(self)
self.ActivityMan:GetActivity():SwitchToActor(self,Activity.PLAYER_1,self.Team);
end


Too many "end's"
;)

Crap ninja'd by grif

Author:  CaveCricket48 [ Sun Aug 16, 2009 1:39 am ]
Post subject:  Re: Quick Actor Switching Script Needed

Another error. :(
Attachment:
Error.bmp
Error.bmp [ 9 KiB | Viewed 4235 times ]


BTW, the actor that the script is attached to is a rocket that dies instantly and has an actor in its inventory.

Author:  Grif [ Sun Aug 16, 2009 1:43 am ]
Post subject:  Re: Quick Actor Switching Script Needed

Just ActivityMan, not self.ActivityMan.

Author:  CaveCricket48 [ Sun Aug 16, 2009 1:56 am ]
Post subject:  Re: Quick Actor Switching Script Needed

It's working now, thanks!

Author:  CaveCricket48 [ Sun Aug 16, 2009 3:57 am ]
Post subject:  Re: Quick Actor Switching Script Needed *More help needed

I need another script which is also beyond my abilities. It would be attached to an actor and would...
-Find the nearest actor within a 50 pixel range.
-Check if the actor is being controlled by a human player.
-If yes, switch control to self.
-If no, delete self.
-Entire script would not effect all human players, only one (if found).

Author:  Mind [ Sun Aug 16, 2009 4:16 am ]
Post subject:  Re: Quick Actor Switching Script Needed *More help needed

Code:
function Create(self)
local curdist = 50;
   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 then
       curdist = dist;
       self.closestactor = actor;
         end
    end
    if self.closestactor == true then
        if self.closestactor:IsPlayerControlled == true() then
            self.ActivityMan:GetActivity():SwitchToActor(self,Activity.PLAYER_1,self.Team);
        else
            self.ToDelete = true
      end   
   end
end


Dunno for sure if this will work, but this is my guess for now.

This is when it's created, fyi. If it's not sposed to be that, make sure to tell me :)

Edit: the activityman is sposed to be one line :)

Author:  CaveCricket48 [ Sun Aug 16, 2009 4:26 am ]
Post subject:  Re: Quick Actor Switching Script Needed *More help needed

Mind wrote:
Edit: the activityman is sposed to be one line


What does that mean?

And error:
Attachment:
Error.bmp [10.77 KiB]
Not downloaded yet

Author:  Mind [ Sun Aug 16, 2009 4:28 am ]
Post subject:  Re: Quick Actor Switching Script Needed *More help needed

Try and line up the tabs. The tabs are messed up, so make sure to line em up with the designated statement.

Author:  CaveCricket48 [ Sun Aug 16, 2009 4:37 am ]
Post subject:  Re: Quick Actor Switching Script Needed *More help needed

Tabs seem to have no effect.

Author:  TheValiant [ Sun Aug 16, 2009 4:43 am ]
Post subject:  Re: Quick Actor Switching Script Needed *More help needed

Remove the "()" in this line:

Code:
if self.closestactor:IsPlayerControlled == true() then

Author:  Mind [ Sun Aug 16, 2009 4:49 am ]
Post subject:  Re: Quick Actor Switching Script Needed *More help needed

Code:
function Create(self)
local curdist = 50;
   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 then
       curdist = dist;
       self.closestactor = actor;
         end
    end
    if self.closestactor == true then
        if self.closestactor:IsPlayerControlled() == true then
          self.ActivityMan:GetActivity():SwitchToActor(self,Activity.PLAYER_1,self.Team);
        else
            self.ToDelete = true
      end   
   end
end


Sorry, ya like the valiant said, it should be if self.closestactor:IsPlayerControlled() == true.

Page 1 of 2 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/