Zaloguj się by uzyskać pełen dostęp. Nie masz jeszcze konta? Założ je już teraz w kilka sekund.

Wysłany: 2018-12-02, 16:02


adisonboss







Wiek: 23
Na forum: 3332 dni
Posty: 237

Piwa: 6

Respekt: 50

Witam tak jak w temacie nie dzia?a przycisk zamknij okno oraz panel shader?w pojawia si? ka?demu graczowi od razu po wej?ciu na serwer a nie po wscisnieciu "f5"
ZA POMOC JA ZAWSZE R* ORAZ :piwo:

GUIEditor = {
    checkbox = {},
    window = {},
    button = {}
}
local snowflakes = {}
local snowing false

local box_widthbox_depthbox_heightbox_width_doubledbox_depth_doubled 4,4,4,8,8
local position = {0,0,0}
local flake_removal nil
local snow_fadein 10
local snow_id 1
settings = {type "real"density 2000wind_direction = {0.01,0.01}, wind_speed 1snowflake_min_size 1snowflake_max_size 3fall_speed_min 1fall_speed_max 4jitter true}
sx,sy guiGetScreenSize()
sx2,sy2 sx/2,sy/2
localPlayer getLocalPlayer()



--local random math.random
function random(lower,upper)
    return lower+(math.random()*(upper-lower))
end

function startSnow()
    if not snowing then
        snowflakes = {}
            
        local lx,ly,lz getWorldFromScreenPosition(0,0,1)
        local rx,ry,rz getWorldFromScreenPosition(sx,0,1)
        box_width getDistanceBetweenPoints3D(lx,ly,lz,rx,ry,rz)+-- +1.5 each side of the screen
        box_depth box_width
        
        box_width_doubled box_width*2
        box_depth_doubled box_depth*2

        lx,ly,lz getWorldFromScreenPosition(sx2,sy2,box_depth)
        position = {lx,ly,lz}        
        
        -- let it snow
        for i=1settings.density do
            local x,y,random(0,box_width*2),random(0,box_depth*2),random(0,box_height*2)
            createFlake(x-box_width,y-box_depth,z-box_height,0)
        end
        
    --    outputChatBox(string.format("Width/Depth: %.1f",box_width))
        addEventHandler("onClientRender",root,drawSnow)
        snowing true
    --    outputChatBox("Snow started")
        return true
    else
    --    outputChatBox("Its already snowing")
        return false
    end
    return false
end

function toggleSnow()
    if snowing then
        stopSnow()
    else
        startSnow() 
    end
end


addCommandHandler("snow",function()
    if snowToggle then 
        toggleSnow()
    else
        outputChatBox("Snow toggling is disabled.")
    end
end)


