Jump to content


Scripting Moderators
  • Posts

  • Joined

  • Days Won


Everything posted by srslyyyy

  1. srslyyyy

    new log

    Wrong category. About function, here's my function which i've created for custom logs system. First version which could be improved and it should be improved (in my final ver, i've added buffer to reduce usage of file functions.) local function logEvent(file, text) local file_exists = fileExists("logs/"..file) local real_time = getRealTime() local year = real_time.year + 1900 local month = real_time.month < 10 and "0"..real_time.month + 1 or real_time.month + 1 local month_day = real_time.monthday < 10 and "0"..real_time.monthday or real_time.monthday local hour = real_time.hour < 10 and "0"..real_time.hour or real_time.hour local minute = real_time.minute < 10 and "0"..real_time.minute or real_time.minute local second = real_time.second < 10 and "0"..real_time.second or real_time.second if file_exists then local log_file = fileOpen("logs/"..file) if log_file then fileSetPos(log_file, fileGetSize(log_file)) fileWrite(log_file, "\r\n["..year.."-"..month.."-"..month_day.." "..hour..":"..minute..":"..second.."] "..text) fileFlush(log_file) fileClose(log_file) else outputDebugString("Couldn't open log file.", 0, 255, 127, 0) return false end else local new_log = fileCreate("logs/"..file) if new_log then outputDebugString(file.." log file created successfully.", 0, 255, 127, 0) fileWrite(new_log, "["..year.."-"..month.."-"..month_day.." "..hour..":"..minute..":"..second.."] Log file created successfully.") if text then fileSetPos(new_log, fileGetSize(new_log)) fileWrite(new_log, "\r\n["..year.."-"..month.."-"..month_day.." "..hour..":"..minute..":"..second.."] "..text) end fileFlush(new_log) fileClose(new_log) else outputDebugString("Couldn't create new log file.", 0, 255, 127, 0) return false end end end Usage: logEvent("path_to_file.txt", "Text you want to save")
  2. You attach this function to internal MTA events which have completely other parameters than veh and seat. Did u even checked for warnings/errors? Example which should be helpful: 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 -- do your stuff end end end end end
  3. Yeah, exactly. I'm talking about samr46. He develops DayZ server since 2013.
  4. I am not sure about that, server i'm talking about it's well done in almost every way, including PvP between players thanks to this "bullet sync", i think it's very complex feature. Atleast it looks like it is, honestly i wouldn't need such thing for my server, but i was everytime curious how it could be done. In my honest opinion, it's incomparable to others servers, maybe just one which have similar, but other in every aspect gamemode. Developer of this server is very experienced, 6+ years of practise, he's contributing to MTA SA, and he's the one of person which was engaged in releasing 1.5.7 version.
  5. I've played on server which created some kind of own "bullet sync". I'm just curious how it could be done, server owner explained that attacker fully decides if victim was hit (victim got hit on attacker screen - probably ping was not that important factor). Honestly i don't think there is other way than using processLineOfSight + some other event, anyways i don't even know if that function is used for this, just wondering.
  6. Sorry but i didn't last 60 seconds at last test, at 1000 objects Screenshot comparing old one and new one, running at same time. 1 object: 10 objects: 100 objects: 1000 objects:
  7. Hey @IIYAMA Probably i've finished this. I just need to fix rotation, and test server-side. But at the moment, i've tested it only by myself, with 1 attached object. This is the result: - Localized Lua functions, tables, and any other functions which returns data. - Used int loop instead of pairs, didn't took me so long since i'm practising tables from the time when you showed me how to sync data between server/client. - With thing above i get rid of timer, coroutine and while loop. (hopefully this will fix an annoying error, i check if element actually exists, if not, script removing it from table) Glad that you helped me
  8. -- Client-side local guiText = guiGetText(pin) triggerServerEvent("check", resourceRoot, guiText) -- pass data -- Server-side function checkEvent(text) outputChatBox(text) end addEvent("check", true) addEventHandler("check", resourceRoot, checkEvent)
  9. Hi. Is there any idea to get a scrollbar which isn't created by script itself but by gridlist? I would need to save position of it. I've tried to get a scrollbar by: https://wiki.multitheftauto.com/wiki/OnClientGUIScroll But it looks like this event doesn't trigger for scrollbar which was created by gridlist.
  10. I would choose tables, after that what @IIYAMA taught me, i use tables almost everywhere. I feel like tables are very efficient comparing to element data, yet they require more code to sync which imho gives an better control how do you send data.
  11. Then you should use this. https://wiki.multitheftauto.com/wiki/OnClientVehicleCollision Get theHitElement (if it exists - it's parameter from event), check element type if is equal to vehicle, check if vehicle is frozen, and use: https://wiki.multitheftauto.com/wiki/TriggerServerEvent To unfroze vehicle for everyone, good luck. You should try to do that yourself, after that, when something will not work i wil try to help you with that.
  12. Does attachedTo works for table? local vehicles_table = { [vehicle], [vehicle], } And if so, then it will trigger for all vehicles which are in table?
  13. srslyyyy

    no limit

    I doubt, that is possible. If it would be possible, then probably such feature would exist since long times. Afaik without modifying GTA SA nothing could be done.
  14. srslyyyy


    1. local character local forbidden_characters = { ["w"] = "w", ["a"] = "a", ["s"] = "s", ["d"] = "d", } function onClientCharacter(char) if forbidden_characters[char] then character = char end end addEventHandler("onClientCharacter", getRootElement(), onClientCharacter) function onClientGUIChanged(element) if element then -- add check for your element local gui_text = guiGetText(element) if gui_text then local forbidden_character = character local check = forbidden_characters[forbidden_character] if check then local replace = string.gsub(gui_text, check, "") guiSetText(element, replace) end end end end addEventHandler("onClientGUIChanged", getRootElement(), onClientGUIChanged) Tested a bit, and looks like works for typing, you would need to replace string with characters to "" when player paste something. Also you need to fill table with forbidden characters. https://wiki.multitheftauto.com/wiki/OnClientPaste
  15. Your code is badly optimized, i've fixed it. Should work, untested. -- Useful function function isVehicleEmpty(vehicle) if not isElement(vehicle) or getElementType(vehicle) ~= "vehicle" then return true end local passengers = getVehicleMaxPassengers(vehicle) if type(passengers) == "number" then for seat = 0, passengers do if getVehicleOccupant(vehicle, seat) then return false end end end return true end -- Unfroze when entering function onPlayerVehicleEnter(vehicle, seat, jacked) if isElementFrozen(vehicle) then -- don't froze if element is frozen setElementFrozen(vehicle, false) end end addEventHandler("onPlayerVehicleEnter", getRootElement(), onPlayerVehicleEnter) -- Froze on exit function onPlayerVehicleExit(vehicle, seat, jacker, forced) if not isElementFrozen(vehicle) and isVehicleEmpty(vehicle) then -- don't froze if element is frozen, and be sure that vehicle is empty setElementFrozen(vehicle, true) end end addEventHandler("onPlayerVehicleExit", getRootElement(), onPlayerVehicleExit) -- Check all vehicles on resource start function onResourceStart() local vehicles = getElementsByType("vehicle") for i = 1, #vehicles do -- no need for ipairs, int loop faster local vehicle = vehicles[i] -- get vehicle if vehicle and isVehicleEmpty(vehicle) then -- check if vehicle is empty. if not isElementFrozen(vehicle) then -- don't froze if element is frozen setElementFrozen(vehicle, true) end end end end addEventHandler("onResourceStart", resourceRoot, onResourceStart) -- Froze on vehicle spawn function onVehicleRespawn(exploded) if isVehicleEmpty(source) then -- ditto if not isElementFrozen(source) then -- ditto setElementFrozen(source, true) end end end addEventHandler("onVehicleRespawn", getRootElement(), onVehicleRespawn) --[[for all vehicles, change to resourceRoot instead of getRootElement() - if it should happen for vehicles created only by this resource]]
  16. But excluding those, everything should be alright? I was worried about such situation (i don't really know what's happening when resource stops) for example: there's a lot of data to save, and resource saves few files (yet, not my case), JSON, sqlite3 database. Unloading code follows before/after or together with functions which are executed at resource stop?
  17. Hi, @IIYAMA I've already created buffer for log system, to reduce impact on server. After reaching x messages it saves everything to file and clears table. Also in case of resource restart, when buffer < max size, to not lost anything that was in table, i've done saving it on resource stop. And here comes question, is there any chance that it would fail? For example if there will be a lot of data in table (not my case, though).
  18. One resource. Ye but this is not what i want. For example. 2 GUI's opened, i close 1st, cursor stays until i close 2nd.
  19. Hey, i've encountered a annoying issue. I use: showCursor(not isCursorShowing(), true) For toggle on/off cursor. Code works well, when it's a single use, but whenever i use it 2 times at once (different GUIs), it causes that cursor enables when closing GUI, so to fix this i need to reconnect or mess up with toggling on/off cursor with console. So i am curious how i could fix it. Any ideas?
  20. Yes i know that i can check it via browser. I've used site to it - https://jsonlint.com But i need to check if JSON is correct via script. So it will not mess up settings like when player change something in it - manually.
  21. Hello. I need a way to check if JSON file is correct, and if some values are boolean/number etc. About 2nd i know that i can simply use type function. JSON file is on client-side, and user settings are saved there (visuals).
  22. Check that. https://wiki.multitheftauto.com/wiki/GetLocalization
  23. Hi, thanks for answer. I've checked by myself and probably it worked for Lua functions (looks like), but for some reason on MTA functions it showed mostly less or rarely - more ticks, there was a few times when it taked even more than non-localized things. (maybe fault of fast restart of script but i don't think so).
  • Create New...