Jump to content

I need help with triggering again :(


Piorun

Recommended Posts

I've got this code :

Server side :

  
function gettingPlayerPos() 
addEventHandler("onResourceStart", getRootElement(), 
function () 
local result = mysql_query(handler, "SELECT * FROM tc_biznesy" ) 
   if (result) then 
      while true do 
      local data = mysql_fetch_assoc(result) 
      if (not data) then break end 
         bizx = data["bizx"] 
         bizy = data["bizy"] 
         bizz = data["bizz"] 
         triggerClientEvent("gettingPos", getRootElement(), bizx, bizy, bizz) 
      end 
      mysql_free_result(result) 
   end 
end) 
end 
  

Client side:

  
function gettingPlayerPos (bizx, bizy, bizz) 
addEventHandler("onClientRender", getRootElement(), 
function () 
local cx, cy, cz = getElementPosition( localPlayer ) 
if cx == bizx and cy == bizy and cz == bizz then 
outputChatBox("Witaj") 
end 
end) 
end 
addEvent("gettingPos", true) 
addEventHandler("gettingPos", getRootElement(), gettingPlayerPos) 
  

This code doesn't work. I want to do something like this: When player is on the bizx, bizy, bizz (data["bizx"], data["bizy"], data["bizz"]) position then server outputing into the client "Witaj" messege. Please, help :(

Link to comment

You won't get the position you want just like that.

x,y,z = nil,nil,nil 
  
function gettingPlayerPos (bizx, bizy, bizz) 
x,y,z = bizx,bizy,bizz 
end 
addEvent("gettingPos", true) 
addEventHandler("gettingPos", getRootElement(), gettingPlayerPos) 
  
addEventHandler("onClientRender", getRootElement(), 
function () 
local cx, cy, cz = getElementPosition( localPlayer ) 
if cx >= x and cy >= y and cz >= z then 
outputChatBox("Witaj") 
end 
end) 

Try that.

Link to comment
  • Moderators

Try this:

Server:

      
function gettingPlayerPos() 
    addEventHandler("onResourceStart", getRootElement(), 
    function () 
        local result = mysql_query(handler, "SELECT * FROM tc_biznesy" ) 
       if (result) then 
          while true do 
            local data = mysql_fetch_assoc(result) 
            if (not data) then break end 
                local bizx,bizy,bizz 
                bizx = data["bizx"] 
                bizy = data["bizy"] 
                bizz = data["bizz"] 
                outputChatBox("1st Trigger" ) 
                triggerClientEvent("gettingPos", getRootElement(), bizx, bizy, bizz) 
                --- For test --- 
                outputChatBox("2st Trigger" ) 
                bizx = 1 
                bizy = 2 
                bizz = 3 
                triggerClientEvent("gettingPos", getRootElement(), bizx, bizy, bizz) 
            end 
            mysql_free_result(result) 
        end 
    end) 
end 
      

Client:

addEvent("gettingPos", true) 
 function gettingPlayerPos (bizx, bizy, bizz) 
    outputChatBox( bizx.."  "..bizy.."  "..bizz ) 
    addEventHandler("onClientRender", getRootElement(), 
    function () 
        local cx, cy, cz = getElementPosition( localPlayer ) 
        if cx == bizx and cy == bizy and cz == bizz then 
            outputChatBox("Witaj") 
        end 
    end) 
end 
addEventHandler("gettingPos", getRootElement(), gettingPlayerPos) 

Link to comment

I changed my code to:

CLIENT

  
function gettingPlayerPos (bizx, bizy, bizz) 
outputDebugString("Yo") -- for test 
local cx, cy, cz = getElementPosition( localPlayer ) 
if cx == bizx and cy == bizy and cz == bizz then 
outputChatBox("Witaj") 
end 
end 
addEvent("gettingPos", true) 
addEventHandler("gettingPos", getRootElement, gettingPlayerPos) 
  

SERVER

  
addEventHandler("onResourceStart", getRootElement(), 
function () 
local result = mysql_query(handler, "SELECT * FROM tc_biznesy" ) 
   if (result) then 
      while true do 
      local data = mysql_fetch_assoc(result) 
      if (not data) then break end 
         bizx = data["bizx"] 
         bizy = data["bizy"] 
         bizz = data["bizz"] 
         bizid = data["id"] 
         bizname = data["name"] 
         triggerClientEvent("gettingPos", getRootElement(), bizx, bizy, bizz) 
      end 
      mysql_free_result(result) 
   end 
end) 
  

because i found one bad thing with event "onResourceStart". Now works only serverside function (tested), clientside function still doesn't work, but now, when i'm typing "debugscript 3" in console i've got this errors:

errorbs.png

Link to comment

Ok, so i changed my code to:

CLIENT

  
function exampleGetFunc( bizx, bizy, bizz, bizname ) 
addEventHandler("onClientRender", getRootElement(), 
function() 
local cx, cy, cz = getElementPosition( localPlayer ) 
local dist = getDistanceBetweenPoints3D( bizx, bizy, bizz, cx, cy, cz ) 
if dist <= 2 then 
   outputChatBox(bizname) 
end 
end) 
end 
addEvent("playerPos", true) 
addEventHandler("playerPos", getRootElement(), exampleGetFunc) 
  

SERVER:

  
function getingPlayerBizPos() 
local result = mysql_query(handler, "SELECT * FROM tc_biznesy" ) 
   if (result) then 
      while true do 
      local data = mysql_fetch_assoc(result) 
      if (not data) then break end 
         bizx = data["bizx"] 
         bizy = data["bizy"] 
         bizz = data["bizz"] 
         bizid = data["id"] 
         bizname = data["name"] 
         triggerClientEvent("playerPos", getRootElement(), bizx, bizy, bizz, bizname) 
      end 
      mysql_free_result(result) 
   end 
end 
addEventHandler("onResourceStart", getRootElement(), getingPlayerBizPos) 
  

and i still have the same errors, but when i change addEventHandler from "onResourceStart" to ex "onPlayerLogin" - it's working with no errors.

Link to comment
  • Moderators

Maybe try this:

function getingPlayerBizPos() 
    outputChatBox("getingPlayerBizPos" ) 
    local result = mysql_query(handler, "SELECT * FROM tc_biznesy" ) 
    if (result) then 
        while true do 
            local data = mysql_fetch_assoc(result) 
            if (not data) then break end 
            bizx = data["bizx"] 
            bizy = data["bizy"] 
            bizz = data["bizz"] 
            bizid = data["id"] 
            bizname = data["name"] 
            triggerClientEvent("playerPos", getRootElement(), bizx, bizy, bizz, bizname) 
        end 
        mysql_free_result(result) 
    end 
end 
-- addEventHandler("onResourceStart", getRootElement(), getingPlayerBizPos) 
setTimer( getingPlayerBizPos, 5000, 1 ) 

Link to comment
  • Moderators

Are you really sure ? Ok try this:

function getingPlayerBizPos() 
    outputChatBox("getingPlayerBizPos" ) 
    local result = mysql_query(handler, "SELECT * FROM tc_biznesy" ) 
    if (result) then 
        while true do 
            local data = mysql_fetch_assoc(result) 
            if (not data) then break end 
            bizx = data["bizx"] 
            bizy = data["bizy"] 
            bizz = data["bizz"] 
            bizid = data["id"] 
            bizname = data["name"] 
            for k,i in ipairs ( getElementsByType( "player" ) ) do 
                triggerClientEvent(i, "playerPos", getRootElement(), bizx, bizy, bizz, bizname) 
            end 
        end 
        mysql_free_result(result) 
    end 
end 
setTimer( getingPlayerBizPos, 5000, 1 ) 

Link to comment

Try to check your date

insert this code after:

  
            bizx = data["bizx"] 
            bizy = data["bizy"] 
            bizz = data["bizz"] 
            bizid = data["id"] 
            bizname = data["name"] 
  

  
outputChatBox("Data =  "..tostring(bizy).." , "..tostring(bizz).." , "..tostring(bizid).." , "..tostring(bizname))    
  

Link to comment

you need to be shure that the client downloaded all files.

add this on the end of client side file outside any function:

triggerServerEvent("onMyResourceFileDownload",getLocalPlayer()) 

and use this in server side:

addEvent("onMyResourceFileDownload",true) 
addEventHandler("onMyResourceFileDownload",getRootElement(),getingPlayerBizPos) 

instead of

setTimer( getingPlayerBizPos, 5000, 1 ) 

and triggering client event can be like this

triggerClientEvent(source, "playerPos", source, bizx, bizy, bizz, bizname) 

instead of

for k,i in ipairs ( getElementsByType( "player" ) ) do             triggerClientEvent(i, "playerPos", getRootElement(), bizx, bizy, bizz, bizname) 
           end 

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