Jump to content

I need help with triggerClientEvent


sharkbrgo

Recommended Posts

I'm doing a modification of Play gamemode in which it will open a panel where the player will choose to spawn

However the file gamemode play = broph.lua is a script type server, so I'm trying to make a triggerClientEvent to open a function with the panel!

broph.lua

local spawnpoint 
  
addEventHandler("onResourceStart", resourceRoot, 
    function() 
        triggerClientEvent ("escolherSpawn")    --I tried to do triggerClientEvent here 
    end 
) 
  
function spawn(player) 
    if not isElement(player) then return end 
    if get("spawnreset") == "onSpawn" then 
        spawnpoint = getRandomSpawnPoint() 
    end 
    exports.spawnmanager:spawnPlayerAtSpawnpoint(player,spawnpoint,false) 
    repeat until setElementModel(player,math.random(312)) 
    fadeCamera(player, true) 
    setCameraTarget(player, player) 
    showChat(player, true) 
end 
  
function getRandomSpawnPoint ()  
    local spawnpoints = getElementsByType("spawnpoint") 
    return spawnpoints[math.random(1,#spawnpoints)] 
end 
  
addEventHandler("onPlayerJoin", root, 
    function() 
        spawn(source) 
    end 
) 
  
addEventHandler("onPlayerQuit",root, 
    function () 
        if getPlayerCount() == 1 and get("spawnreset") == "onServerEmpty" then 
            spawnpoint = getRandomSpawnPoint() 
        end 
    end 
) 
  
addEventHandler("onPlayerWasted", root, 
    function() 
        setTimer(spawn, 1800, 1, source) 
    end 
) 

janela.lua (client side)

function painelEscolha() 
local screenW, screenH = guiGetScreenSize() 
  
    janelaSpawn = guiCreateWindow((screenW - 840) / 2, (screenH - 198) / 2, 840, 198, "", false) 
        guiWindowSetSizable(janelaSpawn, false) 
  
    botLs = guiCreateButton(10, 29, 197, 74, "Los Santos", false, janelaSpawn) 
        guiSetProperty(botLs, "NormalTextColour", "FFFD0000") 
    labelBarra = guiCreateLabel(10, 93, 820, 15, "_____________________________________________________________________________________________________________________", false, janelaSpawn) 
    botSf = guiCreateButton(217, 29, 197, 74, "San Fierro", false, janelaSpawn) 
        guiSetProperty(botSf, "NormalTextColour", "FF10ED00") 
    botLv = guiCreateButton(424, 29, 197, 74, "Las Venturas", false, janelaSpawn) 
        guiSetProperty(botLv, "NormalTextColour", "FFF4FC00") 
    botTp = guiCreateButton(631, 29, 197, 74, "Tierra Perdida", false, janelaSpawn) 
        guiSetProperty(botTp, "NormalTextColour", "FFFA00E0") 
    botLsPraia = guiCreateButton(10, 113, 95, 43, "Praia\nLos Santos", false, janelaSpawn) 
        guiSetProperty(botLsPraia, "NormalTextColour", "FFF90000") 
    botLsFavela = guiCreateButton(112, 113, 95, 43, "Favela\nLos Santos", false, janelaSpawn) 
        guiSetProperty(botLsFavela, "NormalTextColour", "FFF90000") 
    botSfPraia = guiCreateButton(217, 113, 95, 43, "Praia\nSan Fierro", false, janelaSpawn) 
        guiSetProperty(botSfPraia, "NormalTextColour", "FF10ED00") 
    botSfFavela = guiCreateButton(319, 113, 95, 43, "Favela\nSan Fierro", false, janelaSpawn) 
        guiSetProperty(botSfFavela, "NormalTextColour", "FF10ED00") 
    botLvGoldPier = guiCreateButton(424, 113, 95, 43, "Gold Pier", false, janelaSpawn) 
        guiSetProperty(botLvGoldPier, "NormalTextColour", "FFF4FC00") 
    botLvEstadio = guiCreateButton(526, 113, 95, 43, "Estadio", false, janelaSpawn) 
        guiSetProperty(botLvEstadio, "NormalTextColour", "FFF4FC00") 
    botTpPara = guiCreateButton(631, 113, 95, 43, "Pular de\nPara-quedas", false, janelaSpawn) 
        guiSetProperty(botTpPara, "NormalTextColour", "FFFA00E0") 
    botTpPista = guiCreateButton(733, 113, 95, 43, "Pista de\nDrift", false, janelaSpawn) 
        guiSetProperty(botTpPista, "NormalTextColour", "FFFA00E0") 
    labelTutorial = guiCreateLabel(10, 162, 818, 15, "Escolha nos botões acima o local que deseja aparecer!", false, janelaSpawn) 
        guiLabelSetColor(labelTutorial, 255, 254, 254) 
        guiLabelSetHorizontalAlign(labelTutorial, "center", false) 
    labelCreditos = guiCreateLabel(10, 177, 818, 15, "LucasMonteiro - Evolution Server", false, janelaSpawn) 
        guiLabelSetColor(labelCreditos, 0, 72, 254) 
        guiLabelSetHorizontalAlign(labelCreditos, "center", false) 
end 
addEvent( "escolherSpawn", true ) 
addEventHandler( "escolherSpawn", painelEscolha ) 

Please help me!

sorry for bad english!!!

Link to comment
local spawnpoint 
  
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), 
    function() 
        triggerClientEvent ( resourceRoot, "escolherSpawn", resourceRoot )    --I tried to do triggerClientEvent here 
    end 
) 
  
