-
Posts
6,058 -
Joined
-
Last visited
-
Days Won
208
Everything posted by IIYAMA
-
Hi Lus, good to have you! It is recommended to read these guidelines, this information will help you in many ways to get the right answers for your questions.
-
Just a little details, it is actually the hidden argument 'warp' that is responsible for the cancellation. In the past this argument was not present and was applied by default. https://wiki.multitheftauto.com/wiki/SetElementPosition
-
---@param ID number ---@return player | nil function findPlayerByID(ID) local players = getElementsByType ( "player" ) for i, p in ipairs(players) do if getElementData(p, "Player.ID") == ID then return p end end end ---@param player element ---@param cmd string ---@param rawID string | nil function tp(player, cmd, rawID) -- Admin level check if getElementData(player, "Player.AdminLevel") <= 1 then return end local ID = tonumber(rawID) if type(ID) ~= "number" then outputChatBox("#000000<#910e07Wise#ffffffRolePlay#000000> #ffffff /gethere [ID]", player, 255, 255, 255, true) return end local targetPlayer = findPlayerByID(ID) if not targetPlayer then outputChatBox("#000000<#910e07Wise#ffffffRolePlay#000000> #ffffff Rossz ID-t adtál meg.", player, 255, 255, 255, true) return end local x, y, z = getElementPosition(targetPlayer) setElementPosition(player, x, y, z) end
-
Oke, in that case please show me the code so that I can check if it is applied correctly.
-
You should move this condition before the loop and if it fails, do the outputChatBox + return statement.
-
It inserts a row into the database and returns the generated primary key. But most of it are just examples for you to apply in to your own code. (also not tested, I haven't combined insert + update with the multipleResults statement myself) If something is unclear, please be specific in which part or function you do not understand. Then I will explain how that part/function works.
-
In that case you can try to work with the following building blocks. (untested) local userName = "root" local password = "root" local host = "127.0.0.1" local db = dbConnect( "mysql", host, userName, password, "multi_statements=1" -- optional ) -- ... local player -- = ??? local serial = 1234567890 if db then dbQuery(onRegisterPlayer, {player}, db, [[ INSERT INTO characters (serial) VALUES (?) ON DUPLICATE KEY UPDATE id=VALUES(id); ]], serial) end -- ... ---@param queryHandle userdata ---@param player userdata function onRegisterPlayer(queryHandle, player) if not isElement(player) then return end local multipleResults = true -- return the id of the inserted row local result = dbPoll(queryHandle, -1, multipleResults) if not result then --- Something went wrong error("Failed to register player") return end iprint("Table", result[1]) iprint("Affected rows", result[2]) iprint("Last insert id", result[3]) end
-
And at what point do you save the character? After filling in info of some sort? Are you using SQLite or MySQL?
-
So you mean the user case when no ID is assigned to a new player? Based on what criteria are you assigning the ID?
-
It does indeed In that case, could you explain the following with some more context? It is unclear what an `individual ID` is in the current context.
-
No, it returns a player<element> or nil function getPlayerFromPartialName(name) local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil if name then for _, player in ipairs(getElementsByType("player")) do local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() if name_:find(name, 1, true) then return player end end end end local name = "IIYAMA" local player = getPlayerFromPartialName ( name ) if player then -- Found else -- Not found end
-
Maybe you should switch over to teleport by player (partial) name? https://wiki.multitheftauto.com/wiki/GetPlayerFromPartialName Makes things a little bit easier.
-
When use the keyword break, it jumps from: for i, p in ipairs(players) do if getElementData(p, "Player.ID") == tonumber(ID) then local x, y, z = getElementPosition(player) setElementPosition(p, x, y, z) break -- FROM HERE else outputChatBox("#000000<#910e07Wise#ffffffRolePlay#000000> #ffffff Rossz ID-t adtál meg.", player, 255, 255, 255, true) end end -- TO HERE The following code prints: A, D for i=1, 10 do if true then print("A") break print("B") else print("C") end end print("D") Run here to test: https://onecompiler.com/lua/42zdspdkb Not sure what exactly the problem is that you are facing, but in your current code you could also use the return keyword to immediately stop the function.
-
If this code is ran clientside, it will create a lot of lag (because of setElementData). If ran serverside, it will have impact but consistent. (If the problem is purely located here and not created somewhere else) For now I consider this code to be ran serverside, because that would be the most logic place for this code to be used. The following components can be considered an impact multiplier on clientside: https://wiki.multitheftauto.com/wiki/AddDebugHook https://wiki.multitheftauto.com/wiki/OnClientElementDataChange Does the pass have to be refreshed every 1 second? Can't it be refreshed every 10sec/1 min? A small improvement, make the value of NewPass an integer. Which helps with the transfer speed.
-
No worries take your time, just checking if you may have mist it. Serverside (as well as shared~serverside) are limited by the ACL, clientside is not. That is possible. You can double verify if the resource has access to loadstring using: https://wiki.multitheftauto.com/wiki/HasObjectPermissionTo addEventHandler("onResourceStart", resourceRoot, function (startedResource) if not hasObjectPermissionTo ( startedResource, "function.loadstring", true ) then local cancelReason = "Missing permission function.loadstring" outputDebugString(cancelReason, 2) cancelEvent(true, cancelReason) -- Something is wrong, stop startup end end, false) You could also make a copy of your current ACL and use the default one: https://github.com/multitheftauto/mtasa-blue/blob/master/Server/mods/deathmatch/acl.xml
-
In most cases it works by default. But in some cases you need to restart the server. I ran in to that issue myself, restarting did resolve the problem for me. For the following info, I used the resource runcode as example. Step 1A, check if the request is applied: aclrequest list runcode all Step 1B, if not, run: aclrequest allow runcode all Step 2A Test if the error is gone. Step 2B, not working? Restart the server Step 2C Still not working? Give the resource temporary admin rights and resolve it later. btw. not to go offtopic, but a reminder that I replied on your other topic with `PointOfInterest`.
-
That is why you can capture those by surrounding the fromJSON with a table: local result = {fromJSON(data)} Although this solution might be more optimised: local result = fromJSON("[" .. data .. "]") It changes your data string to: [[ { "id": 49, "username": "framef318", "email": "[email protected]" }, { "id": 50, "username": "framef3188", "email": "[email protected]" } ]] Which helps returning everything inside of 1 variable, instead of multiple.
-
And if you do: local result = {fromJSON(data)} ? { "id": 49, "username": "framef318", "email": "[email protected]" }, This is one return value. local a, b = fromJSON(data) { "id": 50, "username": "framef3188", "email": "[email protected]" } And this is one return value. local a, b = fromJSON(data) Other way (untested): local result = fromJSON("[" .. data .. "]")
-
It is just an integer, 213821 nothing in terms of memory. No matter how long the number is, it will not use more memory than if it was a string. 10000000000 consumes less memory than "10000000000". If you do not believe me, ask Chat GPT... Also, I asked Chat GPT the following: How many times can fit 10000000000 in 8gb of memory table.remove is only useful when you want to use a table as an array. It is very useful if order matters, but in your case there is no need for maintaining an order. It might save some memory, but the look up speed will consumes (incremental) a lot more CPU(you need to loop) which is a big trade off. local temp = {1, 2, 3, 7, 10, 100} -- id's inside For example the table pointOfInterestCollection. do local id = 0 ---@return integer function generateId () id = id + 1 return id end end ---@type {[integer]: table|nil} local pointOfInterestCollection = {} ---@param poi table function savePointOfInterest (poi) local id = generateId () poi.id = id pointOfInterestCollection[id] = poi end ---@param id integer ---@return table|nil function loadPointOfInterest(id) return pointOfInterestCollection[id] end ---@param id integer ---@return boolean function removePointOfInterest(id) if not pointOfInterestCollection[id] then return false end pointOfInterestCollection[id] = nil return true end
-
When are using the following: bindKey timers trigger(server/client)Event (set/get)ElementData etc... The data that you pass through these functions is being cloned. The reason behind that is: the data is leaving it's current Lua environment. With as goal to maintain the data, else it is lost. Unfortunately metatables and functions can't be cloned, which is why you did encounter data loss. Fortunately, because they can't be cloned you know that something is wrong. If they were be able to get cloned, you would have ended up with multiple clones of the same entity that do not share data. Which becomes really hard to debug. To resolve this issue, do not pass the element but use a self made id(integer). And make it look up able by using another table.
-
Have you used debug lines to debug/verify every part of the call chain?
-
I tested the following code with this compiler and it works. https://onecompiler.com/lua/42wdewngs Are you sure you are not synchronizing the data or exporting it(call/export)? Because in that case interactionFunction becomes nil. PointOfInterest = {} PointOfInterest.__index = PointOfInterest function PointOfInterest:create(x, y, z, interactionRadius, interactionFunction, visibleDistance, interior, dimension, renderOffsetX, renderOffsetY, renderOffsetZ, onFootOnly) if type(x) ~= "number" or type(y) ~= "number" or type(z) ~= "number" then error("Bad argument @ PointOfInterest:create [Expected number at argument 1, 2, 3, got "..type(x)..", "..type(y)..", "..type(z).."]", 2) end if type(interactionFunction) ~= "function" then error("Bad argument @ PointOfInterest:create [Expected function at argument 5, got "..type(interactionFunction).."]", 2) end local poi = {} setmetatable(poi, PointOfInterest) poi.x = x poi.y = y poi.z = z poi.interactionRadius = type(interactionRadius) == "number" and interactionRadius or 1 -- [temp disabled] poi.collision = createColSphere(x, y, z, poi.interactionRadius) -- [temp disabled] poi.collision:setID("poi") -- Set the ID to "poi" to identify it as a point of interest poi.interactionFunction = interactionFunction -- [simplified] poi.visibleDistance = type(visibleDistance) == "number" and visibleDistance or 10 poi.interior = type(interior) == "number" and interior or 0 poi.dimension = type(dimension) == "number" and dimension or 0 poi.renderOffsetX = type(renderOffsetX) == "number" and renderOffsetX or 0 poi.renderOffsetY = type(renderOffsetY) == "number" and renderOffsetY or 0 poi.renderOffsetZ = type(renderOffsetZ) == "number" and renderOffsetZ or 0 poi.onFootOnly = (type(onFootOnly) == "boolean" and onFootOnly) or false -- [temp disabled] TBL_POIS[poi.collision] = poi return poi end function testfunc() print('You are near the point of interest!') return true end local test = PointOfInterest:create(195.00665283203, -141.83079528809, 1.5858917236328, 1, testfunc, 10, 0, 0, 0, 0, 1, true) print(test.interactionFunction()) Output: You are near the point of interest! true
-
That should be fine. You can make a bug report here. As a temporary solution you can stop the rendering process: https://wiki.multitheftauto.com/wiki/SetBrowserRenderingPaused (Note: This does not free up the memory.)
-
How do you close the browser? (as in code)
-
Correct! Please mind that the primary language of this section is English. It is fine to add additional translations for clarification.