Jump to content

Home

Lua


ensiform

Recommended Posts

Lua is a programming language now being widely used for many script situations for games, such as Far Cry/Crysis? HL2, etc, ETPro, etc.

 

Currently, I'm trying to get ICARUS removed and adding in Lua to JKA. Eventually, I would like to add a regular API where people can add scripts that control other things than map scripting similar to what ETPro does but not quite advanced because I felt they went a little overkill with supporting so much stuff.

 

As of right now, you can call the following:

 

game.Print(string...)
integer = game.Time()
game.Broadcast(string...)
entity = game.FindEntity(string)
entity = game.FindScriptEntity(string)
game.Remove(string)
game.Declare(type string, string)
game.Set(ent, string, string)
game.SetVar(string, string)
string = game.GetString(ent, string)
number = game.GetFloat(ent, string)
vector = game.GetVector(ent, string)
string = game.GetStringVar(string)
number = game.GetFloatVar(string)
vector = game.GetVectorVar(string)
game.UseEnt(ent, string)
game.PlaySound(ent, string, string)

game.Version = "base_lua"

sys.Printf(string...)
sys.LogPrintf(string...)
integer = sys.Argc()
string = sys.Argv(number)
integer = sys.Time()
string = sys.Cvar_Get(string)
sys.Cvar_Set(string, string)
sys.Cvar_Clear(string)
sys_Command(integer, string)

sys.Version = "base_lua"
sys.EXEC_NOW = 0
sys.EXEC_INSERT = 1
sys.EXEC_APPEND = 2

number = entity.GetNumber(ent)
boolean = entity.IsClient(ent)
vector = entity.Spawn()
entity.Print(ent, string...)
entity.CenterPrint(ent, string...)
string = entity.ToString(ent)

number = qmath.abs(number)
number = qmath.sin(number)
number = qmath.cos(number)
number = qmath.tan(number)
number = qmath.asin(number)
number = qmath.acos(number)
number = qmath.atan(number)
number = qmath.atan2(number, number)
number = qmath.ceil(number)
number = qmath.floor(number)
number = qmath.fmod(number, number)
number, number = qmath.modf(number)
number = qmath.sqrt(number)
number = qmath.pow(number, number)
number = qmath.log(number)
number = qmath.log10(number)
number = qmath.exp(number)
number = qmath.deg(number)
number = qmath.rad(number)
number = qmath.frexp(number)
number = qmath.ldexp(number, integer)
number = qmath.min(number...)
number = qmath.max(number...)
number = qmath.random() - random num between 0 and 1
number = qmath.random(integer) - random int between 1 and number
number = qmath.random(integer, integer) - random int between num1 and num2
qmath.randomseed(integer)

qmath.pi = 3.14159265358979323846f
qmath.huge = not really sure on this one (suz)

vector = vector.New()
vector = vector.Construct(number, number, number)
vector.Set(vector, number, number, number)
number = vector.__index(vector, string)
vector.__newindex(vector, string)
string = vector.__tostring(vector)

strlib also works (for string.format, string.find, etc)

 

if you change the . between the main type and the function to a _ it becomes a global function instead of a local function. ... signifies a va type arg expected

Link to comment
Share on other sites

Scripts that work now with Lua:

mp/wander.lua {

-- Set Droid to Wander
local droid = game.FindEntity("droidhead")
game.Set(droid, "SET_BEHAVIOR_STATE", "BS_WANDER")
return 1

}

mp/siege_desert.lua {

-- Spawn Swoops
local ent1 = game.FindEntity("worldspawn_script")
game.UseEnt(ent1, "swoop1");
game.UseEnt(ent1, "swoop2");
game.UseEnt(ent1, "swoop3");
game.UseEnt(ent1, "swoop4");
game.UseEnt(ent1, "swoop5");
game.UseEnt(ent1, "swoop6");
game.UseEnt(ent1, "swoop7");
game.UseEnt(ent1, "swoop8");
game.UseEnt(ent1, "swoop9");
game.UseEnt(ent1, "swoop10");
game.UseEnt(ent1, "swoop11");
game.UseEnt(ent1, "swoop12");
game.UseEnt(ent1, "swoop13");
game.UseEnt(ent1, "swoop14");
game.UseEnt(ent1, "swoop15");
game.UseEnt(ent1, "swoop16");
return 1

}

mp/siege_hoth/atst_forward.lua {

-- Change Target On ATST
local atst = game.FindEntity("atst_rear")
game.Set(atst, "SET_TARGET", "atst_2")
return 1

}

mp/siege_hoth/hangar_turrets.lua {

-- Remove Hangar Turrets On Hoth
game.Remove("hangar_turrets")
return 1

}

mp/siege_hoth/npc_spawner.lua {

-- Call the AT-ST to Spawn
local ent1 = game.FindEntity("worldspawn_script")
game.UseEnt(ent1, "atst_1")
return 1

}

 

Unused Scripts:

mp/siege_hoth/update_atst_spawnpoint

mp/siege_hoth/atst_death

mp/siege3_shipspawn

Link to comment
Share on other sites

Well for starters: ICARUS scripts need to be compiled to something we cannot read and Lua is just raw script files that we can, plus with a cmd you can load on the fly.

 

And because ICARUS code is not shared to us, we cannot change it much from what is not already in the server code, but since I have full access to Lua and am in total control of it, I can do practically anything and everything with it.

Link to comment
Share on other sites

Working on simple task functions too but Not really sure what exactly they will do, and it would be nice to see the actual ICARUS engine code.

 

void lua_TaskIDClear( int *taskID ) {
*taskID = -1;
}

qboolean lua_TaskIDPending(gentity_t *ent, int taskType) {
if ( ent->taskID[taskType] >= 0 ) {
	return qtrue;
} else {
	return qfalse;
}
}

void lua_TaskIDSet(gentity_t *ent, int taskType, int taskID) {
int i = 0;
for ( i = 0; i < 10; i++) {
	if (ent->taskID[i] = taskID)
		return;
}
ent->taskID[taskType] = taskID;
}

void lua_TaskIDComplete(gentity_t *ent, int taskType) {
ent->taskID[taskType] = -1;
}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...