O Ilusionista
Captain 100K
Updated November 2026:
Finally, after a long time, I’ve managed to update this code, incorporating programming best practices and making it more secure.
Now, all functions include guard clauses that follow the "early bailing" (or "fail-fast") principle—in other words, a function or loop will halt execution and return immediately upon encountering an error, an invalid case, or a trivial scenario.
In simpler instances, it will log a message noting that something is missing. But in more critical cases, it initiates a shutdown process while logging the details of what occurred. And thanks to Damon Current for the tips!
Note: keep in mind all those functions were made for V3.0, I haven't tested them in 4.0 yet and some may not work in 4.0
---
Hi everyone.
During the development of my projects, I just stop creating simple codes several tasks. Even I do not have the same level of programmers as BB and DC, I think it does not hurt to share, they can be useful
And you will see that I am a random fan 
All those codes should be saved in a file and called in ANIMATIONSCRIPT.
Some of those codes are based in codes from other coders, remember to credit then also, ok?
Useful when you need to change from one animation to another, where an attack will be performed.
Based on anichangee function (I forgot the author).
Note: there are some cases where anichange should be used, thanks to the flags. Read more about it here
Usage:
@cmd anichangeattack openborconstant("ANI_FOLLOW5")
(yes, the part openborconstant() is mandatory)
This will make the entity go to FOLLOW5 animation.
Useful to make the entity to do a jump into random directions. One of the nice ways to use it is to put this in your itens when they are spawned from obstacles
Usage:
@cmd randomJump 3 4
3 - X velocity
4 - Y velocity
The usage is the same as before, but your animationscript need to have the funcion
The same case as above, but including the Z axis too.
Usage:
@cmd randomJumpZ 3 4 2
3 - X velocity
4 - Y velocity
2 - Z velocity
4 - Y velocity
The usage is the same as before, but your animationscript need to have the funcion
Useful for changing the entity name.
NOTE: There is a limitation in this code - it won't work on the first frame of spawn/respawn animation.
You need to put it on the second frame.
Usage:
@cmd changeName "New_Name"
Same as before, but failing to provide "New_name" will cause a shutdown.
Also, "New_Name" is limited to 50 characters. Any value beyond this will cause a shutdown
5. unbind
If you use a binded entity to another entity and need to unbind it, this code is useful for that.
Usage:
@cmd unbind
Same as before
Spawns another entity (which needs to be loaded first) at random X and Y positions, giving a very cool looking.
This code uses the Spawn01 function by Damon Caskey and you need that function to make it works.
Usage:
@cmd spawnRandom "name" 50 100
Requires
Keep in mind that the given value will work from its negative value to the positive value. IOW, 50 pixels means "from -50 to 50 pixels"
This is the customized version of
It's the same of the original but:
1 - have guards
2 - will automatically set the caller as parent of the spawned entity
The same case of above, but works for X, Y and Z axis.
This code was based on a modified version of Damon Caskey's Spawn01 function, that doesn't cares for direction, called spawn000. You need that spawn000 function to make this work. Also requires
spawn000
spawnRandomZ
Usage:
@cmd spawnRandom "name" 50 100 120
Same as before
Refill the MP bar with the desired value.
Usage:
@cmd refill 50
Same as before. Refill 50 points of MP
Spend some MP
Usage:
@cmd mpcost 50
Same as before. Drains 50 points of MP
--------------------------------------
I have many other codes to share, I will edit this post once I have time.
See ya,
O Ilusionista.
Finally, after a long time, I’ve managed to update this code, incorporating programming best practices and making it more secure.
Now, all functions include guard clauses that follow the "early bailing" (or "fail-fast") principle—in other words, a function or loop will halt execution and return immediately upon encountering an error, an invalid case, or a trivial scenario.
In simpler instances, it will log a message noting that something is missing. But in more critical cases, it initiates a shutdown process while logging the details of what occurred. And thanks to Damon Current for the tips!
Note: keep in mind all those functions were made for V3.0, I haven't tested them in 4.0 yet and some may not work in 4.0
---
Hi everyone.
During the development of my projects, I just stop creating simple codes several tasks. Even I do not have the same level of programmers as BB and DC, I think it does not hurt to share, they can be useful
All those codes should be saved in a file and called in ANIMATIONSCRIPT.
Some of those codes are based in codes from other coders, remember to credit then also, ok?
1. anichangeattack
Useful when you need to change from one animation to another, where an attack will be performed.
Based on anichangee function (I forgot the author).
Note: there are some cases where anichange should be used, thanks to the flags. Read more about it here
C-like:
void anichangeattack(int Ani)
{
// Douglas Baldan / O Ilusionista
// version 1.0 - 23/07/13
// Animation changer into attacks
if (typeof(Ani) != openborconstant("VT_INTEGER"))
{
shutdown(1, "\n\n ERROR: anichangeattack(Ani) - Missing or invalid parameter.\n");
}
void self = getlocalvar("self");
if (!self)
{
return;
}
performattack(self, Ani); //Change the animation
}
Usage:
@cmd anichangeattack openborconstant("ANI_FOLLOW5")
(yes, the part openborconstant() is mandatory)
This will make the entity go to FOLLOW5 animation.
2. randomJump
Useful to make the entity to do a jump into random directions. One of the nice ways to use it is to put this in your itens when they are spawned from obstacles
C-like:
void randomJump(int vx, int vy)
{
// Douglas Baldan / O Ilusionista
// version 2.0 - 26.11.26
// version 1.0 - 23/07/13
// makes the entity execute a jump into a random direction
if (!isRandRangeOrEmpty(vx) || !isRandRangeOrEmpty(vy))
{
shutdown(1, "\n\n ERROR: randomJump(vx, vy) - Missing or invalid parameter.\n");
}
void vSelf = getlocalvar("self"); // Gets the caller
if (!vSelf)
{
return;
}
void Xr = NULL();
void Yr = NULL();
if (typeof(vx) != openborconstant("VT_EMPTY"))
{
Xr = rand() % vx + 0.5; // Random X vel, between the chosen velocity
}
if (typeof(vy) != openborconstant("VT_EMPTY"))
{
Yr = 2 + rand() % vy; // Random Y vel, to ensure a vertical jump, between the chosen velocity
if (Yr < 0) // If the Y is negative,
{
Yr = Yr * -1; // Make it positive
}
Yr = Yr + 1;
}
changeentityproperty(vSelf, "velocity", Xr, NULL(), Yr); // Change entity velocity
}
int isRandRangeOrEmpty(void v)
{// 1 if v is empty or a number >= 1 (valid as a rand() divisor %)
int t = typeof(v);
if (t == openborconstant("VT_EMPTY"))
{
return 1;
}
if (t == openborconstant("VT_INTEGER") || t == openborconstant("VT_DECIMAL"))
{
if (v >= 1)
{
return 1;
}
}
return 0;
}
Usage:
@cmd randomJump 3 4
3 - X velocity
4 - Y velocity
The usage is the same as before, but your animationscript need to have the funcion
isRandRangeOrEmpty() provided on the same code block3. randomJumpZ
The same case as above, but including the Z axis too.
C-like:
void randomJumpZ(int vx, int vy, int vz)
{
// Douglas Baldan / O Ilusionista
// version 2.0 - 26/11/26
// version 1.0 - 23/07/13
// makes the entity execute a jump into a random direction
if (!isRandRangeOrEmpty(vx) || !isRandRangeOrEmpty(vy) || !isRandRangeOrEmpty(vz))
{
shutdown(1, "\n\n ERROR: randomJumpZ(vx, vy, vz) - Missing or invalid parameter.\n");
}
void vSelf = getlocalvar("self"); // Gets the caller
if (!vSelf)
{
return;
}
void Xr = NULL();
void Yr = NULL();
void Zr = NULL();
if (typeof(vx) != openborconstant("VT_EMPTY"))
{
Xr = rand() % vx + 0.5; // Random X vel, between the chosen velocity
}
if (typeof(vy) != openborconstant("VT_EMPTY"))
{
Yr = 2 + rand() % vy; // Random Y vel, to ensure a vertical jump, between the chosen velocity
if (Yr < 0) // If the Y is negative,
{
Yr = Yr * -1; // Make it positive
}
Yr = Yr + 1;
}
if (typeof(vz) != openborconstant("VT_EMPTY"))
{
Zr = rand() % vz; // Random Z vel, between the chosen velocity
}
changeentityproperty(vSelf, "velocity", Xr, Zr, Yr); // Change entity velocity
}
Usage:
@cmd randomJumpZ 3 4 2
3 - X velocity
4 - Y velocity
2 - Z velocity
4 - Y velocity
The usage is the same as before, but your animationscript need to have the funcion
isRandRangeOrEmpty() provided on the first code block4. changeName
Useful for changing the entity name.
NOTE: There is a limitation in this code - it won't work on the first frame of spawn/respawn animation.
You need to put it on the second frame.
C-like:
void changeName(char iName)
// Change entity name
// 24.09.2013 - Douglas Baldan - The Illusionist
{
if (typeof(iName) != openborconstant("VT_STR"))
{
shutdown(1, "\n\n ERROR: changeName(iName) - Missing or invalid parameter.\n");
}
if (strlength(iName) >= 50) // name[MAX_NAME_LEN] = 50: the setter's strcpy would overflow the buffer
{
shutdown(1, "\n\n ERROR: changeName(iName) - Name too long (max 49 characters).\n");
}
void vSelf = getlocalvar("self");
if (!vSelf)
{
return;
}
changeentityproperty(vSelf, "name", iName);
}
Usage:
@cmd changeName "New_Name"
Same as before, but failing to provide "New_name" will cause a shutdown.
Also, "New_Name" is limited to 50 characters. Any value beyond this will cause a shutdown
5. unbind
If you use a binded entity to another entity and need to unbind it, this code is useful for that.
C-like:
void unbind()
// unbind entity
// 24.09.2013 - Douglas Baldan - O Ilusionista
{
void vSelf = getlocalvar("self");
if (!vSelf)
{
return;
}
bindentity(vSelf, NULL());
}
Usage:
@cmd unbind
Same as before
6. spawnRandom
Spawns another entity (which needs to be loaded first) at random X and Y positions, giving a very cool looking.
This code uses the Spawn01 function by Damon Caskey and you need that function to make it works.
C-like:
void spawnRandom(char vName, int vx, int vy)
// Spawn entity at random places
// 24.09.2013 - Douglas Baldan - O Ilusionista
// Based in Damon Caskey "spawn01" function, and you need that function to make it works.
// vx = maximum X position range
// vy = maximum Y position range
{
if (typeof(vName) != openborconstant("VT_STR")
|| !isRandRange(vx)
|| !isRandRange(vy))
{
shutdown(1, "\n\n ERROR: spawnRandom(vName, vx, vy) - Missing or invalid parameter.\n");
}
int Xr = rand() % vx; // Random X pos
int Yr = rand() % vy; // Random Y pos
spawn01(vName, vx + Xr, vy + Yr, 0);
}
Usage:
@cmd spawnRandom "name" 50 100
Requires
isRandRange() and spawn01() to workKeep in mind that the given value will work from its negative value to the positive value. IOW, 50 pixels means "from -50 to 50 pixels"
This is the customized version of
spawn01 function I am using.It's the same of the original but:
1 - have guards
2 - will automatically set the caller as parent of the spawned entity
C-like:
void spawn01(void vName, float fX, float fY, float fZ)
{
/* Guards */
if (typeof(vName) != openborconstant("VT_STR")
|| (typeof(fX) != openborconstant("VT_INTEGER") && typeof(fX) != openborconstant("VT_DECIMAL"))
|| (typeof(fY) != openborconstant("VT_INTEGER") && typeof(fY) != openborconstant("VT_DECIMAL"))
|| (typeof(fZ) != openborconstant("VT_INTEGER") && typeof(fZ) != openborconstant("VT_DECIMAL") && typeof(fZ) != openborconstant("VT_EMPTY")))
{
shutdown(1, "\n\n ERROR: spawn01(vName, fX, fY, fZ) - Missing or invalid parameter.\n");
}
// fZ (optional, default 0): omitted in the @cmd = no depth adjustment.
if (typeof(fZ) == openborconstant("VT_EMPTY"))
{
fZ = 0;
}
// spawn01 (Generic spawner)
// Damon Vaughn Caskey
// 07/06/2007
//
// Spawns entity next to caller.
//
// vName: Model name of entity to be spawned in.
// fX: X location adjustment.
// fY: Y (altitude) location adjustment.
// fZ: Z (depth) location adjustment.
// --- Category A: self supplied by the engine (animationscript) ---
void self = getlocalvar("self");
if (!self)
{
log("\nError: spawn01 empty value= self");
return NULL();
}
// --- Extra check: empty vName (passes typeof but fails on setspawnentry) ---
if (!vName)
{
log("\nError: spawn01 empty value= vName");
return NULL();
}
// --- Cache self properties (optimization) ---
int iDirection = getentityproperty(self, "direction");
float baseX = getentityproperty(self, "x");
float baseA = getentityproperty(self, "a");
float baseZ = getentityproperty(self, "z");
// Facing left: reverse X adjustment to match facing
if (iDirection == 0)
{
fX = -fX;
}
clearspawnentry();
setspawnentry("name", vName);
// --- Category C: newly created handle (exists check not needed) ---
void vSpawn = spawn();
if (!vSpawn)
{
log("\nError: spawn01 empty value= vSpawn (spawn failed for model: " + vName + ")");
return NULL();
}
changeentityproperty(vSpawn, "position", baseX + fX, baseZ + fZ, baseA + fY);
changeentityproperty(vSpawn, "direction", iDirection);
changeentityproperty(vSpawn, "parent", self);
return vSpawn;
}
7. spawnRandomZ
The same case of above, but works for X, Y and Z axis.
This code was based on a modified version of Damon Caskey's Spawn01 function, that doesn't cares for direction, called spawn000. You need that spawn000 function to make this work. Also requires
isRandRangeOrEmpty() provided on the first code blockspawn000
C-like:
void spawn000(char vName, float fX, float fY, float fZ)
{
//spawn01 (Generic spawner) without direction
//Damon Vaughn Caskey
//07/06/2007 -- Modified by Douglas Baldan/O Ilusionista
//
//Spawns entity next to caller.
//
//vName: Model name of entity to be spawned in.
//fX: X location adjustment.
//fZ: Y location adjustment.
//fY: Z location adjustment.
if (typeof(vName) != openborconstant("VT_STR")
|| !isNumberOrEmpty(fX)
|| !isNumberOrEmpty(fY)
|| !isNumberOrEmpty(fZ))
{
shutdown(1, "\n\n ERROR: spawn000(vName, fX, fY, fZ) - Missing or invalid parameter.\n");
}
void self = getlocalvar("self"); //Get calling entity.
if (!self)
{
log("\nError: spawn000 empty value= self");
return NULL();
}
void vSpawn; //Spawn object.
if (typeof(fX) == openborconstant("VT_EMPTY"))
{
fX = 0;
}
if (typeof(fY) == openborconstant("VT_EMPTY"))
{
fY = 0;
}
if (typeof(fZ) == openborconstant("VT_EMPTY"))
{
fZ = 0;
}
fX = fX + getentityproperty(self, "x"); //Get X location and add adjustment.
fY = fY + getentityproperty(self, "a"); //Get Y location and add adjustment.
fZ = fZ + getentityproperty(self, "z"); //Get Z location and add adjustment.
clearspawnentry(); //Clear current spawn entry.
setspawnentry("name", vName); //Acquire spawn entity by name.
vSpawn = spawn(); //Spawn in entity.
clearspawnentry();
if (!vSpawn)
{
log("\nError: spawn000 empty value= vSpawn (spawn failed for model: " + vName + ")");
return NULL();
}
changeentityproperty(vSpawn, "position", fX, fZ, fY); //Set spawn location.
return vSpawn; //Return spawn.
}
spawnRandomZ
C-like:
void spawnRandomZ(char vName, int vx, int vy, int vz)
// Spawn entity at random places
// 24.09.2013 - Douglas Baldan - O Ilusionista
// Based in Damon Caskey "spawn01" function, and you need that function to make it works.
// vx = maximum X position range
// vy = maximum Y position range
// vz = maximum Z position range
{
if (typeof(vName) != openborconstant("VT_STR")
|| !isRandRange(vx)
|| !isRandRange(vy)
|| !isRandRange(vz))
{
shutdown(1, "\n\n ERROR: spawnRandomZ(vName, vx, vy, vz) - Missing or invalid parameter.\n");
}
int Xr = rand() % vx; // Random X pos
int Yr = rand() % vy; // Random Y pos
int Zr = rand() % vz; // Random Z pos
spawn000(vName, Xr, Yr, Zr);
}
Usage:
@cmd spawnRandom "name" 50 100 120
Same as before
8. refill
Refill the MP bar with the desired value.
C-like:
void refill(int iValue)
//Refill the health with the desired value.
//Douglas Baldan
{
if (typeof(iValue) != openborconstant("VT_INTEGER"))
{
shutdown(1, "\n\n ERROR: refill(iValue) - Missing or invalid parameter.\n");
}
void self = getlocalvar("self");
if (!self)
{
return;
}
int Health = getentityproperty(self, "health"); //get health
changeentityproperty(self, "health", Health + iValue);
}
Usage:
@cmd refill 50
Same as before. Refill 50 points of MP
9. mpcost
Spend some MP
C-like:
void mpcost(int MCost)
{// Spend some mp
if (typeof(MCost) != openborconstant("VT_INTEGER"))
{
shutdown(1, "\n\n ERROR: mpcost(MCost) - Missing or invalid parameter.\n");
}
void self = getlocalvar("self");
if (!self)
{
return;
}
int MPower = getentityproperty(self, "mp"); //get mp
changeentityproperty(self, "mp", MPower - MCost); //consume mp
}
Usage:
@cmd mpcost 50
Same as before. Drains 50 points of MP
--------------------------------------
I have many other codes to share, I will edit this post once I have time.
See ya,
O Ilusionista.
Last edited: