Jump to content

[HELP] TriggerClientEvent


Death

Recommended Posts

I am not able to use the trigger

-------------- server

  
resourceRoot = getResourceRootElement() 
function createNew() 
for _, areia in pairs ( radar_table ) do 
pesq = executeSQLQuery("SELECT * FROM `area` WHERE `nome`=?", area.nome ) 
for k, a in ipairs (pesq) do 
triggerClientEvent( "onSetOwner", root, areia.nome, a.owner, areia.preco, areia.x, areia.y, areia.z, a.corR, a.corG, a.corB) 
end 
end 
end 
addEventHandler("onResourceStart", resourceRoot, createNew) 
  

client

  
addEvent("onSetOwner", true) 
  
function lol(name, owner, preco, x, y, z, red, green, blue) 
    outputChatBox(name) 
    outputChatBox(owner) 
    outputChatBox(preco) 
    outputChatBox(x) 
    outputChatBox(y) 
    outputChatBox(z) 
    outputChatBox(red) 
    outputChatBox(green) 
    outputChatBox(blue) 
end 
addEventHandler ( "onSetOwner", root, lol ) 

Link to comment
Bad argument @ 'triggerClientEvent' [Expected element at argument 2, got nil]

try this

resourceRoot = getResourceRootElement() 
function createNew() 
for _, areia in pairs ( radar_table ) do 
pesq = executeSQLQuery("SELECT * FROM `area` WHERE `nome`=?", area.nome ) 
for k, a in ipairs (pesq) do 
triggerClientEvent( root,"onSetOwner", root, areia.nome, a.owner, areia.preco, areia.x, areia.y, areia.z, a.corR, a.corG, a.corB) 
end 
end 
end 
addEventHandler("onResourceStart", resourceRoot, createNew) 

Link to comment
ERROR : Server triggered clientside event onSetOwner, but event is not added clientside

ok all what you need to do is

-- Client side

addEventHandler("onClientResourceStart",resourceRoot, 
function() 
    triggerServerEvent( "clientReady", resourceRoot ) 
end 
) 

-- Server side

readyPlayerList = {} 
  
addEvent("clientReady", true ) 
addEventHandler("clientReady",resourceRoot, 
function() 
    table.insert( readyPlayerList, client ) 
    createNew() 
end 
) 
  
addEventHandler("onPlayerQuit",root, 
function() 
    table.removevalue( readyPlayerList, source ) 
end 
) 
  
-- Your function 
function createNew() 
for _, areia in pairs ( radar_table ) do 
pesq = executeSQLQuery("SELECT * FROM `area` WHERE `nome`=?", areia.nome ) 
for k, a in ipairs (pesq) do 
triggerClientEvent(readyPlayerList,"onSetOwner",readyPlayerList, areia.nome, a.owner, areia.preco, areia.x, areia.y, areia.z, a.corR, a.corG, a.corB) 
end 
end 
end 
  
  
-- table.removevalue function, in case you don't already have it 
function table.removevalue(t, val) 
    for i,v in ipairs(t) do 
        if v == val then 
            table.remove(t, i) 
            return i 
        end 
    end 
    return false 
end 

Link to comment
other error :|

[2015-04-21 14:52:03] WARNING: Sistema_BASES\script.lua:35: Bad argument @ 'triggerClientEvent' [Expected element at argument 3, got table]

try this

triggerClientEvent(readyPlayerList,"onSetOwner",root, areia.nome, a.owner, areia.preco, areia.x, areia.y, areia.z, a.corR, a.corG, a.corB) 

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