function showSnowToggleBind()
    if getKeyState("lctrl") or getKeyState("rctrl"then
        if snowToggle then 
            toggleSnow()
        else
            outputChatBox("Snow toggling is disabled.")
        end
    end
end
addCommandHandler("Snow Toggle (hold ctrl)",showSnowToggleBind)
bindKey("s","down","Snow Toggle (hold ctrl)")


function stopSnow()
    if snowing then
        removeEventHandler("onClientRender",root,drawSnow)
        for i,flake in pairs(snowflakes) do
            snowflakes[i] = nil
        end
        snowflakes nil
        flake_removal nil
        snowing false
    --    outputChatBox("Snow stopped")
        return true
    end
    return false
end
addEventHandler("onClientResourceStop",resourceRoot,stopSnow)


function updateSnowType(type)
    if type then
        settings.type type
    --    outputChatBox("Snow type set to "..type)
        return true
    end
    return false
end


function updateSnowDensity(dense,blend,speed)
    if dense and tonumber(densethen
        dense tonumber(dense)
        if snowing then
            if blend then
                -- if we are blending in more flakes
                if dense settings.density then
                    -- default speed
                    if not tonumber(speedthen
                        speed 300
                    end
                    -- create 1/20 of the new amount every 'speed'ms for 20 iterations
                    setTimer(function(old,new)
                        for i=1, (new-old)/20do
                            local x,random(0,box_width*2),random(0,box_depth*2)
                            createFlake(x-box_width,y-box_depth,box_height,0)                            
                        end
                    end,tonumber(speed),20,settings.density,dense)
                
                -- if we are blending out existing flakesjust flag that we should stop recreating them and check in createFlake()
                elseif dense settings.density then
                    if not tonumber(speedthen
                        speed 10
                    end
                    flake_removal = {settings.density-dense,0,tonumber(speed)}
                end
                
                if not tonumber(speedthen
                    speed 0
                end
            else
                speed 0
                if dense settings.density then
                    for i=settings.density+1dense do
                        local x,random(0,box_width*2),random(0,box_depth*2)
                        createFlake(x-box_width,y-box_depth,box_height,0)                
                    end
                elseif dense settings.density then
                    for i=densitydense+1, -do
                        table.remove(snowflakes,i)
                    end
                end
            end
        else
            speed 0
        end
        
    --    outputChatBox("Snow density set to "..dense.." (b: "..((blend ~= nil) and "yes" or "no").." - "..((dense settings.density) and "in" or "out").." at "..tonumber(speed).."ms : "..settings.density..","..dense..")")
        settings.density tonumber(dense)
        return true
    end
    return false
end


function updateSnowWindDirection(xdir,ydir)
    if xdir and tonumber(xdir) and ydir and tonumber(ydirthen
        settings.wind_direction = {tonumber(xdir)/100,tonumber(ydir)/100}
    --    outputChatBox("Snow winddirection set to "..xdir..","..ydir)
        return true
    end
    return false
end


function updateSnowWindSpeed(speed)
    if speed and tonumber(speedthen
        settings.wind_speed tonumber(speed)
    --    outputChatBox("Snow windspeed set to "..settings.wind_speed)
        return true
    end
    return false
end


function updateSnowflakeSize(min,max)
    if min and tonumber(min) and max and tonumber(maxthen
        settings.snowflake_min_size tonumber(min)
        settings.snowflake_max_size tonumber(max)
    --    outputChatBox("Snowflake size set to "..min.." - "..max)
        return true
    end
    return false
end


function updateSnowFallSpeed(min,max)
    if min and tonumber(min) and max and tonumber(maxthen
        settings.fall_speed_min tonumber(min)
        settings.fall_speed_max tonumber(max)
        return true
    end
    return false
end


function updateSnowAlphaFadeIn(alpha)
    if alpha and tonumber(alphathen
        snow_fadein tonumber(alpha)
    --    outputChatBox("Snow fade in alpha set to "..alpha)
        return true
    end
    return false
end


function updateSnowJitter(jit)
    settings.jitter jit
end


function createFlake(x,y,z,alpha,i)    
    if flake_removal then
        if (flake_removal[2] % flake_removal[3]) == 0 then
            flake_removal[1] = flake_removal[1] - 1
            if flake_removal[1] == 0 then
                flake_removal nil
            end
            table.remove(snowflakes,i)
            return
        else
            flake_removal[2] = flake_removal[2] + 1
        end
    end
    
    snow_id = (snow_id 4) + 1
    
    if i then
        local randy math.random(0,180)
        snowflakes[i] = {xyz, 
                         speed math.random(settings.fall_speed_min,settings.fall_speed_max)/100, 
                         size 2^math.random(settings.snowflake_min_size,settings.snowflake_max_size), 
                         section = {(snow_id == 1) and or 32,  (snow_id 3) and or 32},
                         rot randy, 
                         alpha alpha, 
                         jitter_direction = {math.cos(math.rad(randy*2)), -math.sin(math.rad(math.random(0,360)))}, 
                         jitter_cycle randy*2,
                         jitter_speed 8
                        }
    else
        local randy math.random(0,180)
        table.insert(snowflakes,{xyz, 
                                 speed math.random(settings.fall_speed_min,settings.fall_speed_max)/100, 
                                 size 2^math.random(settings.snowflake_min_size,settings.snowflake_max_size),
                                 section = {(snow_id == 1) and or 32,  (snow_id 3) and or 32},
                                 rot randy, 
                                 alpha alpha,
                                 jitter_direction = {math.cos(math.rad(randy*2)), -math.sin(math.rad(math.random(0,360)))}, 
                                 jitter_cycle randy*2,
                                 jitter_speed 8
                                }                     
                    )
    end
end



function drawSnow()    
    local tick getTickCount()
    
    local cx,cy,cz getCameraMatrix()

    local lx,ly,lz getWorldFromScreenPosition(sx2,sy2,box_depth)

    --local hit,hx,hy,hz processLineOfSight(lx,ly,lz,lx,ly,lz+20,true,true,false,true,false,true,false,false,localPlayer)
    if (isLineOfSightClear(cx,cy,cz,cx,cy,cz+20,true,false,false,true,false,true,false,localPlayer) or
        isLineOfSightClear(lx,ly,lz,lx,ly,lz+20,true,false,false,true,false,true,false,localPlayer)) then
        
        -- if we are underwatersubstitute the water level for the ground level
        local check getGroundPosition
        if testLineAgainstWater(cx,cy,cz,cx,cy,cz+20then
            check getWaterLevel
        end
    --    local gz getGroundPosition(lx,ly,lz)
    
        -- split the box into a 3x3 grideach section of the grid takes its own ground level reading to apply for every flake within it    
        local gpx,gpy,gpz lx+(-box_width),ly+(-box_depth),lz+15
                
        local ground = {}
        
        for i=1do
            local it box_width_doubled*(i*0.25)
            ground[i] = {
                check(gpx+(it), gpy+(box_depth_doubled*0.25), gpz),
                check(gpx+(it), gpy+(box_depth_doubled*0.5), gpz),
                check(gpx+(it), gpy+(box_depth_doubled*0.75), gpz)
            }
        end    
            
        --    outputDebugString(string.format("Gn: %.1f %.1f %.1f",ground[i][1],ground[i][2],ground[i][3]))
        --    outputDebugString(string.format("Gy: %.1f %.1f %.1f",groundy[i][1],groundy[i][2],groundy[i][3]))

    --    outputDebugString(string.format("%.1f %.1f %.1f, %.1f %.1f %.1f, %.1f %.1f %.1f",ground[1][1],ground[1][2],ground[1][3],ground[2][1],ground[2][2],ground[2][3],ground[3][1],ground[3][2],ground[3][3]))
    --    outputDebugString(string.format("%.1f %.1f %.1f, %.1f %.1f %.1f",(-box_width)+grid[1],(-box_width)+grid[1]*3,(-box_width)+grid[1]*5,(-box_depth)+grid[2],(-box_depth)+grid[2]*3,(-box_depth)+grid[2]*5))
    
        local dx,dy,dz position[1]-lx,position[2]-ly,position[3]-lz
    
        --local alpha = (math.abs(dx) + math.abs(dy) + math.abs(dz))*15
        
    --    outputDebugString(tostring(alpha))
    

        for i,flake in pairs(snowflakes) do
            if flake then                
                -- check the flake hasnt moved beyond the box or below the ground
                -- actuallyto preserve a constant density allow the flakes to fall past ground level (just dont show them) and remove once at the bottom of the box
            --    if (flake.z+lz) < ground[gx][gy] or flake.< (-box_heightthen
                if flake.< (-box_heightthen
                --    outputDebugString(string.format("Flake removed. %.1f %.1f %.1f",flake.x,flake.y,flake.z))
                    -- createFlake(xyzalphaindex)
                    createFlake(random(0,box_width*2) - box_widthrandom(0,box_depth*2) - box_depthbox_height0i)    
                else

                    -- find the grid section the flake is in                
                    local gx,gy 2,2
                    if flake.<= (box_width_doubled*0.33)-box_width then gx 1
                    elseif flake.>= (box_width_doubled*0.66)-box_width then gx 3
                    end
                        
                    if flake.<= (box_depth_doubled*0.33)-box_depth then gy 1
                    elseif flake.>= (box_depth_doubled*0.66)-box_depth then gy 3
                    end
                    
                    -- check it hasnt moved past the ground
                    if ground[gx][gy] and (flake.z+lz) > ground[gx][gythen
                        local draw_xdraw_yjitter_xjitter_y nil,nil,0,0
                        
                        -- draw all onscreen flakes
                        if settings.jitter then
                            local jitter_cycle math.cos(flake.jitter_cycle) / flake.jitter_speed
                            
                            jitter_x = (flake.jitter_direction[1] * jitter_cycle )
                            jitter_y = (flake.jitter_direction[2] * jitter_cycle )
                        end
                        
                        draw_x,draw_y getScreenFromWorldPosition(flake.lx jitter_xflake.ly jitter_y ,flake.lz15false)    
                        
                        if draw_x and draw_y then
                            --    outputDebugString(string.format("Drawing flake %.1f %.1f",draw_x,draw_y))
                        
                            -- only draw flakes that are infront of the player
                            -- peds seem to have very vague collisionsresulting in a dome-like space around the player where no snow is drawnso leave this out due to it looking rediculous
                            --    if isLineOfSightClear(cx,cy,cz,flake.x+lx,flake.y+ly,flake.z+lz,true,true,true,true,false,false,false,truethen
                            --dxDrawImage(draw_x,draw_y,flake.size,flake.size,"flakes/snowflake"..tostring(flake.image).."_".. settings.type ..".png",flake.rot,0,0,tocolor(222,235,255,flake.alpha))
                            dxDrawImageSection(draw_xdraw_yflake.sizeflake.sizeflake.section[1], flake.section[2], 3232"flakes/".. settings.type .. "_tile.png"flake.rot00tocolor(222,235,255,flake.alpha))
                            --    end
                            
                            -- rotation and alpha (do not need to be done if the flake isnt being drawn)
                            flake.rot flake.rot settings.wind_speed
                                        
                            if flake.alpha 255 then
                                flake.alpha flake.alpha snow_fadein --[[+ alpha]]
                                if flake.alpha 255 then flake.alpha 255 end
                            end    
                        else
                        --    outputDebugString(string.format("Cannot find screen pos. %.1f %.1f %.1f",flake.x+lx,flake.y+ly,flake.z+lz))
                        end
                    end
    
                
                    if settings.jitter then
                        flake.jitter_cycle = (flake.jitter_cycle 360) + 0.1
                    end
                    
                    -- horizontal movement
                    flake.flake.+ (settings.wind_direction[1] * settings.wind_speed)
                    flake.flake.+ (settings.wind_direction[2] * settings.wind_speed)
                
                    -- vertical movement
                    flake.flake.flake.speed
                    
                    -- update flake position based on movement of the camera                
                    flake.flake.dx
                    flake.flake.dy
                    flake.flake.dz
    
                --    outputDebugString(string.format("Diff: %.1f, %.1f, %.1f",position[1]-lx,position[2]-ly,position[3]-lz))
                    
                    if flake.< -box_width or flake.box_width or
                        flake.< -box_depth or flake.box_depth or
                        flake.box_height then

                        --    outputDebugString(string.format("Flake removed (move). %.1f %.1f %.1f",flake.x,flake.y,flake.z))
                        
                        -- mirror flakes that were removed due to camera movement onto the opposite side of the box (and hope nobody notices)
                        flake.flake.dx
                        flake.flake.dy
                        local x,y,= (flake.and -flake.or math.abs(flake.x)),(flake.and -flake.or math.abs(flake.y)),random(0,box_height*2)
                    
                        createFlake(xybox_height255i)    
                    end
                end
            end
        end
    else
    --    outputDebugString("Not clear (roof)")
    end
    position = {lx,ly,lz}
    
    --outputDebugString(string.format("Snow took: %.6f",getTickCount() - tick))
end

local maxEffectDistance 250    

function wylaczsha()
engineRemoveShaderFromWorldTexture (roadshader"*" maxEffectDistance)
            
            destroyElement(roadshader)
            roadshader=nil
end

function wlaczsnieg()
    if not snowShader then snowShader dxCreateShader "snow_ground.fx"0maxEffectDistance end

    engineApplyShaderToWorldTexture snowShader"*" )
end

function wylaczsnieg()
engineRemoveShaderFromWorldTexture (snowShader"*" maxEffectDistance)    
dxSetShaderValuesnowShader"sStrength"90)    
dxSetShaderValuesnowShader"sFadeEnd"maxEffectDistance )
    dxSetShaderValuesnowShader"sFadeStart"maxEffectDistance/)
    destroyElement(snowShader)
            snowShader=nil
end

function wlaczsha()
    if not roadshader then roadshader dxCreateShader "roadshine3.fx"0end

    dxSetShaderValueroadshader"sStrength"1.5 )
    dxSetShaderValueroadshader"sFadeEnd"maxEffectDistance )
    dxSetShaderValueroadshader"sFadeStart"maxEffectDistance/)
    engineApplyShaderToWorldTexture roadshader"*" )
end



function wlaczauta()
if not autoshader then autoshaderdxCreateShader "car_paint.fx" end
            local AutatextureVol dxCreateTexture "images/smallnoise3d.dds" )
            local AutatextureCube dxCreateTexture "images/cube_env256.dds" )
            dxSetShaderValue autoshader"sRandomTexture"AutatextureVol )
            dxSetShaderValue autoshader"sReflectionTexture"AutatextureCube )
engineApplyShaderToWorldTexture autoshader"vehiclegrunge256" )
            engineApplyShaderToWorldTexture (autoshader"?emap*" )
end
function wylaczauta()
engineRemoveShaderFromWorldTexture autoshader"vehiclegrunge256" )
            engineRemoveShaderFromWorldTexture (autoshader"?emap*" )
            
            destroyElement(autoshader)
            autoshader=nil
end

addEventHandler("onClientResourceStart"resourceRoot,
    function()
        GUIEditor.window[1] = guiCreateWindow(1053227226391""false)
        guiWindowSetSizable(GUIEditor.window[1], false)

        GUIEditor.button[1] = guiCreateButton(934320738"Zamknij okno"falseGUIEditor.window[1])
        GUIEditor.checkbox[1] = guiCreateCheckBox(102620667"Karoseria Pojazd?w"falsefalseGUIEditor.window[1])
        GUIEditor.checkbox[2] = guiCreateCheckBox(99420771"Odbicie pod?o?a"falsefalseGUIEditor.window[1])
        GUIEditor.checkbox[3] = guiCreateCheckBox(916820768"?nieg na Ulicy"falsefalseGUIEditor.window[1])
        GUIEditor.checkbox[4] = guiCreateCheckBox(923720763"Opady ?niegu"falsefalseGUIEditor.window[1])    
    end)
    showCursor(true)
    addEventHandler "onClientGUIClick",root,
    function() 
    if source==GUIEditor.checkbox[1then
    
        if guiCheckBoxGetSelected(GUIEditor.checkbox[1])==true then 
        wlaczauta()
        elseif guiCheckBoxGetSelected(GUIEditor.checkbox[1])==false then
        wylaczauta()
        
        end
        end
    end)
    addEventHandler "onClientGUIClick",root,
    function() 
    if source==GUIEditor.checkbox[2then
    
    if guiCheckBoxGetSelected(GUIEditor.checkbox[2])==true then
        wlaczsha()
        elseif guiCheckBoxGetSelected(GUIEditor.checkbox[2])==false then
        wylaczsha()
        
        end
        end
    end)
    
        addEventHandler "onClientGUIClick",root,
    function() 
    if source==GUIEditor.checkbox[3then
    
    if guiCheckBoxGetSelected(GUIEditor.checkbox[3])==true then
        wlaczsnieg()
        elseif guiCheckBoxGetSelected(GUIEditor.checkbox[3])==false then
        wylaczsnieg()
        
        end
        end
    end)
    
            addEventHandler "onClientGUIClick",root,
    function() 
    if source==GUIEditor.checkbox[4then
    
    if guiCheckBoxGetSelected(GUIEditor.checkbox[4])==true then
         startSnow()
        elseif guiCheckBoxGetSelected(GUIEditor.checkbox[4])==false then
         stopSnow()
        
        end
        end
    end)
    
addEventHandler("onClientKey",root,function(bttn,por)
if bttn=="F5" and por then
 if guiGetVisibleGUIEditor.window[1])==true then
 guiSetVisibleGUIEditor.window[1],false)
 showCursor(false)
