Jump to content

chris1384

Members
  • Posts

    33
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by chris1384

  1. -- onClientVehicleReverse / chris1384 local reversing = {vehicles = {}} local getElementsByType = getElementsByType local root = getRootElement() local pairs = pairs local triggerEvent = triggerEvent local getElementType = getElementType local getElementMatrix = getElementMatrix local getElementVelocity = getElementVelocity function reversing.start() local vehicles = getElementsByType("vehicle", root, true) local vehicles_count = #vehicles if vehicles_count > 0 then for i=1, vehicles_count do local vehicle = vehicles[i] reversing.vehicles[vehicle] = reversing.detect(vehicle) end end end addEventHandler("onClientResourceStart", resourceRoot, reversing.start) function reversing.render() for vehicle, d in pairs(reversing.vehicles) do local r = reversing.detect(vehicle) if d ~= r then reversing.vehicles[vehicle] = r triggerEvent("onClientVehicleReverse", vehicle, r == 1) end end end addEventHandler("onClientRender", root, reversing.render) function reversing.add() local vehicle = source if getElementType(vehicle) == "vehicle" then reversing.vehicles[vehicle] = reversing.detect(vehicle) end end addEventHandler("onClientElementStreamIn", root, reversing.add) function reversing.remove() local vehicle = source if getElementType(vehicle) == "vehicle" then reversing.vehicles[vehicle] = nil end end addEventHandler("onClientElementDestroy", root, reversing.remove) addEventHandler("onClientElementStreamOut", root, reversing.remove) function reversing.detect(vehicle) local m = getElementMatrix(vehicle) local x, y, z = getElementVelocity(vehicle) local d = (x * m[2][1]) + (y * m[2][2]) + (z * m[2][3]) return (d < 0 and 1) or 0 end usage: addEvent("onClientVehicleReverse") addEventHandler("onClientVehicleReverse", root, function(reversing) iprint(vehicle, reversing) -- OUTPUT -- vehicle:element, true if reversing, false otherwise end)
  2. Everything is working now. It was easier than I thought lol. I was planning to use this in the future, I had to get over the basics first because that's where it screwed me up the most. Thanks for the tip And thank you all for helping!
  3. It's going to be hard to explain so bear with me. Supposed we have a function like this (function is in a string): exports.myresource:addProperty("security", "function(player) return getPlayerName(player) == 'owner' end") Then, in myresource the string is then put in a loadstring function, as following (it only checks it, doesn't add it anywhere): local testPlayer = getPlayerFromName("player1") -- testing purposes local loadstringed = loadstring(name.. " = ".. func_str) local success, info = pcall(loadstringed, testPlayer) iprint(success, info) -- outputs: true, nil Apparently everything seems to work, the function does indeed exist, but doesn't seem to take any parameters into it. How do you make a function loaded with loadstring() that also supports parameters?
  4. since you mentioned that you would use IDs for the players, perhaps you are using (My)SQL for your saves use dbExec to insert or update a database column, dbQuery and dbPoll to get the results, use os.date() to retrieve the exact date and time (it's using servers time) or.. use getPlayerAccount, setAccountData and os.date() to set an accounts last login data then use getPlayerFromName, getPlayerAccount and getAccountData for /lastlogin
  5. math.lerp pentru euler angles (generat de chatgpt pentru python, convertit de mine pentru lua) function lerp_angle(start_angle, end_angle, progress) local start_angle = math.rad(start_angle) local end_angle = math.rad(end_angle) if math.abs(end_angle - start_angle) > math.pi then if end_angle > start_angle then start_angle = start_angle + 2*math.pi else end_angle = end_angle + 2*math.pi end end local angle = (1 - progress) * start_angle + progress * end_angle return math.deg(angle) end
  6. Hey everyone, I'd like to introduce you to my tool that essentially lets you create seamless segmented runs for any race map. The tool is still in development (and I'm very lazy lol) so updates will be shown on the main GitHub page: https://github.com/chris1384/mta-tas-dm Here's a little showcase using the janky, older tool that I've made back in 2020: Here's the behind the scenes using the newer tool that's available for download: Thanks for the attention and have fun!
  7. un server de race n-am mai avut de multi ani servere de freeroam sunt dar nu populate dayz-ul a murit si nu mai e nimeni interesat sa mai faca unul de ctv/tactics/assault sau chiar multigamemode nu s-au mai auzit sau n-a facut nimeni (except 4 me) daca nu le faci la playeri pe plac, te trezesti cu hate de la copii care cred ei ca stiu mai bine daca se face roleplay sau orice altceva si nu bagati moduri de 3gb in total, degeaba vi l-ati mai deschis am ajuns la peak-ul mta-ului.
  8. - noclip ver. 1.3.0 Resursa de airbreak intitulat noclip, fiindca n-am gasit pe nicaieri unul up-to-date sau functional, am decis sa fac eu unul. Este recomandat doar pentru development, setarile le gasiti in fisierele din resursa, acestea sunt necompilate. Have fun! Download: https://community.multitheftauto.com/index.php?p=resources&s=details&id=18592
  9. part ii returneaza playerul dupa o parte a numelui (useful af) 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 return false end verifica daca contul player-ului este intr-un ACL Group function isPlayerInACL ( player, acl ) local account = getPlayerAccount ( player ) if ( isGuestAccount ( account ) ) then return false end return isObjectInACLGroup ( "user."..getAccountName ( account ), aclGetGroup ( acl ) ) end verifica daca player-ul este intr-un team function isPlayerInTeam(player, team) return getPlayerTeam(player) == (type(team) == "string" and getTeamFromName(team) or (type(team) == "userdata" and team or (getPlayerTeam(player) or true))) end returneaza distanta dintre camera si element function getElementDistanceFromCamera(element) local cX, cY, cZ = getCameraMatrix() local eX, eY, eZ = getElementPosition(element) return getDistanceBetweenPoints3D(cX, cY, cZ, eX, eY, eZ) end returneaza viteza unui element in km/h function getElementKMh(element) if element and isElement(element) then local v = {getElementVelocity(element)} return math.floor(((v[1]^2 + v[2]^2 + v[3]^2)^(0.5))*180) end end returneaza un string fara Hex color codes: #00FF00Player > Player function unHex(string) return (type(string) == "string" and string:gsub("#%x%x%x%x%x%x", "")) or false end recomandat pentru cei ce lucreaza cu functii dx, screenR returneaza raportul ecranului (de obicei 16/9 sau 1.(7)) local screenW, screenH = guiGetScreenSize() local screenR, screenN = screenW/screenH, 1280/screenW screenN il folositi pentru dx scaling, daca lucrati in rezolutia 1920/1080, folositi 1920/screenW, dupa va folositi de acea variabila de a inmulti fiecare constanta folosit in functiile dx (nu inmultiti screenN cu screenW sau screenH fiindca aceste 2 nu sunt constante) exemplu: local screenW, screenH = guiGetScreenSize() local screenN, screenYnative = 1280/screenW, 720/screenH -- // a 2-a variabila este foarte putin folosita, dar o vom folosi aici doar ca exemplu addEventHandler("onClientRender", root, function() -- FOLOSIND DOAR CONSTANTE (rosu) dxDrawRectangle(screenW/2 - sizeX/2, screenH/2 - sizeY/2, 100, 200, tocolor(255, 0, 0, 255)) -- // -- FOLOSIND x*screenN, y*screenYnative (verde) local sizeX, sizeY = 100*screenN, 200*screenYnative dxDrawRectangle(screenW/2 - sizeX/2, screenH/2 - sizeY/2, sizeX, sizeY, tocolor(0, 255, 0, 150)) -- // end) acest script deseneaza doua dreptunghiuri (rosu si verde) in mijlocul ecranului, veti observa ca dreptunghiul verde va avea dimensiunile relative rezolutiei ecranului, try it out. evident, se poate folosi aceasta variabila si in pozitionarea *elementelor* dx
  10. genereaza un float intre lower si greater function randomFloat(lower, greater) return lower+math.random()*(greater-lower) end returneaza offset ul unui element in object space function getPositionFromElementOffset(element, offX, offY, offZ) local m = getElementMatrix(element) local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1] local y = offX * m[1][2] + offY * m[2][2] + offZ * m[3][2] + m[4][2] local z = offX * m[1][3] + offY * m[2][3] + offZ * m[3][3] + m[4][3] return x, y, z end self-made: returneaza secundele+ms gametime-ului local secondChange = 0 local secondStart = getTickCount() function convertTimeToSeconds() local hour, minute = getTime() if minute ~= secondChange then secondChange = minute secondStart = getTickCount() end return hour*60+minute+((getTickCount()-secondStart)/getMinuteDuration()) end sterge value dintr-un table function removeValueFromTable(table, value) if type(table) == "table" then for k,v in ipairs(table) then if v == value then table.remove(table, k) return true end end end return false end limiteaza value intr-un interval function clamp(value, min, max) return math.max(min, math.min(value, max)) end returneaza offset-ul unui punct bazat pe rotatie si distanta 2D function getPointFromDistanceRotation(x, y, dist, angle) return x+math.cos(math.rad(90-angle))*dist, y+math.sin(math.rad(90-angle))*dist end self-made: genereaza un cubic bezier curve in 3D -- x, y, z - start -- x2, y2, z2 - end -- bx, by, bz - start handle -- b2x, b2y, b2z - end handle -- t - time float function cubicBezier3D(x, y, z, x2, y2, z2, bx, by, bz, b2x, b2y, b2z, t) local p1 = {lerp(x, bx, t), lerp(y, by, t), lerp(z, bz, t)} local p2 = {lerp(bx, b2x, t), lerp(by, b2y, t), lerp(bz, b2z, t)} local p3 = {lerp(b2x, x2, t), lerp(b2y, y2, t), lerp(b2z, z2, t)} local l1 = {lerp(p1[1], p2[1], t), lerp(p1[2], p2[2], t), lerp(p1[3], p2[3], t)} local l2 = {lerp(p2[1], p3[1], t), lerp(p2[2], p3[2], t), lerp(p2[3], p3[3], t)} return lerp(l1[1], l2[1], t), lerp(l1[2], l2[2], t), lerp(l1[3], l2[3], t) end function lerp(a, b, c) return a + (b - a) * c end
  11. Oh, now I realised that i didn't wrote the title correctly ? my bad. Anyway, I want the dxDrawLine3D to be visible through objects, for example: Point A at Caligulas Casino and point B at Grove Street, without dissapearing.
  12. The question is in the title, is it possible? And how?
  13. Learned a lot from your code, I didn't know how to deal with the "onClientRender" and "onClientColshapeHit" events, so I though tables were a good idea for solving this . Thanks!
  14. Hi there! I was working on a custom grenade and got stuck into this issue: addEventHandler("onClientProjectileCreation", root, function(creator) if getProjectileType(source) == 17 then setTimer(markerfunc, 2000, 1, source) end end) ms = 0 mst = 0.5 function markerfunc(elem) local x,y,z = getElementPosition(elem) setElementPosition(elem, 0,0,0) m = createMarker(x,y,z,"cylinder",1,0,255,0,255) col = createColSphere(x,y,z,mst*12) addEventHandler("onClientRender", root, markersize) addEventHandler("onClientColShapeHit", col, colhit) setTimer(function() removeEventHandler("onClientColShapeHit", col, colhit) removeEventHandler("onClientRender", root, markersize) destroyElement(m) destroyElement(col) ms = 0 end, 500, 1) end function markersize() ms = ms + mst setMarkerSize(m, ms) local mx,my,mz = getElementPosition(m) setElementPosition(m, mx, my, mz-mst/1.3) end function colhit(thePlayer, matchingDimension) if getElementType ( thePlayer ) == "player" then outputChatBox(tostring(getPlayerName(thePlayer))) end end - "So.. What's the problem?" you may ask. Well, the problem is when 2 players throw a teargas simultaneously, one of the markers does not dissapear, and a debug error appears that something's wrong with the lines 18 - 21. Maybe a table is needed..? Someone?
  15. Getting a vehicle health when using setCameraTarget on a different player I meant, not from localPlayer. Nevermind, solved
  16. Hi there! I'm working at the race resource and I was wondering if I can get the spectator target's health and nitro and other elements data (like.. I'm spectating a player and I want to know how much nitro he has left). Is it possible? And how?
  17. Sorry for the late response, but before making this topic I edited something in the LUA code and I didn't noticed it was wrong edited. However, this is the part that really kills me and I still didn't figured out how to fix it: if getElementData(source, "zp_Class") == "Zombie" and #table_allZombiesAlive == 1 then outputChatBox("true", root) end When the player is infected by a zombie, (using onPlayerDamage) I use again updateTeamTables() to update the tables, but as it mentioned before, it doesn't update correctly so after the zombie is killed nothing happens, but after the round start and the zombie choosed infects another player, triggers the outputChatBox function.s. Edit: Maybe the updateTeamTables() isn't necessary, but I don't know an alternative to that. Someone?
  18. Did it with a tester Before round start (or resource start): 0 humans alive , 0 zombies alive After round start (choosing random zombie): 2 humans alive, 0 zombies alive After zombie killed (onPlayerWasted): 1 human alive, 1 zombie alive
  19. Hi there. Recently I have this issue with this part of the code, I'm trying to trigger something with onPlayerWasted, but it looks like the updateTeamTables() is not updated as it should be. To be more explicit, if there's only one zombie in the team, it should trigger the outputChatBox function, but that doesn't happen. Can someone help? Thanks. function updateTeamTables() table_allHumans = {} table_allHumansAlive = {} table_allZombies = {} table_allZombiesAlive = {} for k,v in ipairs(getElementsByType("player")) do if isPlayerInTeam(v, team_Humans) then table.insert(table_allHumans, v) if getElementData(v, "State") == "Alive" then table.insert(table_allHumansAlive, v) end elseif isPlayerInTeam(v, team_Zombies) then table.insert(table_allZombies, v) if getElementData(v, "State") == "Alive" then table.insert(table_allZombiesAlive, v) end end end end addEventHandler("onPlayerWasted", root, function(ammo, attacker, weapon, bodypart) updateTeamTables() for k,v in ipairs(getElementsByType("player")) do if getElementData(v, "zp_Class") == "Spectator" then setspectator(v) end end if getElementData(source, "zp_Class") == "Zombie" then if attacker ~= nil and isElement(attacker) then setspectator(source) local scr = getElementData(attacker, "Score") setElementData(attacker, "Score", tonumber(getElementData(attacker, "Score")+2)) end end local dths = getElementData(source, "Deaths") setElementData(source, "Deaths", tonumber(dths + 1)) setElementData(source, "State", "Dead") setElementData(source, "zp_Class", "None (Dead)") local allHumans = getPlayersInTeam(team_Humans) local allZombies = getPlayersInTeam(team_Zombies) elseif getElementData(source, "zp_Class") == "Zombie" and #table_allZombiesAlive == 1 then outputChatBox("true", root) end end)
  20. Oh I didn't know about this function .Thank you!
  21. Is there a way to check if the player has the chatbox opened? I'm using onClientKey for choosing things and I want to cancel it if the player pressed 'T' for chatbox.
×
×
  • Create New...