Stealthy Serval

triggerClientEvent does nothing

Recommended Posts

EDIT:

I realize now the issue is that I am calling SQL functions client-side.

Any tips on how to migrate the majority of that client-side script server-side?

END EDIT

I'm trying to make it so when the player signs in, it will count how many characters they have, and create a GUI based on that.

But I can not get my script to talk to my clientside event, no matter what I try.

Any help on this would be appreciated!

 

Server-Side Script:

function characterMain()
    charCount = 0
    acq = sql:query("SELECT * FROM characters")
    for i,c in ipairs(acq)do
        cq = sql:query("SELECT * FROM characters WHERE account=?",getElementData(source,"getPlayerUsername"))
        characters = cq[1]
        if characters then
            charCount = charCount+1
        end
    end
    outputDebugString("Account: "..getElementData(source,"getPlayerUsername").." has "..charCount.." character(s).")
    triggerClientEvent(source,"showCharacters",source,source,charCount)
    --return charCount
end
addEvent("character.main",true)
addEventHandler("character.main",getRootElement(),characterMain)

Client-Side Script (It's lengthy):

function showCharacters(player, characterCount)
    local loopCount = 0
    local character = {}
    character[1] = {}
    character[2] = {}
    character[3] = {}
    acq = sql:query("SELECT * FROM characters WHERE account=?",getElementData(source,"getPlayerUsername"))
    for i,c in ipairs(acq)do
        if(characterCount == 1)then
            if(loopCount == 0)then
                character[1].skin = tonumber(c.skin)
                character[1].name = c.name
                character[1].cash = c.cash
                character[1].bank = c.bank
                loopCount = loopCount+1
            end
        elseif(characterCount == 2)then
            if(loopCount == 0)then
                character[1].skin = tonumber(c.skin)
                character[1].name = c.name
                character[1].cash = c.cash
                character[1].bank = c.bank
                loopCount = loopCount+1
            elseif(loopCount == 1)then
                character[2].skin = tonumber(c.skin)
                character[2].name = c.name
                character[2].cash = c.cash
                character[2].bank = c.bank
                loopCount = loopCount+1
            end
        elseif(characterCount == 3)then
            if(loopCount == 0)then
                character[1].skin = tonumber(c.skin)
                character[1].name = c.name
                character[1].cash = c.cash
                character[1].bank = c.bank
                loopCount = loopCount+1
            elseif(loopCount == 1)then
                character[2].skin = tonumber(c.skin)
                character[2].name = c.name
                character[2].cash = c.cash
                character[2].bank = c.bank
                loopCount = loopCount+1
            elseif(loopCount == 2)then
                character[3].skin = tonumber(c.skin)
                character[3].name = c.name
                character[3].cash = c.cash
                character[3].bank = c.bank
                loopCount = loopCount+1
            end
        end
    end
    local screenW, screenH = guiGetScreenSize()
    characterWindow.window = guiCreateWindow(10, (screenH - 391) / 2, 272, 391, "Select character image to continue", false)
    guiWindowSetSizable(characterWindow.window, false)
    characterWindow.accountLogout = guiCreateButton(10, 366, 85, 15, "Logout", false, characterWindow.window)
    guiSetProperty(characterWindow.accountLogout, "NormalTextColour", "FFAAAAAA")
    characterWindow.accountDisconnect = guiCreateButton(174, 367, 85, 14, "Disconnect", false, characterWindow.window)
    guiSetProperty(characterWindow.button[2], "NormalTextColour", "FFAAAAAA")
    --First Character, position for subsequent characters is +60        
    if(characterCount == 1)then
        --[[CHARACTER #1]]
        characterSelection.character[1] = guiCreateStaticImage(10, 29, 55, 50, ":character-system/images/chars/"..character[1].skin..".png", false, characterWindow.window)
        characterWindow.characterName[1] = guiCreateLabel(75, 32, 119, 15, character[1].name, false, characterWindow.window)
        characterWindow.characterCash[1] = guiCreateLabel(75, 47, 119, 15, character[1].cash, false, characterWindow.window)
        characterWindow.characterBank[1] = guiCreateLabel(75, 62, 119, 15, character[1].bank, false, characterWindow.window)
        characterWindow.deleteCharacter = guiCreateStaticImage(204, 29, 55, 50, ":character-system/images/delete-char.png", false, characterWindow.window)
        guiSetVisible(characterWindow.window,true)
    elseif(characterCount == 2)then
        --[[CHARACTER #1]]
        characterSelection.character[1] = guiCreateStaticImage(10, 29, 55, 50, ":character-system/images/chars/"..character[1].skin..".png", false, characterWindow.window)
        characterWindow.characterName[1] = guiCreateLabel(75, 32, 119, 15, character[1].name, false, characterWindow.window)
        characterWindow.characterCash[1] = guiCreateLabel(75, 47, 119, 15, character[1].cash, false, characterWindow.window)
        characterWindow.characterBank[1] = guiCreateLabel(75, 62, 119, 15, character[1].bank, false, characterWindow.window)
        characterWindow.deleteCharacter = guiCreateStaticImage(204, 29, 55, 50, ":character-system/images/delete-char.png", false, characterWindow.window)
        --[[CHARACTER #2]]
        characterSelection.character[2] = guiCreateStaticImage(10, 89, 55, 50, ":character-system/images/chars/"..character[2].skin..".png", false, characterWindow.window)
        characterWindow.characterName[2] = guiCreateLabel(75, 92, 119, 15, character[2].name, false, characterWindow.window)
        characterWindow.characterCash[2] = guiCreateLabel(75, 107, 119, 15, character[2].cash, false, characterWindow.window)
        characterWindow.characterBank[2] = guiCreateLabel(75, 122, 119, 15, character[2].bank, false, characterWindow.window)
        characterWindow.deleteCharacter = guiCreateStaticImage(204, 89, 55, 50, ":character-system/images/delete-char.png", false, characterWindow.window)
        guiSetVisible(characterWindow.window,true)
    elseif(characterCount == 3)then
        --[[CHARACTER #1]]
        characterSelection.character[1] = guiCreateStaticImage(10, 29, 55, 50, ":character-system/images/chars/"..character[1].skin..".png", false, characterWindow.window)
        characterWindow.characterName[1] = guiCreateLabel(75, 32, 119, 15, character[1].name, false, characterWindow.window)
        characterWindow.characterCash[1] = guiCreateLabel(75, 47, 119, 15, character[1].cash, false, characterWindow.window)
        characterWindow.characterBank[1] = guiCreateLabel(75, 62, 119, 15, character[1].bank, false, characterWindow.window)
        characterWindow.deleteCharacter = guiCreateStaticImage(204, 29, 55, 50, ":character-system/images/delete-char.png", false, characterWindow.window)
        --[[CHARACTER #2]]
        characterSelection.character[2] = guiCreateStaticImage(10, 89, 55, 50, ":character-system/images/chars/"..character[2].skin..".png", false, characterWindow.window)
        characterWindow.characterName[2] = guiCreateLabel(75, 92, 119, 15, character[2].name, false, characterWindow.window)
        characterWindow.characterCash[2] = guiCreateLabel(75, 107, 119, 15, character[2].cash, false, characterWindow.window)
        characterWindow.characterBank[2] = guiCreateLabel(75, 122, 119, 15, character[2].bank, false, characterWindow.window)
        characterWindow.deleteCharacter = guiCreateStaticImage(204, 89, 55, 50, ":character-system/images/delete-char.png", false, characterWindow.window)
        --[[CHARACTER #3]]
        characterSelection.character[3] = guiCreateStaticImage(10, 149, 55, 50, ":character-system/images/chars/"..character[3].skin..".png", false, characterWindow.window)
        characterWindow.characterName[3] = guiCreateLabel(75, 152, 119, 15, character[3].name, false, characterWindow.window)
        characterWindow.characterCash[3] = guiCreateLabel(75, 167, 119, 15, character[3].cash, false, characterWindow.window)
        characterWindow.characterBank[3] = guiCreateLabel(75, 182, 119, 15, character[3].bank, false, characterWindow.window)
        characterWindow.deleteCharacter = guiCreateStaticImage(204, 149, 55, 50, ":character-system/images/delete-char.png", false, characterWindow.window)
        guiSetVisible(characterWindow.window,true)
    else
        outputDebugString("It worked, finally.")
        guiSetVisible(characterWindow.window,false)
    end
end
addEvent("showCharacters",true)
addEventHandler("showCharacters",getRootElement(),showCharacters)

The server-side function is working, and will return to the server "Account has X characters" correctly, but will not trigger the client-side event.

Edited by Stealthy Serval

Share this post


Link to post

I remember having issues with the player as source element, try using resourceRoot

triggerClientEvent(source,"showCharacters",resourceRoot,source,charCount)

 

Share this post


Link to post
5 minutes ago, Zango said:

I remember having issues with the player as source element, try using resourceRoot


triggerClientEvent(source,"showCharacters",resourceRoot,source,charCount)

 

So, the issue actually was that I forgot you can't call SQL functions client-side. So I've got to find a way to migrate the bulk of that data server-side.

Any tips? lol

Share this post


Link to post

Well it looks like you are already selecting the account data in the server code, so you could pass it to the client in the event?

Share this post


Link to post

@Stealthy Serval

Why not move this to serverside? As far as I can see your code is already starting there.

 

 

    local loopCount = 0
    local character = {}
    character[1] = {}
    character[2] = {}
    character[3] = {}
    acq = sql:query("SELECT * FROM characters WHERE account=?",getElementData(source,"getPlayerUsername"))
    for i,c in ipairs(acq)do
        if(characterCount == 1)then
            if(loopCount == 0)then
                character[1].skin = tonumber(c.skin)
                character[1].name = c.name
                character[1].cash = c.cash
                character[1].bank = c.bank
                loopCount = loopCount+1
            end
        elseif(characterCount == 2)then
            if(loopCount == 0)then
                character[1].skin = tonumber(c.skin)
                character[1].name = c.name
                character[1].cash = c.cash
                character[1].bank = c.bank
                loopCount = loopCount+1
            elseif(loopCount == 1)then
                character[2].skin = tonumber(c.skin)
                character[2].name = c.name
                character[2].cash = c.cash
                character[2].bank = c.bank
                loopCount = loopCount+1
            end
        elseif(characterCount == 3)then
            if(loopCount == 0)then
                character[1].skin = tonumber(c.skin)
                character[1].name = c.name
                character[1].cash = c.cash
                character[1].bank = c.bank
                loopCount = loopCount+1
            elseif(loopCount == 1)then
                character[2].skin = tonumber(c.skin)
                character[2].name = c.name
                character[2].cash = c.cash
                character[2].bank = c.bank
                loopCount = loopCount+1
            elseif(loopCount == 2)then
                character[3].skin = tonumber(c.skin)
                character[3].name = c.name
                character[3].cash = c.cash
                character[3].bank = c.bank
                loopCount = loopCount+1
            end
        end
    end

 

Share this post


Link to post

just move the SQL function to the server-side script and pass the resulted table with the same triggerClientEvent

Share this post


Link to post

Hey all, thanks for the replies.

So, I ended up migrating a bit of it serverside, and changing it up clientside. If anyone has any general feedback on my code, or anything they see that makes them really question why the heck I did things a certain way, please feel free to share as I am still very very new to Lua and programming in general.

Server-side script:

sql = exports["sql-system"]
function characterMain()
    charCount = 0
    character = {}
    character[1] = {}
    character[2] = {}
    character[3] = {}
    allAccountQuery = sql:query("SELECT * FROM characters")
    selectedID = 0
    for i,c in ipairs(allAccountQuery)do
        selectedID = selectedID+1
        userCharacterQuery = sql:query("SELECT * FROM characters WHERE id=?",selectedID)
        characters = userCharacterQuery[1]
        if characters then
            if(characters.account == getElementData(source,"getPlayerUsername"))then
                charCount = charCount+1
                if(charCount == 1)then
                    character[1].skin = characters.skin
                    character[1].name = characters.name
                    character[1].cash = characters.cash
                    character[1].bank = characters.bank
                    character[1].valid = true
                elseif(charCount == 2)then
                    character[2].skin = characters.skin
                    character[2].name = characters.name
                    character[2].cash = characters.cash
                    character[2].bank = characters.bank
                    character[2].valid = true
                elseif(charCount == 3)then
                    character[3].skin = characters.skin
                    character[3].name = characters.name
                    character[3].cash = characters.cash
                    character[3].bank = characters.bank
                    character[3].valid = true
                end
            end
        end
    end
    if(character[1].valid == true)then
        setElementData(source,"char1skin",character[1].skin)
        setElementData(source,"char1name",character[1].name)
        setElementData(source,"char1bank",character[1].bank)
        setElementData(source,"char1cash",character[1].cash)
    end
    if(character[2].valid == true)then
        setElementData(source,"char2skin",character[2].skin)
        setElementData(source,"char2name",character[2].name)
        setElementData(source,"char2bank",character[2].bank)
        setElementData(source,"char2cash",character[2].cash)
    end
    if(character[3].valid == true)then
        setElementData(source,"char3skin",character[3].skin)
        setElementData(source,"char3name",character[3].name)
        setElementData(source,"char3bank",character[3].bank)
        setElementData(source,"char3cash",character[3].cash)
    end
    triggerClientEvent(source,"showCharacters",resourceRoot,source,charCount)
end
addEvent("character.main",true)
addEventHandler("character.main",getRootElement(),characterMain)

and the Client-Side script:

characterWindow = {}
characterWindow.character = {}
characterWindow.characterName = {}
characterWindow.characterCash = {}
characterWindow.characterBank = {}
characterWindow.characterButton = {}
characterWindow.deleteCharacterButton = {}

function showCharacters(player, characterCount)
    local screenW, screenH = guiGetScreenSize()
    characterWindow.window = guiCreateWindow(10, (screenH - 391) / 2, 272, 391, "Select character image to continue", false)
    guiWindowSetSizable(characterWindow.window, false)
    characterWindow.accountLogout = guiCreateButton(10, 366, 85, 15, "Logout", false, characterWindow.window)
    guiSetProperty(characterWindow.accountLogout, "NormalTextColour", "FFAAAAAA")
    characterWindow.accountDisconnect = guiCreateButton(174, 367, 85, 14, "Disconnect", false, characterWindow.window)
    guiSetProperty(characterWindow.accountDisconnect, "NormalTextColour", "FFAAAAAA")
    --First Character, position for subsequent characters is +60
    if(characterCount == 0)then
        --[[CREATE CHARACTER]]
        characterWindow.newChar = guiCreateStaticImage(10, 29, 55, 50, ":character-system/images/create-char.png", false, characterWindow.window)
        characterWindow.newCharLabel = guiCreateLabel(75, 32, 155, 15, "Create New Character", false, characterWindow.window)
        characterWindow.newCharSlots = guiCreateLabel(75, 62, 155, 15, "3 Character Slots Remaining", false, characterWindow.window)
        characterWindow.newCharButton = guiCreateButton(10, 28, 252, 52, "", false, characterWindow.window)
        guiSetAlpha(characterWindow.newCharButton, 0.00)
        guiSetProperty(characterWindow.newCharButton, "Alpha", "0.000000")
        guiSetProperty(characterWindow.newCharButton, "NormalTextColour", "FFAAAAAA")
        guiSetVisible(characterWindow.window,true)        
    elseif(characterCount == 1)then
        --[[CHARACTER #1]]
        characterWindow.character[1] = guiCreateStaticImage(10, 29, 55, 50, ":character-system/images/chars/"..getElementData(player,"char1skin")..".png", false, characterWindow.window)
        characterWindow.characterName[1] = guiCreateLabel(75, 32, 119, 15, getElementData(player,"char1name"), false, characterWindow.window)
        characterWindow.characterCash[1] = guiCreateLabel(75, 47, 119, 15, "Cash: $"..getElementData(player,"char1cash"), false, characterWindow.window)
        characterWindow.characterBank[1] = guiCreateLabel(75, 62, 119, 15, "Bank: $"..getElementData(player,"char1bank"), false, characterWindow.window)
        characterWindow.deleteCharacter = guiCreateStaticImage(204, 29, 55, 50, ":character-system/images/delete-char.png", false, characterWindow.window)
        characterWindow.characterButton[1] = guiCreateButton(10, 28, 192, 52, "", false, characterWindow.window)
        characterWindow.deleteCharacterButton[1] = guiCreateButton(202, 28, 60, 52, "", false, characterWindow.window)
        guiSetAlpha(characterWindow.characterButton[1], 0.00)
        guiSetProperty(characterWindow.characterButton[1], "Alpha", "0.000000")
        guiSetAlpha(characterWindow.deleteCharacterButton[1], 0.00)
        guiSetProperty(characterWindow.deleteCharacterButton[1], "Alpha", "0.000000")
        guiSetProperty(characterWindow.characterButton[1], "NormalTextColour", "FFAAAAAA")
        addEventHandler("onClientGUIClick",characterWindow.characterButton[1],selectCharacter,false)
        addEventHandler("onClientGUIClick",characterWindow.deleteCharacterButton[1],deleteCharacter,false)
        --[[CREATE CHARACTER]]
        characterWindow.newChar = guiCreateStaticImage(10, 89, 55, 50, ":character-system/images/create-char.png", false, characterWindow.window)
        characterWindow.newCharLabel = guiCreateLabel(75, 92, 155, 15, "Create New Character", false, characterWindow.window)
        characterWindow.newCharSlots = guiCreateLabel(75, 122, 155, 15, "2 Character Slots Remaining", false, characterWindow.window)
        characterWindow.newCharButton = guiCreateButton(10, 88, 252, 52, "", false, characterWindow.window)
        guiSetAlpha(characterWindow.newCharButton, 0.00)
        guiSetProperty(characterWindow.newCharButton, "Alpha", "0.000000")
        guiSetProperty(characterWindow.newCharButton, "NormalTextColour", "FFAAAAAA")
        addEventHandler("onClientGUIClick",characterWindow.newCharButton,createCharacter,false)
        guiSetVisible(characterWindow.window,true)
    elseif(characterCount == 2)then
        --[[CHARACTER #1]]
        characterWindow.character[1] = guiCreateStaticImage(10, 29, 55, 50, ":character-system/images/chars/"..getElementData(player,"char1skin")..".png", false, characterWindow.window)
        characterWindow.characterName[1] = guiCreateLabel(75, 32, 119, 15, getElementData(player,"char1name"), false, characterWindow.window)
        characterWindow.characterCash[1] = guiCreateLabel(75, 47, 119, 15, "Cash: $"..getElementData(player,"char1cash"), false, characterWindow.window)
        characterWindow.characterBank[1] = guiCreateLabel(75, 62, 119, 15, "Bank: $"..getElementData(player,"char1bank"), false, characterWindow.window)
        characterWindow.deleteCharacter = guiCreateStaticImage(204, 29, 55, 50, ":character-system/images/delete-char.png", false, characterWindow.window)
        characterWindow.characterButton[1] = guiCreateButton(10, 28, 192, 52, "", false, characterWindow.window)
        characterWindow.deleteCharacterButton[1] = guiCreateButton(202, 28, 60, 52, "", false, characterWindow.window)
        guiSetAlpha(characterWindow.characterButton[1], 0.00)
        guiSetProperty(characterWindow.characterButton[1], "Alpha", "0.000000")
        guiSetAlpha(characterWindow.deleteCharacterButton[1], 0.00)
        guiSetProperty(characterWindow.deleteCharacterButton[1], "Alpha", "0.000000")
        guiSetProperty(characterWindow.characterButton[1], "NormalTextColour", "FFAAAAAA")
        guiSetProperty(characterWindow.deleteCharacterButton[1], "NormalTextColour", "FFAAAAAA")
        addEventHandler("onClientGUIClick",characterWindow.characterButton[1],selectCharacter,false)
        addEventHandler("onClientGUIClick",characterWindow.deleteCharacterButton[1],deleteCharacter,false)
        --[[CHARACTER #2]]
        characterWindow.character[2] = guiCreateStaticImage(10, 89, 55, 50, ":character-system/images/chars/"..getElementData(player,"char2skin")..".png", false, characterWindow.window)
        characterWindow.characterName[2] = guiCreateLabel(75, 92, 119, 15, getElementData(player,"char2name"), false, characterWindow.window)
        characterWindow.characterCash[2] = guiCreateLabel(75, 107, 119, 15, "Cash: $"..getElementData(player,"char2cash"), false, characterWindow.window)
        characterWindow.characterBank[2] = guiCreateLabel(75, 122, 119, 15, "Bank: $"..getElementData(player,"char2bank"), false, characterWindow.window)
        characterWindow.deleteCharacter = guiCreateStaticImage(204, 89, 55, 50, ":character-system/images/delete-char.png", false, characterWindow.window)
        characterWindow.characterButton[2] = guiCreateButton(10, 88, 192, 52, "", false, characterWindow.window)
        characterWindow.deleteCharacterButton[2] = guiCreateButton(202, 88, 60, 52, "", false, characterWindow.window)
        guiSetAlpha(characterWindow.characterButton[2], 0.00)
        guiSetProperty(characterWindow.characterButton[2], "Alpha", "0.000000")
        guiSetAlpha(characterWindow.deleteCharacterButton[2], 0.00)
        guiSetProperty(characterWindow.deleteCharacterButton[2], "Alpha", "0.000000")
        guiSetProperty(characterWindow.characterButton[2], "NormalTextColour", "FFAAAAAA")
        guiSetProperty(characterWindow.deleteCharacterButton[2], "NormalTextColour", "FFAAAAAA")
        addEventHandler("onClientGUIClick",characterWindow.characterButton[2],selectCharacter,false)
        addEventHandler("onClientGUIClick",characterWindow.deleteCharacterButton[2],deleteCharacter,false)
        --[[CREATE CHARACTER]]
        characterWindow.newChar = guiCreateStaticImage(10, 149, 55, 50, ":character-system/images/create-char.png", false, characterWindow.window)
        characterWindow.newCharLabel = guiCreateLabel(75, 152, 155, 15, "Create New Character", false, characterWindow.window)
        characterWindow.newCharSlots = guiCreateLabel(75, 182, 155, 15, "1 Character Slot Remaining", false, characterWindow.window)
        characterWindow.newCharButton = guiCreateButton(10, 148, 252, 52, "", false, characterWindow.window)
        guiSetAlpha(characterWindow.newCharButton, 0.00)
        guiSetProperty(characterWindow.newCharButton, "Alpha", "0.000000")
        guiSetProperty(characterWindow.newCharButton, "NormalTextColour", "FFAAAAAA")
        addEventHandler("onClientGUIClick",characterWindow.newCharButton,createCharacter,false)
        guiSetVisible(characterWindow.window,true)
    elseif(characterCount == 3)then
        --[[CHARACTER #1]]
        characterWindow.character[1] = guiCreateStaticImage(10, 29, 55, 50, ":character-system/images/chars/"..getElementData(player,"char1skin")..".png", false, characterWindow.window)
        characterWindow.characterName[1] = guiCreateLabel(75, 32, 119, 15, getElementData(player,"char1name"), false, characterWindow.window)
        characterWindow.characterCash[1] = guiCreateLabel(75, 47, 119, 15, "Cash: $"..getElementData(player,"char1cash"), false, characterWindow.window)
        characterWindow.characterBank[1] = guiCreateLabel(75, 62, 119, 15, "Bank: $"..getElementData(player,"char1bank"), false, characterWindow.window)
        characterWindow.deleteCharacter = guiCreateStaticImage(204, 29, 55, 50, ":character-system/images/delete-char.png", false, characterWindow.window)
        characterWindow.characterButton[1] = guiCreateButton(10, 28, 192, 52, "", false, characterWindow.window)
        characterWindow.deleteCharacterButton[1] = guiCreateButton(202, 28, 60, 52, "", false, characterWindow.window)
        guiSetAlpha(characterWindow.characterButton[1], 0.00)
        guiSetProperty(characterWindow.characterButton[1], "Alpha", "0.000000")
        guiSetAlpha(characterWindow.deleteCharacterButton[1], 0.00)
        guiSetProperty(characterWindow.deleteCharacterButton[1], "Alpha", "0.000000")
        guiSetProperty(characterWindow.characterButton[1], "NormalTextColour", "FFAAAAAA")
        guiSetProperty(characterWindow.deleteCharacterButton[1], "NormalTextColour", "FFAAAAAA")
        addEventHandler("onClientGUIClick",characterWindow.characterButton[1],selectCharacter,false)
        addEventHandler("onClientGUIClick",characterWindow.deleteCharacterButton[1],deleteCharacter,false)
        --[[CHARACTER #2]]
        characterWindow.character[2] = guiCreateStaticImage(10, 89, 55, 50, ":character-system/images/chars/"..getElementData(player,"char2skin")..".png", false, characterWindow.window)
        characterWindow.characterName[2] = guiCreateLabel(75, 92, 119, 15, getElementData(player,"char2name"), false, characterWindow.window)
        characterWindow.characterCash[2] = guiCreateLabel(75, 107, 119, 15, "Cash: $"..getElementData(player,"char2cash"), false, characterWindow.window)
        characterWindow.characterBank[2] = guiCreateLabel(75, 122, 119, 15, "Bank: $"..getElementData(player,"char2bank"), false, characterWindow.window)
        characterWindow.deleteCharacter = guiCreateStaticImage(204, 89, 55, 50, ":character-system/images/delete-char.png", false, characterWindow.window)
        characterWindow.characterButton[2] = guiCreateButton(10, 88, 192, 52, "", false, characterWindow.window)
        characterWindow.deleteCharacterButton[2] = guiCreateButton(202, 88, 60, 52, "", false, characterWindow.window)
        guiSetAlpha(characterWindow.characterButton[2], 0.00)
        guiSetProperty(characterWindow.characterButton[2], "Alpha", "0.000000")
        guiSetAlpha(characterWindow.deleteCharacterButton[2], 0.00)
        guiSetProperty(characterWindow.deleteCharacterButton[2], "Alpha", "0.000000")
        guiSetProperty(characterWindow.characterButton[2], "NormalTextColour", "FFAAAAAA")
        guiSetProperty(characterWindow.deleteCharacterButton[2], "NormalTextColour", "FFAAAAAA")
        addEventHandler("onClientGUIClick",characterWindow.characterButton[2],selectCharacter,false)
        addEventHandler("onClientGUIClick",characterWindow.deleteCharacterButton[2],deleteCharacter,false)
        --[[CHARACTER #3]]
        characterWindow.character[3] = guiCreateStaticImage(10, 149, 55, 50, ":character-system/images/chars/"..getElementData(player,"char3skin")..".png", false, characterWindow.window)
        characterWindow.characterName[3] = guiCreateLabel(75, 152, 119, 15, getElementData(player,"char3name"), false, characterWindow.window)
        characterWindow.characterCash[3] = guiCreateLabel(75, 167, 119, 15, "Cash: $"..getElementData(player,"char3cash"), false, characterWindow.window)
        characterWindow.characterBank[3] = guiCreateLabel(75, 182, 119, 15, "Bank: $"..getElementData(player,"char3bank"), false, characterWindow.window)
        characterWindow.deleteCharacter = guiCreateStaticImage(204, 149, 55, 50, ":character-system/images/delete-char.png", false, characterWindow.window)
        characterWindow.characterButton[3] = guiCreateButton(10, 148, 192, 52, "", false, characterWindow.window)
        characterWindow.deleteCharacterButton[3] = guiCreateButton(202, 148, 60, 52, "", false, characterWindow.window)
        guiSetAlpha(characterWindow.characterButton[3], 0.00)
        guiSetProperty(characterWindow.characterButton[3], "Alpha", "0.000000")
        guiSetAlpha(characterWindow.deleteCharacterButton[3], 0.00)
        guiSetProperty(characterWindow.deleteCharacterButton[3], "Alpha", "0.000000")
        guiSetProperty(characterWindow.characterButton[3], "NormalTextColour", "FFAAAAAA")
        guiSetProperty(characterWindow.deleteCharacterButton[3], "NormalTextColour", "FFAAAAAA")
        addEventHandler("onClientGUIClick",characterWindow.characterButton[3],selectCharacter,false)
        addEventHandler("onClientGUIClick",characterWindow.deleteCharacterButton[3],deleteCharacter,false)
        guiSetVisible(characterWindow.window,true)
    end
end
addEvent("showCharacters",true)
addEventHandler("showCharacters",getRootElement(),showCharacters)

 

Edited by Stealthy Serval
Deleted experimental code I pasted by mistake

Share this post


Link to post

Add more comments! What does your code do?

The word `character` means in English different things: https://dictionary.cambridge.org/dictionary/english/character
A person? A letter from a word?

Variable names can only partly clarify what the code does. Comments will have to do the rest!

 

 

 

Learn some more about local and global variables:

 

 

Edited by IIYAMA

Share this post


Link to post

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.