else
 guiSetVisibleGUIEditor.window[1],true)
  showCursor(true)
 end
 end 
 end)


[ Dodano: 2018-12-02, 16:04 ]
*jak

Postaw piwo autorowi tego posta
 

 
Wysłany: 2018-12-02, 16:06


Kalizman







Wiek: 23
Na forum: 3652 dni
Posty: 1394

Piwa: 4619

Respekt: 358,8
Respekt: 358,8Respekt: 358,8Respekt: 358,8Respekt: 358,8

nie rozumiem

Postaw piwo autorowi tego posta
 

 
Wysłany: 2018-12-02, 16:08


adisonboss







Wiek: 23
Na forum: 3332 dni
Posty: 237

Piwa: 6

Respekt: 50

1. Panel w??cza si? graczowi jak tylko wejdzie na serwer a nie po kliknieciu F5
2. Przycisk zamknij okno nie dzia?a poniewa? nie zamyka panelu

Postaw piwo autorowi tego posta
 

 
Wysłany: 2018-12-02, 16:41


Gravgor







Wiek: 22
Na forum: 3620 dni
Posty: 380
Nick w MP: 1944

Piwa: 702

Respekt: 57,8

1. guiSetVisible na false do wszystkich czesci GUI
2. bindKey

Podpis
Portfolio marceliborowczak.me
Postaw piwo autorowi tego posta
 

 
Wysłany: 2018-12-02, 20:13


