-
Posts
6,097 -
Joined
-
Last visited
-
Days Won
218
Everything posted by IIYAMA
-
@Einheit-101 If we keep looping out of it and only talk about indexing. This below is just an assumption: If this is the userdata key: (which is at the very end just a complex and unique identifier.) "userdata-324ftfdbgfd" And this is the data: table = { ["userdata-424ftfsdgsf"] = true, ["userdata-3sd3524ftfd"] = true, ["userdata-325524ftfdb"] = true, ["userdata-324ftfdbgfd"] = true } Depending on which algorithm is used, the search time variates. (algorithm < which I have no knowledge of) But if I would program this search, I might do it like this in my first try: I know already the type, so my start would be: "userdata-" >>> userdata-424ftfsdgsf userdata-3sd3524ftfd userdata-325524ftfdb userdata-324ftfdbgfd Collect all items with userdata. steps * items >>> userdata-424ftfsdgsf userdata-3sd3524ftfd userdata-325524ftfdb userdata-324ftfdbgfd print(string.byte("3")) -- 51 + update position * 4 + 4 steps >>> userdata-3sd3524ftfd userdata-325524ftfdb userdata-324ftfdbgfd print(string.byte("s")) -- 115 print(string.byte("2")) -- 50 + update position * 3 + 3 steps >>> print(string.byte("4")) -- 52 userdata-325524ftfdb userdata-324ftfdbgfd < found item in table + update position * 2 + 2 steps Lua would probably be better in this then I do. But this has multiple search steps in it, no matter what kind of algorithm you use. table = { true, -- 1 true, -- 2 true, -- 3 true -- 4 } table = { [1] = true, [2] = true, [3] = true, [4] = true } Finding the index in this kind of table should be technically be faster based on two ways. Position of the characters do not matter. It is a single value, the cpu knows very well how to work with that. As with user-data's/strings, not only the position matters, the value is also different: print(string.byte("a")) -- 97 Much complexer values X position. Everything is already placed in order if you keep the table as an clean array. Just as with cleaning your room. After the cleaning, you do not have to look everywhere in your room. You more or less know where to find what and how many things you have of it. Searching for item 4? no, no, no, yes (4 steps) Note: looping to find an item VS using a custom key to find an item is a different subject. If somebody knows how this really works, then that would be nice fun facts.
-
Something like that: dbExec (db, "UPDATE accounts SET serial = ? WHERE username = ?", u_serial, username)
-
Does that player already has an account?
-
Add data to a database? INSERT INTO table_name (column1, column2 ) VALUES (?, ?) OR Get data from a database? SELECT * FROM table_name OR Import data to a database from another database.
-
True is true. It means just, yes go add it. It has probably been added to not have to add another Lua IF statement for the AND sql keyword. "true" .. " and serial = 3442" Or if the table is empty. Anyway, the example is correct, the query on the other hand doesn't looks like it is correct: true and serial = 3442 and serial = 3663 and serial = 4532 Shouldn't this be more logic? serial = 2332 or serial = 3442 or serial = 2324 It can be my imagination...
-
Get the correct table index depending on other values
IIYAMA replied to Dzsozi (h03)'s topic in Scripting
That table structure will not work well. Back to basic: local list = { {value = 25, id = "a"}, {value = 50, id = "b"}, {value = 75, id = "c"}, {value = 100} } function findSomething(value) for i = 1, #list - 1 do if value >= list[i].value and value < list[i + 1].value then return list[i] end end end local result = findSomething(27) if result then print(result.id) end -
That is normally not recommend, because you put a limit on your database. Your database will consider your data as text. (Or blob) But sure it is fine if you are not going to use your db to do stuff with the data. Columns should be used for properties and properties only. So if a player has multiple items. We need two tables, and not more columns. Each new item should a row in the second table. This page has a good example of how you would bind items/orders to a person: https://www.w3schools.com/sql/sql_foreignkey.asp
-
You are only setting it ON, even when you are trying to set it OFF. engineSetModelLODDistance(elementID, eventName == "onClientResourceStart" and 1000 or 150) 1000 is ON. Something below 170 is OFF. ( probably each object has an unique LOD distance value )
-
I copied the first from the wiki page: serialsToUse = { "111", "222", "333" } local queryString = dbPrepareString( connection, "SELECT * FROM `player_info` WHERE true" ) for _,serial in ipairs(serialsToUse) do queryString = queryString .. dbPrepareString( connection, " AND `serial`=?", serial ) end local handle = dbQuery( connection, queryString ) And changed it a bit serialsToUse = { "111", "222", "333" } local queryTable = {} queryTable[#queryTable + 1] = dbPrepareString( connection, "SELECT * FROM `player_info` WHERE true" ) for _,serial in ipairs(serialsToUse) do queryTable[#queryTable + 1] = dbPrepareString( connection, " AND `serial`=?", serial ) end local handle = dbQuery( connection, table.concat(queryTable) ) The performance increasement is exponential. Which depends on the content. With just 2 strings, the performance will probably not getting any better. (worse) String concatenate * strings VS (table index: .concat) + function call
-
dbExec should be fine, your server might experience performance impact, but shouldn't freeze in a badly way. dbQuery is a different story. This is where you should use the callback function. You do not want your resource to wait for the database [doing something ...] > while starting up. The callback function will inform you when the player is ready to play.
-
How to determine if something attached to player's hand?
IIYAMA replied to thund3rbird23's topic in Scripting
That is the same resource. -
What are you waiting for? You know which function is not working properly and yet you are only looking at your own resource? Question for yourself: What are the conditions and expected returned results of the takeitm function?
-
Looks like a typo: exports.dota:takeitm( thePlayer, 1 <missing: , > 50)
-
He probably means: https://wiki.multitheftauto.com/wiki/RemoveEventHandler Or just destroy the function: trigger = nil ?
-
I assume /webfile/ is a different resource then where the file is loaded from? (In that case it is important that the webfile has atleast started once and the file has been downloaded before the browser request. Check the client folder for the html file. ) If it is not that, then indeed it might be a bug. (They disabled the old local url method after all)
-
Can't you do the samething, as in this topic? ?
-
Does this person have a name? Bigbadbutler/PhatLooser from chaos.de perhaps? Probably not, as he is not active any more. He indeed used processLineOfSight. A player will 0.5k+ ping still manages to kill another player. But never the less, it looks advanced, but it is still at the very bone, similar to the headshot resource. It is just way less enchanted, without overwrites. Is the person you meant on this list?
-
It is more dirt than magic. ? One of the first concepts of it was used in this headshot resource: https://community.multitheftauto.com/index.php?p=resources&s=details&id=1600 It is really a disgusting concept... ? function sendHeadshot ( attacker, weapon, bodypart, loss ) At first it looks innocent, but if you see this line, you know you kissed your opponent: if attacker == getLocalPlayer() then if bodypart == 9 then triggerServerEvent( "onServerHeadshot", getRootElement(), source, attacker, weapon, loss ) setElementHealth ( source, 0 ) setPedHeadless( source, true ) end end end addEventHandler ( "onClientPedDamage", getRootElement(), sendHeadshot ) addEventHandler ( "onClientPlayerDamage", getRootElement(), sendHeadshot )
-
You could try this for your sound issue. addEventHandler("onClientResourceStart", root, function () if open == false then setSoundVolume(source, 0) local resourceRoot_ = source setTimer(function () if isElement(resourceRoot_) then setSoundVolume(resourceRoot_, 0) end end, 1000, 1) end end, true, "low")
-
Hmm normally you would have to shoot in front of the target and not behind the target. Except when the target his fps is below the standards. The player movement speed is based on fps. So that is why they do not recommend to put the max fps too high for PvP modus. MTA is correcting this by reupdate the position, but that is not enough for the exact position. This issue is hard to solve, even in modern games like battlefield and cod. But there they have serverside bullet detection, that solves partly the issue. DO: exclude players with a too low fps OR reduce the max fps to something most machines can handle. Increased sync works well with good internet, but has the opposite effect for players with bad internet. With other words pick your target group for PvP or find a target group unlike yourself that doesn't mind lag.
-
More than 50% performance boost. ? Nicely done!
-
And what was it before? If you want to measure this correctly you need multiple samples. 0 AttachElements (idle). 10 AttachElements (doing something). 1000 AttachElements (doing a lot). 10000 AttachElements (doing too much).
-
After the installation you should be able to run this. callBack should be a function as 3e argument where the end-result goes to. function getEngineVehData (id, parte, callBack) callServer("preGetEngineVehData", getPlayerName(localPlayer), id, parte, callBack) return true end function preGetEngineVehData (nombre, id, parte) --... return "something" end
-
http://Lua-users.org/wiki/FormattingNumbers
-
@enzoDs You can't return later without coroutine which is your last resort, how about you solve your issue with a callback? async functionalities are very complex to build, as you do have to mind delays, process flow and cleaning of used code. This enchantment allows you to use callbacks: You can also use the code as inspiration for your own.