function spawn(player) 
    if not isElement(player) then return end 
    if get("spawnreset") == "onSpawn" then 
        spawnpoint = getRandomSpawnPoint() 
    end 
    exports.spawnmanager:spawnPlayerAtSpawnpoint(player,spawnpoint,false) 
    repeat until setElementModel(player,math.random(312)) 
    fadeCamera(player, true) 
    setCameraTarget(player, player) 
    showChat(player, true) 
end 
  
function getRandomSpawnPoint () 
    local spawnpoints = getElementsByType("spawnpoint") 
    return spawnpoints[math.random(1,#spawnpoints)] 
end 
  
addEventHandler("onPlayerJoin", root, 
    function() 
        spawn(source) 
    end 
) 
  
addEventHandler("onPlayerQuit",root, 
    function () 
        if getPlayerCount() == 1 and get("spawnreset") == "onServerEmpty" then 
            spawnpoint = getRandomSpawnPoint() 
        end 
    end 
) 
  
addEventHandler("onPlayerWasted", root, 
    function() 
        setTimer(spawn, 1800, 1, source) 
    end 
) 

Link to comment
try with: onClientResourceStart

You want me to put this here?

beginning of the file broph.lua (server side)

local spawnpoint 
  
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        triggerClientEvent ("escolherSpawn")    --I tried to do triggerClientEvent here 
    end 
) 
  

still does not work, it does not call the client-side event when the script start.

Please help me!

Link to comment
local spawnpoint 
  
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), 
    function() 
        triggerClientEvent ( resourceRoot, "escolherSpawn", resourceRoot )    --I tried to do triggerClientEvent here 
    end 
) 
  
function spawn(player) 
    if not isElement(player) then return end 
    if get("spawnreset") == "onSpawn" then 
        spawnpoint = getRandomSpawnPoint() 
    end 
    exports.spawnmanager:spawnPlayerAtSpawnpoint(player,spawnpoint,false) 
    repeat until setElementModel(player,math.random(312)) 
    fadeCamera(player, true) 
    setCameraTarget(player, player) 
    showChat(player, true) 
end 
  
