Jump to content

I need a help with the character picker


Recommended Posts

This script is works when i have a character in my sql table but if i dont then i want to log in doesnt bring me to the character picker resource and i cant find the wrong place why :( and doesnt give me anything in the debugscript

There is my login sourceS

local mysql = exports.cG_MySQL 
  
function logThePlayer(thePlayer, userName, passWord) 
    if thePlayer and userName and passWord then 
        if getElementType(thePlayer) == "player" then 
            local account = mysql:db_Query("SELECT * FROM accounts WHERE userName='" .. userName .. "'") 
            for i, sor in ipairs(account) do 
                if sor["passWord"] == passWord then 
                    local lastLogin = getRealTime() 
                    if tostring(lastLogin.month+1):len() < 2 then 
                        lastLogin.month = "0" .. tostring(lastLogin.month)+1 
                    end 
                    if tostring(lastLogin.monthday):len() < 2 then 
                        lastLogin.monthday = "0" .. tostring(lastLogin.monthday) 
                    end 
                    local lastLoginText = tostring(lastLogin.year+1900 .. "-" .. lastLogin.month .. "-" .. lastLogin.monthday) 
                    mysql:db_Exec("UPDATE accounts SET pLastLogin='" .. lastLoginText .. "' WHERE userName='" .. userName .. "'") 
                    mysql:db_Exec("UPDATE accounts SET pIP='" .. getPlayerIP(thePlayer) .. "' WHERE userName='" .. userName .. "'") 
                    mysql:db_Exec("UPDATE accounts SET pSerial='" .. getPlayerSerial(thePlayer) .. "' WHERE userName='" .. userName .. "'") 
                    local character = mysql:db_Query("SELECT * FROM characters WHERE accountName ='" .. userName .. "'") 
                    setElementData(thePlayer, "acc:adminLevel", sor["adminLevel"]) 
                    --outputChatBox("a") 
                    if character then 
                        outputChatBox("a") 
                        for i, sor in ipairs(character) do 
                            setElementData(thePlayer, "acc:userName", userName) 
                            setPlayerMoney(thePlayer, sor["pMoney"]) 
                            spawnPlayer(thePlayer, sor["pX"], sor["pY"], sor["pZ"], sor["pRot"], sor["pSkin"], sor["pInt"], sor["pDim"]) 
                            setElementData(thePlayer, "acc:legalChange", true) 
                            setPlayerName(thePlayer, sor["characterName"]) 
                            setCameraTarget(thePlayer, thePlayer) 
                            --setElementData(thePlayer "acc:legalChange", false) 
                            triggerClientEvent(thePlayer, "hideLGP", getRootElement()) 
                            local itemTable = sor["pItems"]:gsub(",", "") 
                            outputChatBox(itemTable:gsub(itemTable:sub(-1), "")) 
                            for i, k in ipairs(itemTable) do 
                                setElementData(thePlayer, "acc:pItems" .. i, k) 
                                outputChatBox(i .. " slot iteme: " .. k) 
                            end 
                        end 
                    else 
                        triggerClientEvent(thePlayer, "addChar", getRootElement()) 
                        triggerClientEvent(thePlayer, "hideLGP", getRootElement()) 
                    end 
                end 
            end 
        end 
    end 
end 
addEvent("logIn", true) 
addEventHandler("logIn", getRootElement(), logThePlayer) 

And there is my character picker

local sX, sY = guiGetScreenSize() 
local gW, gH = 300, 425 
local eW, eH = 250, 25 
local malevSkins =  {0, 1, 2, 7, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 32, 33, 34, 35, 36, 37, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 57, 58, 59, 60, 61, 62, 66, 67, 68, 70, 71, 72, 73, 78, 79, 80, 81, 82, 83, 84, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 120, 121, 122, 123, 124, 125, 126, 127, 128, 132, 133, 134, 135, 136, 137, 142, 143, 144, 146, 147, 153, 154, 155, 156, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 170, 171, 173, 174, 175, 176, 177, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 200, 202, 203, 204, 206, 209, 210, 212, 213, 217, 220, 221, 222, 223, 227, 228, 229, 230, 234, 235, 236, 239, 240, 241, 242, 247, 248, 249, 250, 252, 253, 254, 255, 258, 259, 260, 261, 262, 264, 265, 266, 267, 268, 269, 270, 271, 272, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 290, 291, 292, 293, 294, 295, 296, 297, 299, 300, 301, 302, 303, 305, 306, 307, 308, 309, 310, 311, 312} 
local femalevSkins = {9, 10, 11, 12, 13, 31, 38, 39, 40, 41, 53, 54, 55, 56, 63, 64, 69, 75, 76, 77, 85, 87, 88, 89, 90, 91, 92, 93, 129, 130, 131, 138, 139, 140, 141, 145, 148, 150, 151, 152, 157, 169, 172, 178, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 201, 205, 207, 211, 214, 215, 216, 218, 219, 224, 225, 226, 231, 232, 233, 237, 238, 243, 244, 245, 246, 251, 256, 257, 263, 298, 304} 
local cSkin = 1 
local font = guiCreateFont("nyil.ttf", 20) 
local gP = guiCreateWindow(10, (sY-gH)/2, gW, gH, "Karakter létrehozás", false) 
local aB = guiCreateButton(gW/2-150/2, gH-30, 150, 25, "Létrehozás", false, gP) 
local fL = guiCreateLabel(gW/2-dxGetTextWidth("Karakter neve:")/2, 25, eW, eH, "Karakter neve:", false, gP) 
local fE = guiCreateEdit((gW-eW)/2, 50, eW, eH, "Krobi", false, gP) 
local nL = guiCreateLabel(gW/2-dxGetTextWidth("Neme:")/2, 80, eW, eH, "Neme:", false, gP) 
local fR = guiCreateRadioButton(gW/2-20, 95, 50, 15, "Férfi", false, gP) 
local nR = guiCreateRadioButton(gW/2-20, 110, 50, 15, "Nő", false, gP) 
local kL = guiCreateLabel(gW/2-dxGetTextWidth("Kezdőpont:")/2, 135, eW, eH, "Kezdőpont:", false, gP) 
local lsS = guiCreateCheckBox(75, 155, 50, 15, "LS", true, false, gP) 
local lvS = guiCreateCheckBox(135, 155, 50, 15, "LV", false, false, gP) 
local sfS = guiCreateCheckBox(195, 155, 50, 15, "SF", false, false, gP) 
local sL = guiCreateLabel(gW/2-dxGetTextWidth("Kinézet:")/2, 185, eW, eH, "Kinézet:", false, gP) 
local bG = guiCreateLabel(100, 200, 20, 35, "<", false, gP) 
local jG = guiCreateLabel(185, 200, 20, 35, ">", false, gP) 
local pPed = createPed(0, 2186.09937, -1156.86914, 1029.79688, -90) 
guiSetVisible(gP, false) 
setElementInterior(pPed, 15) 
guiRadioButtonSetSelected(fR, true) 
guiSetFont(bG, font) 
guiSetFont(jG, font) 
guiWindowSetMovable(gP, false) 
guiWindowSetSizable(gP, false) 
  
function showCharacterCreate() 
    showCursor(true) 
    setCameraMatrix(2190.66138, -1156.88782, 1029.79688,2186.09937, -1156.86914, 1029.79688) 
    guiSetVisible(gP, true) 
    setElementInterior(localPlayer, 15) 
end 
addEvent("addChar", true) 
addEventHandler("addChar", getRootElement(), showCharacterCreate) 
  
function clickOnThings() 
    if source == lsS then 
        guiCheckBoxSetSelected(lsS, true) 
        guiCheckBoxSetSelected(lvS, false) 
        guiCheckBoxSetSelected(sfS, false) 
    elseif source == lvS then 
        guiCheckBoxSetSelected(lvS, true) 
        guiCheckBoxSetSelected(lsS, false) 
        guiCheckBoxSetSelected(sfS, false) 
    elseif source == sfS then 
        guiCheckBoxSetSelected(sfS, true) 
        guiCheckBoxSetSelected(lsS, false) 
        guiCheckBoxSetSelected(lvS, false) 
    elseif source == fR or source == nR then 
        cSkin = 1 
        if source == fR then 
            setElementModel(pPed, malevSkins[cSkin]) 
        else 
            setElementModel(pPed, femalevSkins[cSkin]) 
        end 
    elseif source == bG then 
        if guiRadioButtonGetSelected(fR) then 
            if cSkin > 1 then 
                cSkin = cSkin - 1 
                setElementModel(pPed, malevSkins[cSkin]) 
            end 
        elseif guiRadioButtonGetSelected(nR) then 
            if cSkin > 1 then 
                cSkin = cSkin - 1 
                setElementModel(pPed, femalevSkins[cSkin]) 
            end 
        end 
    elseif source == jG then 
        if guiRadioButtonGetSelected(fR) then 
            if cSkin < #malevSkins then 
                cSkin = cSkin + 1 
                setElementModel(pPed, malevSkins[cSkin]) 
            end 
        elseif guiRadioButtonGetSelected(nR) then 
            if cSkin < #femalevSkins then 
                cSkin = cSkin + 1 
                setElementModel(pPed, femalevSkins[cSkin]) 
            end 
        end 
    elseif source == aB then 
        if guiGetText(fE) ~= "" then 
            triggerServerEvent("addChar", getRootElement(), localPlayer, guiGetText(fE),setElementModel(pPed), guiRadioButtonGetSelected(fR), guiCheckBoxGetSelected(lsS), guiCheckBoxGetSelected(lvS), guiCheckBoxGetSelected(sfS)) 
        else 
        end 
    end 
end 
addEventHandler("onClientGUIClick", getRootElement(), clickOnThings) 

Link to comment

Just add an elemend data as a verification like this:

function check() 
    local caracter = getElementData(source, "Is.Player.Have.Caracter") 
    if (caracter == true) then 
        --Do something. 
    else 
        --Send him to caracter choser. 
    end 
end 
addEventHandler("EventName", root, check) 

You will also need to set that element data as true after player chose his caracter

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...