Jump to content

ds1-e

Scripting Moderators
  • Posts

    636
  • Joined

  • Days Won

    8

Everything posted by ds1-e

  1. Not sure if it's related to your case, but IIYAMA showed me how this could be done for onClientVehicleDamage. For important details, you would need to wait for his answer. In my case: Instead of triggering each hit, damage would be saved in table and after certain time, timer would execute triggerServerEvent, after data is cleared. This is called buffer/data reduction (probably?), as far i know. So, basically you reduce triggerServerEvent calls and you save bandwith. This might be helpful, it's also IIYAMA code local sendingDelay = 100 -- ms local fps = 60 local timeSlice = 1000/fps local dataReduction = sendingDelay/timeSlice print("~"..(dataReduction - 1 ).." x times LESS per "..sendingDelay.."ms") https://www.Lua.org/cgi-bin/demo edit: great timing
  2. iprint result: And i've also check that in SQLite Browser.
  3. I used dbPrepareString in other way (adding items only by modyfing table), could you check if everything is correct? Looks like table and columns created normally. local query_table = {} query_table[#query_table + 1] = dbPrepareString(serverTable.db, "CREATE TABLE IF NOT EXISTS `Items` (`Serial`, ") for i = 1, #serverTable.config.save_items do local item = serverTable.config.save_items[i] local check_index = i == #serverTable.config.save_items and ")" or ", " query_table[#query_table + 1] = dbPrepareString(serverTable.db, "`"..item.."` INT"..check_index) end dbExec(serverTable.db, table.concat(query_table))
  4. Thanks! Could you suggest some community scripts which are using SQLite in good way. I would prefer to learn more from script itself.
  5. It is possible to create 2-3 tables using dbExec once?
  6. Oh. I will experiment more soon. @IIYAMA thanks for sharing this site, i've just noticed that it contains a lot of SQL Stuff which would help me in learning
  7. Issue: addEventHandler ("onPlayerWasted", getRootElement() Fixed: addEventHandler("onPlayerWasted", getRootElement(), spawnThePlayer) You should start reading what debug says. Edit: Besides, this event doesn't have such parameter as player. Read carefully - https://wiki.multitheftauto.com/wiki/OnPlayerWasted
  8. I would like to try this way, but what do u mean by saying "a little buggy"? @IIYAMA I have question about dbPrepareString. 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 ) Not sure if i understand it correctly. "SELECT * FROM `player_info` WHERE true" Select everything from `player_info` table, where true? (what is true exactly for?) And later concatenate string with using serials (available in serialsToUse) as parameter.
  9. Next time use this: To show your code, it will help in readability for others. About problem, i doubt that you check /debugscript 3 for errors/warnings, without debug you couldn't go any further, trust me. Lua is case sensitive Fixed code: local spawnX, spawnY, spawnZ = 1769.55469, -1862.20325, 13.57658 function joinHandler() spawnPlayer(source, spawnX, spawnY, spawnZ) fadeCamera(source, true) -- case sensitive setCameraTarget(source) -- case sensitive + there's no such arguments like x, y, z outputChatBox("Welcome to Los Angeles Roleplay", source) end addEventHandler("onPlayerJoin", getRootElement(), joinHandler)
  10. Is there any way to store whole table with items in column? Instead of doing x columns for every item? local cache = {} local player = getPlayerFromName("majqq") cache[player] = { -- item, count ["First item"] = 1, ["Second item"] = 3, ["Third item"] = 4, }
  11. ds1-e

    new log

    Honestly, i don't know. Never tried. But according to this, this could be done for database. https://wiki.multitheftauto.com/wiki/DbConnect
  12. ds1-e

    new log

    Check: https://wiki.multitheftauto.com/wiki/Filepath If you need to edit something out of resource folder. Example: fileOpen(":resource_2/file_2.txt")
  13. ds1-e

    new log

    Are you trying to edit script file or text file? This matters.
  14. What about this? https://wiki.multitheftauto.com/wiki/DbPrepareString savour mentioned it: Could you show me an example, because i'm not sure how it should be done.
  15. Since i've just started my experience with SQLite (the time has come ), i am sorry about probably lots of incoming questions. Gotta learn when and where i should use certain functions. Excuse me in case of missing them, or using them in wrong time. Here comes first question, i would need to get some basic data on resource start about player, in this case nick, serial and IP. local database = dbConnect("sqlite", "db/database.db") --[[***************************************************]] function testFunction() local players = getElementsByType("player") for i = 1, #players do local player = players[i] local player_nick = getPlayerName(player) local player_serial = getPlayerSerial(player) local player_ip = getPlayerIP(player) local dbQ = dbQuery(database, "SELECT * FROM `players` WHERE `serial` = ?", player_serial) local dbR = dbPoll(dbQ, -1) if dbR and #dbR == 0 then dbExec(database, "INSERT INTO `players` (`name`, `serial`, `ip`) VALUES (?, ?, ?)", player_nick, player_serial, player_ip) end end end --[[***************************************************]] function onResourceStart() if database then local qh = dbExec(database, "CREATE TABLE IF NOT EXISTS `players` (`name` TEXT, `serial` TEXT, `ip` text)") testFunction() outputDebugString("Established connection to database.", 0, 255, 127, 0) else outputDebugString("Failed to establish connection.", 0, 255, 127, 0) stopResource(getThisResource()) end end addEventHandler("onResourceStart", resourceRoot, onResourceStart) I'm just worried about dbExec calls, f.e when 40 players are online on server, i am not sure if this could be done at once.
  16. Hey, i'm beginning experimenting with sqlite stuff, and i have few questions about that. 1. https://wiki.multitheftauto.com/wiki/DbPoll I don't clearly understand, what means that it will freeze entire server? It is some kind of lag, until function is executed? If so, then how many ms would be a decent value here? 2. https://wiki.multitheftauto.com/wiki/DbExec This function is meant to change something in database, and it doesn't give any return in back? For example creating tables if they not exist? Should be always used within dbFree? 3. https://wiki.multitheftauto.com/wiki/DbQuery This one should be used within dbPoll to get result? Plus dbFree in case of don't using dbPoll? 4. https://wiki.multitheftauto.com/wiki/DbFree About dbFree, what if this function should be executed, but it wouldn't be executed? 5. I can't access debugdb for some reason, probably is due of ACL, however i couldn't find anything related with them in ACL, or i simply removed/skipped it. 6. https://wiki.multitheftauto.com/wiki/DbPrepareString This function is meant to help and prevent SQL injections. So it should be all the time i guess? As i see this function also allows to create a big query with loop.
  17. Imho, you should use this. This way it's much better, meanwhile with the way above i had some issues.
  18. Rumpo[AparecerBike] = setTimer(destroyVehicle, 5000 * minutos, 0, AparecerBike) 5000 * minutos, 0 - change 0 to 1, otherwise this will never stop. Besides, code, it's badly optimized. No need for ipairs loop, use int loop instead.
  19. Are you sure that bike have elementdata? Did you check for warnings/erros? /debugscript 3
  20. What exactly doesn't work? Any errors, warnings?
  21. Nope, like this: function destroyVehicle() local occupied_seat = getPedOccupiedVehicleSeat(source) if occupied_seat and occupied_seat == 0 then local occupied_vehicle = getPedOccupiedVehicle(source) if occupied_vehicle then local element_data = getElementData(occupied_vehicle, "starter_pack") or false if element_data then -- destroy vehicle with such element data destroyElement(occupied_vehicle) end end end end addEventHandler("onPlayerWasted", getRootElement(), destroyVehicle)
  22. Ye, there you should add your missing code.
  23. According to my function: addEventHandler("onPlayerWasted", getRootElement(), destroyVehicle)
  24. There's no such MTA event, or it's a event created by yourself. If you want attach this function, simply do it as above, you'll just need to complete this by adding missing functions from your code. https://wiki.multitheftauto.com/wiki/Server_Scripting_Events
×
×
  • Create New...