mirror of
https://github.com/UberGames/RPG-X2.git
synced 2025-03-22 15:31:15 +00:00
Added lua library cvar which allows to get the values of cvars in lua.
This commit is contained in:
parent
363aa41389
commit
166ef0cad7
7 changed files with 136 additions and 30 deletions
|
@ -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)
|
||||
|
|
|
@ -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]++;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
84
game/lua_cvar.c
Normal file
84
game/lua_cvar.c
Normal file
|
@ -0,0 +1,84 @@
|
|||
// lua library for cvars
|
||||
|
||||
#include "g_lua.h"
|
||||
#include <string.h>
|
||||
|
||||
#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
|
|
@ -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},
|
||||
|
|
|
@ -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},
|
||||
|
|
|
@ -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}
|
||||
};
|
||||
|
||||
|
|
BIN
stefgame.suo
BIN
stefgame.suo
Binary file not shown.
Loading…
Reference in a new issue