Jump to content

Scyrix

Members
  • Posts

    12
  • Joined

  • Last visited

Posts posted by Scyrix

  1. Hi ,

    I wanted to create a scroll for rectangles that i have inserted into a table. I tried to avoid rendertargets :( Does anyone have idea of how i can make that scroll so it acctually works.

    Or maybe someone correct me because i might have made the whole function just wrong :P 

    local przecho = {
        {1000.79, 1069.15, 11.07-1,"CODELV",981.18, 1070.89, 10.81-0.98}
    }
    local oknoprzecho = false
    local data = nil
    local gridlisto = {}


     
    for _,v in ipairs(przecho) do
        local markerekPrzecho = createMarker(v[1],v[2],v[3],"cylinder",1.0,255,255,255,255)
        local markerOdbior = createMarker(v[5],v[6],v[7],"cylinder",2.0,255,255,255,255)
        addEventHandler("onClientMarkerHit",markerekPrzecho,function(plr)
            if plr == localPlayer then
            oknoprzecho = true
            showCursor(true)
            data = getElementData(localPlayer,"veh:list")
            showVehicles(748, 375, 416, 37)
            end
        end)
        addEventHandler("onClientMarkerHit",markerOdbior,function()
     
        end)
    end
     
    function showVehicles(x,y,z,h)
        local offset = 0
        for k,v in pairs(gridlisto) do
         gridlisto[k]=nil
        end
        for k,v in ipairs(data) do
        table.insert(gridlisto,{x=x,y=y+offset,z=z,h=h,model=v.model})
        offset = offset + 50
        end
        print(#gridlisto)
    end
     
    --dxDrawRectangle(732, 321, 450, 294, tocolor(255, 255, 255, 255), true)
    addEventHandler("onClientRender", root,function()
        if oknoprzecho then
            dxDrawRectangle(561, 207, 798, 666, tocolor(32, 32, 32, 255), false)
            dxDrawRectangle(1290, 236, 41, 34, tocolor(255, 0, 0, 255), false)
                for i,v in ipairs(gridlisto) do
                    dxDrawRectangle(v.x,v.y,v.z,v.h,tocolor(255,255,255,255))
                    dxDrawText(v.model, v.x, v.y, v.z, v.h, tocolor(0, 0, 0, 255), 1.00, "default", "left", "top", false, false, false, false, false)
                    end
     
        end
    end)



     
    addEventHandler("onClientClick",root,function(btn,state)
        if btn == "left" and state == "down" then
            if oknoprzecho then
                if isMouseIn(1290, 236, 41, 34) then
                    oknoprzecho = false
                    showCursor(false)
                end
                for k,v in ipairs(gridlisto) do  
                    if isMouseIn(v.x, v.y, v.z, v.h) then
                        outputChatBox(v.model)
                    end
                end
     
        end
    end
    end)




     
    function isMouseIn( x, y, width, height )
        if ( not isCursorShowing( ) ) then
            return false
        end
        local sx, sy = guiGetScreenSize ( )
        local cx, cy = getCursorPosition ( )
        local cx, cy = ( cx * sx ), ( cy * sy )
       
        return ( ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) )
    end
  2. So i tried to make a script which on client click on gui creates 4 markers randomly selected and to those 4 markers i attached a blip which is deleted with marker on markerhit but the problem i'm having is when the client leaves the vehcile it should destroy all markers and blips attached to it but it only destroys markers and 1 blip. I know my code is messy i'm learning tho ;/

    Looking forward for any feedback ;/

    Miejsca = {
        {-2374.76,848.06,40.26},
        {-2411.90,917.68,45.58},
        {-2503.44,918.54,64.94},
        {-2502.92,899.47,64.90},
    }
    Miejsca2 = {
        {-2175.37,-42.62,35.31},
        {-2078.89,-1.16,35.32},
        {-2027.23,-51.83,35.37},
        {-2158.88,-6.57,35.32},
    }
    Miejsca3 = {
        {-2509.17,-109.50,25.62},
        {-2514.50,-190.11,25.15},
        {-2540.79,-144.05,15.88},
        {-2576.06,-142.61,6.54},
    }
    Miejsca4 = {
        {-1929.75,1189.20,45.45},
        {-1956.40,1189.02,45.45},
        {-2053.97,1193.66,45.46},
        {-2065.96,1161.57,46.66},
    }
    Miejsca5 = {
        {-2575.85,1148.27,55.73},
        {-2534.61,1141.51,55.73},
        {-2479.18,1141.16,55.73},
        {-2451.32,1139.70,55.73},
    }
    Miejsca6 = {
        {-2880.85,737.10,29.49},
        {-2863.24,682.77,23.44},
        {-2877.86,797.28,35.74},
        {-2837.11,877.44,44.06},
    }
    miejscaa = 0
    function Rozwoz(plr) 
        if plr == localPlayer then 
            miejscaa = math.random(1,6)
                if miejscaa == 1 then 
                    Miejsca = Miejsca
                elseif miejscaa == 2 then 
                    Miejsca = Miejsca2
                elseif miejscaa == 3 then
                    Miejsca = Miejsca3
                elseif miejscaa == 4 then 
                    Miejsca = Miejsca4 
                elseif miejscaa == 5 then 
                    Miejsca = Miejsca5
                elseif miejscaa == 6 then 
                    Miejsca = Miejsca6
                end 
            end 
            StartPracaa(plr)
        end 
    punktyp = 0 
    maxpunktyp = 4
    markerdelete = createElement("markerusune")
    
    
    function StartPracaa(plr)
        if plr == localPlayer then 
            for _,v in ipairs(Miejsca) do 
            local blipGroupElement = createElement("blipGroupElement")
            markerPizzaStart = createMarker(v[1],v[2],v[3],"cylinder",3.0,255,255,255)
            blipPizzaStart = createBlipAttachedTo(markerPizzaStart,12)
                setElementParent(blipPizzaStart, blipGroupElement) 
                setElementParent(markerPizzaStart,markerdelete)
    
            
    
                addEventHandler("onClientMarkerHit",markerPizzaStart,function(plr)
                    if plr == localPlayer then 
                        
                    punktyp = punktyp + 1 
                    if punktyp < maxpunktyp then
                        outputChatBox("Trwa Oddawanie pizzy..")
                        fadeCamera(false)
                        triggerServerEvent("Freeze",localPlayer,localPlayer)
                        setTimer(function()
                            fadeCamera(true)
                            outputChatBox("Jedz oddaj kolejna pizze")
                            triggerServerEvent("unFreeze",localPlayer,localPlayer)
                        end,5000,1)
                        if isElement(blipGroupElement) then 
                            destroyElement(blipGroupElement) end
                    setElementData( localPlayer, 'm', source) 
                    usunmarker(hitElement)
                        elseif punktyp == maxpunktyp then 
                            if isElement(blipGroupElement) then 
                                destroyElement(blipGroupElement) end
                            fadeCamera(false)
                            setElementData( localPlayer, 'm', source) 
                            usunmarker(hitElement)
                            triggerServerEvent("Freeze",localPlayer,localPlayer)
                            setTimer(function()
                            outputChatBox("wracaj na baze")
                            fadeCamera(true)
                            triggerServerEvent("unFreeze",localPlayer,localPlayer)
                            end,5000,1)
                        end
                                
                    end
                end)
            end 
        end 
    end 
    
    function usunmarker(hitElement)
        destroyElement(getElementData(localPlayer, 'm') ) 
    end
    function guipizza()
        dxDrawImage(10/scale, 0/scale, 1920/scale, 1080/scale, ":AC-Kosiarki/tlop.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
        dxDrawImage(383/scale, 154/scale, 411/scale, 304/scale, ":AC-Kosiarki/logo.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
        exports['yd-gui_system']:customButton('Rozpocznij Prace',799/scale, 457/scale, 323/scale, 167/scale)
        exports['yd-gui_system']:customButton('Zakoncz Prace',799/scale, 624/scale, 323/scale, 167/scale)
        pizzaokno = true
    end 
    function guiTimer()
        dxDrawText("Trwa zaladunek pizzy , Dostawca skonczy zamowienie za  : "..czas.." sekund", 733, 28, 1143, 128, tocolor(255, 255, 255, 255), 1.00, "default", "center", "top", false, false, false, false, false)
    end 
    
    function zakonczprace(plr)
        if plr == localPlayer then 
            triggerServerEvent("ZniszczPojazdPizza",localPlayer,localPlayer)
                destroyElement(markerdelete)
                outputChatBox("zakonczyles\as prace")
            end
        end 
    
    addEventHandler("onClientVehicleExit",resourceRoot,function(plr)
        if plr == localPlayer then 
            zakonczprace(plr)
        end 
    end)
    

     

  3. function cursorPosition(x, y, w, h) 
        if (not isCursorShowing()) then 
        return false 
        end 
        local mx, my = getCursorPosition() 
        local fullx, fully = guiGetScreenSize() 
        cursorx, cursory = mx*fullx, my*fully 
        if cursorx > x and cursorx < x + w and cursory > y and cursory < y + h then 
        return true 
        else 
        return false 
        end 
        end 
    
    local screenW, screenH = guiGetScreenSize()
    guipracka = false
    function guiPraca ()
        dxDrawLine((screenW * 0.3792) - 1, (screenH * 0.2833) - 1, (screenW * 0.3792) - 1, screenH * 0.7167, tocolor(0, 0, 0, 255), 1, false)
        dxDrawLine(screenW * 0.6208, (screenH * 0.2833) - 1, (screenW * 0.3792) - 1, (screenH * 0.2833) - 1, tocolor(0, 0, 0, 255), 1, false)
        dxDrawLine((screenW * 0.3792) - 1, screenH * 0.7167, screenW * 0.6208, screenH * 0.7167, tocolor(0, 0, 0, 255), 1, false)
        dxDrawLine(screenW * 0.6208, screenH * 0.7167, screenW * 0.6208, (screenH * 0.2833) - 1, tocolor(0, 0, 0, 255), 1, false)
        dxDrawRectangle(screenW * 0.3792, screenH * 0.2833, screenW * 0.2417, screenH * 0.4333, tocolor(0, 24, 254, 15), false)
        dxDrawText("Praca Rybaka", screenW * 0.4193, screenH * 0.3120, screenW * 0.5776, screenH * 0.3639, tocolor(255, 255, 255, 255), 2.00, "default", "center", "top", false, false, false, false, false)
        dxDrawRectangle(screenW * 0.4193, screenH * 0.5167, screenW * 0.1646, screenH * 0.0500, tocolor(126, 126, 127, 224), false)
        dxDrawRectangle(screenW * 0.4193, screenH * 0.5759, screenW * 0.1646, screenH * 0.0500, tocolor(126, 126, 127, 224), false)
        dxDrawText("Rozpocznij prace", screenW * 0.4375, screenH * 0.5231, screenW * 0.5646, screenH * 0.5574, tocolor(255, 255, 255, 255), 1.00, "default", "center", "top", false, false, false, false, false)
        dxDrawText("Anuluj", screenW * 0.4380, screenH * 0.5824, screenW * 0.5651, screenH * 0.6167, tocolor(255, 255, 255, 255), 1.00, "default", "center", "top", false, false, false, false, false)
    end
    local markerStartRybak = createMarker(1629.55, 582.18, 1.76-1,"cylinder",1.5,255,0,0,255)
    
    addEventHandler("onClientMarkerHit",markerStartRybak,function()
        if guipracka == false then 
            if isElementWithinMarker(localPlayer, markerStartRybak) then
            pokazOkno()
            guipracka = true
            setElementData(localPlayer,"gui:showed",true)
            showCursor(true)
            end
        end
    
    end)
    
    
    
    function pokazOkno()
        addEventHandler("onClientRender",root,guiPraca)
    end
    
    function zamknijOkno()
        removeEventHandler("onClientRender",root,guiPraca)
    end
    
    addEventHandler("onClientClick",getRootElement(),function(button, state)
        if button == "left" and state == "down" and guipracka == true then
            if getElementData(localPlayer,"gui:showed") then
            if cursorPosition(screenW * 0.4193, screenH * 0.5759, screenW * 0.1646, screenH * 0.0500) then
                removeEventHandler("onClientRender",root,guiPraca)
                guipracka = false
                setElementData(localPlayer,"gui:showed",false)
                showCursor(false)
            end
            end
        end
    end)
    
    
    addEventHandler("onClientClick",getRootElement(),function(button, state)
        if button == "left" and state == "down" and guipracka == true then
            if getElementData(localPlayer,"gui:showed",true) then
            if cursorPosition(screenW * 0.4193, screenH * 0.5167, screenW * 0.1646, screenH * 0.0500) then
            removeEventHandler("onClientRender",root,guiPraca)
            showCursor(false)
            setElementData(localPlayer,"player:working",true)
            setElementData(localPlayer,"gui:showed",false)
            end
        end
        end
    end)
    
    
    local markery = {
        
        {1633.33, 589.55, 1.76-1},
        {1622.88, 583.13, 1.76-1},
    
    }
    
    for _,v in ipairs(markery) do
        if getElementData(localPlayer,"player:working") == true then
        markerpraca = createMarker(v[1],v[2],v[3],"cylinder",2.0,255,255,255)
        end
    end
    addEventHandler("onClientMarkerHit",markerpraca,function(hitElement)
        if getElementData(localPlayer,"player:working") == true then
            setElementData(localPlayer,"player:working", false) 
            setElementData(localPlayer,"player:fishing",true)
            setElementFrozen(hitElement,true)
            triggerServerEvent("Lowienie",localPlayer,localPlayer)
        end
        setTimer(function()
                rnd = math.random(10,20)
                triggerServerEvent("givePlayerMoney",localPlayer,rnd)
                outputChatBox("Otrzymujesz"..rnd.. "PLN za zlowiona rybke",0,255,0)
                setElementFrozen(hitElement,false)
                triggerServerEvent("StopLowienie",localPlayer,localPlayer)
                setElementData(localPlayer,"player:fishing",false)
         end ,5000,1)
    end)

    WARNING : Bad argument addEventHandler : Expected element at argument 2 got nil

    (WARNING LINE : 93 ) at the bottom

    So my idea was to create a fishing job. I wanted the to make dxGui on which client clicks it shows randomly 2 markers that are in the table

     "markery" and after hitting that marker the player starts fishing ( Animation , and the timer starts ) but it does'nt really work the way i wanted to work as it shows the warning and the markers are showing after i click on the "rozpocznij prace " and then restart the script. Please help I'm starting with Lua and i went straight into it too fast. 

     

  4. Hello so i just watched a tutorial and tried to re-write exactly the same code as on the video it seemed to work throughout the tutorial but then at the end the error's started to pop up ,

    BAD ARGUMENT @ 'setElementData' [Expected element at argument 1 got boolean]

    I have no idea what to do i tried to solve it for a long time now without effects.

     

    Spoiler
    function createVehicleForPlayer(player, command, model)
        local db = exports.db:getConnection()
        local x,y,z = getElementPosition(player)
        y = y+5
        dbExec(db,"INSERT INTO vehicles(model, x, y, z) VALUES (?,?,?,?)",model, x , y , z)
        local vehicleObject = createVehicle(model,x, y, z)
        setElementData(vehicleObject, "id",vehicle.id,true)
     
       
        dbQuery(function(queryHandle)
            local results = dbPoll(queryHandle, 0)
            local vehicle = results[1]
        
        
        end, db,"SELECT id FROM vehicles ORDER BY id DESC LIMIT 1")
    end 
    addCommandHandler("createvehicle",createVehicleForPlayer,false,false)
     
    function loadAllVehicles(queryHandle, player)
        local results = dbPoll(queryHandle, 0)
     
        for index, vehicle in pairs(results) do
        local vehicleObject = createVehicle(vehicle.model, vehicle.x, vehicle.y, vehicle.z)
        setElementData(vehicleObject,"id",vehicle.id,true)
     
    end
    end
     
    addEventHandler("onResourceStart",resourceRoot,function ()
        local db = exports.db:getConnection()
     
        dbQuery(loadAllVehicles, db,"SELECT*FROM vehicles")
    end)
     
    addEventHandler("onResourceStop", resourceRoot,function ()
        local db = exports.db:getConnection()
        local vehicles = getElementsByType("vehicle")
        
        for index, vehicle in pairs(vehicles) do
            local id = getElementData(vehicle, "id")
            local x,y,z = getElementPosition(vehicle)
            dbExec(db,"UPDATE vehicles SET x = ?, y = ?, z = ? WHERE id = ?",x,y,z,model)
        end
    end)

     

  5. Hello,

    So i just started my journey with Lua and wanted to create an simple "info pickup". Basically you hit the pickup ((invisible marker)) and you see the info gui and i wanted to make few of these pickups around the map so i used a table to store the coordinates there but i found out that only 1 marker show the gui and other doesn't. I would like all the markers to show the same gui.

    Spoiler
    local ok = false
    local markery = {  
        { -2413.51171875-602.2509765625 , 132.5625-1 }, 
        { -2412.392578125-590.11328125 , 132.6484375-1 } 
     
    for k,v in ipairs( markery ) do 
        marki = createMarker ( v[1],v[2],v[3], "cylinder"2255255255255 ) 
        createPickup( v[1],v[2],v[3],3,1239,2000)
    end 
     
    addEventHandler("onClientMarkerHit",marki,function(player)
        if (player == localPlayerthen
            if (not ok) then
                ok = true
                addEventHandler("onClientRender",root,gui)
     
            end
        end
    end)
     
    addEventHandler("onClientMarkerLeave",marki,function( player )
        if (player == localPlayerthen
            if ( ok ) then
                ok = false
            end
        end 
    end)
    local screenW, screenH = guiGetScreenSize()
    function gui()
        if (not ok) then
        removeEventHandler("onClientRender",root,gui)
            return false
        end
        dxDrawLine((screenW * 0.2526- 1, (screenH * 0.3190- 1, (screenW * 0.2526- 1, screenH * 0.4922tocolor(000255), 1false)
        dxDrawLine(screenW * 0.7101, (screenH * 0.3190- 1, (screenW * 0.2526- 1, (screenH * 0.3190- 1tocolor(000255), 1false)
        dxDrawLine((screenW * 0.2526- 1, screenH * 0.4922, screenW * 0.7101, screenH * 0.4922tocolor(000255), 1false)
        dxDrawLine(screenW * 0.7101, screenH * 0.4922, screenW * 0.7101, (screenH * 0.3190- 1tocolor(000255), 1false)
        dxDrawRectangle(screenW * 0.2526, screenH * 0.3190, screenW * 0.4575, screenH * 0.1732tocolor(212025262), false)
        dxDrawText("Informacja", screenW * 0.3338, screenH * 0.3854, screenW * 0.6120, screenH * 0.4583tocolor(255255255255), 1.00"bankgothic""center""top"falsefalsefalsefalsefalse)
    end

     

×
×
  • Create New...