BR3NT explains a little bit about scripting - and the basics of creating a syntax
SCRIPTING 101
First Of I Have To say If You Have Issues With This Stuff I Can Give Limited Support.[I Have Used This Many Times And It Works]
The Forums Will Help You Anyways...Always Ask There.
This Tutorial Assumes You Have Some Scripting Knowledge...If Not Go Read The Tutorials.
Today... Lets Use A Function. For Those Of You Who Are New To Scripting.
A Function Is Like a Tool That A Script Uses For Different Purposes.
A Function Can Be Designed For A Specific Entity, Or Designed To Serve Many Entities.
They Can Even Be Designed To Perform Only One Action, Or Many Actions.
They Can Be called From Within A Script Or From Another External Script.
Ex:
maps\_load::main();
Where
main() Is A Function Located In A Script Named
_load That Is Located in a Folder Named
maps
A Function Is Its Own Entity In The Script With Its Own Name.
Today We Will Be Looking At The Function "attack_move_node" A Function
From Within The Game Scripts That Tells An AI-Actor To Fight Its Way To
A Goal Node.
Its A Sweet Deal For Juicing Up Your Single-Player Levels.
Here Is The Function Breakdown.
attack_move_node Is The Main function Name.
nSoldier, fWaitMin, fWaitMax, fClosureRate, nGoalNode, fStartRadius, And fEndRadius
Are Variables That The Function Uses.
![[exclamation]](images/BBCode/smilies/exclamation.gif)
fWaitMin, fWaitMax, fClosureRate, fStartRadius, fEndRadius Have Default Settings.
nSoldier, nGoalNode Must Be Defined In Your Script.
attack_move_node(nSoldier, fWaitMin, fWaitMax, fClosureRate, nGoalNode, fStartRadius, fEndRadius)
nSoldier = the soldier - This Can Also Be Applied To An Array Or Group Of Ai-Actors
fWaitMin = wait at least this many seconds before advancing (default 0.5)
fWaitMax = wait no more than this many seconds before advancing (default 2.5)
fClosureRate = pare down the goalradius by this amount (use values < 1) (default 0.85)
nGoalNode = variable assigned goalnode (required, get this just before calling attack_move_node)
fStartRadius = initial goalradius of the soldier (default 1200, or set on node or in call)
fEndRadius = final goalradius of the soldier (default 512, or set directly in call)
Using The Function:
Say I Had An array Or Group Of Soilders I Wanted To Execute The Function.
I Would Do This:
Add Some Ai-Actors To My Map.
Give Them All The Same target Name. I'm Using
my_ai As A Targetname For The Example.
Put A Node Where They Will Fight There Way Toward.For The Example I Named Mine
my_ai_node
Make Sure Path Nodes Create A Path So They Can Get To It.
I Would Call The Attack Function By Creating My Own Function.
Ex:
Code:my_soldiers()
{
mySoldiers = getentarray("my_ai","targetname");
nGoalNode = getnode ("my_ai_node","targetname");
for(i=0; i<mySoldiers.size; i++)
{
level thread attack_move_node(mySoldiers[i], 0.5, 2.5, 0.85, nGoalNode, 1200, 512);
}
}
And Calling It Like This: thread my_soldiers();
When I Want It To Execute.
Below Is The Function 'attack_move_node' . If You Really Examine The function You Can See That Its Not Too Difficult To Grasp.
Code:
attack_move_node(nSoldier, fWaitMin, fWaitMax, fClosureRate, nGoalNode, fStartRadius, fEndRadius)
{
nSoldier endon("death");
if(!isdefined(nGoalNode))
{
maps\_utility::error("Missing a goal node.");
}
if(isdefined(nGoalNode.radius) && !isdefined(fStartRadius))
{
fStartRadius = nGoalNode.radius;
}
if(!isdefined(fStartRadius))
{
fStartRadius = 1200;
}
if(!isdefined(fWaitMin))
{
fWaitMin = 0.5;
}
if(!isdefined(fWaitMax))
{
fWaitMax = 2.5;
}
if(!isdefined(fClosureRate))
{
fClosureRate = 0.85;
}
if(isdefined(fEndRadius))
{
fDestRadius = fEndRadius;
}
else
{
fDestRadius = 512;
}
wait (randomfloatrange(0.5,2.25));
nSoldier setgoalnode(nGoalNode);
nSoldier.goalradius = fStartRadius;
while(nSoldier.goalradius > fDestRadius)
{
wait (randomfloatrange(fWaitMin,fWaitMax));
nSoldier.goalradius = nSoldier.goalradius * fClosureRate;
nSoldier waittill("goal");
}
}
Scripting Is Fun![[thumbs_up]](images/BBCode/smilies/thumbs_up.gif)
This Stuff Is Hard In The Beginning But If You Can Grasp Scripting You
Can Open Up A Whole New Level Of Adding To Your Games. I Dig It.
Anyways Guys Thats It For Scripting 101.."attack_move_node"
Stay Tuned...
Maybe I Will Get Motivated And Do More.
Well Sorry For Any Mistakes ...![[crazy]](images/BBCode/smilies/crazy.gif)
Hope This Helps Someone...
![[smokin]](images/BBCode/smilies/smokin.gif)
Sometimes When I view The Forums ..In The Code Boxes I sometimes see the symbol < br />.I Know What They Are But Dont Know Why I see Them.Anyhow
If You Copy And Paste Code and see These In Your Script Delete Them, Thanx.