View unanswered posts | View active topics It is currently Fri Dec 27, 2024 8:10 am



Reply to topic  [ 11 posts ] 
 Can a game object have more than one ScriptPath? 
Author Message
User avatar

Joined: Tue Jul 21, 2009 4:36 am
Posts: 347
Location: The place where asses go to be bad
Reply with quote
Post Can a game object have more than one ScriptPath?
Just a yes or no question really, but I want to hear if anyone has done it.


Sat Jun 05, 2010 9:07 pm
Profile
User avatar

Joined: Mon Jun 15, 2009 4:02 pm
Posts: 905
Reply with quote
Post Re: Can a game object have more than one ScriptPath?
There are absolutely zero occasions on which you would need more than one script to run on an MO.
Which makes your question somewhat irrelevant.

What are you trying to do?


Sat Jun 05, 2010 9:08 pm
Profile WWW
User avatar

Joined: Tue Mar 16, 2010 7:38 pm
Posts: 447
Location: The Ninth Circle
Reply with quote
Post Re: Can a game object have more than one ScriptPath?
Well, there are occasions in which one would like to use two different scripts on an object, but does not necessarily know how to combine the scripts effectively and without losing functionality.


Sat Jun 05, 2010 9:22 pm
Profile
User avatar

Joined: Mon Jun 15, 2009 4:02 pm
Posts: 905
Reply with quote
Post Re: Can a game object have more than one ScriptPath?
Combining scripts is really simple though. Lets do a quick walkthrough:


I have two scripts I wish to combine.

This script, which I made for Commander Clark. It changes a selected actor into a different actor when a key is pressed,
Code:
function Update(self) <--we don't copy this
   if self:IsPlayerControlled() and UInputMan:KeyPressed(key) then
      local new = CreateAHuman("youractor");
      new.Pos = self.Pos;
      new.Vel = self.Vel;
      new.Team = self.Team;
      MovableMan:AddActor(new);
      self.ToDelete = true;
   end
end <--don't copy this either

and this script, by Abdul, from the Lua Tricks topic, which restricts the aim angle of an ACrab.
Code:
function Create(self)
   for i = 1, MovableMan:GetMOIDCount()-1 do
      if MovableMan:GetRootMOID(i) == self.ID then
         self.Gun = MovableMan:GetMOFromID(i)
         if self.Gun.ClassName == "HDFirearm" then
            self.Gun = ToAttachable(self.Gun)
            break
         end
      end
   end
end

function Update(self)
   if self.Gun:IsAttached() then
      if self.HFlipped then
         if self.Gun.RotAngle > 0.3 then
            self.Gun.RotAngle = 0.3
         end
      elseif self.Gun.RotAngle < -0.3 then
         self.Gun.RotAngle = -0.3
      end
   end
end <--this end closes the Update(self) function.

They both have code under the Update(self) function.
Combining them is as simple as copying the code under the Update(self) function (not including the closing end) from the top script to somewhere under the Update(self) function in the bottom script.
As long as you place it just before the end which closes the function, then the script will work perfectly.

We combine the two scripts as described above to create:
Code:
function Create(self)
   for i = 1, MovableMan:GetMOIDCount()-1 do
      if MovableMan:GetRootMOID(i) == self.ID then
         self.Gun = MovableMan:GetMOFromID(i)
         if self.Gun.ClassName == "HDFirearm" then
            self.Gun = ToAttachable(self.Gun)
            break
         end
      end
   end
end

function Update(self)
   if self.Gun:IsAttached() then
      if self.HFlipped then
         if self.Gun.RotAngle > 0.3 then
            self.Gun.RotAngle = 0.3
         end
      elseif self.Gun.RotAngle < -0.3 then
         self.Gun.RotAngle = -0.3
      end
   end
   if self:IsPlayerControlled() and UInputMan:KeyPressed(key) then
      local new = CreateAHuman("youractor");
      new.Pos = self.Pos;
      new.Vel = self.Vel;
      new.Team = self.Team;
      MovableMan:AddActor(new);
      self.ToDelete = true;
   end
end

So yeah. I don't see the difficulty. If you are just copy/pasting scripts without any basic knowledge of Lua, then I suppose you might run into difficulties.


Sat Jun 05, 2010 9:39 pm
Profile WWW
User avatar

Joined: Wed Jan 07, 2009 10:26 am
Posts: 4074
Location: That quaint little British colony down south
Reply with quote
Post Re: Can a game object have more than one ScriptPath?
If I remember correctly, however, there is a line you can use that does that automatically.


Sun Jun 06, 2010 3:10 am
Profile WWW
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: Can a game object have more than one ScriptPath?
you could do dofile("path/to/script") but that doesn't work where there's still the function definition lines in there, so you may as well manually combine them.


Sun Jun 06, 2010 3:33 am
Profile WWW
User avatar

Joined: Tue Jul 21, 2009 4:36 am
Posts: 347
Location: The place where asses go to be bad
Reply with quote
Post Re: Can a game object have more than one ScriptPath?
What I mean is, say I have a modular system of lua scripts, as in one handles the self healing, one handles the built in grappler, etc., and I want one actor to have say code A & B, but the other actor to have code B & C. How do I make this happen without combining each code on an individual basis, and having one code per actor?


Sun Jun 06, 2010 3:49 am
Profile
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: Can a game object have more than one ScriptPath?
If we make 2 scripts:
Script 1: wtev.rte/scripts/addrandomhealth.lua
Code:
function arh(self)
 self.Health = self.Health + math.random(10) --add some random health
end
Script 2: wtev.rte/scripts/velocrazy.lua
Code:
function vlc(self)
 self.Vel = self.Vel + Vector(math.random(10),math.random(10)) --do crazy things to the velocity
then we can use them in another:

Script 3: wtev.rte/scripts/arh+vlc.lua
Code:
require("wtev.rte/scripts/addrandomhealth.lua); require("wtev.rte/scripts/velocrazy.lua")
function Update(self)
 self:arh()
 self:vlc()
end
so yeah, you can do the whole modular thing if you want.


Sun Jun 06, 2010 4:00 am
Profile WWW
User avatar

Joined: Tue Jul 21, 2009 4:36 am
Posts: 347
Location: The place where asses go to be bad
Reply with quote
Post Re: Can a game object have more than one ScriptPath?
Perfect! Thanks a million, Geti!


Sun Jun 06, 2010 6:42 am
Profile
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: Can a game object have more than one ScriptPath?
No worries, glad it helped.


Sun Jun 06, 2010 7:30 am
Profile WWW
User avatar

Joined: Mon Jun 15, 2009 4:02 pm
Posts: 905
Reply with quote
Post Re: Can a game object have more than one ScriptPath?
I suppose I was mistaken. :oops:

But as you're going to have more than one actor, obviously you'd need more than one script.
But you didn't mention that, so my ego remains intact. Hurrah.


Sun Jun 06, 2010 10:23 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 11 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.046s | 13 Queries | GZIP : Off ]