adisonboss







Wiek: 23
Na forum: 3332 dni
Posty: 237

Piwa: 6

Respekt: 50

1. Wtedy przy wej?ciu na serwer nadal si? pokazuje a po kliknieciu f5 nie
2. Ale oto chodzi ze f5 dzia?a ale klawisz zamknij okno nie

Postaw piwo autorowi tego posta
 

 
Wysłany: 2018-12-02, 20:16


Gravgor







Wiek: 22
Na forum: 3620 dni
Posty: 380
Nick w MP: 1944

Piwa: 702

Respekt: 57,8

"adisonboss" napisał/a:

1. Wtedy przy wej?ciu na serwer nadal si? pokazuje a po kliknieciu f5 nie
2. Ale oto chodzi ze f5 dzia?a ale klawisz zamknij okno nie


Poka? aktualny kod.

Podpis
Portfolio marceliborowczak.me
Postaw piwo autorowi tego posta
 

 
Wysłany: 2018-12-02, 20:18


adisonboss







Wiek: 23
Na forum: 3332 dni
Posty: 237

Piwa: 6

Respekt: 50


GUIEditor = {
    checkbox = {},
    window = {},
    button = {}
}
local snowflakes = {}
local snowing false

local box_widthbox_depthbox_heightbox_width_doubledbox_depth_doubled 4,4,4,8,8
local position = {0,0,0}
local flake_removal nil
local snow_fadein 10
local snow_id 1
settings = {type "real"density 2000wind_direction = {0.01,0.01}, wind_speed 1snowflake_min_size 1snowflake_max_size 3fall_speed_min 1fall_speed_max 4jitter true}
sx,sy guiGetScreenSize()
sx2,sy2 sx/2,sy/2
localPlayer getLocalPlayer()



