Lua Interface - MyEyes/Igorr GitHub Wiki
This article is ment to give an overview for the lua interface used for scripting in the game.
Name | Parameters | Description |
---|---|---|
Text(string) | Prints Text to the server window. Used for debug purposes. | |
GetInfo | Client(string), Name(string) | Gets client/account specific info(int32). Name specifies the handle of the information |
SetInfo | Client(string), Name(string), value(int32) | Sets client/account specific info. Name specifies handle of info, value specifies value to set. |
GetGlobal | Name(string) | Gets value(bool) of a global trigger |
SetGlobal | Name(string), value(bool) | Sets value of a global trigger |
There is a generic interface for NPCs this part describes the scripting aspect of it.
LuaNPCs have an internal command queue. The job of the script file is to fill this command queue in a way that makes sense using predefined commands. An LuaNPC script file is a lua module that should implement some or all of the functions defined in this table. Functions with a trigger will only be triggered when the appropriate trigger is set to true.
Name | Parameters | Description | Mandatory | Triggered By (when true) |
---|---|---|---|---|
spawn | Called when NPC spawns, use for setup | ✔ | ||
spawn_equip | Called after NPC spawns, use to equip NPC | ✔ | ||
react_attackReady | Called when the attack cooldown runs out | reacts_attackReady | ||
react_idle | Called when the command queue is empty | reacts_idle | ||
react_spotEnemy | Called when an enemy comes close enough to be spotted | reacts_spotEnemy | ||
react_spotFriendly | Called when a friendly player comes close enough to be spotted | reacts_spotFriendly | ||
react_damageTaken | Called when damage is taken | reacts_damageTaken | ||
interact | sinfo(string), info(int) | Called when a player tries to interact with the NPC. | interacts |
Name | Description |
---|---|
lookingForTarget | If set to true this NPC will poll for Enemies in the surrounding area |
lookingForFriendly | If set to true this NPC will poll for friendly Players in the surrounding area |
When any of the events are triggered the Lua VM will set the local variable "me" to the value of the NPC. If another player is involved that player will be set to "enemy" no matter wether he is actually friendly or not. The exception being the interact method which sets the interacting player to "player"
The following table contains the calls that can be made to "me" from the script.
Name | Parameters | Description |
---|---|---|
ClearState | Empties the Command Queue | |
Move | time(int), dir(float) | Adds a move command to the command queue that will move in the direction dir for time milliseconds. |
Wait | time(int) | Adds a command to the command queue that will wait for time milliseconds. |
JumpCmd | Adds a command to the command queue that will jump immediately. | |
SetAnimation | force(bool), id(int) | Sets a custom animation for the NPC, if force is set to false the NPC reverts back to default animations. |
Say | Text(string), timeout(float) | Creates a Text bubble containing Text that will dissapear after timeout seconds |
Say | Text(string), timeout(float), player(Player) | Creates a Text bubble containing Text that will dissappear after timeout seconds and is only visible to player |
Ask | questionString(string), player(Player) | Opens a text bubble for player that can contain multiple choices and only dissapears after a choice is made or it is canceled. |
The question string has the following format:
string+(';'+string+';'+string)*
Text +(';'+ID +';'+choice)*
Example: "Do you see this Question?;1;Yes!;2;No!"
Here while ID is a string it must be convertible to an integer by int.Parse. Important when the client has made his choice it causes a new call to interact where info will be set to the choices id!
module(..., package.seeall)
function spawn()
me.interacts=true
end
function spawn_equip()
end
function react_attackReady()
end
function react_idle()
end
function react_spotEnemy()
end
function react_spotFriendly()
end
function react_damageTaken()
end
function interact(sinfo, info)
flag = GetInfo(player.Name,"TalksToChickens");
if(flag == -1) then
SetInfo(player.Name,"TalksToChickens", 0);
me:Ask("Do you always talk\nto Chickens?;0;Yes;0;Mmmhh Chicken", player);
elseif(info == 0 and flag == 0) then
me:Ask("Do you see this Question?;1;Yes!;2;No :(;3;What can you do?", player);
elseif (info==1) then
me:Say("Great!", 2000, player);
elseif (info==2) then
me:Say("Oh no!", 2000, player);
elseif (info==3) then
me:Ask("Hello!\nI can lay eggs.\nWith those eggs you\ncan blow people up!;4;And then?", player);
elseif (info==4) then
me:Say("You can now throw eggs!\nGive it a try.", 3500, player);
player:GivePart(80);
end
end