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.