Code:
-- List of loaded scripts and their parameters by time value
-- 3 Dimensional array.
-- First : Script Name
-- Second: Time Value
-- Third: Parameters
-- (String,Number,Number) -> @Value@
scriptArray = {};
-- List of currently active event indexes
-- 1 Dimensional array
-- First: Index of active event
-- (Number) -> @Value@
eventArray = {};
-- List of current script's time values
-- 1 & 2 Dimensional array
-- First: Index of active script's time value
-- also
-- First: Name of script
-- Second: Index of time value
-- (Number) -> @Bool@
-- (Name,Number) -> @Bool@
scriptTimeArray = {};
for k=1, 128 do
scriptTimeArray[k] = 0;
end
-- 1 Dimensional array
-- Ties tag name to object ID #
-- (String) -> @Value@
tagArray = {};
-- Currently active script string
-- @String@
currentScript = "";
-- Current frame time
-- @Value@
currentTime = 0;
-- Number of active events
-- @Value@
currentActive = 0;
-- Initializes a new script with the given name
-- (string) -> @LUA@
function initScript(Name)
currentScript = Name;
scriptArray[currentScript] = {};
scriptArray[currentScript]["Max"] = 0;
scriptArray[currentScript]["Number"] = 0;
scriptTimeArray[currentScript] = {};
end
-- Adds an event to currently active script
-- (String,Number,Number,Number,Number,Number,Number,Number,Number,Number,Number) -> @LUA@
function addEvent(Name, Time, Duration, P1, P2, P3, P4, P5, P6, P7, P8)
scriptArray[currentScript][Time] = {};
scriptArray[currentScript][Time][1] = Name;
scriptArray[currentScript][Time][2] = Duration;
scriptArray[currentScript][Time][3] = P1;
scriptArray[currentScript][Time][4] = P2;
scriptArray[currentScript][Time][5] = P3;
scriptArray[currentScript][Time][6] = P4;
scriptArray[currentScript][Time][7] = P5;
scriptArray[currentScript][Time][8] = P6;
scriptArray[currentScript][Time][9] = P7;
scriptArray[currentScript][Time][10] = P8;
if Time + Duration > scriptArray[currentScript]["Max"] then
scriptArray[currentScript]["Max"] = Time + Duration;
end
tempv = scriptArray[currentScript]["Number"] + 1;
scriptArray[currentScript]["Number"] = tempv;
scriptTimeArray[currentScript][tempv] = Time;
end
-- Tags an object based on Alterable String T
-- (String) -> @LUA@
function tagObject(Name)
for k=1, maxObjects do
if objectArray[k] == 1 then
if Name == mmf.Object.GetString(k,5) then
tagArray[Name] = k;
return;
end
end
end
end
-- Untags all objects
-- NOTE: INVOKE THIS ONLY AFTER FULL ROTATION THROUGH TIME CYCLE
-- IN A ZERO-TAG ZONE
-- Otherwise, rewinding logic would get all screwy
-- () -> @LUA@
function resetTags()
tagArray = {};
end
-- Activates a script
-- (String) -> @LUA@
function activateScript(Name)
currentScript = Name;
currentTime = 0;
for j=1, 128 do
scriptTimeArray[j] = 0;
end
tempv = 0;
for k=1, scriptArray[currentScript]["Number"] do
tempv = scriptTimeArray[currentScript][k];
scriptTimeArray[tempv] = 1;
end
end
-- Activates a script from MMF
-- () -> @LUA@
-- (String)
function activateScriptMMF(Name)
currentScript = mmf.LocalStore.GetString(1);
currentTime = 0;
for j=1, 128 do
scriptTimeArray[j] = 0;
end
tempv = 0;
for k=1, scriptArray[currentScript]["Number"] do
tempv = scriptTimeArray[currentScript][k];
scriptTimeArray[tempv] = 1;
end
end
-- Reactivates a script
-- () -> @LUA@
-- (String)
function reactivateScript()
currentScript = mmf.LocalStore.GetString(1);
currentTime = scriptArray[currentScript]["Max"];
end
-- Executes active script forwards at given time value
-- Executes open events forwards at given time value
-- () -> @MMF@
function forwardScript()
if currentTime > scriptArray[currentScript]["Max"] + 1 then
DoCall("deactivateScript");
if currentActive > 0 then
DoCall("Sound");
end
return;
end
if scriptTimeArray[currentTime] == 1 then
currentActive = currentActive + 1;
eventArray[currentActive] = currentTime;
end
currentTime = currentTime + 1;
if currentActive == 0 then
return;
end
tempv = 0;
k = 1;
while k <= currentActive do
tempv = eventArray[k];
type = scriptArray[currentScript][tempv][1];
if (_G[type]~=nil) then
_G[type ](tempv);
end
if currentTime >= (tempv + scriptArray[currentScript][tempv][2]) then
removeActive(k);
DoCall("number",currentTime);
k = k - 1;
end
k = k + 1;
end
end
-- Removes an event from the eventArray, lowering all above it
-- (Number) -> @LUA@
function removeActive(Numb)
currentActive = currentActive - 1;
for k=Numb, currentActive do
eventArray[k] = eventArray[k+1];
eventArray[k+1] = 0;
end
end
-- Executes active script reverse at given time value
-- Executes open events reverse at given time value
-- () -> @MMF@
function reverseScript()
end
function testthis()
DoCall("number", tagArray["Player"]);
end
-- ######################### SCRIPT FUNCTIONS ##########################
-- Moves object ID from point A to B by percent
-- (Number) -> @MMF@
-- (Name, Ax, Ay, Bx, By)
function eventMove(Event)
percent = (currentTime - Event) / scriptArray[currentScript][Event][2];
Ax = scriptArray[currentScript][Event][4];
Ay = scriptArray[currentScript][Event][5];
Bx = scriptArray[currentScript][Event][6];
By = scriptArray[currentScript][Event][7];
Px = (Bx - Ax) * percent + Ax;
Py = (By - Ay) * percent + Ax;
Name = scriptArray[currentScript][Event][3];
tagName = tagArray[Name];
mmf.Object.SetPosition(tagName, Px, Py);
if Name == "Player" then
mmf.Object.SetValue(tagName, 1, Px * 1000);
mmf.Object.SetValue(tagName, 2, Py * 1000);
end
end
-- Deactivates camera control
-- (Number) -> @MMF@
-- ()
function eventLockCamera(Event)
end
-- Activates camera control
-- (Number) -> @MMF@
-- ()
function eventUnlockCamera(Event)
end
-- Deactivates player control
-- (Number) -> @MMF@
-- ()
function eventLockPlayer(Event)
end
-- Activates player control
-- (Number) -> @MMF@
-- ()
function eventUnlockPlayer(Event)
end
-- Moves camera from point A to B by percent
-- (Number) -> @MMF@
-- (Ax, Ay, Bx, By)
function eventCameraMove(Event)
end
-- Makes an object play a given animation sequence
-- (Number) -> @MMF@
-- (Name, Anim)
function eventAnim(Event)
end
-- Make an object play a given animation frame
-- (Number) -> @MMF@
-- (Name, Frame)
function eventAnimFrame(Event)
end
-- Set a value of an object
-- 0-based index
-- (Number) -> @MMF@
-- (Name, Index, Value)
function eventSetValue(Event)
end
-- Set a flag of an object
-- (Number) -> @MMF@
-- (Name, Index, Flag)
function eventSetFlag(Event)
end
-- Destroy an object
-- (Number) -> @MMF@
-- (Name)
function eventDestroy(Event)
end
-- Set quest flag on or off
-- (Number) -> @MMF@
-- (Flag)
function eventQuest(Event)
end