ah shoot the spell checker screwed up my formating!
Ok i had some people ask me about about LUA and.... i thought its about time i share what i have learned about it......
..em..... yea..... i should release this as a download but im to lazy right now plus if there are any other lua coders out there they can add to the list......though i don't think theres more than 3 or 4 of us i sware.
a few extra quick notes about lua
- Warning Debugging lua is a PAIN in the butt if you do something wrong 90% of the time the script wont run but the game will. il give a few tips at the end for debuging.
|There IS a debug console for scripts (not normal eaw console) but we cant access it (saw it with a resource hacker once )
- Variables do not have a defining type (eg not " int somenumber =12" but "somenumber = 12") lua automatically changes variable types
- Im not sure how the how global variables work i think you need the "require" command to show where to get the variable
- Comments are defined by a " -- " infront of them there are no brackets or end line statments (like ; in java)
- quick if statment format ......
If some expression then
some code
else
some code
end
Find_First_Object("")
Find_Hint("") -- finds object with hint located ( YES thats what that is for in map editor )
there are more but i dont fell like finding them
i spelled check this stuff just for you guys
Quote
aren't known causing us to look through diferent missions
but im gona put them in this list
Lua notes:
1.Variables seem to be global throughout the script and posibly throught all scripts
2.When scripting and you update the script it seems you need to restart the
map (not the game) for them to update (at least in my experiences
3. On many petroglyph scripts you will notice whats called state messages
(eg: onEnter , OnUpdate , OnExit) these reprent the state of which the
script is in.... (entering the script.... updating the script.... exiting the script)
90% sure thats right
warning most of these are guses for functions
functions list-----
Find_All_Objects_Of_Type(object)
Replace with object with a type of unit seems to be the name in the xml
Use this to define your object variables
.Activate_Ability("Turbo", false)
you can use this to activea unit abilitys by script! good for AI
Letter_Box_In(int)
WHAT? possibly the size of the wide screen view....
Sleep(int)
This seems to pause current function
MessageBox("string")
string = some text u type in there
--UPDATE!!! I know how toget this working.... more details in future
(cant get working btw)
Fade_Screen_In(int)
cool..... self explanatory
Find_player("factionname")
faction name = name. where name is a faction defined in xml I think
used for putting used factions to variables
.Make_Invulnerable(true)
-- can't be killed
.Prevent_All_Fire(true)
-- can't shoot (not sure if this is for whole level?)
.Set_Selectable(false) -- can't be controlled by player
for these three above before the dot u need a unit variable
.play_animation("deploy", false)
not sure how to use it but its usefull
needs indicator infront of dot like prox_object (somehow defined somewhere
else in code not sure where) and deploy could be a name of animation but i
could be wrong
.Change_Owner(String) -updated
string = defined some where else in La ie: Rebel_player = Find_player("rebel")
in string you would have rebel_player
needs identifiers like prox_obj
.Despawn()
despawns defined object
Spawn_Ambush_Squad("spawn1",spawn1)
Thats exactly how i found it.... i need to research into these more
note to self: Found in Story_Rebel_ActIII_M09_LAND only known instance... interesting...
.Set_Selectable(boolean)
Self explanitory
.Set_Garrison_Spawn(boolean)
Enables or diables the building garrison even if its multiplayer
.Give_Money(int)
Gives cash!!
.Retreat() -- WARNING NOT UNIT COMMAND
In front you put a player variable causes all units to retreat
from that player
.Hyperspace_Away()
Unit command : makes unit hyperspace away(probly space only)
(does not naturally "retreate " just looks like it used in sigleplayer()
/----------------------------------------------------------------/
With an object variable before the dot you can give units commands via scripts!
i tryd to keep them all hear
\---------------------------------------------------------------/
.Attack_Move()
moves unit to a location(defined with a marker) or object and attacks it
dosint attack friendlys but does attack marker flags
.Move_To()
self explanitory
.Select_Object()
Forces user to temporarily (or if set up right perminatly
.Take_Damage(int)
Well.... maybe not a unit command but still useful
.Override_Max_Speed(int)
Self explanatory... this command looks like so much fun!
(haven't used it >.<)
.Stop()
self explanitiory
/----------------------------------------------------------------/
These commands bellow have to do with cinimatic cammera
\---------------------------------------------------------------/
Scroll_Camera_To(object)
Replace object with some object variable can be markers (markers are objects)
and watch it fly!!
Point_Camera_At(cine_start)
needs to be pointed at an object
Start_Cinematic_Camera()
Self explanatory doesn't seem to have any thing acociated with it
------ These commands have 1 for on 0 for off----
Suspend_AI(1)
self explanitory
Lock_Controls(1)
self explanitory
Examples:
This IS NOT MINE its Petroglyphs but its a great starting script to learn from
-- $Id: //depot/Projects/StarWars/Run/Data/Scripts/GameObject/CreditPowerUp.lua#5 $
--/////////////////////////////////////////////////////////////////////////////////////////////////
--
-- © Petroglyph Games, Inc.
--
--
-- ***** ** * *
-- * ** * * *
-- * * * * *
-- * * * * * * * *
-- * * *** ****** * ** **** *** * * * ***** * ***
-- * ** * * * ** * ** ** * * * * ** ** ** *
-- *** ***** * * * * * * * * ** * * * *
-- * * * * * * * * * * * * * * *
-- * * * * * * * * * * ** * * * *
-- * ** * * ** * ** * * ** * * * *
-- ** **** ** * **** ***** * ** *** * *
-- * * *
-- * * *
-- * * *
-- * * * *
-- **** * *
--
--/////////////////////////////////////////////////////////////////////////////////////////////////
-- C O N F I D E N T I A L S O U R C E C O D E -- D O N O T D I S T R I B U T E
--/////////////////////////////////////////////////////////////////////////////////////////////////
--
-- $File: //depot/Projects/StarWars/Run/Data/Scripts/GameObject/CreditPowerUp.lua $
--
-- Original Author: James Yarrow
--
-- $Author: Dan_Etter $
--
-- $Change: 24235 $
--
-- $DateTime: 2005/08/18 16:56:17 $
--
-- $Revision: #5 $
--
--/////////////////////////////////////////////////////////////////////////////////////////////////
require("PGStateMachine")
function Definitions()
-- Object isn't valid at this point so don't do any operations that
-- would require it. State_Init is the first chance you have to do
-- operations on Object
DebugMessage("%s -- In Definitions", tostring(Script))
Define_State("State_Init", State_Init);
player = nil
end
function State_Init(message)
if message == OnEnter then
-- Set up event handling for when an object moves within range
Object.Event_Object_In_Range(object_in_range_handler, 150)
--Paws note that was added: this not the best way of doing object in range
-- usualy beter to do Register_Prox()
elseif message == OnUpdate then
-- Do nothing
elseif message == OnExit then
-- Do nothing
end
end
function object_in_range_handler(prox_object, object)
player = object.Get_Owner()
if player.Is_Human() then
object.Get_Owner().Give_Money(1000)
-- Cancel the object in range event from signaling anymore.
Object.Cancel_Event_Object_In_Range(object_in_range_handler)
Object.Despawn()
end
end
--------------------------
my example:
This is NOT FUNCTIONAL i dont know what hapend to the functioning versian
might be that i had a glitch and started commenting out all the parts
and this script wont work without the proper xml ask me for it if you want it
--------------------
--*****************************************************
--\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
--Paws Scipt:
-- Chronosphere script 0.o :
--
--
--
--
--////////////////////////////////////////////////////////
--*****************************************************
require("PGStateMachine")
--require("PGStoryMode")
function Definitions()
Define_State("State_Init", State_Init);
--1 for on 0 for off...and we start off (animations are not yet included)
Chrono_state=1
--for now no timer between jumps for simplisity and testing perpuses
--
--this is slightly misleading the range is the range around the cronospher to teleport troops
-- yousualy you want this size to be about the size of building of little bigger
range =150
Cronosphere = Find_First_Object("Rebel_Command_Center")
Cronosphere.Set_Selectable(false)
end
function State_Init(message)
if message == OnEnter then
Cronosphere.Set_Selectable(false)
--becon = Find_First_Object("R_Multiplayer_Beacon")
--timer if statement would go hear
--testing if becon is on the map
--if not TestValid(becon) then
-- If its not valid do nothing
--else
-- The player has summand the cronosphere! Move out!
--chrono_state =1
--end
--if chrono_state == 1 then
--Register_Prox(Object, object_in_range_handler, range, rebel_player)
-- Animation placeholder... thing in quote is animation name. then the false and 0.....
-- no idea what thoughs are for
--self_obj.Play_Animation("cinematic", false, 0)
-- end animation at spawning location
--becon.Play_Animation("cinematic", false ,0 )
--end
`elseif message == OnUpdate then
elseif message == OnExit then
-- Do nothing
end
end
function object_in_range_handler(self_obj, trigger_obj)
--ok this part of script interigates something i havent tryd before
-- trigger_obj.Set_Selectable(false)
-- this is the lazzy way to teleport.... its.....to instant
-- could b e bad for animations that later i will want to play
--trigger_obj.Teleport(becon)
end
------------------------------------------
Debugging tips
--------------------------------------------
*Comment out code that seems suspecius if your codes not worrking
* if your not shure if your object is found or not do (your object hear).Set_Selectable(false)
and if you cant select it the game found the object
* if your haveing problems with number varibles (like i was for my leveling up script in production)
use (playergoeshear).Give_Money( varible your haveing trouble with) and check the difrence in money each time script sould run )
EDIT!!!!
AH FORGOT VERY IMPORTANT THING ABOUT useing scripts..... to add them to the game you add it through xml..... some of you might know it
its
<Lua_Script>scriptnamegoeshear</Lua_Script>
and you put the lua script in the data/Scripts/* folder the * means you can put it in that directory (not shure) but i recoment the data/Scripts/GameObject folder or data/Scripts/Story
(yes you have to make the folders your self)
also to note that the file must have the .lua tag at end for it to work
also to note that scripts in FOC are encoded probly untel they releace the editor
BUT the demo of foc's scripts are not
(some new foc command it hink will make diplomatsy posible!!!that was in demo)
end edit
and that sums it up for now post any questions you might have
Edited by Berek-PG, 04 August 2009 - 11:48 AM.