--local random math.random
function random(lower,upper)
    return lower+(math.random()*(upper-lower))
end

function startSnow()
    if not snowing then
        snowflakes = {}
            
        local lx,ly,lz getWorldFromScreenPosition(0,0,1)
        local rx,ry,rz getWorldFromScreenPosition(sx,0,1)
        box_width getDistanceBetweenPoints3D(lx,ly,lz,rx,ry,rz)+-- +1.5 each side of the screen
        box_depth box_width
        
        box_width_doubled box_width*2
        box_depth_doubled box_depth*2

        lx,ly,lz getWorldFromScreenPosition(sx2,sy2,box_depth)
        position = {lx,ly,lz}        
        
        -- let it snow
        for i=1settings.density do
            local x,y,random(0,box_width*2),random(0,box_depth*2),random(0,box_height*2)
            createFlake(x-box_width,y-box_depth,z-box_height,0)
        end
        
    --    outputChatBox(string.format("Width/Depth: %.1f",box_width))
        addEventHandler("onClientRender",root,drawSnow)
        snowing true
    --    outputChatBox("Snow started")
        return true
    else
    --    outputChatBox("Its already snowing")
        return false
    end
    return false
end

function toggleSnow()
    if snowing then
        stopSnow()
    else
        startSnow() 
    end
end


addCommandHandler("snow",function()
    if snowToggle then 
        toggleSnow()
    else
        outputChatBox("Snow toggling is disabled.")
    end
end)


