View unanswered posts | View active topics It is currently Tue Apr 23, 2024 1:21 pm



Reply to topic  [ 7 posts ] 
 Script trouble (resolved by TLB) 
Author Message
User avatar

Joined: Tue Jan 12, 2010 8:25 pm
Posts: 400
Location: mukilteo, wa
Reply with quote
Post 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. :)


Last edited by salt_1219 on Wed Apr 28, 2010 8:57 am, edited 1 time in total.



Sat Apr 10, 2010 9:08 pm
Profile
User avatar

Joined: Fri Dec 22, 2006 4:20 am
Posts: 4772
Location: Good news everyone!
Reply with quote
Post 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


Sun Apr 11, 2010 12:33 am
Profile WWW
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3138
Location: A little south and a lot west of Moscow
Reply with quote
Post 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.


Sun Apr 11, 2010 12:43 am
Profile WWW
User avatar

Joined: Tue Jan 12, 2010 8:25 pm
Posts: 400
Location: mukilteo, wa
Reply with quote
Post 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?


Sun Apr 11, 2010 3:21 am
Profile
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3138
Location: A little south and a lot west of Moscow
Reply with quote
Post Re: Script trouble
http://www.lua.org/pil/
This is your best bet. Read it thoroughly.


Sun Apr 11, 2010 3:24 am
Profile WWW
User avatar

Joined: Wed Sep 09, 2009 3:16 am
Posts: 3032
Location: Somewhere in the universe
Reply with quote
Post 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.


Last edited by dragonxp on Sun Apr 11, 2010 3:33 am, edited 1 time in total.



Sun Apr 11, 2010 3:25 am
Profile
User avatar

Joined: Tue Jan 12, 2010 8:25 pm
Posts: 400
Location: mukilteo, wa
Reply with quote
Post Re: Script trouble
thanks I will read that tonight.
Not all of it tonight of coarse


Sun Apr 11, 2010 3:32 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 7 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.055s | 17 Queries | GZIP : Off ]