From 166ef0cad744ee2ffcca682d28f5800ab72a2d82 Mon Sep 17 00:00:00 2001 From: UberGames Date: Tue, 26 Jul 2011 00:02:53 +0200 Subject: [PATCH] Added lua library cvar which allows to get the values of cvars in lua. --- game/Makefile | 4 ++- game/g_weapon.c | 8 ----- game/lua_cvar.c | 84 +++++++++++++++++++++++++++++++++++++++++++++ game/lua_entity.c | 1 - game/lua_game.c | 48 ++++++++++++++++++++++++++ game/lua_weapons.c | 21 +----------- stefgame.suo | Bin 204800 -> 204800 bytes 7 files changed, 136 insertions(+), 30 deletions(-) create mode 100644 game/lua_cvar.c diff --git a/game/Makefile b/game/Makefile index ff6e80a..d17e814 100644 --- a/game/Makefile +++ b/game/Makefile @@ -75,7 +75,8 @@ OBJ = \ lua_cinematic.o \ lua_sound.o \ lua_weapons.o \ - lua_trace.o + lua_trace.o \ + lua_cvar.o # game object for syscalls to the engine SOOBJ = \ @@ -176,6 +177,7 @@ lua_cinematic.o: lua_cinematic.c; $(DO_CC) lua_sound.o: lua_sound.c; $(DO_CC) lua_weapons.o: lua_weapons.c; $(DO_CC) lua_trace.o: lua_trace.c; $(DO_CC) +lua_cvar.o: lua_cvar.c; $(DO_CC) # game syscalls g_syscalls.o : g_syscalls.c; $(DO_CC) diff --git a/game/g_weapon.c b/game/g_weapon.c index 47640a6..3f216d0 100644 --- a/game/g_weapon.c +++ b/game/g_weapon.c @@ -243,14 +243,6 @@ void WP_FirePhaser( gentity_t *ent, qboolean alt_fire ) } } } - if (damage) - { - // log hit - /*if (ent->client) - { - ent->client->ps.persistant[PERS_ACCURACY_HITS]++; - }*/ - } } diff --git a/game/lua_cvar.c b/game/lua_cvar.c new file mode 100644 index 0000000..df9b089 --- /dev/null +++ b/game/lua_cvar.c @@ -0,0 +1,84 @@ +// lua library for cvars + +#include "g_lua.h" +#include + +#ifdef G_LUA + + +static int Cvar_Integer(lua_State *L) { + char *cvar; + char buf[1024]; + + cvar = (char *)luaL_checkstring(L, 1); + if(!cvar[0]) { + lua_pushinteger(L, 0); + return 1; + } + if(strstr(Q_strlwr(cvar), "password") != NULL + || strstr(Q_strlwr(cvar), "pass") != NULL + || strstr(Q_strlwr(cvar), "sql") != NULL) { + lua_pushinteger(L, 0); + return 1; + } + trap_Cvar_VariableStringBuffer(cvar, buf, sizeof(buf)); + lua_pushinteger(L, atoi(buf)); + + return 1; +} + +static int Cvar_Value(lua_State *L) { + char *cvar; + char buf[1024]; + + cvar = (char *)luaL_checkstring(L, 1); + if(!cvar[0]) { + lua_pushnumber(L, 0); + return 1; + } + if(strstr(Q_strlwr(cvar), "password") != NULL + || strstr(Q_strlwr(cvar), "pass") != NULL + || strstr(Q_strlwr(cvar), "sql") != NULL) { + lua_pushnumber(L, 0); + return 1; + } + trap_Cvar_VariableStringBuffer(cvar, buf, sizeof(buf)); + lua_pushnumber(L, atof(buf)); + + return 1; +} + +static int Cvar_String(lua_State *L) { + char *cvar; + char buf[1024]; + + cvar = (char *)luaL_checkstring(L, 1); + if(!cvar[0]) { + lua_pushstring(L, ""); + return 1; + } + if(strstr(Q_strlwr(cvar), "password") != NULL + || strstr(Q_strlwr(cvar), "pass") != NULL + || strstr(Q_strlwr(cvar), "sql") != NULL) { + lua_pushstring(L, ""); + return 1; + } + trap_Cvar_VariableStringBuffer(cvar, buf, sizeof(buf)); + lua_pushstring(L, buf); + + return 1; +} + +static const luaL_Reg lib_cvar[] = { + {"Integer", Cvar_Integer}, + {"Value", Cvar_Value}, + {"String", Cvar_String}, + {NULL, NULL} +}; + +int Luaopen_Cvar(lua_State *L) { + luaL_register(L, "cvar", lib_cvar); + + return 1; +} +#endif \ No newline at end of file diff --git a/game/lua_entity.c b/game/lua_entity.c index 10c241a..71ceedd 100644 --- a/game/lua_entity.c +++ b/game/lua_entity.c @@ -816,7 +816,6 @@ static int Entity_SetParm(lua_State *L) { static const luaL_Reg Entity_ctor[] = { {"Spawn", Entity_Spawn}, - {"Find", Entity_Find}, {"FindNumber", Entity_FindNumber}, {"FindBModel", Entity_FindBModel}, diff --git a/game/lua_game.c b/game/lua_game.c index 4162258..f7a67a9 100644 --- a/game/lua_game.c +++ b/game/lua_game.c @@ -296,7 +296,55 @@ static int Game_Leveltime(lua_State * L) return 1; } +static int Game_Damage(lua_State *L) { + lent_t *lent; + gentity_t *targ = NULL, *inflictor = NULL, *attacker = NULL; + vec_t *dir = NULL, *point = NULL; + int damage = 0, dflags = 0, mod = 0; + + lent = Lua_GetEntity(L, 1); + if(!lent || !lent->e) return 1; + targ = lent->e; + if(!lua_isnil(L, 2)) { + lent = Lua_GetEntity(L, 2); + if(lent && lent->e) + inflictor = lent->e; + } + if(!lua_isnil(L, 3)) { + lent = Lua_GetEntity(L, 3); + if(lent && lent->e) + attacker = lent->e; + } + if(!lua_isnil(L, 4)) + dir = Lua_GetVector(L, 4); + if(!lua_isnil(L, 5)) + point = Lua_GetVector(L, 5); + damage = (int)luaL_checknumber(L, 6); + dflags = (int)luaL_checknumber(L, 7); + mod = (int)luaL_checknumber(L, 8); + + G_Damage(targ, inflictor, attacker, dir, point, damage, dflags, mod); + + return 1; +} + +static int Game_Repair(lua_State *L) { + lent_t *lent; + float rate; + + lent = Lua_GetEntity(L, 1); + if(!lent || !lent->e) return 1; + + rate = (float)luaL_checknumber(L, 2); + + G_Repair(lent->e, rate); + + return 1; +} + static const luaL_Reg lib_game[] = { + {"Damage", Game_Damage}, + {"Repair", Game_Repair}, {"Print", Game_Print}, {"MessagePrint", Game_MessagePrint}, {"CenterPrint", Game_CenterPrint}, diff --git a/game/lua_weapons.c b/game/lua_weapons.c index 975d4fa..1c229d3 100644 --- a/game/lua_weapons.c +++ b/game/lua_weapons.c @@ -3,29 +3,10 @@ #include "g_lua.h" #ifdef G_LUA -static int Weapons_DoTrace(lua_State *L) { - /* - things that should be returned/set by this: - * tr.entityNum - * tr.fraction - */ - /*trace_t tr; - vec_t *start, *mins, *maxs, *end; - int passEntNum, contentMask; - start = Lua_GetVector(L, 1); - mins = Lua_GetVector(L, 2); - maxs = Lua_GetVector(L, 3); - end = Lua_GetVector(L, 4); - passEntNum = luaL_checknumber(L, 5); - - trap_Trace(&tr, start, mins, maxs, end, passEntNum, contentMask);*/ - - return 1; -} static const luaL_Reg lib_weapons[] = { - {"DoTrace", Weapons_DoTrace}, + {NULL, NULL} }; diff --git a/stefgame.suo b/stefgame.suo index 84c8b7840c3fb0df5514a7d7a617545d8cc1a384..5b3cf5dd948e25ac618bb84006139a3774f16dc9 100644 GIT binary patch delta 150 zcmZoTz|(MmXG1Ov>*q(i_`Nq5u>`WSF$gm* C*gRMO delta 155 zcmZoTz|(MmXG1Ov>xUCNHN7?$u>`WSF$yy>FbGX&oWi8t{Dph_7jDM$UIG=XW_V^y zxX83ce7Vbi^1k$=dGVFC%=8o!nt_K*6D%=8O7VP<}q&1 zn#Xk0YqB%9;q;Q1O#UFo_AfvN%k;w%%!b=b-Z2GeamWB|`ws-u75bQzCL6G@ZT}*{ H%)<@<&PF|T