Jump to content

Ayuda con triggerclientevent


CeKiT

Recommended Posts

Hola que tal, estoy queriendo remplazar un mensaje simple que agregue al server-side, y quiero crear un dxDrawText con mas diseño. Cuestion que se esta funcion es solo para client-side tambien se para que son los triggerclientevent, lo que no se es como usarla de un modo correcto.

Este es mi server-side actual:

-- Comprobamos jugadores activos al agarrar el hunter. 
function checkForHunter(number, sort, model) 
        if sort == "vehiclechange" then 
        if model == 425 then 
        if getActivePlayerCount() <= 1 and getMapDM() then 
         
        -- Creando cuenta regresiva, y definiendo el mensaje. 
        local pName = getPlayerName(source) 
        local text = pName..' ES EL BUEN GANADOR!\n' 
        Countdown.create(5, RaceMode.startNextMapSelect, text,0, 102, 255, 0.5, 2,"default-bold"):start() 
        setTimer ( RaceMode.startNextMapSelect, 8000, 1) 
         
        -- Congelando al agarrar el hunter. 
        local playerVehicle = getPedOccupiedVehicle (source) 
        setElementFrozen(playerVehicle, true ) 
        -- 
end 
end 
end 
end 
addEvent("onPlayerPickUpRacePickup",true) 
addEventHandler("onPlayerPickUpRacePickup",getRootElement(),checkForHunter) 
------------------------------------------------------------------------------------------------------------------------------------- 
  

y quiero remplazar esto:

     local pName = getPlayerName(source) 
        local text = pName..' ES EL BUEN GANADOR!\n' 
        Countdown.create(5, RaceMode.startNextMapSelect, text,0, 102, 255, 0.5, 2,"default-bold"):start() 

por esto:

local screenWidth, screenHeight = guiGetScreenSize ( ) 
mensajev = dxDrawText (pName.." ES EL GANADOR!", 44, screenHeight - 43, screenWidth, screenHeight, tocolor ( 255, 255, 255, 255 ), 1, "pricedown" )  
  

y nose como realizarlo, alguien que me pueda dar una mano y me explique como llamar al cliente desde el server side

Link to comment

Cliente:

  
local screenWidth, screenHeight = guiGetScreenSize ( ) 
  
addEvent("callingWinnerMessage", true) 
addEvent("callingWinnerMessage", root,  
    function ( whoWon )  
        whoWon = whoWon 
        addEventHandler ( "onClientRender", root, printWinner ) 
        setTimer ( removeEventHandler, 5000, 1, root, printWinner ) 
    end 
) 
  
  
function printWinner (  ) 
    dxDrawText (whoWon.." ES EL GANADOR!", 44, screenHeight - 43, screenWidth, screenHeight, tocolor ( 255, 255, 255, 255 ), 1, "pricedown" ) 
end 
  

Ahora, reemplaza esta línea:

  
        Countdown.create(5, RaceMode.startNextMapSelect, text,0, 102, 255, 0.5, 2,"default-bold"):start() 
  

Por esta:

  
triggerClientEvent (root,  "callingWinnerMessage", resourceRoot, pName ) 
  

Link to comment

¿Hola mira, no lo hacerlo funcionar para mi que es un problema entre "root" , "resourceRoot" o "source" del server-side y el client-side.

Mira el server-side lo puse a si:

function checkForHunter(number, sort, model) 
        if sort == "vehiclechange" then 
        if model == 425 then 
        if getActivePlayerCount() <= 1 and getMapDM() then 
        if stateAllowsPostFinish() then 
        gotoState('PostFinish') 
        setTimer ( RaceMode.startNextMapSelect, 8000, 1)       
-- Creando cuenta regresiva, y definiendo el mensaje. 
        local pName = getPlayerName(source) 
-- Llamando al mensaje de victoria. 
        triggerClientEvent (root,  "callingWinnerMessage", resourceRoot, pName ) 
-- Llamando al sonido de victoria. 
        triggerClientEvent("wsonido",getRootElement()) 
end 
end 
end 
end 
end 
addEvent("onPlayerPickUpRacePickup",true) 
addEventHandler("onPlayerPickUpRacePickup",getRootElement(),checkForHunter) 

y el client-side

local screenWidth, screenHeight = guiGetScreenSize ( ) 
  
addEvent("callingWinnerMessage", true) 
addEvent("callingWinnerMessage", root, 
    function ( whoWon ) 
        whoWon = whoWon 
        addEventHandler ( "onClientRender", root, printWinner ) 
        setTimer ( removeEventHandler, 5000, 1, root, printWinner ) 
    end 
) 
  
function printWinner () 
    dxDrawText (whoWon.." ES EL GANADOR!", 44, screenHeight - 43, screenWidth, screenHeight, tocolor ( 255, 255, 255, 255 ), 1, "pricedown" ) 
end 

El triggerclientevent del sonido de victoria funciona perfecto, pero fijate que dice GetRootElement(), hay cosas que no entiendo bien.

Gracias por tu ayuda.

Link to comment
root es lo mismo que getRootElement, no hay ningún debug?

