Scripts / [STICKY] LUA Scripting commands and structure

Author
Message
Scene Commander
Support Manager
16
Years of Service
User Offline
Joined: 3rd May 2008
Location:
Posted: 12th Jun 2014 14:04 Edited at: 21st Oct 2014 12:18
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.







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
almightyhood
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 12th Jun 2014 14:19
that's great scene commander thanks, is there going to be a guide made for erm guiding us non coders through some basic how to use them in the engine please m8? like example how to scripts or something like that? would be much appreciated im sure

evga GeForce gtx 750 ti boost2.0 2gb gddr5. win 8.1 quad core 4gb ram.
PM
BarZaTTacKS
10
Years of Service
User Offline
Joined: 3rd Feb 2014
Location:
Posted: 12th Jun 2014 14:39
Thanks and I second almightyhoods request. I know my skill would increase if I had a learning resource that was accurate to what I was trying to learn. It is hard trying to translate the information found on various sites that offer LUA instruction. In a begginers mindset I am more comfortable investing time to learn something that I know I can apply right into the game, thanks for starting off with this list!
PM
Scene Commander
Support Manager
16
Years of Service
User Offline
Joined: 3rd May 2008
Location:
Posted: 12th Jun 2014 14:40
Eventually yes, I will expand on this a little, and a coding guide is being investigated.

i7-4770s 3.10ghz - Geforce GTX 650ti
almightyhood
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 12th Jun 2014 14:43
that's awesome news scene commander m8 thanks for reply

evga GeForce gtx 750 ti boost2.0 2gb gddr5. win 8.1 quad core 4gb ram.
PM
Sparrowhawk
GameGuru TGC Backer
13
Years of Service
User Offline
Joined: 12th Apr 2011
Location: Planet Magrathea
Posted: 14th Jun 2014 16:46
I see a lot of "IF" statements.

Can we not use other basic loops, eg FOR(int i = 0, i <=256, i+)?
It would make some manipulations a lot easier - as I've not seen any examples of this I can only assume its not possible? Or am I wrong? The doc's don't seem to show anything of the kind.

Passmark detects an incorrect GPU! I have 2x FirePro D500's 3GB VRAM each

Avram
GameGuru TGC Backer
18
Years of Service
User Offline
Joined: 3rd Sep 2006
Location: Serbia
Posted: 14th Jun 2014 18:38 Edited at: 14th Jun 2014 18:39
Of course you can. Here's two simple examples:







You can try to loop over g_Entity[e] this way (just replace "table" in second loop with "g_Entity[e]") and see what happens. Though, you might have some issues displaying so much data using one-line Prompt(). We should have ability to add new lines in Prompt with standard \n



p.s. IF is not a loop. It doesn't loop over anything



p.s.2. 2nd result on https://www.google.com/search?q=lua+for

Sparrowhawk
GameGuru TGC Backer
13
Years of Service
User Offline
Joined: 12th Apr 2011
Location: Planet Magrathea
Posted: 14th Jun 2014 18:51
Thanks for the tips

I know "IF" aren't loops, I've just seen quite a few scripts using IF's where a single loop such as a While(Condition true) would be far more efficient

I also wasn't sure if Reloaded LUA had less functionality to standard LUA, so I wasn't really going by the online docs, I was looking in the LUA doc that's with reloaded, which only mentions "IF's".

I'm trying to iron out bugs with the sound, but as there's a new sound system coming up, I've given up. Leaving a sound zone causes the sound to cut off sharply, so I was going to use int i = 100 to 0, change volume, but it would also need delays for that to work properly, and I'm again not sure of those in LUA.

I've bookmarked that link, I think I'll come back to this when I don't have a splitting headache, thanks for the examples as well, its good to know the syntax I get mixed up between languages now, because I have to do quite a lot on my course!

Lua seems fairly simple actually, I'm not really a fan of their formatting though, brackets and braces I now find to be very helpful when reading code. Not too fond of end-of-line ;'s though..

