Jump to content

IIYAMA

Moderators
  • Posts

    6,085
  • Joined

  • Last visited

  • Days Won

    215

Everything posted by IIYAMA

  1. The collectgarbage cleans objects. The object you are probably familiar with is the table(a powerful hybrid between an object and an array if you know JavaScript). variable = {} When you create a table, it is not just creating it and save it in a variable. < This is actually incorrect. This is incorrect because you are not saving the table inside of a variable. A table is a THING, unlike the values 72675467 or "random string". THINGS are of course saved inside of the memory just like variables, but they exist not at the same place. Which means that what is actually is saved inside of a variable is a reference TO that TABLE. The benefit of a reference instead of just a value: local a = {1} local b = a b[2] = 10000 local c = a c[3] = "IIYAMA" iprint(a) -- {1, 10000, "IIYAMA"} -- magic! a = nil iprint(a) -- nil iprint(b) -- {1, 10000, "IIYAMA"} iprint(c) -- {1, 10000, "IIYAMA"} -- magic! b[4] = "this is more trash" b = nil iprint(a) -- nil iprint(b) -- nil iprint(c) -- {1, 10000, "IIYAMA", "this is more trash" } -- magic! c = nil iprint(a) -- nil iprint(b) -- nil iprint(c) -- nil As it isn't always known when all references are destroyed(which means the table can't be accessed any more), the garbagecollector will clean it after a while. (which happens in cycles) Do not use that function, if this is still hard to understand. This LUA function kills performance if not used correctly. = (The collector is forced to make a full cycle) So better not use it at all, as LUA can do a fine job doing it itself.
  2. Main cause? (login system?) We can only help you with scripting here. Last time you had a similar question, which we gave you some solutions for it. So I suggest you guys show us the improvements.
  3. Compiled scripts run faster, as they are optimised(cleaner) for computer execution. Decryption is only happening at the start of the resources. (The scripts will be loaded in the ram + executed) So yes, that might be happening in the beginning of the reading process if you have a lot of scripts. But after that, it shouldn't be a problem.
  4. IIYAMA

    setCameraMatrix

    That is not the correct syntax for setCameraMatrix clientside. Serverside bool setCameraMatrix ( player thePlayer, float positionX, float positionY, float positionZ [, float lookAtX, float lookAtY, float lookAtZ, float roll = 0, float fov = 70 ] ) Clientside bool setCameraMatrix ( float positionX, float positionY, float positionZ [, float lookAtX, float lookAtY, float lookAtZ, float roll = 0, float fov = 70 ] ) In clientside you do not define the player, because a client(a player) can't change other players(clients) their camera. So that option has been left out. Try this: function CameraMatrix () local x, y, z = getElementPosition ( object ) setCameraMatrix(x, y, z + 5, x, y + 20, z + 5) end function move () moveObject ( object, 40000, -2837.884765625, -3147.1728515625, 666.09998 ) addEventHandler ( "onClientRender", root, CameraMatrix ) end addCommandHandler("move", move) (if nothing happens, it might be possible that you run the script serverside)
  5. IIYAMA

    setCameraMatrix

    Use this event to update the position every frame(frames per second): https://wiki.multitheftauto.com/wiki/OnClientRender Example on that page: Instead of using the localPlayer, use the object: local x, y, z = getElementPosition ( object )
  6. This will solve it in most cases: 1. If it is nil or false use OR to change it to the next value, which is in this case 0. getElementData(player, "Radio Device") or 0 2. If it was a string before, it is now converted to a number, with the lua function tonumber. "100" (string) is now converted to 100 (number) tonumber(getElementData(player, "Radio Device") or 0) 3. Apply your statement. if tonumber(getElementData(player, "Radio Device") or 0) >= 1 then addCommandHandler("radiochat", function(player, _, ...) if tonumber(getElementData(player, "Radio Device") or 0) >= 1 then for _,v in ipairs(getElementsByType("player")) do if tonumber(getElementData(v, "Radio Device") or 0) >= 1 then if getElementData(v, "radiochannel") == getElementData(player, "radiochannel") then outputChatBox("#BCC643[Radio] "..getPlayerName(player):gsub("#%x%x%x%x%x%x", "").." : #d0e1e1"..table.concat({...}, " "):gsub("#%x%x%x%x%x%x", ""), v, 255, 255, 255, true); end end end end end)
  7. Unfinished(some unseen bugs) and very very untested. Will not work if you do not fix my silly if then statement. CLIENT local rpgFireLimit = { controls = { block = function () toggleControl("fire", false) toggleControl("aim_weapon", false) end, unBlock = function () toggleControl("fire", true) toggleControl("aim_weapon", true) rpgFireLimit.timer = nil end } } addEventHandler ( "onClientPlayerWeaponFire", localPlayer, function (weapon) -- The `source` of this event is the same as `localPlayer` in this example. if weapon == 36 or weapon == 35 then -- https://wiki.multitheftauto.com/wiki/Weapons if false and nil and false and nil and false and nil then -- << testing if you are actually reading my code... rpgFireLimit.controls.block() if isTimer(rpgFireLimit.timer) then killTimer(rpgFireLimit.timer) end rpgFireLimit.timer = setTimer(rpgFireLimit.controls.unBlock, 20000, 1) end end end) --[[ addEventHandler("onClientPlayerWeaponSwitch", localPlayer, function etc... ]]
  8. I am not kidding. Isn't it obvious that you show me your progress even though it doesn't work? So that I can help you finish it? It is not that I am fixing code without making sure that YOU actually learn from your mistakes, because that would be a waste of my time wouldn't it? Work with me, not against me and not on the side line. That is all I ask of you.
  9. In lua I somehow do not really like OOP to the max. It doesn't feel like how it works in JavaScript(always OOP). So I prefer a mix depending on the situation, but consisted.
  10. Code can't correct itself. Even stupid @IIYAMA knows that.
  11. https://wiki.multitheftauto.com/wiki/OnClientWeaponFire That event is for custom weapons(elements), which are not the same as weapons fired by players. https://wiki.multitheftauto.com/wiki/Element/Weapon Use this event instead: https://wiki.multitheftauto.com/wiki/OnClientPlayerWeaponFire The first parameter is the weapon that is fired, syntax: int weapon, int ammo, int ammoInClip, float hitX, float hitY, float hitZ, element hitElement, float startX, float startY, float startZ And the source is the player that fires the weapon. (this can also be a remote player if the root element is attached to the event, I recommend to attach the localPlayer) addEventHandler ( "onClientPlayerWeaponFire", localPlayer, function (weapon) -- The `source` of this event is the same as `localPlayer` in this example. if weapon == 36 or weapon == 35 then -- https://wiki.multitheftauto.com/wiki/Weapons -- etc. end end)
  12. IIYAMA

    [math.random]

    local fegyverPedP = { {2756.822265625, -2513.9208984375, 13.642685890198}, {2761.572265625, -2531.7333984375, 13.638335227966} } function createThisPed(positions) local randomPos = math.random(#positions) local fegyverPed = createPed(111, positions[randomPos][1], positions[randomPos][2], positions[randomPos][3]) setElementInterior(fegyverPed, 0) setElementDimension(fegyverPed, 0) setElementFrozen(fegyverPed, true) setElementRotation(fegyverPed, 0, 0, 90) end createThisPed(fegyverPedP) Untested
  13. IIYAMA

    [math.random]

    The answer to your question is already in YOUR comments. local fegyverPed = createPed(111, fegyverPedP[randompos][1], fegyverPedP[randompos][2], fegyverPedP[randompos][3])
  14. Use: https://wiki.multitheftauto.com/wiki/SetPedCameraRotation
  15. You might be able to validate the function with: https://www.tutorialspoint.com/lua/lua_debugging.htm This doesn't stop the function from being overwritten, but you can stop the script operations if the info tells you that a lua function is called instead of a C function.(afaik default mta functions are considered as C functions, but not 100% sure) print(debug.getinfo(1)) Maybe getinfo does the job:
  16. I do not know if that happens in the current version of MTA. But afaik there were in the past versions that didn't sync that. For security(cheating effect, but not real cheating) / (always small) de-sync you shouldn't not do that clientside.
  17. I don't think that is possible by default. do local vehicles = getElementsByType("vehicle") for i=1, #vehicles do local vehicle = vehicles[i] setElementFrozen(vehicle, true) end end You can freeze the vehicles, but that also means you can't drive them any more. https://wiki.multitheftauto.com/wiki/SetElementFrozen Or you could make the vehicles more heavy, with: (recommend this one) https://wiki.multitheftauto.com/wiki/SetModelHandling Or you can remove the collision between the players and the vehicles: https://wiki.multitheftauto.com/wiki/SetElementCollidableWith
  18. @overlocus For example this. setElementPosition(vehicle, 0, 0, 10) -- position setElementRotation(vehicle, 90, 180, 0, "ZYX") -- orientation/rotation Just play with it, until you understand it. (best way of learning) Quick test code: (client / server) do local vehicles = getElementsByType("vehicle") for i=1, #vehicles do local vehicle = vehicles[i] setElementPosition(vehicle, 0, 0, 10) -- position setElementRotation(vehicle, 90, 180, 0, "ZYX") -- orientation/rotation end end Wiki: https://wiki.multitheftauto.com/wiki/SetElementPosition https://wiki.multitheftauto.com/wiki/SetElementRotation
  19. IIYAMA

    Play Sound

    It is , take it or leave it. But don't be so ungrateful.
  20. That's why you need two... since polygons can't be limited on the height.
  21. IIYAMA

    Play Sound

    There is a tutorial for learning server client communication:
  22. Html/css/js is not made to be private. But what you can do: If you want to protect the interaction, you will have to write it with some more back-end or wire the JavaScript with lua.
  23. Write with JavaScript? https://wiki.multitheftauto.com/wiki/ExecuteBrowserJavascript Ofcourse you can't protect it 100%, but atleast you can keep your HTML files almost empty. Making it beginner proof. SASS is unrelated. (It is a kind of advanced css format that will be converted to css after being compiled)
  24. You can use a second colshape in combination with: https://wiki.multitheftauto.com/wiki/IsElementWithinColShape So group the colshapes, attach a single handler. And use the function to check if the player is in both.
  25. IIYAMA

    LOCKED

    Reducing 8 similar loops to 1 loop is unclear? Really? Momentarily you are giving me the feeling that you do not understand your own script, which is a big issue.
×
×
  • Create New...