Basandome en el script que me diste pude modificarlo y logre que aparezca y desaparezca pasado un tiempo a si me quedo:

addEventHandler("callingWinnerMessage", root, 
    function ( whoWon ) 
        whoWon = whoWon 
        addEventHandler ( "onClientRender", root, printWinner ) 
        setTimer(detener, 8000, 1)  
    end 
) 
function detener() 
removeEventHandler("onClientRender", root, printWinner) 
removeEventHandler("callingWinnerMessage", root, printWinner) 
end 
  
function printWinner(root) 
dxDrawText(whoWon.." ES EL GANADOR!", 229, 217, 629, 219, tocolor(255, 255, 255, 255), 2.00, "sans", "left", "top", false, false, false, true, false) 
end 

Ahora me dice que "whoWon" no recibe ningun valor, osea que esta nulo. Nose como obtener el string, ya que tengo que saber el nombre del jugador que gano, no el que esta viendo el mesaje. Desde el server-side es facil lo hago con:

local whoWon = getPlayerName(source) 

como lo envio hacia el client-side?

Saludos

Link to comment
Postea los dos sides completos así veo que hiciste.

SERVER-SIDE:

DestructionDerby = setmetatable({}, RaceMode) 
DestructionDerby.__index = DestructionDerby 
  
DestructionDerby:register('Destruction derby') 
  
function DestructionDerby:isApplicable() 
    return not RaceMode.checkpointsExist() and RaceMode.getMapOption('respawn') == 'none' 
end 
  
function DestructionDerby:getPlayerRank(player) 
    return #getActivePlayers() 
end 
  
-- Copy of old updateRank 
function DestructionDerby:updateRanks() 
    for i,player in ipairs(g_Players) do 
        if not isPlayerFinished(player) then 
            local rank = self:getPlayerRank(player) 
            if not rank or rank > 0 then 
                setElementData(player, 'race rank', rank) 
            end 
        end 
    end 
    -- Make text look good at the start 
    if not self.running then 
        for i,player in ipairs(g_Players) do 
            setElementData(player, 'race rank', '' ) 
            setElementData(player, 'checkpoint', '' ) 
        end 
    end 
end 
  
function DestructionDerby:onPlayerWasted(player) 
    if isActivePlayer(player) then 
        self:handleFinishActivePlayer(player) 
        if getMapDM() then 
            if getActivePlayerCount() <= 0 then 
                triggerClientEvent ( "showWinMessage", getRootElement()) 
                RaceMode.endMap() 
            else 
                TimerManager.createTimerFor("map",player):setTimer(clientCall, 2000, 1, player, 'Spectate.start', 'auto') 
            end 
            local activePlayers = getActivePlayers() 
            if getActivePlayerCount() == 1 then 
                if getElementModel(getPedOccupiedVehicle(activePlayers[1])) == 425 then 
                     
                     if getActivePlayerCount() <= 1 and getMapDM() then 
        if stateAllowsPostFinish() then 
        gotoState('PostFinish') 
                local whoWon = getPlayerName(source) 
        setTimer ( RaceMode.startNextMapSelect, 8000, 1)       
-- Creando cuenta regresiva, y definiendo el mensaje. 
  
-- Llamando al sonido de victoria 
triggerClientEvent("wsonido",getRootElement()) 
triggerClientEvent (root,  "callingWinnerMessage", source, whoWon ) 
  
end 
end 
                end 
            end 
        else 
            if getActivePlayerCount() <= 1 then 
                triggerClientEvent ( "showWinMessage", getRootElement()) 
                RaceMode.endMap() 
            else 
                TimerManager.createTimerFor("map",player):setTimer(clientCall, 2000, 1, player, 'Spectate.start', 'auto') 
            end 
        end 
    end 
    RaceMode.setPlayerIsFinished(player) 
    showBlipsAttachedTo(player, false) 
end 
  
-- Comprobamos jugadores activos al agarrar el hunter. 
function checkForHunter(number, sort, model) 
        if sort == "vehiclechange" then 
        if model == 425 then 
        if getActivePlayerCount() <= 1 and getMapDM() then 
        if stateAllowsPostFinish() then 
        gotoState('PostFinish') 
                local whoWon = getPlayerName(source) 
        setTimer ( RaceMode.startNextMapSelect, 8000, 1)       
-- Creando cuenta regresiva, y definiendo el mensaje. 
  
-- Llamando al sonido de victoria 
triggerClientEvent("wsonido",getRootElement()) 
triggerClientEvent (root,  "callingWinnerMessage", source, whoWon ) 
  
end 
end 
end 
end 
end 
addEvent("onPlayerPickUpRacePickup",true) 
addEventHandler("onPlayerPickUpRacePickup",getRootElement(),checkForHunter) 
------------------------------------------------------------------------------------------------------------------------------------- 
  
  
  