Passmark detects an incorrect GPU! I have 2x FirePro D500's 3GB VRAM each

Avram
GameGuru TGC Backer
18
Years of Service
User Offline
Joined: 3rd Sep 2006
Location: Serbia
Posted: 14th Jun 2014 19:13 Edited at: 14th Jun 2014 19:19
LUA will accept semicolons [;] at the end of line of code, and I think they are required if you place multiple function calls in one line (not sure, though), but they are not required in most cases.



I was working almost whole my life in C-like languages (C, C++, ASP.NET w/ C#, Java, PHP, JavaScript, ...) so I would also like the braces instead of do-end but what the hell. Been working in Delphi/Pascal and Basic long time ago so I got familiar with the syntax pretty easy



Most of the stuff from official documentation will work. However, I didn't manage to count table items with #table syntax and some other things that, at first look, should work fine. Instead I've made helper functions for most of the stuff I need.



My OOP LUA framework's main functionality (getting nearest object(s) from player/entity) actually just loops over g_Entity table, gets distance for each entity, place the entity's e number and distance into another table, sort it by distance and return it (or just one or couple of entities from that table). Simple



p.s. Note that all game code (and LUA functions) are getting executed in a game loop which is happening really fast (probably as fast as your FPS result) so I wouldn't recommend using loops such as while (condition) do ... end as it can freeze or break a game. Using loops to loop over a (not too big) set of data is okay.

Sparrowhawk
GameGuru TGC Backer
13
Years of Service
User Offline
Joined: 12th Apr 2011
Location: Planet Magrathea
Posted: 14th Jun 2014 19:21
You sound like you've rather more experience than I, haha
I've done various Basic's, C++, C-sharp*, C, Java - but only VB.net, C and Java recently.

If you know how to do distances, would you know how to raise or lower sound volume depending on proximity to object? (or the middle of a sound zone) I'm having a major issue where the sound just cuts out when you leave. Maybe assigning a sound as the default entity script which checks for the players proximity is the way to go instead?

Passmark detects an incorrect GPU! I have 2x FirePro D500's 3GB VRAM each

Avram
GameGuru TGC Backer
18
Years of Service
User Offline
Joined: 3rd Sep 2006
Location: Serbia
Posted: 14th Jun 2014 22:43
I didn't want to poison this thread and go offtopic too much (as this so far is not enough ) so here it is, in another thread.

kehagiat
11
Years of Service
User Offline
Joined: 16th Jul 2013
Location:
Posted: 21st Jun 2014 14:23
Hidden commands ??

@Scene Commander

I only saw your original post (and the rest of the thread) today. I couldn't help noticing:

!!!NOT ALL COMMANDS ARE INCLUDED!!!

For example, looking at the ai_soldier.lua script (from v1007) I see:

AIEntityStop(EntObjNo)
AIEntityGoToPosition(EntObjNo,ai_start_x[e],ai_start_z[e])
AIEntityMoveToCover(EntObjNo,g_PlayerPosX,g_PlayerPosZ)
AIGetEntityViewRange(EntObjNo)
AIPathGetPointX(ai_soldier_pathindex[e],ai_path_point_index[e])
AIPathGetPointZ(ai_soldier_pathindex[e],ai_path_point_index[e])
AICouldSee ( EntObjNo , ai_dest_x[e] , g_Entity[e]['y'] , ai_dest_z[e] )

I couldn't help noticing that these are a subset of the Dark AI function set. In fact, opening FPSC-MapEditor.exe with a text editor we can see the string "DarkAI.dll" at several points (e.g. at line 63593). And at line 64892 we can see strings for the entire set of DarkAI functions, including the much sought after "AIGetEntityAngleY". However, UNFORUNATELY, most of these commands are not active in v1007 and 10071.

All of which leads me to the following conclusions:

1. On compilation, FPSC-MapEditor.exe is linked to DarkAI.dll (and also Unity.dll / Lua.dll).
2. However, the coding/linking options are such that not all DarkAI functions are available.

So it is natural to ask: When will we get a richer DarkAI function set?

Form a coding point of view, it must be trivial to enable the additional functions. Is there a reason this has not been done yet? Because of performance issues? Because TGC do not want to give away the entire DarkAI plugin as part of FPSC-R? (Let me add that I would be totally willing to pay a higher price to get a fully-DarkAI-enabled FPSC-R). Or is it some other issue?

Scene Commander, please please please answer these questions!

Thn

Whereof one cannot speak thereof one must be silent
Avram
GameGuru TGC Backer
18
Years of Service
User Offline
Joined: 3rd Sep 2006
Location: Serbia
Posted: 22nd Jun 2014 01:46
As far as I know, they've dedicated some significant time to LUA in 1.007. Everything before and after that was focused on performance, which is from my point of view reasonable thing to do because there is no point in building on LUA if you can't have decent FPS on a slightly complex level. Now you can, so they're just starting with LUA.

I don't see how would they benefit with not giving access to those functions to us, so I guess eventually all of those functions will be supported by LUA. That's why it's important to pledge early, as that's what's pushing the development {note: I am not related to TGC in any way, except that I'm pledger for reloaded)

