Example #1
0
//Lua扩展函数,取得对象位置x,y,z = GetUnitPosition("player")
int lua_GetUnitPosition( void* l ){
	float v[6];

	if( Lua_isstring(l,1) ){
		size_t len;
		const char * name = Lua_tolstring(l,1,&len);
		void* punit = GetUnitByName( name );
		if( punit ){
			GetUnitPosition( punit,v );
			Lua_pushnumber(l,v[0]);
			Lua_pushnumber(l,v[1]);
			Lua_pushnumber(l,v[2]);
			return 3;
		}else if(g_pFocusID&&strcmp(name,"focus")==0){
			punit = GetUnit(*g_pFocusID,1);
			if( punit ){
				GetUnitPosition( punit,v );
				Lua_pushnumber(l,v[0]);
				Lua_pushnumber(l,v[1]);
				Lua_pushnumber(l,v[2]);
				return 3;
			}
		}
	}
	Lua_pushnil(l);
	return 1;
}
Example #2
0
//计算x,y,z和你的角度a=GetAngle(x,y,z)
int lua_GetAngle( void* l ){
	float uv[3],pv[3],av[3],sv[3];

	bool isok = true;
	if( Lua_isnumber(l,1) ){
		uv[0] = (float)Lua_tonumber(l,1);
	}else isok = false;
	if( Lua_isnumber(l,2) ){
		uv[1] = (float)Lua_tonumber(l,2);
	}else isok = false;
	if( Lua_isnumber(l,3) ){
		uv[2] = (float)Lua_tonumber(l,3);
	}else isok = false;

	if( isok ){
		size_t len;
		const char * name = Lua_tolstring(l,1,&len);
		void* pplayer = GetUnitByName(sPlayer);
		if( pplayer ){
			GetUnitPosition( pplayer,pv );
			GetUnitDirection( pplayer,av );
			vector_sub( sv,uv,pv );
			sv[2] = 0;
			double a = vector_angle(av,sv);

			a *= 180/M_PI;
			Lua_pushnumber( l,a );
			return 1;
		}
	}
	Lua_pushnil(l);
	return 1;
}
Example #3
0
//计算x,y,z和你的距离d=GetDistance(x,y,z)
int lua_GetDistance( void* l ){
	float uv[3],pv[3],v[3];
	bool isok = true;
	if( Lua_isnumber(l,1) ){
		uv[0] = (float)Lua_tonumber(l,1);
	}else isok = false;
	if( Lua_isnumber(l,2) ){
		uv[1] = (float)Lua_tonumber(l,2);
	}else isok = false;
	if( Lua_isnumber(l,3) ){
		uv[2] = (float)Lua_tonumber(l,3);
	}else isok = false;

	if( isok ){
		size_t len;
		const char * name = Lua_tolstring(l,1,&len);
		void* pplayer = GetUnitByName(sPlayer);
		if( pplayer ){
			GetUnitPosition( pplayer,pv );
	//		pv[2] = 0;
	//		uv[2] = 0;
			vector_sub(v,pv,uv);

			Lua_pushnumber( l,vector_mod( v ) );
			return 1;
		}
	}
	Lua_pushnil(l);
	return 1;
}
/** Generates a pseudo-random unit vector, uniformly distributed over all directions. */
FVector4 GetUnitVector(FLMRandomStream& RandomStream)
{
	return GetUnitPosition(RandomStream).GetUnsafeNormal3();
}