Jump to content

guiGridListGetItem issue


Recommended Posts

Posted

GUI Client side is not affected by other players, post your code so we can see what you're doing wrong.

Posted (edited)
function attivaSceltaPersonaggi() 
    local screenWidth, screenHeight = guiGetScreenSize() 
    local sx, sy = screenWidth/1440, screenHeight/900 
    listapersonaggi = guiCreateGridList(360*sx, 185*sy, 320*sx, 168*sy, false) 
    guiGridListSetSelectionMode(listapersonaggi, 2) 
    guiSetVisible(listapersonaggi, false) 
    creapgbutt = guiCreateButton(360*sx, 366*sy, 120*sx, 80*sy, "Crea Personaggio", false) 
    eliminapgbutt = guiCreateButton(560*sx, 368*sy, 120*sx, 80*sy, "Elimina Personaggio", false) 
    selezionapgbutt = guiCreateButton(460*sx, 500*sy, 150*sx, 50*sy, "SELEZIONA", false) 
    guiSetVisible(creapgbutt, false) 
    guiSetVisible(eliminapgbutt, false) 
    guiSetVisible(selezionapgbutt, false) 
    addEventHandler("onClientGUIClick", selezionapgbutt, spawnaPg, false) 
    addEventHandler("onClientGUIClick", creapgbutt, creaPg, false) 
end 
  
addEvent("onSceltaPersonaggioAttiva", true) 
addEventHandler("onSceltaPersonaggioAttiva", getRootElement(), attivaSceltaPersonaggi) 
function spawnaPg(button, state, absoluteX, absoluteY) -- Funzione invio spawn Personaggio SERVER 
    --outputChatBox(itemselezionato) 
    local riga, colonna = guiGridListGetSelectedItem ( listapersonaggi ) 
    local itemselezionato = guiGridListGetItemText ( listapersonaggi, riga, colonna ) 
    if button == "left" then 
        if state == "up" then 
            outputChatBox(riga .. colonna) 
            if riga ~= -1 and colonna ~= -1 then 
                outputChatBox(itemselezionato) 
                disattivaSelezionePersonaggio() 
                showCursor(false) 
                stopSound(logintheme) 
                triggerServerEvent("spawnaPersonaggio", localPlayer, itemselezionato) 
            else 
                outputChatBox("ERROR: Niente selezionato.") 
            end 
        end 
    end 
end 

Edited by Guest
Posted
Where is the server side?

Where the function creaPg?

This is a part of the code, but these functions work, while this part of the code is bugged (it works, but if two players click on the selezionapgbutt button at the same time, the row value is -1).

Posted

I know that and i asking you to show the server side as you're doing trigger from the server to the client side and from client side to server side of course this will affect the client side if you doing it wrong, also column is not defined and i can't see the function disattivaSelezionePersonaggio and where are you adding any row in the gird list.

Posted
function spawnaPersonaggioF(itemselezionato) 
    --print(itemselezionato) 
    --outputChatBox(itemselezionato) 
    --if client then 
        --if source == sourceRoot then 
            print("lezzetti") 
            setPlayerName(client, itemselezionato) 
            spawnPlayer(client, 0.0, 0.0, 4.0) 
            fadeCamera(client, true) 
            setCameraTarget(client) 
        --end 
    --end 
end 
  
addEvent("spawnaPersonaggio", true) 
addEventHandler("spawnaPersonaggio", root, spawnaPersonaggioF) 

Posted

Client-side:

function attivaSceltaPersonaggi() 
    local screenWidth, screenHeight = guiGetScreenSize() 
    local sx, sy = screenWidth/1440, screenHeight/900 
    listapersonaggi = guiCreateGridList(360*sx, 185*sy, 320*sx, 168*sy, false) 
    guiGridListSetSelectionMode(listapersonaggi, 2) 
    guiSetVisible(listapersonaggi, false) 
    creapgbutt = guiCreateButton(360*sx, 366*sy, 120*sx, 80*sy, "Crea Personaggio", false) 
    eliminapgbutt = guiCreateButton(560*sx, 368*sy, 120*sx, 80*sy, "Elimina Personaggio", false) 
    selezionapgbutt = guiCreateButton(460*sx, 500*sy, 150*sx, 50*sy, "SELEZIONA", false) 
    guiSetVisible(creapgbutt, false) 
    guiSetVisible(eliminapgbutt, false) 
    guiSetVisible(selezionapgbutt, false) 
    addEventHandler("onClientGUIClick", selezionapgbutt, spawnaPg, false) 
    addEventHandler("onClientGUIClick", creapgbutt, creaPg, false) 
end 
  
addEvent("onSceltaPersonaggioAttiva", true) 
addEventHandler("onSceltaPersonaggioAttiva", getRootElement(), attivaSceltaPersonaggi) 
function spawnaPg(button, state, absoluteX, absoluteY) -- Funzione invio spawn Personaggio SERVER 
    --outputChatBox(itemselezionato) 
    local riga, colonna = guiGridListGetSelectedItem ( listapersonaggi ) 
    local itemselezionato = guiGridListGetItemText ( listapersonaggi, riga, colonna ) 
    if button == "left" then 
        if state == "up" then 
            outputChatBox("Riga: " .. riga .. " Colonna: " .. colonna) 
            if riga ~= -1 and colonna ~= -1 then 
                outputChatBox(itemselezionato) 
                disattivaSelezionePersonaggio() 
                showCursor(false) 
                stopSound(logintheme) 
                triggerServerEvent("spawnaPersonaggio", localPlayer, itemselezionato) 
            else 
                outputChatBox("ERROR: Niente selezionato.") 
            end 
        end 
    end 
end 

Server-side:

function spawnaPersonaggioF(itemselezionato) 
    --print(itemselezionato) 
    --outputChatBox(itemselezionato) 
    --if client then 
        --if source == sourceRoot then 
            print("test") 
            setPlayerName(client, itemselezionato) 
            spawnPlayer(client, 0.0, 0.0, 4.0) 
            fadeCamera(client, true) 
            setCameraTarget(client) 
        --end 
    --end 
end 
  
addEvent("spawnaPersonaggio", true) 
addEventHandler("spawnaPersonaggio", root, spawnaPersonaggioF) 

Posted
triggerClientEvent("onSceltaPersonaggioAttiva", getRootElement()) 

Should be:

triggerClientEvent(thePlayer, "onSceltaPersonaggioAttiva", getRootElement()) 

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...