Hi all,
For all you budding scripters here is a list of all current LUA commands unique to
Reloaded and a brief description of what they do.
I've also attached a default script, the one to pick up
health in this case to
give scripters an idea of layout.
In the code below, four important things to note are:-
1) A script must be saved under the same name as it is referenced by in the script function. In the example below that would be
health.lua
2) A script may contain remarks (words or sentences that are
not scripting commands) and these must use the prefix --
3) All scripts must start with
function NAME_init(e)
end
In the example below is
function health_init(e)
end
4) All main script functions must start and end with
function NAME_main(e)
end
In the example below, this is
function health_main(e)
some code
end
Click the code snippet to see it all in action.
-- LUA Script - precede every function and global member with lowercase name of
script + '_main'
-- Player Collects Health
function health_init(e)
end
function health_main(e)
PlayerDX = g_Entity[e]['x'] - g_PlayerPosX;
PlayerDY = g_Entity[e]['y'] - g_PlayerPosY;
PlayerDZ = g_Entity[e]['z'] - g_PlayerPosZ;
PlayerDist = math.sqrt(math.abs(PlayerDX*PlayerDX)+math.abs(PlayerDY*PlayerDY)+math.abs
(PlayerDZ*PlayerDZ));
if PlayerDist < 80 then
PlaySound(e,0);
AddPlayerHealth(e);
Destroy(e);
end
end
Another very useful addition to the LUA scripting is the new suffix _exit.
“The _exit function in an optional routine that can be added to any script. When an entity is destroyed in game, and goes through the process of being removed from the game, the _exit function for that entity will be called, if it exists. This presents an opportunity to have a custom way for your character, object etc. to go out with a bit of style. Perhaps you would like to play a custom death sound, damage the player if he is nearby etc.”
Finally, here is a list of all the current commands, I'll keep this up to date as the scripting expands. As always, any questions please PM or email me. I don't have time to write scripts for users, but will advise and guide where possible.
Prompt(string) - Display the string for several seconds at the bottom of the screen
SetFogNearest(distance) - set the start distance of the fog
SetFogDistance(distance) - set the end distance of the fog where it is opaque
SetFogRed(red) - set the fog red component from 0 to 255
SetFogGreen(green) - set the fog green component from 0 to 255
SetFogBlue(blue) - set the fog blue component from 0 to 255
SetAmbienceIntensity(percentage) - set the ambient intensity from 0 to 100
SetAmbienceRed(red) - set the ambient red component from 0 to 255
SetAmbienceGreen(green) - set the ambient green component from 0 to 255
SetAmbienceBlue(blue) - set the ambient blue component from 0 to 255
SetSurfaceRed(red) - set the global surface red component from 0 to 255
SetSurfaceGreen(green) - set the global surface green component from 0 to 255
SetSurfaceBlue(blue) - set the global surface blue component from 0 to 255
StartTimer(entity index) - resets the timer associated with the specified entity index
GetTimer(entity index) - get the timer for the entity in milliseconds
Destroy(entity index) - destroy the specified entity
CollisionOn(entity index) - create a physics body around the specified entity
CollisionOff(entity index) - destroy the physics body around the specified entity
Hide(entity index) - hide the specified entity
Show(entity index) - show the specified entity
Spawn(entity index) - if the specified entity was not spawned at start, spawn it
Collected(entity index) - mark the specified entity has having been collected
MoveUp(entity index,amount) - move the specified entity upwards by amount
MoveForward(entity index,amount) - move the specified entity forward by amount
MoveBackward(entity index,amount) - move the specified entity backward by amount
ModulateSpeed(entity index,speed) - alter the move and animation speed of entity
SetAnimation(entity index) - set an animation index value for later use
SetAnimationFrames(entity index,v) - set an animation range for later use
PlayAnimation(entity index) - play the animation index or range as previously set
LoopAnimation(entity index) - loop the animation index or range as previously set
StopAnimation(entity index) - stop the animation for the specified entity
SetAnimationSpeed(entity index,speed) - set the animation speed of the entity
GetAnimationFrame(entity index) - get the animation frame number from the entity
CharacterControlUnarmed(entity index) - switch character to unarmed state
CharacterControlLimbo(entity index) - switch character to limbo state
CharacterControlArmed(entity index) - switch character to armed state
CharacterControlFidget(entity index) - switch character to fidget state
CharacterControlDucked(entity index) - switch character to crouched state
CharacterControlStand(entity index) - switch character to stood state
SetCharacterToWalk(entity index) - set the character to walk when moving
SetCharacterToRun(entity index) - set the character to run when moving
RotateToPlayer(entity index) - rotate the specified entity to face the player
AddPlayerWeapon(entity index) - trigger player to collect the weapon entity
AddPlayerAmmo(entity index) - trigger player to collect the ammo entity
AddPlayerHealth(entity index) - trigger player to collect the health entity
WinZone(entity index) - trigger player to win this level and move to next level
Checkpoint(entity index) - trigger player to record checkpoint for later use
GetPlayerInZone(entity index) - return 1 if the player is inside entity zone area
PlaySound(entity index,slot) - play the sound stored in the specified slot
LoopSound(entity index,slot) - loop the sound stored in the specified slot
StopSound(entity index,slot) - stop the sound stored in the specified slot
SetSoundSpeed(speed) - set the speed of the last sound handled in hertz
SetSoundVolume(volume) - set the volume of the last sound handled 0 to 100
FireWeapon(entity index) - cause the specified entity to fire at the player
Include ("ai_cover.lua") - Use within the init function to ensure the script is pre loaded
SwitchScript ( e,"ai_cover" ) - Switch AI to use a different script
SetCharacterToStrafeLeft(e) - AI to strafe to the left
SetCharacterToStrafeRight(e) - AI to strafe to the right
RotateX(e,v) - Rotate an entity along the X axis.
RotateY(e,v) - Rotate an entity along the Y axis.
RotateZ(e,v) - Rotate an entity along the Z axis.
Scale(e,v) - Scales an entity to V%
SetCharacterVisionDelay(e,v) - Sets the speed at which a
V1.008
Entity "If Used" now works.
SetEntityHealth(e,health) - can be used to set the health of an entity. If the new health is 0 then it will be destroyed.
SetPlayerHealth(health) - assign a new health value to the player (total health).
AddPlayerHealth(health) - adds additional health to the player
CollisionOff(e) - turn off physics collision for this entity (handy for a custom entity perhaps dying, where you want to turn off physics so they don't move and play a death animation)
CollisionOn(e) - restore collision for this entity
SetPosition(e,x,y,z) - sets the absolute position of an entity, use only on entities with physics off (Note: If GravityOff(e) has not been called, positioned object will still align themselves with the terrain floor)
SetRotation(e,x,y,z)- set the absolute rotation of an entity. Only for use on a non physics entity.
ResetPosition(e,x,y,z) - reposition a physics entity
GravityOff(e) - turns off non physics entities snapping to the terrain floor, handy to call inside _init
GravityOn(e) - turns on non physics entities snapping to the terrain floor
HurtPlayer(e,v) - injure the player, great for custom objects
HideTerrain() - stop the terrain drawing
ShowTerrain() - show the terrain again
HideWater() - stop water from being drawn
ShowWater() - show water again
V1.0085
PlaySoundIfSilent(e,v) - plays the entities sound if not playing
PlayNon3DSound(e,v) - play the entities sound as non-3D
TransportToIfUsed(e) - moves the player to the position of the object in the IFUSED field
FinishLevel() - Forces the level to finish.
PlayCombatMusic(playTime,fadeTime) - Plays the combat music
PlayFinalAssaultMusic(fadeTime) - Plays the assault music
Coming Soon - V1.009 - Teaser
g_PlayerLives = 0 - can read the current number of player lives
PromptTextSize(v) - change the size of the prompt text from 1 through 5, 5 being largest
HideHuds() - hide huds for weapon and player status
ShowHuds() - show huds for weapon and player status
FreezeAI() - freeze all DarkAI activity used by character AI
UnFreezeAI() - unfreeze all DarkAI activity used by character AI
FreezePlayer() - freeze the ability of the player to move, mouselook or take action
UnFreezePlayer() - [unfreeze the ability of the player to move, mouselook or take action
DisableMusicReset(v) - call at start of game to suspend normal music restart behaviour
LoadImages(str,v) - specify a folder inside 'scriptbank\images\"' to load images at slot V onwards
SetImagePosition(x,y) - set the X and Y position of where the image should be drawn
ShowImage(i) - select the image slot number to be drawn
HideImage(i) - hide the image from being drawn
SetImageAlignment(i) - use 0 to position image using center hotspot, 1 is top left hotspot
i7-4770s 3.10ghz - Geforce GTX 650ti