hipolitalakaj Posted January 20, 2019 Share Posted January 20, 2019 Hi! I trying to trigger a clientside event in server.lua which exists in client.lua but the debugscript says "Server triggered clientside event onClientReceiveItems, but event is not added clientside" What's wrong? ---- client ---- function receiveItems(data) item_table = {} item_table = data if(itemElement and getElementType(itemElement) == "player" and itemElement == localPlayer or itemElement==nil )then item_table_player = data for index, value in ipairs (item_table) do if value[5] > 0 then item_table_action[tonumber(value[5])] = {item_table[tonumber(index)][6], item_table[tonumber(index)][1], item_table[tonumber(index)][3]} end end end isMove = false movedItem = 0 newCount = 0 movedSlot = -1 movedCount = 0 movedValue = 0 selectedAmount = 0 currentActionSlot = 0 end addEvent("onClientReceiveItems", true) addEventHandler("onClientReceiveItems", getRootElement(), receiveItems) ---- server ---- function loadPlayerItems(element) local ownerID = tonumber(getElementData(element, "acc:id") or -1) array[0][ownerID] = {} local item = -1 for i = 1, 50 do array[0][ownerID][i] = {-1, -1, -1, -1, -1, -1, -1} end local loadItems = dbPoll(dbQuery(connection, "SELECT * FROM items WHERE owner = ? AND type = 0", ownerID), -1) if #loadItems > 0 then for i, row in ipairs(loadItems) do item = tonumber(row['itemid']) or -1 value = row['value'] or -1 count = tonumber(row['count']) or -1 slot = tonumber(row['slot']) or -1 type = tonumber(row['type']) or -1 slot = tonumber(row['slot']) or -1 id = tonumber(row['id']) or -1 actionslot = tonumber(row['actionslot']) or -1 duty = tonumber(row['dutyitem']) or -1 array[tonumber(getType(element)) or 0][ownerID][slot] = {tonumber(item), value, tonumber(count), tonumber(id), tonumber(actionslot), tonumber(slot), tonumber(duty)} end end triggerClientEvent(element, "onClientReceiveItems", element, array[tonumber(getType(element)) or 0][ownerID]) end addEvent("playerLoadItemsToServer", true) addEventHandler("playerLoadItemsToServer", root, loadPlayerItems) Link to comment
Moderators IIYAMA Posted January 20, 2019 Moderators Share Posted January 20, 2019 (edited) See this topic: That guy has the same issue. You get this error because you send a trigger event, but the clients/players haven't loaded their scripts. This can be either an timing issue or there is another error which causes the script to fail loading. The event onClientResourceStart is a great way to detect when a player can receive triggerClientEvents Edited January 20, 2019 by IIYAMA Link to comment
hipolitalakaj Posted January 20, 2019 Author Share Posted January 20, 2019 Um, thanks for your reply. So I need to put a timer? if yes, where I need to put that timer? I still don't get it Link to comment
DNL291 Posted January 21, 2019 Share Posted January 21, 2019 (edited) Use onClientResourceStart to trigger the event "playerLoadItemsToServer" or trigger another server event to mark that the client is ready to communicate with the server side. Also, you'll need to remove any call for the function 'loadPlayerItems' in events that should be causing that error (it may be the event "onResourceStart" for example). Edited January 21, 2019 by DNL291 Link to comment
hipolitalakaj Posted January 21, 2019 Author Share Posted January 21, 2019 What do you mean? Something like this? ---- client ---- function receiveItems(data) item_table = {} item_table = data if(itemElement and getElementType(itemElement) == "player" and itemElement == localPlayer or itemElement==nil )then item_table_player = data for index, value in ipairs (item_table) do if value[5] > 0 then item_table_action[tonumber(value[5])] = {item_table[tonumber(index)][6], item_table[tonumber(index)][1], item_table[tonumber(index)][3]} end end end isMove = false movedItem = 0 newCount = 0 movedSlot = -1 movedCount = 0 movedValue = 0 selectedAmount = 0 currentActionSlot = 0 end addEventHandler("onClientResourceStart", getRootElement(), receiveItems) Link to comment
DNL291 Posted January 23, 2019 Share Posted January 23, 2019 Nope, actually in that code the table "data" isn't being passed to the function. What I mean is, where are you calling the function 'loadPlayerItems'? You should first fix what is causing this error message. After that, follow this step I said above: On 21/01/2019 at 00:30, DNL291 said: Use onClientResourceStart to trigger the event "playerLoadItemsToServer" or trigger another server event to mark that the client is ready to communicate with the server side. Link to comment
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