function showSnowToggleBind()
    if getKeyState("lctrl") or getKeyState("rctrl"then
        if snowToggle then 
            toggleSnow()
        else
            outputChatBox("Snow toggling is disabled.")
        end
    end
end
addCommandHandler("Snow Toggle (hold ctrl)",showSnowToggleBind)
bindKey("s","down","Snow Toggle (hold ctrl)")


function stopSnow()
    if snowing then
        removeEventHandler("onClientRender",root,drawSnow)
        for i,flake in pairs(snowflakes) do
            snowflakes[i] = nil
        end
        snowflakes nil
        flake_removal nil
        snowing false
    --    outputChatBox("Snow stopped")
        return true
    end
    return false
end
addEventHandler("onClientResourceStop",resourceRoot,stopSnow)


function updateSnowType(type)
    if type then
        settings.type type
    --    outputChatBox("Snow type set to "..type)
        return true
    end
    return false
end


function updateSnowDensity(dense,blend,speed)
    if dense and tonumber(densethen
        dense tonumber(dense)
        if snowing then
            if blend then
                -- if we are blending in more flakes
                if dense settings.density then
                    -- default speed
                    if not tonumber(speedthen
                        speed 300
                    end
                    -- create 1/20 of the new amount every 'speed'ms for 20 iterations
                    setTimer(function(old,new)
                        for i=1, (new-old)/20do
                            local x,random(0,box_width*2),random(0,box_depth*2)
                            createFlake(x-box_width,y-box_depth,box_height,0)                            
                        end
                    end,tonumber(speed),20,settings.density,dense)
                
                -- if we are blending out existing flakesjust flag that we should stop recreating them and check in createFlake()
                elseif dense settings.density then
                    if not tonumber(speedthen
                        speed 10
                    end
                    flake_removal = {settings.density-dense,0,tonumber(speed)}
                end
                
                if not tonumber(speedthen
                    speed 0
                end
            else
                speed 0
                if dense settings.density then
                    for i=settings.density+1dense do
                        local x,random(0,box_width*2),random(0,box_depth*2)
                        createFlake(x-box_width,y-box_depth,box_height,0)                
                    end
                elseif dense settings.density then
                    for i=densitydense+1, -do
                        table.remove(snowflakes,i)
                    end
                end
            end
        else
            speed 0
        end
        
    --    outputChatBox("Snow density set to "..dense.." (b: "..((blend ~= nil) and "yes" or "no").." - "..((dense settings.density) and "in" or "out").." at "..tonumber(speed).."ms : "..settings.density..","..dense..")")
        settings.density tonumber(dense)
        return true
    end
    return false
end


function updateSnowWindDirection(xdir,ydir)
    if xdir and tonumber(xdir) and ydir and tonumber(ydirthen
        settings.wind_direction = {tonumber(xdir)/100,tonumber(ydir)/100}
    --    outputChatBox("Snow winddirection set to "..xdir..","..ydir)
        return true
    end
    return false
end


function updateSnowWindSpeed(speed)
    if speed and tonumber(speedthen
        settings.wind_speed tonumber(speed)
    --    outputChatBox("Snow windspeed set to "..settings.wind_speed)
        return true
    end
    return false
end


function updateSnowflakeSize(min,max)
    if min and tonumber(min) and max and tonumber(maxthen
        settings.snowflake_min_size tonumber(min)
        settings.snowflake_max_size tonumber(max)
    --    outputChatBox("Snowflake size set to "..min.." - "..max)
        return true
    end
    return false
end


function updateSnowFallSpeed(min,max)
    if min and tonumber(min) and max and tonumber(maxthen
        settings.fall_speed_min tonumber(min)
        settings.fall_speed_max tonumber(max)
        return true
    end
    return false
end


function updateSnowAlphaFadeIn(alpha)
    if alpha and tonumber(alphathen
        snow_fadein tonumber(alpha)
    --    outputChatBox("Snow fade in alpha set to "..alpha)
        return true
    end
    return false
end


function updateSnowJitter(jit)
    settings.jitter jit
end


function createFlake(x,y,z,alpha,i)    
    if flake_removal then
        if (flake_removal[2] % flake_removal[3]) == 0 then
            flake_removal[1] = flake_removal[1] - 1
            if flake_removal[1] == 0 then
                flake_removal nil
            end
            table.remove(snowflakes,i)
            return
        else
            flake_removal[2] = flake_removal[2] + 1
        end
    end
    
    snow_id = (snow_id 4) + 1
    
    if i then
        local randy math.random(0,180)
        snowflakes[i] = {xyz, 
                         speed math.random(settings.fall_speed_min,settings.fall_speed_max)/100, 
                         size 2^math.random(settings.snowflake_min_size,settings.snowflake_max_size), 
                         section = {(snow_id == 1) and or 32,  (snow_id 3) and or 32},
                         rot randy, 
                         alpha alpha, 
                         jitter_direction = {math.cos(math.rad(randy*2)), -math.sin(math.rad(math.random(0,360)))}, 
                         jitter_cycle randy*2,
                         jitter_speed 8
                        }
    else
        local randy math.random(0,180)
        table.insert(snowflakes,{xyz, 
                                 speed math.random(settings.fall_speed_min,settings.fall_speed_max)/100, 
                                 size 2^math.random(settings.snowflake_min_size,settings.snowflake_max_size),
                                 section = {(snow_id == 1) and or 32,  (snow_id 3) and or 32},
                                 rot randy, 
                                 alpha alpha,
                                 jitter_direction = {math.cos(math.rad(randy*2)), -math.sin(math.rad(math.random(0,360)))}, 
                                 jitter_cycle randy*2,
                                 jitter_speed 8
                                }                     
                    )
    end
end



function drawSnow()    
    local tick getTickCount()
    
    local cx,cy,cz getCameraMatrix()

    local lx,ly,lz getWorldFromScreenPosition(sx2,sy2,box_depth)

    --local hit,hx,hy,hz processLineOfSight(lx,ly,lz,lx,ly,lz+20,true,true,false,true,false,true,false,false,localPlayer)
    if (isLineOfSightClear(cx,cy,cz,cx,cy,cz+20,true,false,false,true,false,true,false,localPlayer) or
        isLineOfSightClear(lx,ly,lz,lx,ly,lz+20,true,false,false,true,false,true,false,localPlayer)) then
        
        -- if we are underwatersubstitute the water level for the ground level
        local check getGroundPosition
        if testLineAgainstWater(cx,cy,cz,cx,cy,cz+20then
            check getWaterLevel
        end
    --    local gz getGroundPosition(lx,ly,lz)
    
        -- split the box into a 3x3 grideach section of the grid takes its own ground level reading to apply for every flake within it    
        local gpx,gpy,gpz lx+(-box_width),ly+(-box_depth),lz+15
                
        local ground = {}
        
        for i=1do
            local it box_width_doubled*(i*0.25)
            ground[i] = {
                check(gpx+(it), gpy+(box_depth_doubled*0.25), gpz),
                check(gpx+(it), gpy+(box_depth_doubled*0.5), gpz),
                check(gpx+(it), gpy+(box_depth_doubled*0.75), gpz)
            }
        end    
            
        --    outputDebugString(string.format("Gn: %.1f %.1f %.1f",ground[i][1],ground[i][2],ground[i][3]))
        --    outputDebugString(string.format("Gy: %.1f %.1f %.1f",groundy[i][1],groundy[i][2],groundy[i][3]))

    --    outputDebugString(string.format("%.1f %.1f %.1f, %.1f %.1f %.1f, %.1f %.1f %.1f",ground[1][1],ground[1][2],ground[1][3],ground[2][1],ground[2][2],ground[2][3],ground[3][1],ground[3][2],ground[3][3]))
    --    outputDebugString(string.format("%.1f %.1f %.1f, %.1f %.1f %.1f",(-box_width)+grid[1],(-box_width)+grid[1]*3,(-box_width)+grid[1]*5,(-box_depth)+grid[2],(-box_depth)+grid[2]*3,(-box_depth)+grid[2]*5))
    
        local dx,dy,dz position[1]-lx,position[2]-ly,position[3]-lz
    
        --local alpha = (math.abs(dx) + math.abs(dy) + math.abs(dz))*15
        
    --    outputDebugString(tostring(alpha))
    

        for i,flake in pairs(snowflakes) do
            if flake then                
                -- check the flake hasnt moved beyond the box or below the ground
                -- actuallyto preserve a constant density allow the flakes to fall past ground level (just dont show them) and remove once at the bottom of the box
            --    if (flake.z+lz) < ground[gx][gy] or flake.< (-box_heightthen
                if flake.< (-box_heightthen
                --    outputDebugString(string.format("Flake removed. %.1f %.1f %.1f",flake.x,flake.y,flake.z))
                    -- createFlake(xyzalphaindex)
                    createFlake(random(0,box_width*2) - box_widthrandom(0,box_depth*2) - box_depthbox_height0i)    
                else

                    -- find the grid section the flake is in                
                    local gx,gy 2,2
                    if flake.<= (box_width_doubled*0.33)-box_width then gx 1
                    elseif flake.>= (box_width_doubled*0.66)-box_width then gx 3
                    end
                        
                    if flake.<= (box_depth_doubled*0.33)-box_depth then gy 1
                    elseif flake.>= (box_depth_doubled*0.66)-box_depth then gy 3
                    end
                    
                    -- check it hasnt moved past the ground
                    if ground[gx][gy] and (flake.z+lz) > ground[gx][gythen
                        local draw_xdraw_yjitter_xjitter_y nil,nil,0,0
                        
                        -- draw all onscreen flakes
                        if settings.jitter then
                            local jitter_cycle math.cos(flake.jitter_cycle) / flake.jitter_speed
                            
                            jitter_x = (flake.jitter_direction[1] * jitter_cycle )
                            jitter_y = (flake.jitter_direction[2] * jitter_cycle )
                        end
                        
                        draw_x,draw_y getScreenFromWorldPosition(flake.lx jitter_xflake.ly jitter_y ,flake.lz15false)    
                        
                        if draw_x and draw_y then
                            --    outputDebugString(string.format("Drawing flake %.1f %.1f",draw_x,draw_y))
                        
                            -- only draw flakes that are infront of the player
                            -- peds seem to have very vague collisionsresulting in a dome-like space around the player where no snow is drawnso leave this out due to it looking rediculous
                            --    if isLineOfSightClear(cx,cy,cz,flake.x+lx,flake.y+ly,flake.z+lz,true,true,true,true,false,false,false,truethen
                            --dxDrawImage(draw_x,draw_y,flake.size,flake.size,"flakes/snowflake"..tostring(flake.image).."_".. settings.type ..".png",flake.rot,0,0,tocolor(222,235,255,flake.alpha))
                            dxDrawImageSection(draw_xdraw_yflake.sizeflake.sizeflake.section[1], flake.section[2], 3232"flakes/".. settings.type .. "_tile.png"flake.rot00tocolor(222,235,255,flake.alpha))
                            --    end
                            
                            -- rotation and alpha (do not need to be done if the flake isnt being drawn)
                            flake.rot flake.rot settings.wind_speed
                                        
                            if flake.alpha 255 then
                                flake.alpha flake.alpha snow_fadein --[[+ alpha]]
                                if flake.alpha 255 then flake.alpha 255 end
                            end    
                        else
                        --    outputDebugString(string.format("Cannot find screen pos. %.1f %.1f %.1f",flake.x+lx,flake.y+ly,flake.z+lz))
                        end
                    end
    
                
                    if settings.jitter then
                        flake.jitter_cycle = (flake.jitter_cycle 360) + 0.1
                    end
                    
                    -- horizontal movement
                    flake.flake.+ (settings.wind_direction[1] * settings.wind_speed)
                    flake.flake.+ (settings.wind_direction[2] * settings.wind_speed)
                
                    -- vertical movement
                    flake.flake.flake.speed
                    
                    -- update flake position based on movement of the camera                
                    flake.flake.dx
                    flake.flake.dy
                    flake.flake.dz
    
                --    outputDebugString(string.format("Diff: %.1f, %.1f, %.1f",position[1]-lx,position[2]-ly,position[3]-lz))
                    
                    if flake.< -box_width or flake.box_width or
                        flake.< -box_depth or flake.box_depth or
                        flake.box_height then

                        --    outputDebugString(string.format("Flake removed (move). %.1f %.1f %.1f",flake.x,flake.y,flake.z))
                        
                        -- mirror flakes that were removed due to camera movement onto the opposite side of the box (and hope nobody notices)
                        flake.flake.dx
                        flake.flake.dy
                        local x,y,= (flake.and -flake.or math.abs(flake.x)),(flake.and -flake.or math.abs(flake.y)),random(0,box_height*2)
                    
                        createFlake(xybox_height255i)    
                    end
                end
            end
        end
    else
    --    outputDebugString("Not clear (roof)")
    end
    position = {lx,ly,lz}
    
    --outputDebugString(string.format("Snow took: %.6f",getTickCount() - tick))
end

local maxEffectDistance 250    

function wylaczsha()
engineRemoveShaderFromWorldTexture (roadshader"*" maxEffectDistance)
            
            destroyElement(roadshader)
            roadshader=nil
end

function wlaczsnieg()
    if not snowShader then snowShader dxCreateShader "snow_ground.fx"0maxEffectDistance end

    engineApplyShaderToWorldTexture snowShader"*" )
end

function wylaczsnieg()
engineRemoveShaderFromWorldTexture (snowShader"*" maxEffectDistance)    
dxSetShaderValuesnowShader"sStrength"90)    
dxSetShaderValuesnowShader"sFadeEnd"maxEffectDistance )
    dxSetShaderValuesnowShader"sFadeStart"maxEffectDistance/)
    destroyElement(snowShader)
            snowShader=nil
end

function wlaczsha()
    if not roadshader then roadshader dxCreateShader "roadshine3.fx"0end

    dxSetShaderValueroadshader"sStrength"1.5 )
    dxSetShaderValueroadshader"sFadeEnd"maxEffectDistance )
    dxSetShaderValueroadshader"sFadeStart"maxEffectDistance/)
    engineApplyShaderToWorldTexture roadshader"*" )
end



function wlaczauta()
if not autoshader then autoshaderdxCreateShader "car_paint.fx" end
            local AutatextureVol dxCreateTexture "images/smallnoise3d.dds" )
            local AutatextureCube dxCreateTexture "images/cube_env256.dds" )
            dxSetShaderValue autoshader"sRandomTexture"AutatextureVol )
            dxSetShaderValue autoshader"sReflectionTexture"AutatextureCube )
engineApplyShaderToWorldTexture autoshader"vehiclegrunge256" )
            engineApplyShaderToWorldTexture (autoshader"?emap*" )
end
function wylaczauta()
engineRemoveShaderFromWorldTexture autoshader"vehiclegrunge256" )
            engineRemoveShaderFromWorldTexture (autoshader"?emap*" )
            
            destroyElement(autoshader)
            autoshader=nil
end

addEventHandler("onClientResourceStart"resourceRoot,
    function()
        GUIEditor.window[1] = guiCreateWindow(1053227226391""false)
        guiWindowSetSizable(GUIEditor.window[1], false)

        GUIEditor.button[1] = guiCreateButton(934320738"Zamknij okno"falseGUIEditor.window[1])
        GUIEditor.checkbox[1] = guiCreateCheckBox(102620667"Karoseria Pojazd?w"falsefalseGUIEditor.window[1])
        GUIEditor.checkbox[2] = guiCreateCheckBox(99420771"Odbicie pod?o?a"falsefalseGUIEditor.window[1])
        GUIEditor.checkbox[3] = guiCreateCheckBox(916820768"?nieg na Ulicy"falsefalseGUIEditor.window[1])
        GUIEditor.checkbox[4] = guiCreateCheckBox(923720763"Opady ?niegu"falsefalseGUIEditor.window[1])    
    end)
    showCursor(true)
    addEventHandler "onClientGUIClick",root,
    function() 
    if source==GUIEditor.checkbox[1then
    
        if guiCheckBoxGetSelected(GUIEditor.checkbox[1])==true then 
        wlaczauta()
        elseif guiCheckBoxGetSelected(GUIEditor.checkbox[1])==false then
        wylaczauta()
        
        end
        end
    end)
    addEventHandler "onClientGUIClick",root,
    function() 
    if source==GUIEditor.checkbox[2then
    
    if guiCheckBoxGetSelected(GUIEditor.checkbox[2])==true then
        wlaczsha()
        elseif guiCheckBoxGetSelected(GUIEditor.checkbox[2])==false then
        wylaczsha()
        
        end
        end
    end)
    
        addEventHandler "onClientGUIClick",root,
    function() 
    if source==GUIEditor.checkbox[3then
    
    if guiCheckBoxGetSelected(GUIEditor.checkbox[3])==true then
        wlaczsnieg()
        elseif guiCheckBoxGetSelected(GUIEditor.checkbox[3])==false then
        wylaczsnieg()
        
        end
        end
    end)
    
            addEventHandler "onClientGUIClick",root,
    function() 
    if source==GUIEditor.checkbox[4then
    
    if guiCheckBoxGetSelected(GUIEditor.checkbox[4])==true then
         startSnow()
        elseif guiCheckBoxGetSelected(GUIEditor.checkbox[4])==false then
         stopSnow()
        
        end
        end
    end)
    
addEventHandler("onClientKey",root,function(bttn,por)
if bttn=="F5" and por then
 if guiGetVisibleGUIEditor.window[1])==false then
 guiSetVisibleGUIEditor.window[1],false)
 showCursor(false)
