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

Wysłany: 2020-07-05, 21:24


NorbiTTT

Nbi#1824






Wiek: 27
Na forum: 3207 dni
Posty: 193
Nick w MP: Nbi

Piwa: 698

Respekt: 60


--[[
    AutorMalentas
]]

local sxsy guiGetScreenSize()
local font dxCreateFont("cz.ttf"12)


local panel false
local kupno false
local tryb 1

local idni guiCreateEdit(0.7130.560.130.04"Dni"true)
guiSetVisible(idnifalse)

function gui()
    if panel == 1 then
        local wlasciciel info["nwlasciciel"]
        if info["wlasciciel"] == 0 then
            wlasciciel "brak"
        end
        local zamek "otwarty"
        if info["zamkniety"] == 1 then
            zamek "zamkni?ty"
        end
        dxDrawImage(scale_x(548), scale_y(282), scale_x(345), scale_y(337), ":np-gui/grafiki/tlo.png"000tocolor(255255255255), false)
        shadowText(info["nazwa"], scale_x(546), scale_y(281), scale_x(893), scale_y(347), tocolor(255255255255), 1.00font"center""center"falsefalsefalsefalsefalse)
        shadowText("W?a?ciciel: "..wlasciciel.."\nCena: "..info["cena"].." PLN\nZamek: "..zamek..""scale_x(546), scale_y(348), scale_x(893), scale_y(497), tocolor(255255255255), 1.00font"center""center"falsefalsefalsefalsefalse)
        dxDrawImage(scale_x(633), scale_y(549), scale_x(175), scale_y(51), ":np-gui/grafiki/button_off.png"000tocolor(255255255255), false)
        if info["wlasciciel"] == 0 then
            dxDrawImage(scale_x(633), scale_y(487), scale_x(175), scale_y(51), ":np-gui/grafiki/button_off.png"000tocolor(255255255255), false)
            shadowText("Kup biznes"scale_x(633), scale_y(486), scale_x(808), scale_y(538), tocolor(255255255255), 1.00font"center""center"falsefalsefalsefalsefalse)
        elseif info["wlasciciel"] == getElementData(localPlayer"player:sid"then
            dxDrawImage(scale_x(633), scale_y(487), scale_x(175), scale_y(51), ":np-gui/grafiki/button_off.png"000tocolor(255255255255), false)
            shadowText("Ustawienia"scale_x(633), scale_y(486), scale_x(808), scale_y(538), tocolor(255255255255), 1.00font"center""center"falsefalsefalsefalsefalse)
        end
        shadowText("Wejd?"scale_x(633), scale_y(548), scale_x(808), scale_y(600), tocolor(255255255255), 1.00font"center""center"falsefalsefalsefalsefalse)
        dxDrawImage(scale_x(867), scale_y(292), scale_x(16), scale_y(16), ":guieditor/images/cross.png"000tocolor(255255255255), false)
    end
    if kupno == true then
        dxDrawImage(scale_x(949), scale_y(407), scale_x(324), scale_y(212), ":np-gui/grafiki/tlo.png"000tocolor(255255255255), false)
        shadowText("Kupno biznesu\nCena za dobe: "..info["cena"].." PLN"scale_x(949), scale_y(407), scale_x(1273), scale_y(520), tocolor(255255255255), 1.00font"center""center"falsefalsefalsefalsefalse)
        dxDrawImage(scale_x(1036), scale_y(561), scale_x(146), scale_y(43), ":np-gui/grafiki/button_off.png"000tocolor(255255255255), false)
        shadowText("Zakup"scale_x(1035), scale_y(561), scale_x(1182), scale_y(604), tocolor(255255255255), 1.00font"center""center"falsefalsefalsefalsefalse)
        dxDrawImage(scale_x(1247), scale_y(417), scale_x(16), scale_y(16), ":guieditor/images/cross.png"000tocolor(255255255255), false)
    end
    if panel == 2 then
        dxDrawImage(scale_x(429), scale_y(260), scale_x(583), scale_y(381), ":np-gui/grafiki/tlo.png"000tocolor(255255255255), false)
        dxDrawImage(scale_x(448), scale_y(277), scale_x(140), scale_y(49), ":np-gui/grafiki/button_off.png"000tocolor(255255255255), false)
        dxDrawImage(scale_x(448), scale_y(336), scale_x(140), scale_y(49), ":np-gui/grafiki/button_off.png"000tocolor(255255255255), false)
        dxDrawImage(scale_x(448), scale_y(395), scale_x(140), scale_y(49), ":np-gui/grafiki/button_off.png"000tocolor(255255255255), false)
        dxDrawImage(scale_x(448), scale_y(454), scale_x(140), scale_y(49), ":np-gui/grafiki/button_off.png"000tocolor(255255255255), false)
        shadowText("Informacje"scale_x(447), scale_y(277), scale_x(588), scale_y(326), tocolor(255255255255), 1.00font"center""center"falsefalsefalsefalsefalse)
        shadowText("Pracownicy"scale_x(447), scale_y(336), scale_x(588), scale_y(385), tocolor(255255255255), 1.00font"center""center"falsefalsefalsefalsefalse)
        shadowText("Op?acanie"scale_x(447), scale_y(395), scale_x(588), scale_y(444), tocolor(255255255255), 1.00font"center""center"falsefalsefalsefalsefalse)
        shadowText("Zamek"scale_x(448), scale_y(454), scale_x(589), scale_y(503), tocolor(255255255255), 1.00font"center""center"falsefalsefalsefalsefalse)
        dxDrawImage(scale_x(986), scale_y(270), scale_x(16), scale_y(16), ":guieditor/images/cross.png"000tocolor(255255255255), false)
        if tryb == 1 then
            shadowText("Informacje"scale_x(595), scale_y(276), scale_x(992), scale_y(613), tocolor(255255255255), 1.00font"center""center"falsefalsefalsefalsefalse)
        elseif tryb == 2 then
            dxDrawText("Pracownicy"scale_x(591), scale_y(276), scale_x(1007), scale_y(325), tocolor(255255255255), 1.00"default""center""center"falsefalsefalsefalsefalse)
            for i,v in ipairs(info["pracownicy"]) do
                local dodatekY = (scale_y(50))*(i-1)

                dxDrawRectangle(scale_x(602), scale_y(330)+dodatekYscale_x(395), scale_y(47), tocolor(000120), false)
                dxDrawText("1"scale_x(602), scale_y(330)+(dodatekY*2), scale_x(663), scale_y(377), tocolor(255255255255), 1.00"default""center""center"falsefalsefalsefalsefalse)
                dxDrawText("Malentas"scale_x(663), scale_y(330)+(dodatekY*2), scale_x(997), scale_y(377), tocolor(255255255255), 1.00"default""center""center"falsefalsefalsefalsefalse)
            end
        elseif tryb == 3 then
        end
    end
end

addEvent("biznes:gui"true)
addEventHandler("biznes:gui"root, function(spr)
    if not spr then return end
    if info then return end
    info spr
    addEventHandler("onClientRender"rootgui)
    showCursor(true)
    panel 1
    tryb 1
end)

addEvent("odswiez:info"true)
addEventHandler("odswiez:info"root, function(spr)
    info spr
end)

addEventHandler("onClientClick"root, function(btnstate)
    if btn == "left" and state == "down" then
        if mysz(scale_x(867), scale_y(292), scale_x(16), scale_y(16)) and panel == 1 then
            zamknij()
        elseif mysz(scale_x(633), scale_y(487), scale_x(175), scale_y(51)) and panel == 1 then
            if info["wlasciciel"] == 0 then
                kupno true
                guiSetVisible(idnitrue)
            elseif info["wlasciciel"] == getElementData(localPlayer"player:sid"then
                panel 2
            end
        elseif mysz(scale_x(633), scale_y(549), scale_x(175), scale_y(51)) and panel == 1 then
            triggerServerEvent("wejdz:biznes"localPlayerinfo)
            zamknij()
        elseif mysz(scale_x(1247), scale_y(417), scale_x(16), scale_y(16)) and kupno == true then
            kupno false
            guiSetVisible(idnifalse)
        elseif mysz(scale_x(1036), scale_y(561), scale_x(146), scale_y(43)) and kupno == true then
            local dni guiGetText(idni)
            if dni == "" or dni == "Dni" then return end
            if not tonumber(dnithen return end
            if dni:len() < 1 then return end
            triggerServerEvent("kup:biznes"localPlayerinfo["id"], tonumber(dni))
            zamknij()
        elseif mysz(scale_x(986), scale_y(270), scale_x(16), scale_y(16)) and panel == 2 then
            panel 1
        elseif mysz(scale_x(448), scale_y(454), scale_x(140), scale_y(49)) and panel == 2 then
            triggerServerEvent("biznes:zamek"localPlayerinfo["id"])
        elseif mysz(scale_x(448), scale_y(277), scale_x(140), scale_y(49)) and panel == 2 then
            tryb 1
        elseif mysz(scale_x(448), scale_y(336), scale_x(140), scale_y(49)) and panel == 2 then
            tryb 2
        elseif mysz(scale_x(448), scale_y(395), scale_x(140), scale_y(49)) and panel == 2 then
            tryb 3
        end
    end
end)


function zamknij()
    panel false
    kupno false
    info false
    removeEventHandler("onClientRender"rootgui)
    showCursor(false)
    guiSetVisible(idnifalse)
end
--opcje

function shadowText(text,x,y,w,h,color,size,font,xx,yy,x1,x2,x3,x4,x5)
    dxDrawText(text,x+1,y+1,w+1,h+1,tocolor(0,0,0),size,font,xx,yy,x1,x2,x3,x4,x5)
    dxDrawText(text,x,y,w,h,color,size,font,xx,yy,x1,x2,x3,x4,x5)
end

function mysz(psx,psy,pssx,pssy,abx,aby)
    if not isCursorShowing() then return end
    cx,cy=getCursorPosition()
    cx,cy=cx*sx,cy*sy
    if cx >= psx and cx <= psx+pssx and cy >= psy and cy <= psy+pssy then
        return true,cx,cy
    else
        return false
    end
end

function scale_x(value)
    local result = (value 1440) * sx

    return result
end

function scale_y(value)
    local result = (value 900) * sy

    return result
end

b??d: lua:62 bad argument #1 ipairs(table expected, got string)

linijka 62:

for i,v in ipairs(info["pracownicy"]) do


Postaw piwo autorowi tego posta
 

 
Wysłany: 2020-07-05, 21:40


Wilq







Wiek: 24
Na forum: 4428 dni
Posty: 3410

Piwa: 739

Respekt: 1225,8
Respekt: 1225,8

info["pracownicy"] zwraca tekst a nie tabel?. Najwyra?niej to, co zwraca Ci 'spr' w evencie to nie tabela.

Postaw piwo autorowi tego posta
 

 
Wysłany: 2020-07-05, 21:41


NorbiTTT

Nbi#1824






Wiek: 27
Na forum: 3207 dni
Posty: 193
Nick w MP: Nbi

Piwa: 698

Respekt: 60

Dasz przyk?ad jak naprawi? ?

Postaw piwo autorowi tego posta
 

 
Wysłany: 2020-07-05, 21:59


Wilq







Wiek: 24
Na forum: 4428 dni
Posty: 3410

Piwa: 739

Respekt: 1225,8
Respekt: 1225,8

Jak mam da? przyk?ad, po prostu to co triggerujesz w evencie "biznes:gui" pod zmienn? 'spr' nie zawiera tabeli 'pracownicy' tylko string. Sprawdzasz co przekazujesz i zmieniasz.

Postaw piwo autorowi tego posta
 

 
Wysłany: 2020-07-06, 13:49


MeeShuffle

Programista/Grafik






Wiek: 32
Na forum: 4394 dni
Posty: 2758
Nick w MP: Shuffle

Piwa: 8575

Respekt: 535,3
Respekt: 535,3

Dla wi?kszej optymalizacji kodu, polecam r?wnie? zdefiniowa? tabel? na poczatku kodu co wyeliminuje ewentualne b??dy (tabela={})

Postaw piwo autorowi tego posta
 

 
Tagi: ipairs
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