kehagiat
11
Years of Service
User Offline
Joined: 16th Jul 2013
Location:
Posted: 22nd Jun 2014 15:38
I am a bronze pledger, but I would be happy to go gold if there was some kind of commitment that the DarkAI functions will be available reasonably soon.

Thn

Whereof one cannot speak thereof one must be silent
Meows
12
Years of Service
User Offline
Joined: 12th Oct 2011
Location: Totally over the Rainbow
Posted: 11th Aug 2014 03:21
Keep getting the error No Function called
with this. I thought function quest1_main_init(e)
end
was the function call? then the function would run?
function quest1_main(e)

tomjscott
User Banned
Posted: 11th Aug 2014 03:53
You need a function quest1_init(e) and a function quest1_main(e)



And your script in this case should be called quest1.lua.

System Specs: OS - Windows 7 Home Premium 64-bit SP1, CPU - AMD Phenom II X4 945, 3.0Ghz, RAM - 8Gb DDR3, GFX Card - 2048MB NVIDIA GeForce GT 640, FPSC-R Version - Beta 1.0071
Meows
12
Years of Service
User Offline
Joined: 12th Oct 2011
Location: Totally over the Rainbow
Posted: 4th Sep 2014 20:39
Quote: "You need a function quest1_init(e) and a function quest1_main(e)
"


Thank u!

Teabone
Forum Support
18
Years of Service
User Offline
Joined: 8th Jun 2006
Location: Earth
Posted: 7th Oct 2014 09:28
I'm trying out LUA for the first time tonight , so this is very helpful. The basic function are nice but do we not have the ability to control the camera yet?

Currently trying to figure out how to create level specific variables, local variables and global variables (carried from map to map).

i7 -2600 CPU @ 3.40GHz - Windows 7 - 8GB RAM - Nivida GeForce 420 GT
tomjscott
User Banned
Posted: 7th Oct 2014 15:24
Quote: "The basic function are nice but do we not have the ability to control the camera yet?"

Silly you. You want to control the camera in a game engine? What were you thinking? lol. Seriously, though, this would take Lee an entire 15 minutes to implement in Lua, but it's still not there. I really have no clue why not.

System Specs: OS - Windows 7 Home Premium 64-bit SP1, CPU - AMD Phenom II X4 945, 3.0Ghz, RAM - 8Gb DDR3, GFX Card - 2048MB NVIDIA GeForce GT 640, FPSC-R Version - Beta 1.0085
hukuta94
13
Years of Service
User Offline
Joined: 4th Jan 2011
Location: Russian Federation
Posted: 13th Oct 2014 15:37
I have a question.
Why scripts only work in the folder scriptbank? If I put my script (for example) in a folder scriptbank\myscript, then FPSC Reloaded will not see my script. If I return my script in a folder scriptbank, it works. I wrote the script correctly. Script work.