function DestructionDerby:onPlayerQuit(player) 
    if isActivePlayer(player) then 
        self:handleFinishActivePlayer(player) 
        if getMapDM() then 
            if getActivePlayerCount() <= 0 then 
                RaceMode.endMap() 
                triggerEvent ( "activatePodium", getRootElement()) 
  
            end 
        else 
            if getActivePlayerCount() <= 1 then 
                RaceMode.endMap()--sida 
     
                triggerEvent ( "activatePodium", getRootElement()) 
  
            end 
        end 
    end 
end 
  
function DestructionDerby:handleFinishActivePlayer(player) 
    -- Update ranking board for player being removed 
    local activePlayers = getActivePlayers() 
    triggerEvent("onPlayerDeadInRace",getRootElement(),#activePlayers,player) 
    if getActivePlayerCount() == 1 then 
        clientCall(getRootElement(),"setPlayerNameOnWinMessege", activePlayers[1]) 
    end 
    if not self.rankingBoard then 
        self.rankingBoard = RankingBoard:create() 
        self.rankingBoard:setDirection( 'up', getActivePlayerCount() ) 
    end 
    local timePassed = self:getTimePassed() 
    self.rankingBoard:add(player, timePassed) 
    -- Do remove 
    finishActivePlayer(player) 
    -- Update ranking board if one player left 
    local activePlayers = getActivePlayers() 
    if #activePlayers == 1 then 
        self.rankingBoard:add(activePlayers[1], timePassed) 
        clientCall(getRootElement(),"setPlayerNameOnWinMessege", activePlayers[1]) 
        triggerEvent("onPlayerDestructionDerbyWin", getRootElement(), activePlayers[1]) 
    end 
    --PODIUM SCRIPT 
    if #activePlayers == 3 then 
        triggerClientEvent ( "SaveName3",getRootElement(),_getPlayerName(player)) 
    end 
    if #activePlayers == 2 then 
        triggerClientEvent ( "SaveName2",getRootElement(),_getPlayerName(player)) 
    end 
    if #activePlayers == 1 then 
        triggerClientEvent ( "SaveName",getRootElement(),_getPlayerName(player)) 
        triggerEvent("createPeds",getRootElement()) 
    end 
end 
  
  
  
------------------------------------------------------------ 
-- activePlayerList stuff 
-- 
  
function isActivePlayer( player ) 
    return table.find( g_CurrentRaceMode.activePlayerList, player ) 
end 
  
function addActivePlayer( player ) 
    table.insertUnique( g_CurrentRaceMode.activePlayerList, player ) 
end 
  
function removeActivePlayer( player ) 
    table.removevalue( g_CurrentRaceMode.activePlayerList, player ) 
end 
  
function finishActivePlayer( player ) 
    table.removevalue( g_CurrentRaceMode.activePlayerList, player ) 
    table.insertUnique( g_CurrentRaceMode.finishedPlayerList, _getPlayerName(player) ) 
end 
  
function getFinishedPlayerCount() 
    return #g_CurrentRaceMode.finishedPlayerList 
end 
  
function getActivePlayerCount() 
    return #g_CurrentRaceMode.activePlayerList 
end 
  
function getActivePlayers() 
    return g_CurrentRaceMode.activePlayerList 
end 
  
  
function getMapDM() 
    local getMapName = g_MapInfo.name or "" 
    if string.find(getMapName, "[DM]", 1, true) then 
        return true 
    else  
        return false 
    end 
end 
  

CLIENT-SIDE

function wSonido() 
playSound("audio/win.ogg",false) 
end  
addEvent("wsonido",true) 
addEventHandler("wsonido",getRootElement(),wSonido) 
  
  
  
local screenWidth, screenHeight = guiGetScreenSize ( ) 
  
addEvent("callingWinnerMessage", true) 
addEventHandler("callingWinnerMessage", root, 
    function ( whoWon ) 
        whoWon = whoWon 
        addEventHandler ( "onClientRender", root, printWinner ) 
        setTimer(detener, 8000, 1)  
    end 
) 
function detener() 
removeEventHandler("onClientRender", root, printWinner) 
removeEventHandler("callingWinnerMessage", root, printWinner) 
end 
  
function printWinner(root) 
  
local nWIN  = getPlayerName(getLocalPlayer()) 
dxDrawText(nWIN.." ES EL GANADOR!", 229, 217, 629, 219, tocolor(255, 255, 255, 255), 2.00, "sans", "left", "top", false, false, false, true, false) 
end 
  
  
  
  

Link to comment
  
triggerClientEvent ( "callingWinnerMessage", root, whoWon ) 
  

  
addEvent("callingWinnerMessage", true) 
addEventHandler("callingWinnerMessage", root, 
    function ( whoWon ) 
        whoWon = whoWon 
        addEventHandler ( "onClientRender", root, printWinner ) 
        setTimer(detener, 8000, 1) 
    end 
) 
function detener() 
removeEventHandler("onClientRender", root, printWinner) 
  
end 
  
function printWinner() 
dxDrawText(whoWon.." ES EL GANADOR!", 229, 217, 629, 219, tocolor(255, 255, 255, 255), 2.00, "sans", "left", "top", false, false, false, true, false) 
end 
  
  

Link to comment
  • Recently Browsing   0 members

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