Data Realms Fan Forums http://45.55.195.193/ |
|
Can a game object have more than one ScriptPath? http://45.55.195.193/viewtopic.php?f=73&t=18919 |
Page 1 of 1 |
Author: | Joe [ Sat Jun 05, 2010 9:07 pm ] |
Post subject: | 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. |
Author: | Petethegoat [ Sat Jun 05, 2010 9:08 pm ] |
Post subject: | 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? |
Author: | Nocifer [ Sat Jun 05, 2010 9:22 pm ] |
Post subject: | 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. |
Author: | Petethegoat [ Sat Jun 05, 2010 9:39 pm ] |
Post subject: | 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. |
Author: | 411570N3 [ Sun Jun 06, 2010 3:10 am ] |
Post subject: | 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. |
Author: | Geti [ Sun Jun 06, 2010 3:33 am ] |
Post subject: | 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. |
Author: | Joe [ Sun Jun 06, 2010 3:49 am ] |
Post subject: | 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? |
Author: | Geti [ Sun Jun 06, 2010 4:00 am ] |
Post subject: | 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 Code: function vlc(self) self.Vel = self.Vel + Vector(math.random(10),math.random(10)) --do crazy things to the velocity 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 |
Author: | Joe [ Sun Jun 06, 2010 6:42 am ] |
Post subject: | Re: Can a game object have more than one ScriptPath? |
Perfect! Thanks a million, Geti! |
Author: | Geti [ Sun Jun 06, 2010 7:30 am ] |
Post subject: | Re: Can a game object have more than one ScriptPath? |
No worries, glad it helped. |
Author: | Petethegoat [ Sun Jun 06, 2010 10:23 am ] |
Post subject: | Re: Can a game object have more than one ScriptPath? |
I suppose I was mistaken. ![]() 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. |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |