Ejemplo n.º 1
0
int JPLua_Export_Trace( lua_State *L ) {
	trace_t tr;
	vector3 *start, *end, mins, maxs;
	float size;
	int skipNumber, mask;
	int top, top2, top3;

	start = JPLua_CheckVector(L, 1);

	size = lua_tonumber( L, 2 ) / 2.0f;
	VectorSet( &mins, size, size, size );
	VectorScale( &mins, -1.0f, &maxs );

	end = JPLua_CheckVector(L, 3);

	skipNumber = lua_tointeger( L, 4 );
	mask = lua_tointeger( L, 5 );

#if defined(PROJECT_GAME)
	trap->Trace( &tr, start, &mins, &maxs, end, skipNumber, mask, qfalse, 0, 0 );
#elif defined(PROJECT_CGAME)
	CG_Trace( &tr, start, &mins, &maxs, end, skipNumber, mask );
#endif

	lua_newtable( L );
	top = lua_gettop( L );
	lua_pushstring( L, "allsolid" ); lua_pushboolean( L, !!tr.allsolid ); lua_settable( L, top );
	lua_pushstring( L, "startsolid" ); lua_pushboolean( L, !!tr.startsolid ); lua_settable( L, top );
	lua_pushstring( L, "entityNum" ); lua_pushinteger( L, tr.entityNum ); lua_settable( L, top );
	lua_pushstring( L, "fraction" ); lua_pushnumber( L, tr.fraction ); lua_settable( L, top );

	lua_pushstring( L, "endpos" );
	lua_newtable( L ); top2 = lua_gettop( L );
	lua_pushstring( L, "x" ); lua_pushnumber( L, tr.endpos.x ); lua_settable( L, top2 );
	lua_pushstring( L, "y" ); lua_pushnumber( L, tr.endpos.y ); lua_settable( L, top2 );
	lua_pushstring( L, "z" ); lua_pushnumber( L, tr.endpos.z ); lua_settable( L, top2 );
	lua_settable( L, top );

	lua_pushstring( L, "plane" );
	lua_newtable( L ); top2 = lua_gettop( L );
	lua_pushstring( L, "normal" );
	lua_newtable( L ); top3 = lua_gettop( L );
	lua_pushstring( L, "x" ); lua_pushnumber( L, tr.plane.normal.x ); lua_settable( L, top3 );
	lua_pushstring( L, "y" ); lua_pushnumber( L, tr.plane.normal.y ); lua_settable( L, top3 );
	lua_pushstring( L, "z" ); lua_pushnumber( L, tr.plane.normal.z ); lua_settable( L, top3 );
	lua_settable( L, top2 );
	lua_pushstring( L, "dist" ); lua_pushnumber( L, tr.plane.dist ); lua_settable( L, top2 );
	lua_pushstring( L, "type" ); lua_pushinteger( L, tr.plane.type ); lua_settable( L, top2 );
	lua_pushstring( L, "signbits" ); lua_pushinteger( L, tr.plane.signbits ); lua_settable( L, top2 );
	lua_settable( L, top );

	lua_pushstring( L, "surfaceFlags" ); lua_pushinteger( L, tr.surfaceFlags ); lua_settable( L, top );
	lua_pushstring( L, "contents" ); lua_pushinteger( L, tr.contents ); lua_settable( L, top );
	return 1;
}
Ejemplo n.º 2
0
static int JPLua_EntitiesInBox(lua_State *L){
	vector3 *mins = JPLua_CheckVector(L, 1);
	vector3 *maxs = JPLua_CheckVector(L, 2);
	int entityList[MAX_GENTITIES], numListedEntities;
	gentity_t *ent;
	numListedEntities = trap->EntitiesInBox(mins, maxs, entityList, MAX_GENTITIES);

	lua_newtable(L);
	int top = lua_gettop(L);

	for (int i = 0; i < numListedEntities; i++) {
		ent = &g_entities[entityList[i]];
			lua_pushinteger(L, i + 1);
		JPLua_Entity_CreateRef(L, ent);
		lua_settable(L, top);
	}
	return 1;
}
Ejemplo n.º 3
0
static int JPLua_ScreenShake(lua_State *L){
	vector3 *origin = JPLua_CheckVector(L, 1);
	float intense = luaL_checknumber(L, 2);
	int duration = luaL_checkinteger(L, 3);
	qboolean global = lua_toboolean(L, 4);

	G_ScreenShake(origin, NULL, intense, duration, global);
	return 0;
}
Ejemplo n.º 4
0
static int JPLua_Export_WorldCoordToScreenCoord( lua_State *L ) {
	vector3 *v = JPLua_CheckVector( L, 1 );
	float x, y;
	if ( CG_WorldCoordToScreenCoordFloat( v, &x, &y ) ) {
		lua_pushnumber( L, x );
		lua_pushnumber( L, y );
		return 2;
	}
	else {
		lua_pushnil( L );
		return 1;
	}
}
Ejemplo n.º 5
0
static int JPLua_EntitiesInRadius(lua_State *L){
	vector3 *origin = JPLua_CheckVector(L, 1);
	float radius = luaL_checknumber(L, 2);
	gentity_t	*entity_list[MAX_GENTITIES];
	int count;

	count =	G_RadiusList(origin, radius, NULL, qtrue, entity_list);

	lua_newtable(L);
	int top = lua_gettop(L);

	for (int i = 0; i < count; i++) {
		lua_pushinteger(L, i + 1);
		JPLua_Entity_CreateRef(L, entity_list[i]);
		lua_settable(L, top);
	}
	return 1;
}