function getRandomSpawnPoint () 
    local spawnpoints = getElementsByType("spawnpoint") 
    return spawnpoints[math.random(1,#spawnpoints)] 
end 
  
addEventHandler("onPlayerJoin", root, 
    function() 
        spawn(source) 
    end 
) 
  
addEventHandler("onPlayerQuit",root, 
    function () 
        if getPlayerCount() == 1 and get("spawnreset") == "onServerEmpty" then 
            spawnpoint = getRandomSpawnPoint() 
        end 
    end 
) 
  
addEventHandler("onPlayerWasted", root, 
    function() 
        setTimer(spawn, 1800, 1, source) 
    end 
) 

thanks for your help and seems very promising! but still does not open the panel: /

is that the problem is in the client?

Link to comment

Yes maybe.

  
function painelEscolha() 
local screenW, screenH = guiGetScreenSize() 
  
    janelaSpawn = guiCreateWindow((screenW - 840) / 2, (screenH - 198) / 2, 840, 198, "", false) 
        guiWindowSetSizable(janelaSpawn, false) 
    guiSetVisible(janelaSpawn, true) 
    showCursor(true) 
  
    botLs = guiCreateButton(10, 29, 197, 74, "Los Santos", false, janelaSpawn) 
        guiSetProperty(botLs, "NormalTextColour", "FFFD0000") 
    labelBarra = guiCreateLabel(10, 93, 820, 15, "_____________________________________________________________________________________________________________________", false, janelaSpawn) 
    botSf = guiCreateButton(217, 29, 197, 74, "San Fierro", false, janelaSpawn) 
        guiSetProperty(botSf, "NormalTextColour", "FF10ED00") 
    botLv = guiCreateButton(424, 29, 197, 74, "Las Venturas", false, janelaSpawn) 
        guiSetProperty(botLv, "NormalTextColour", "FFF4FC00") 
    botTp = guiCreateButton(631, 29, 197, 74, "Tierra Perdida", false, janelaSpawn) 
        guiSetProperty(botTp, "NormalTextColour", "FFFA00E0") 
    botLsPraia = guiCreateButton(10, 113, 95, 43, "Praia\nLos Santos", false, janelaSpawn) 
        guiSetProperty(botLsPraia, "NormalTextColour", "FFF90000") 
    botLsFavela = guiCreateButton(112, 113, 95, 43, "Favela\nLos Santos", false, janelaSpawn) 
        guiSetProperty(botLsFavela, "NormalTextColour", "FFF90000") 
    botSfPraia = guiCreateButton(217, 113, 95, 43, "Praia\nSan Fierro", false, janelaSpawn) 
        guiSetProperty(botSfPraia, "NormalTextColour", "FF10ED00") 
    botSfFavela = guiCreateButton(319, 113, 95, 43, "Favela\nSan Fierro", false, janelaSpawn) 
        guiSetProperty(botSfFavela, "NormalTextColour", "FF10ED00") 
    botLvGoldPier = guiCreateButton(424, 113, 95, 43, "Gold Pier", false, janelaSpawn) 
        guiSetProperty(botLvGoldPier, "NormalTextColour", "FFF4FC00") 
    botLvEstadio = guiCreateButton(526, 113, 95, 43, "Estadio", false, janelaSpawn) 
        guiSetProperty(botLvEstadio, "NormalTextColour", "FFF4FC00") 
    botTpPara = guiCreateButton(631, 113, 95, 43, "Pular de\nPara-quedas", false, janelaSpawn) 
        guiSetProperty(botTpPara, "NormalTextColour", "FFFA00E0") 
    botTpPista = guiCreateButton(733, 113, 95, 43, "Pista de\nDrift", false, janelaSpawn) 
        guiSetProperty(botTpPista, "NormalTextColour", "FFFA00E0") 
    labelTutorial = guiCreateLabel(10, 162, 818, 15, "Escolha nos botões acima o local que deseja aparecer!", false, janelaSpawn) 
        guiLabelSetColor(labelTutorial, 255, 254, 254) 
        guiLabelSetHorizontalAlign(labelTutorial, "center", false) 
    labelCreditos = guiCreateLabel(10, 177, 818, 15, "LucasMonteiro - Evolution Server", false, janelaSpawn) 
        guiLabelSetColor(labelCreditos, 0, 72, 254) 
        guiLabelSetHorizontalAlign(labelCreditos, "center", false) 
end 
addEvent( "escolherSpawn", true ) 
addEventHandler( "escolherSpawn", painelEscolha ) 
  

Link to comment
Yes maybe.
  
function painelEscolha() 
local screenW, screenH = guiGetScreenSize() 
  
    janelaSpawn = guiCreateWindow((screenW - 840) / 2, (screenH - 198) / 2, 840, 198, "", false) 
        guiWindowSetSizable(janelaSpawn, false) 
    guiSetVisible(janelaSpawn, true) 
    showCursor(true) 
  
    botLs = guiCreateButton(10, 29, 197, 74, "Los Santos", false, janelaSpawn) 
        guiSetProperty(botLs, "NormalTextColour", "FFFD0000") 
    labelBarra = guiCreateLabel(10, 93, 820, 15, "_____________________________________________________________________________________________________________________", false, janelaSpawn) 
    botSf = guiCreateButton(217, 29, 197, 74, "San Fierro", false, janelaSpawn) 
        guiSetProperty(botSf, "NormalTextColour", "FF10ED00") 
    botLv = guiCreateButton(424, 29, 197, 74, "Las Venturas", false, janelaSpawn) 
        guiSetProperty(botLv, "NormalTextColour", "FFF4FC00") 
    botTp = guiCreateButton(631, 29, 197, 74, "Tierra Perdida", false, janelaSpawn) 
        guiSetProperty(botTp, "NormalTextColour", "FFFA00E0") 
    botLsPraia = guiCreateButton(10, 113, 95, 43, "Praia\nLos Santos", false, janelaSpawn) 
        guiSetProperty(botLsPraia, "NormalTextColour", "FFF90000") 
    botLsFavela = guiCreateButton(112, 113, 95, 43, "Favela\nLos Santos", false, janelaSpawn) 
        guiSetProperty(botLsFavela, "NormalTextColour", "FFF90000") 
    botSfPraia = guiCreateButton(217, 113, 95, 43, "Praia\nSan Fierro", false, janelaSpawn) 
        guiSetProperty(botSfPraia, "NormalTextColour", "FF10ED00") 
    botSfFavela = guiCreateButton(319, 113, 95, 43, "Favela\nSan Fierro", false, janelaSpawn) 
        guiSetProperty(botSfFavela, "NormalTextColour", "FF10ED00") 
    botLvGoldPier = guiCreateButton(424, 113, 95, 43, "Gold Pier", false, janelaSpawn) 
        guiSetProperty(botLvGoldPier, "NormalTextColour", "FFF4FC00") 
    botLvEstadio = guiCreateButton(526, 113, 95, 43, "Estadio", false, janelaSpawn) 
        guiSetProperty(botLvEstadio, "NormalTextColour", "FFF4FC00") 
    botTpPara = guiCreateButton(631, 113, 95, 43, "Pular de\nPara-quedas", false, janelaSpawn) 
        guiSetProperty(botTpPara, "NormalTextColour", "FFFA00E0") 
    botTpPista = guiCreateButton(733, 113, 95, 43, "Pista de\nDrift", false, janelaSpawn) 
        guiSetProperty(botTpPista, "NormalTextColour", "FFFA00E0") 
    labelTutorial = guiCreateLabel(10, 162, 818, 15, "Escolha nos botões acima o local que deseja aparecer!", false, janelaSpawn) 
        guiLabelSetColor(labelTutorial, 255, 254, 254) 
        guiLabelSetHorizontalAlign(labelTutorial, "center", false) 
    labelCreditos = guiCreateLabel(10, 177, 818, 15, "LucasMonteiro - Evolution Server", false, janelaSpawn) 
        guiLabelSetColor(labelCreditos, 0, 72, 254) 
        guiLabelSetHorizontalAlign(labelCreditos, "center", false) 
end 
addEvent( "escolherSpawn", true ) 
addEventHandler( "escolherSpawn", painelEscolha ) 
  

But what was the problem? the end of the function ???

I tried and the debug says

cVZx08t.png

janela.lua line 43 (client side)

addEventHandler( "escolherSpawn", painelEscolha ) 

Link to comment
  
  
function painelEscolha() 
local screenW, screenH = guiGetScreenSize() 
  
    janelaSpawn = guiCreateWindow((screenW - 840) / 2, (screenH - 198) / 2, 840, 198, "", false) 
        guiWindowSetSizable(janelaSpawn, false) 
    guiSetVisible(janelaSpawn, true) 
    showCursor(true) 
  
    botLs = guiCreateButton(10, 29, 197, 74, "Los Santos", false, janelaSpawn) 
        guiSetProperty(botLs, "NormalTextColour", "FFFD0000") 
    labelBarra = guiCreateLabel(10, 93, 820, 15, "_____________________________________________________________________________________________________________________", false, janelaSpawn) 
    botSf = guiCreateButton(217, 29, 197, 74, "San Fierro", false, janelaSpawn) 
        guiSetProperty(botSf, "NormalTextColour", "FF10ED00") 
    botLv = guiCreateButton(424, 29, 197, 74, "Las Venturas", false, janelaSpawn) 
        guiSetProperty(botLv, "NormalTextColour", "FFF4FC00") 
    botTp = guiCreateButton(631, 29, 197, 74, "Tierra Perdida", false, janelaSpawn) 
        guiSetProperty(botTp, "NormalTextColour", "FFFA00E0") 
    botLsPraia = guiCreateButton(10, 113, 95, 43, "Praia\nLos Santos", false, janelaSpawn) 
        guiSetProperty(botLsPraia, "NormalTextColour", "FFF90000") 
    botLsFavela = guiCreateButton(112, 113, 95, 43, "Favela\nLos Santos", false, janelaSpawn) 
        guiSetProperty(botLsFavela, "NormalTextColour", "FFF90000") 
    botSfPraia = guiCreateButton(217, 113, 95, 43, "Praia\nSan Fierro", false, janelaSpawn) 
        guiSetProperty(botSfPraia, "NormalTextColour", "FF10ED00") 
    botSfFavela = guiCreateButton(319, 113, 95, 43, "Favela\nSan Fierro", false, janelaSpawn) 
        guiSetProperty(botSfFavela, "NormalTextColour", "FF10ED00") 
    botLvGoldPier = guiCreateButton(424, 113, 95, 43, "Gold Pier", false, janelaSpawn) 
        guiSetProperty(botLvGoldPier, "NormalTextColour", "FFF4FC00") 
    botLvEstadio = guiCreateButton(526, 113, 95, 43, "Estadio", false, janelaSpawn) 
        guiSetProperty(botLvEstadio, "NormalTextColour", "FFF4FC00") 
    botTpPara = guiCreateButton(631, 113, 95, 43, "Pular de\nPara-quedas", false, janelaSpawn) 
        guiSetProperty(botTpPara, "NormalTextColour", "FFFA00E0") 
    botTpPista = guiCreateButton(733, 113, 95, 43, "Pista de\nDrift", false, janelaSpawn) 
        guiSetProperty(botTpPista, "NormalTextColour", "FFFA00E0") 
    labelTutorial = guiCreateLabel(10, 162, 818, 15, "Escolha nos botões acima o local que deseja aparecer!", false, janelaSpawn) 
        guiLabelSetColor(labelTutorial, 255, 254, 254) 
        guiLabelSetHorizontalAlign(labelTutorial, "center", false) 
    labelCreditos = guiCreateLabel(10, 177, 818, 15, "LucasMonteiro - Evolution Server", false, janelaSpawn) 
        guiLabelSetColor(labelCreditos, 0, 72, 254) 
        guiLabelSetHorizontalAlign(labelCreditos, "center", false) 
end 
addEvent( "escolherSpawn", true ) 
addEventHandler( "escolherSpawn", root, painelEscolha ) 
  
  

Link to comment
  
  
function painelEscolha() 
local screenW, screenH = guiGetScreenSize() 
  
    janelaSpawn = guiCreateWindow((screenW - 840) / 2, (screenH - 198) / 2, 840, 198, "", false) 
        guiWindowSetSizable(janelaSpawn, false) 
    guiSetVisible(janelaSpawn, true) 
    showCursor(true) 
  
    botLs = guiCreateButton(10, 29, 197, 74, "Los Santos", false, janelaSpawn) 
        guiSetProperty(botLs, "NormalTextColour", "FFFD0000") 
    labelBarra = guiCreateLabel(10, 93, 820, 15, "_____________________________________________________________________________________________________________________", false, janelaSpawn) 
    botSf = guiCreateButton(217, 29, 197, 74, "San Fierro", false, janelaSpawn) 
        guiSetProperty(botSf, "NormalTextColour", "FF10ED00") 
    botLv = guiCreateButton(424, 29, 197, 74, "Las Venturas", false, janelaSpawn) 
        guiSetProperty(botLv, "NormalTextColour", "FFF4FC00") 
    botTp = guiCreateButton(631, 29, 197, 74, "Tierra Perdida", false, janelaSpawn) 
        guiSetProperty(botTp, "NormalTextColour", "FFFA00E0") 
    botLsPraia = guiCreateButton(10, 113, 95, 43, "Praia\nLos Santos", false, janelaSpawn) 
        guiSetProperty(botLsPraia, "NormalTextColour", "FFF90000") 
    botLsFavela = guiCreateButton(112, 113, 95, 43, "Favela\nLos Santos", false, janelaSpawn) 
        guiSetProperty(botLsFavela, "NormalTextColour", "FFF90000") 
    botSfPraia = guiCreateButton(217, 113, 95, 43, "Praia\nSan Fierro", false, janelaSpawn) 
        guiSetProperty(botSfPraia, "NormalTextColour", "FF10ED00") 
    botSfFavela = guiCreateButton(319, 113, 95, 43, "Favela\nSan Fierro", false, janelaSpawn) 
        guiSetProperty(botSfFavela, "NormalTextColour", "FF10ED00") 
    botLvGoldPier = guiCreateButton(424, 113, 95, 43, "Gold Pier", false, janelaSpawn) 
        guiSetProperty(botLvGoldPier, "NormalTextColour", "FFF4FC00") 
    botLvEstadio = guiCreateButton(526, 113, 95, 43, "Estadio", false, janelaSpawn) 
        guiSetProperty(botLvEstadio, "NormalTextColour", "FFF4FC00") 
    botTpPara = guiCreateButton(631, 113, 95, 43, "Pular de\nPara-quedas", false, janelaSpawn) 
        guiSetProperty(botTpPara, "NormalTextColour", "FFFA00E0") 
    botTpPista = guiCreateButton(733, 113, 95, 43, "Pista de\nDrift", false, janelaSpawn) 
        guiSetProperty(botTpPista, "NormalTextColour", "FFFA00E0") 
    labelTutorial = guiCreateLabel(10, 162, 818, 15, "Escolha nos botões acima o local que deseja aparecer!", false, janelaSpawn) 
        guiLabelSetColor(labelTutorial, 255, 254, 254) 
        guiLabelSetHorizontalAlign(labelTutorial, "center", false) 
    labelCreditos = guiCreateLabel(10, 177, 818, 15, "LucasMonteiro - Evolution Server", false, janelaSpawn) 
        guiLabelSetColor(labelCreditos, 0, 72, 254) 
        guiLabelSetHorizontalAlign(labelCreditos, "center", false) 
end 
addEvent( "escolherSpawn", true ) 
addEventHandler( "escolherSpawn", root, painelEscolha ) 
  
  

Now this correct (debug script not report me any error) however the panel is not open yet!

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