Piorun Posted April 8, 2011 Posted April 8, 2011 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
Castillo Posted April 8, 2011 Posted April 8, 2011 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.
Moderators Citizen Posted April 9, 2011 Moderators Posted April 9, 2011 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)
Piorun Posted April 9, 2011 Author Posted April 9, 2011 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:
Moderators Citizen Posted April 9, 2011 Moderators Posted April 9, 2011 Client: addEventHandler("gettingPos", getRootElement(), gettingPlayerPos) instead of: addEventHandler("gettingPos", getRootElement, gettingPlayerPos)
Piorun Posted April 10, 2011 Author Posted April 10, 2011 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.
Moderators Citizen Posted April 10, 2011 Moderators Posted April 10, 2011 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 )
Piorun Posted April 10, 2011 Author Posted April 10, 2011 Haha .. sh** - it's working .. thanks Citizen. @EDIT F*** - it doesn't work for a player who join into the server -.-. Only when player is on server and resource is restarting.
Cadu12 Posted April 10, 2011 Posted April 10, 2011 addEventHandler("onResourceStart",getResourceRootElement(getThisResource()), getingPlayerBizPos)
Moderators Citizen Posted April 10, 2011 Moderators Posted April 10, 2011 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 )
Kenix Posted April 10, 2011 Posted April 10, 2011 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))
Piorun Posted April 10, 2011 Author Posted April 10, 2011 Nothing is working cool. I check every code that you are post here, but still doesn't work. @UP my data's are good, i check it few days ago.
Castillo Posted April 11, 2011 Posted April 11, 2011 Why don't you execute it using the event: onPlayerJoin?
Wojak Posted April 11, 2011 Posted April 11, 2011 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
Piorun Posted April 14, 2011 Author Posted April 14, 2011 @Solidsnake14 - when i'm using onPlayerJoin it's work but when i type in console "restart [res name]" then everything is turning off, and pff.. doesn't work. @Wojak - I will try your code .. but I have mixed feelings...
Piorun Posted April 15, 2011 Author Posted April 15, 2011 But in "onResourceStart" it doesn't works... so i can use only "onPlayerJoin" or "onPlayerLogin".
Piorun Posted April 15, 2011 Author Posted April 15, 2011 Yo, please close this topic, because i found solution of my problem - I added a timer with func getingPlayerBizPos into "onResourceStart" event .. and it's works ... Thanks for all .
Moderators Citizen Posted April 15, 2011 Moderators Posted April 15, 2011 Mmm it's what I made not ? setTimer( getingPlayerBizPos, 5000, 1 )
Piorun Posted April 16, 2011 Author Posted April 16, 2011 Yes, it is, but you added it without any event, and it works when i restart Resource (you added "addEventHandler" in coment, so i don't know what to do ) ... Thanks anyway everyone
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now