static int Entity_equal (lua_State *L) { centity_t *e1 = lua_toentity(L,1); centity_t *e2 = lua_toentity(L,2); if(e1 != NULL && e2 != NULL) { //CG_Printf("EQ CHECK: %i %i\n",e1->currentState.clientNum,e2->currentState.clientNum); lua_pushboolean(L, (e1->currentState.clientNum == e2->currentState.clientNum) && (e1->currentState.number == e2->currentState.number)); } else { lua_pushboolean(L, 0); } return 1; }
int qlua_getclientinfo(lua_State *L) { centity_t *luaentity; clientInfo_t *ci; luaL_checktype(L,1,LUA_TUSERDATA); luaentity = lua_toentity(L,1); if(luaentity != NULL) { ci = &cgs.clientinfo[ luaentity->currentState.clientNum ]; if(cg.snap && cg.snap->ps.commandTime != 0) { if(luaentity->currentState.clientNum == cg.clientNum) { ci->health = cg.snap->ps.stats[STAT_HEALTH]; ci->armor = cg.snap->ps.stats[STAT_ARMOR]; ci->curWeapon = cg.snap->ps.weapon; #ifndef LUA_WEAPONS ci->ammo = cg.snap->ps.ammo[ci->curWeapon]; #else ci->ammo = BG_GetAmmo(cg.snap->ps.clientNum, ci->curWeapon); #endif } else { ci->health = luaentity->currentState.health; } } CG_PushClientInfoTab(L,ci); } return 1; }
static int l_Entity_addComponent(lua_State* L) { auto entity = lua_toentity(L, 1); auto component = lua_tocomponent(L, 2); entity->addComponent(component); return 0; }
static int l_Entity_setName(lua_State* L) { auto entity = lua_toentity(L, 1); auto name = luaL_checkstring(L, 2); entity->setName(stringType(name)); return 0; }
int luautil_getviewheight(lua_State *L) { gentity_t *ent = lua_toentity(L,1); if(ent == NULL || ent->client == NULL) return 0; lua_pushinteger(L,ent->client->ps.viewheight); return 1; }
int qlua_link(lua_State *L) { centity_t *ent; luaL_checktype(L,1,LUA_TUSERDATA); ent = lua_toentity(L,1); if(ent != NULL) { //qlua_LinkEntity(ent); } return 0; }
int qlua_entityid(lua_State *L) { centity_t *luaentity; luaL_checktype(L,1,LUA_TUSERDATA); luaentity = lua_toentity(L,1); if(luaentity != NULL) { lua_pushinteger(L,luaentity->currentState.number); } return 1; }
int qlua_stopsounds(lua_State *L) { centity_t *luaentity; luaL_checktype(L,1,LUA_TUSERDATA); luaentity = lua_toentity(L,1); if(luaentity != NULL) { trap_S_StopLoopingSound(luaentity->currentState.number); } return 0; }
int qlua_aimvec(lua_State *L) { centity_t *luaentity; luaL_checktype(L,1,LUA_TUSERDATA); luaentity = lua_toentity(L,1); if(luaentity != NULL) { lua_pushvector(L,luaentity->currentState.angles); return 1; } return 0; }
int qlua_getlerpangles(lua_State *L) { centity_t *luaentity; luaL_checktype(L,1,LUA_TUSERDATA); luaentity = lua_toentity(L,1); if(luaentity != NULL) { lua_pushvector(L,luaentity->lerpAngles); return 1; } return 0; }
int qlua_gettrx(lua_State *L) { centity_t *luaentity; luaL_checktype(L,1,LUA_TUSERDATA); luaentity = lua_toentity(L,1); if(luaentity != NULL) { lua_pushtrajectory(L,&luaentity->currentState.pos); return 1; } return 0; }
int lua_customdraw(lua_State *L) { centity_t *luaentity; luaL_checktype(L,1,LUA_TUSERDATA); luaL_checktype(L,2,LUA_TBOOLEAN); luaentity = lua_toentity(L,1); if(luaentity != NULL) { luaentity->customdraw = lua_toboolean(L,2); } return 0; }
int qlua_getflags(lua_State *L) { centity_t *luaentity; luaL_checktype(L,1,LUA_TUSERDATA); luaentity = lua_toentity(L,1); if(luaentity != NULL) { lua_pushinteger(L,luaentity->currentState.eFlags); return 1; } return 0; }
int qlua_gettorsoanim(lua_State *L) { centity_t *luaentity; luaL_checktype(L,1,LUA_TUSERDATA); luaentity = lua_toentity(L,1); if(luaentity != NULL) { lua_pushinteger(L, (luaentity->currentState.torsoAnim & ~ANIM_TOGGLEBIT)); return 1; } return 0; }
int qlua_getflashtime(lua_State *L) { centity_t *luaentity; luaL_checktype(L,1,LUA_TUSERDATA); luaentity = lua_toentity(L,1); if(luaentity != NULL) { lua_pushnumber(L,luaentity->muzzleFlashTime); return 1; } return 0; }
int qlua_getpos(lua_State *L) { centity_t *luaentity = lua_toentity(L,1); //luaL_checktype(L,1,LUA_TUSERDATA); //luaentity = lua_toentity(L,1); if(luaentity != NULL) { lua_pushvector(L,luaentity->lerpOrigin); return 1; } return 0; }
int qlua_getmisctime(lua_State *L) { centity_t *luaentity; luaL_checktype(L,1,LUA_TUSERDATA); luaentity = lua_toentity(L,1); if(luaentity != NULL) { lua_pushinteger(L,luaentity->miscTime); return 1; } return 0; }
int qlua_setangles(lua_State *L) { centity_t *luaentity; luaL_checktype(L,1,LUA_TUSERDATA); luaL_checktype(L,2,LUA_TVECTOR); luaentity = lua_toentity(L,1); if(luaentity != NULL) { lua_tovector(L,2,luaentity->currentState.angles); return 1; } return 0; }
int qlua_getbytedir(lua_State *L) { centity_t *luaentity; vec3_t dir; luaL_checktype(L,1,LUA_TUSERDATA); luaentity = lua_toentity(L,1); if(luaentity != NULL) { ByteToDir( luaentity->currentState.eventParm, dir ); lua_pushvector(L,dir); return 1; } return 0; }
int qlua_getotherentity2(lua_State *L) { centity_t *luaentity; luaL_checktype(L,1,LUA_TUSERDATA); luaentity = lua_toentity(L,1); if(luaentity != NULL) { if(luaentity->currentState.otherEntityNum2 != ENTITYNUM_MAX_NORMAL) { lua_pushentity(L,&cg_entities[ luaentity->currentState.otherEntityNum2 ]); return 1; } } return 0; }
static int l_Entity_getComponents(lua_State* L) { auto entity = lua_toentity(L, 1); auto componentList = entity->getComponentContainer(); //pre-allocating space for our components lua_createtable(L, componentList.size(), 0); int i = 0; for (auto component : componentList) { lua_pushcomponent(L, component); lua_rawseti(L, -2, i+1); i++; } return 1; }
int qlua_getmodelindex(lua_State *L) { centity_t *luaentity; entityState_t *s1; luaL_checktype(L,1,LUA_TUSERDATA); luaentity = lua_toentity(L,1); if(luaentity != NULL) { s1 = &luaentity->currentState; lua_pushinteger(L,s1->modelindex); lua_pushinteger(L,s1->modelindex2); return 2; } return 0; }
int lua_cggetentitytable(lua_State *L) { centity_t *luaentity; luaL_checktype(L,1,LUA_TUSERDATA); luaentity = lua_toentity(L,1); if(luaentity != NULL) { //CG_Printf("ReCalled Table At %i\n",luaentity->luatablecent); lua_cgentitytab(L,luaentity); if(qlua_getstored(L,luaentity->luatablecent)) { return 1; } } return 0; }
static int l_Entity_getComponentsByName(lua_State* L) { auto entity = lua_toentity(L, 1); stringType componentName = luaL_checkstring(L, 2); auto componentList = entity->getComponentsByName(componentName); lua_createtable(L, componentList.size(), 0); int i = 0; for (auto component : componentList) { lua_pushcomponent(L, component); lua_rawseti(L, -2, i+1); i++; } return 1; }
int lua_getweapon(lua_State *L) { centity_t *luaentity; entityState_t *s1; luaL_checktype(L,1,LUA_TUSERDATA); luaentity = lua_toentity(L,1); if(luaentity != NULL) { s1 = &luaentity->currentState; if ( s1->weapon > WP_NUM_WEAPONS ) { s1->weapon = 0; } lua_pushinteger(L,s1->weapon); return 1; } return 0; }
int qlua_isbot(lua_State *L) { centity_t *luaentity; clientInfo_t *ci; luaL_checktype(L,1,LUA_TUSERDATA); luaentity = lua_toentity(L,1); if(luaentity != NULL) { ci = &cgs.clientinfo[ luaentity->currentState.clientNum ]; if(ci != NULL && ci->botSkill != 0) { lua_pushboolean(L,1); } else { lua_pushboolean(L,0); } return 1; } return 0; }
int qlua_setpos(lua_State *L) { centity_t *luaentity; vec3_t origin; luaL_checktype(L,1,LUA_TUSERDATA); luaL_checktype(L,2,LUA_TVECTOR); luaentity = lua_toentity(L,1); if(luaentity != NULL) { BG_EvaluateTrajectory( &luaentity->currentState.pos, cg.time, origin ); lua_tovector(L,2,luaentity->currentState.pos.trBase); luaentity->currentState.pos.trDuration += (cg.time - luaentity->currentState.pos.trTime); luaentity->currentState.pos.trTime = cg.time; VectorCopy(luaentity->currentState.pos.trBase, luaentity->currentState.origin); return 1; } return 0; }
int qlua_trace(lua_State *L) { trace_t results; vec3_t start, end; vec3_t mins, maxs; centity_t *ent; int pass=ENTITYNUM_NONE, mask=MASK_ALL; int top = lua_gettop(L); if(top > 1) { lua_tovector(L,1,start); lua_tovector(L,2,end); VectorSet(mins,vec3_origin[0],vec3_origin[1],vec3_origin[2]); VectorSet(maxs,vec3_origin[0],vec3_origin[1],vec3_origin[2]); if(top > 2) { if(lua_type(L,3) == LUA_TNUMBER) { pass = lua_tointeger(L,3); } else if(lua_type(L,3) == LUA_TUSERDATA) { ent = lua_toentity(L,3); if(ent != NULL) { pass = ent->currentState.number; } } if(top > 3) mask = lua_tointeger(L,4); if(top > 4) { if(lua_type(L,5) == LUA_TVECTOR) lua_tovector(L,5,mins); if(lua_type(L,6) == LUA_TVECTOR) lua_tovector(L,6,maxs); } } CG_Trace(&results,start,mins,maxs,end,pass,mask); lua_pushtrace(L, results); return 1; } return 0; }
static int l_Entity_getComponentsByFamily(lua_State* L) { auto entity = lua_toentity(L, 1); auto familyString = stringType(luaL_checkstring(L, 2)); partialComponentListType componentList; if (familyString == "ABSTRACT") { componentList = entity->getComponentsByFamily( enumComponentFamily::ABSTRACT); } else if (familyString == "COLLISION") { componentList = entity->getComponentsByFamily( enumComponentFamily::COLLISION); } else if (familyString == "PHYSICS") { componentList = entity->getComponentsByFamily( enumComponentFamily::PHYSICS); } else if (familyString == "GRAPHICS") { componentList = entity->getComponentsByFamily( enumComponentFamily::GRAPHICS); } else if (familyString == "CUSTOM") { componentList = entity->getComponentsByFamily( enumComponentFamily::CUSTOM); } else { luaL_error(L, "Incorrect family type"); } lua_createtable(L, componentList.size(), 0); int i = 0; for (auto component : componentList) { lua_pushcomponent(L, component); lua_rawseti(L, -2, i+1); i++; } return 1; }
static int l_Entity_getID(lua_State* L) { auto entity = lua_toentity(L, 1); auto ID = entity->getID(); lua_pushnumber(L, ID); return 1; }