else
 guiSetVisibleGUIEditor.window[1],false)
  showCursor(false)
 end
 end 
 end)


Postaw piwo autorowi tego posta
 

 
Wysłany: 2018-12-02, 20:23


Gravgor







Wiek: 22
Na forum: 3620 dni
Posty: 380
Nick w MP: 1944

Piwa: 702

Respekt: 57,8

Wska? kod odpowiedzialny za zamknij okno.

Na ko?cu kodu wstaw,


guiSetVisible(GUIEditor.window[1], false)
guiSetVisible(GUIEditor.button[1], false)
guiSetVisible(GUIEditor.checkbox[1], false)
guiSetVisible(GUIEditor.checkbox[2], false)
guiSetVisible(GUIEditor.checkbox[3], false)
guiSetVisible(GUIEditor.checkbox[4], false)


Podpis
Portfolio marceliborowczak.me
Postaw piwo autorowi tego posta
 

 
Więcej szczegółów
Wystawiono 1 piw(a):
adisonboss
Wysłany: 2018-12-02, 20:29


adisonboss







Wiek: 23
Na forum: 3332 dni
Posty: 237

Piwa: 6

Respekt: 50

Dzieki dzia?a leci :piwo: oraz respekt. DO ZAMKNIECIA

Postaw piwo autorowi tego posta
 

 
Tagi: przycisk :: zamknij :: okno
Anonymous





Na forum: 245 dni
Posty: 1



Anonymous Koniecznie zajrzyj na:






Skocz do:  
Wyświetl posty z ostatnich:   
GTAONLINE.PL » JĘZYKI PROGRAMOWANIA » LUA Ten temat jest zablokowany bez możliwości zmiany postów lub pisania odpowiedzi

Nie możesz pisać nowych tematów
Nie możesz odpowiadać w tematach
Nie możesz zmieniać swoich postów
Nie możesz usuwać swoich postów
Nie możesz głosować w ankietach
Dodaj temat do Ulubionych
Wersja do druku