Script for trigger-zone:

function terrain_init(e)
end
function terrain_main(e)
if g_Entity[e]['plrinzone']==1 then
HideTerrain()
else
ShowTerrain()
end
end
PM
Plystire
21
Years of Service
User Offline
Joined: 18th Feb 2003
Location: Staring into the digital ether
Posted: 15th Oct 2014 00:07
Quote: " this would take Lee an entire 15 minutes to implement in Lua, but it's still not there. I really have no clue why not."


Adjusting the camera is not as cut and dry as you'd think. If the engine is anything like FPSC classic, I can tell you that there's a lot more going on in the background to get in the way of camera control than you'd think. I agree that it should make it into the engine at some point or another, but right now I think Lee has a lengthy list of TODOs as it is. We will just have to wait and find out.
In the meantime, I've been thinking a lot about the current standing of the LUA implementation and might bring a list of my thoughts to the suggestion board.

I've been looking through a bunch of scripts and this thread in particular takes a lot of the research off my shoulders, so thank you, Scene Commander, for the concise list of commands! Though I did notice that this command has some of its description cut off:
"SetCharacterVisionDelay(e,v) - Sets the speed at which a "


~Plystire
tomjscott
User Banned
Posted: 15th Oct 2014 00:11
Quote: "Adjusting the camera is not as cut and dry as you'd think."


I'm pretty sure it is. Unless there are no actual functions for controlling the camera in the game engine code, which would be near impossible. You see, it's just a matter of providing a Lua wrapper for existing camera control functions. As one who has written a Lua plugin, I am very familiar with just how long it takes to put a Lua wrapper around an existing piece of code. And it's quite trivial.

System Specs: OS - Windows 7 Home Premium 64-bit SP1, CPU - AMD Phenom II X4 945, 3.0Ghz, RAM - 8Gb DDR3, GFX Card - 2048MB NVIDIA GeForce GT 640, FPSC-R Version - Beta 1.0085
hukuta94
13
Years of Service
User Offline
Joined: 4th Jan 2011
Location: Russian Federation
Posted: 27th Oct 2014 06:59
Why the scripts are only loaded from the scriptbank folder ? I want to place my scripts in my folders. How do I do this?
PM
Corno_1
GameGuru Tool Maker
13
Years of Service
User Offline
Joined: 3rd Nov 2010
Location:
Posted: 27th Oct 2014 09:57
This is not possible! But it will come soon!

My dream is to develope games, which makes fun when I create it and fun when other people play it.
PM
TheHartPony
10
Years of Service
User Offline
Joined: 29th Sep 2014
Location:
Posted: 26th Nov 2014 05:33
Hi Reloaded Team,

Is there any updates to the beta V1.009 LUA commands? Since its about to be released and all

Thanks!
PM
Teabone
Forum Support
18
Years of Service
User Offline
Joined: 8th Jun 2006
Location: Earth
Posted: 19th Dec 2014 20:14
Is there a script request thread?

i7 -2600 CPU @ 3.40GHz - Windows 7 - 8GB RAM - Nivida GeForce 420 GT
Old Larry
GameGuru TGC Backer
12
Years of Service
User Offline
Joined: 26th Apr 2012
Location: Bucharest, Romania
Posted: 29th Jan 2015 11:44
Can be changed the sky (not darkzone, or day-night, just sky change) when player enter in zone ?
Like: "sky = night" in zone, then back to "sky = clear" when the player leave the zone ?
Thanks in advance

Smile today, tomorrow could be worse

http://bestradiolarry.ro/fpsarea

"The best forum, game software, operating system or web platform, it's that software which can give you most of the options and speed, not just amazing graphics."

Login to post a reply

Server time is: 2024-10-09 12:01:49
Your offset time is: 2024-10-09 12:01:49