CytrusekLUA
Wiek: 22 Na forum: 2611 dni Posty: 5
Nick w MP: MichaleQ
powiem wprost pr?buje napisa? autorski radar znajduj?cy si? w prawym g?rnym rogu ekranu. Niestety blipy nie chc? si? tworzy?, by? mo?e ja co? namiesza?em w kodzie wi?c prosz? o pomoc osoby lepsze w LUA odemnie.
kod blip?w:
for i , b in pairs ( getElementsByType ( 'blip' )) do
local bX , bY , bZ = getElementPosition ( b );
local pX , pY , pZ = getElementPosition ( localPlayer );
local _ , _ , crZ = getElementRotation ( getCamera ());
local dist = getDistanceBetweenPoints3D ( bX , bY , bZ , pX , pY , pZ );
local maxdist = getBlipVisibleDistance ( b );
if ( dist <= maxdist and getElementDimension ( localPlayer ) == getElementDimension ( b ) and getElementInterior ( b ) == getElementInterior ( getCamera ())) then
local radius = dist / zoom ;
local direction = math . atan2 ( bX - pX , bY - pY ) + math . rad ( crZ );
local blipX = w + math . sin ( direction ) * radius ;
local blipY = h + math . sin ( direction ) * radius ;
blipX = math . max ( 0 , math . min ( blipX , w ));
blipY = math . max ( 0 , math . min ( blipY , h ));
local path = ':radar/files/map_blips/radarBlip_' .. getBlipIcon ( b ).. '.png' ;
if ( path ) then
local color = tocolor ( getBlipColor ( b ));
local size = tonumber ( getBlipSize ( b ));
dxDrawImage ( x + blipX - size / 2 , y + blipY - size / 2 , size , size , path , 0 , 0 , 0 , color );
else return
end ;
end ;
end ;
Oraz ca?o?? kodu:
local fileDirs = {
map = ':radar/files/map_file/map.jpg' ,
circle = ':radar/files/map_circle/circle.png' ,
player = ':radar/files/player_blip/player.png' ,
fx = ':radar/files/map_fx/hud_mask.fx' ,
};
local screenW , screenH = guiGetScreenSize ();
local x , y , w , h = screenW * 0.8516 , screenH * 0.0250 , screenW * 0.1320 , screenH * 0.2264
local render = true ;
local radarTexture , radarCircleMask , radarShader , everythingOkay ;
addEventHandler ( 'onClientResourceStart' , resourceRoot , function()
radarTexture = dxCreateTexture ( fileDirs . map );
radarCircleMask = dxCreateTexture ( fileDirs . circle );
radarShader = dxCreateShader ( fileDirs . fx );
everythingOkay = radarTexture and radarCircleMask and radarShader ;
if ( everythingOkay ) then
dxSetShaderValue ( radarShader , 'sPicTexture' , radarTexture );
dxSetShaderValue ( radarShader , 'sMaskTexture' , radarCircleMask );
end ;
setPlayerHudComponentVisible ( 'all' , false );
-- setPlayerHudComponentVisible ( 'radar' , true );
end );
addEventHandler ( 'onClientRender' , root , function()
if ( render == false ) then return end ;
if ( everythingOkay ) then
dxSetShaderValue ( radarShader , 'sMaskTexture' , radarCircleMask );
local x , y = getElementPosition ( localPlayer );
x = ( x ) / 6000 ;
y = ( y ) / - 6000 ;
dxSetShaderValue ( radarShader , 'gUVPosition' , x , y );
local zoom = 20 ;
if ( not isPedInVehicle ( localPlayer )) then
local zoom = 20 ;
end ;
-- zoom = zoom + math . sin ( getTickCount () / 500 ) * 3 ;
dxSetShaderValue ( radarShader , 'gUVScale' , 1 / zoom , 1 / zoom );
local camX , camY , camZ = getElementRotation ( getCamera ());
dxSetShaderValue ( radarShader , 'gUVRotAngle' , math . rad (- camZ ));
-- dxSetShaderTransform ( radarShader , 0 , - 65 , camZ );
local _ , _ , pROT = getElementRotation ( localPlayer );
dxDrawImage ( screenW * 0.8516 , screenH * 0.0250 , screenW * 0.1320 , screenH * 0.2264 , radarShader , 0 , 0 , 0 , tocolor ( 255 , 255 , 255 , 230 ));
dxDrawImage ( screenW * 0.9117 , screenH * 0.1236 , screenW * 0.0125 , screenH * 0.0236 , fileDirs . player , 0 , 0 , math . rad (- pROT ), tocolor ( 255 , 255 , 255 , 255 ), false );
for i , b in pairs ( getElementsByType ( 'blip' )) do
local bX , bY , bZ = getElementPosition ( b );
local pX , pY , pZ = getElementPosition ( localPlayer );
local _ , _ , crZ = getElementRotation ( getCamera ());
local dist = getDistanceBetweenPoints3D ( bX , bY , bZ , pX , pY , pZ );
local maxdist = getBlipVisibleDistance ( b );
if ( dist <= maxdist and getElementDimension ( localPlayer ) == getElementDimension ( b ) and getElementInterior ( b ) == getElementInterior ( getCamera ())) then
local radius = dist / zoom ;
local direction = math . atan2 ( bX - pX , bY - pY ) + math . rad ( crZ );
local blipX = w + math . sin ( direction ) * radius ;
local blipY = h + math . sin ( direction ) * radius ;
blipX = math . max ( 0 , math . min ( blipX , w ));
blipY = math . max ( 0 , math . min ( blipY , h ));
local path = ':radar/files/map_blips/radarBlip_' .. getBlipIcon ( b ).. '.png' ;
if ( path ) then
local color = tocolor ( getBlipColor ( b ));
local size = tonumber ( getBlipSize ( b ));
dxDrawImage ( x + blipX - size / 2 , y + blipY - size / 2 , size , size , path , 0 , 0 , 0 , color );
else return
end ;
end ;
end ;
end ;
end );
Za pomoc daje zimniutkie piwko