Data Realms Fan Forums
http://45.55.195.193/

Script trouble (resolved by TLB)
http://45.55.195.193/viewtopic.php?f=73&t=18432
Page 1 of 1

Author:  salt_1219 [ Sat Apr 10, 2010 9:08 pm ]
Post subject:  Script trouble (resolved by TLB)

Code:
function Create(self)
   self = ("scud");
   check players team to determine enemys ... not sure how.
   GetPlayerBrain( (number) Team );  ...enemy brain
   if PlayerBrain,IsDead == True then;
   MovableMan:AddActor("scud");
   FlashWhite(500);
   self:GibThis();;
   end
end

I'm trying to learn lua, so sorry about the terrible code. There's a lot missing from the wiki
What I'm trying to make this do is check to see if the enemy brain is dead, if it is then blow up my actor.

If anyone can help make this work I would really appreciate it. :)

Author:  CrazyMLC [ Sun Apr 11, 2010 12:33 am ]
Post subject:  Re: Script trouble

"self" refers to the object the script is applied to, and is automatically set.

function 'Create'(self) means it would only run the whole thing once, on creation. So if the enemy's brain wasn't dead when it spawned, the script would do nothing.

If I understand what you're wanting to do, this is how I'd do it:
Code:
function Create(self)
   self.scud = CreateAHuman("scud")
   -- Do things to self.scud here, like setting Velocity, Position, etc. Can move to function Update(self) if needed.
end

function Update(self)
   for actor in MovableMan.Actor do
      if actor.Team ~= self.Team then
         if not(self:GetPlayerBrain(actor)) then
            MovableMan:AddActor(self.scud)
            FlashWhite(500)
            self:GibThis()
         end
      end
   end
end

Author:  TheLastBanana [ Sun Apr 11, 2010 12:43 am ]
Post subject:  Re: Script trouble

That code isn't going to work very well, either. The main issue is in how you're using GetPlayerBrain. In missions, it's simply called by self:GetPlayerBrain, because self refers to the activity. Outside of activities, you need to get the activity first, so you call it with ActivityMan:GetActivity():GetPlayerBrain.
Secondly, that function takes a number as an argument, not an actor. The number represents which team to check. You want to check the enemy team, so you have to check first of all which team this actor is on.
Here is some working code:

Code:
function Create(self)
   self.scud = CreateAHuman("scud")
   -- Do things to self.scud here, like setting Velocity, Position, etc. Can move to function Update(self) if needed.
end

function Update(self)
   local enemyTeam = -1;
   if self.Team == Activity.TEAM_1 then
      enemyTeam = 1;
   elseif self.Team == Activity.TEAM_2 then
      enemyTeam = 0;
   end

   if MovableMan:IsActor(ActivityMan:GetActivity():GetPlayerBrain(enemyTeam)) == false then
      MovableMan:AddActor(self.scud);
      self:GibThis();
   end
end

You'll notice the FlashWhite was taken out of there. The reason is that it won't have any effect - you were originally telling it to flash for half a second, but explode immediately after it starts the flash. It won't be visible.

Author:  salt_1219 [ Sun Apr 11, 2010 3:21 am ]
Post subject:  Re: Script trouble

thank you guys for not only taking the time to make this script work but also taking a moment to teach me a little about how it works :)

Do you have any good resources for someone who wants to learn lua but is completely new to programming?

Author:  TheLastBanana [ Sun Apr 11, 2010 3:24 am ]
Post subject:  Re: Script trouble

http://www.lua.org/pil/
This is your best bet. Read it thoroughly.

Author:  dragonxp [ Sun Apr 11, 2010 3:25 am ]
Post subject:  Re: Script trouble

Will this somehow make me able to do something useful. I hope it isn't long.

Edit: 28 chapters, time to get reading.

Edit2: Fixed
salt_1219 wrote:
thanks I will read that In the next few weeks.

Author:  salt_1219 [ Sun Apr 11, 2010 3:32 am ]
Post subject:  Re: Script trouble

thanks I will read that tonight.
Not all of it tonight of coarse

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