-
Posts
6,097 -
Joined
-
Last visited
-
Days Won
218
Everything posted by IIYAMA
-
Adjust the handler timing: https://wiki.multitheftauto.com/wiki/AddEventHandler OR (if not working) Pick a different processing moment: https://wiki.multitheftauto.com/wiki/Game_Processing_Order https://wiki.multitheftauto.com/wiki/OnClientPreRender https://wiki.multitheftauto.com/wiki/OnClientHUDRender https://wiki.multitheftauto.com/wiki/OnClientRender
-
The /\ availableMissions /\ variable is from your previous code make sure you check and clean that for yourself too. call ( getResourceFromName (resourceName), resourceConnections[resourceName].communicator, "getCommunicationFunctions", 'function reConnect() call( getResourceFromName ("missionManager"), "reConnect") end') If the problem from above doesn't solve the this problem: Make sure to debug everything: iprint(getResourceFromName ("missionManager")) Can it find the resource? <script src="connect.lua" type="server"/> Is the export line applied to the target resource? This will not work because of the problem from above. @Dzsozi (h03)
-
Small fix, line 7: (forgot to pass the text through the reConnected function (in the string). call ( getResourceFromName (resourceName), availableMissions[resourceName].communicator, "getCommunicationFunctions", 'function reConnect(...) call( getResourceFromName ("missionManager"), "reConnect", ...) end') "" = string (woman) '' = string (man) Nah, they are the same. There are two types in case you want to use string characters inside of the string. So: "''" -- the string contains these characters: '' '""' -- the string contains these characters: "" In the code I posted, I didn't past a function through it. BUT I past un-executed code (as text) from RESOURCE A to RESOURCE B. This is what loadstring does: a = 1 local functionForLoadedCode = loadstring("a = a + 1") -- load the string before execute it. And return a function which will run the code. functionForLoadedCode() -- The code has been executed! print(a) -- 2 functionForLoadedCode() -- The code has been executed! print(a) -- 3 for i=1, 1000 do functionForLoadedCode() -- The code has been executed! X 1000! Woohoo! end print(a) -- 1003 https://www.lua.org/pil/8.html Don't know, might be caused by the timing.(as resources can't be called before they are loaded) Better use the "onResourceStart" event before the calling. And don't forget to make the function call able within the meta.xml. @Dzsozi (h03)
-
Your current problem is that you can't manipulate the same table in two different resources, right? ------------------------------- | ------------------------------- | Environment 1 | Environment 2 | ------------------------------- | ------------------------------- This is indeed a very annoying problem. But lets get back to the possibilities we have. <export /> This exports functions from this resource, so other resources can use them with call function: The function name type Whether function is exported server-side or client-side (valid values are: "client", "server" and "shared") http: Can the function be called via HTTP (true/false) https://wiki.multitheftauto.com/wiki/Meta.xml UNTESTED Example below is untested, but it will probably do something similar to what you want. Write a good wiring example. availableMissions = {} function startMission(resourceName, ...) if resourceName and availableMissions[resourceName] then if availableMissions[resourceName].communicator then call ( getResourceFromName (resourceName), availableMissions[resourceName].communicator, ...) end end end function addMission (missionData) local resourceName = getResourceName(sourceResource) -- https://forum.multitheftauto.com/topic/33407-list-of-predefined-variables/ -- https://wiki.multitheftauto.com/wiki/Call availableMissions[resourceName] = missionData --availableMissions[missionData.resourceName] = missionData end local mission = {} function communicator (functionName, ...) mission[functionName](...) end mission.startFunction = function(text) outputChatBox(text) end call ( getResourceFromName ("missionManager"), "addMission", {communicator = "communicator", resourceName = "example"} ) call ( getResourceFromName ("missionManager"), "startMission", "startFunction", "Hi!" ) UNTESTED You can also build an example which can be dynamic upgrade-able. local resourceConnections = {} function connect (resourceData) local resourceName = getResourceName(sourceResource) resourceConnections[resourceName] = resourceData if resourceData.communicationFunctions then call ( getResourceFromName (resourceName), availableMissions[resourceName].communicator, "getCommunicationFunctions", 'function reConnect() call( getResourceFromName ("missionManager"), "reConnect") end') end return true end function reConnect (text) outputChatBox(text) -- ... end local resourceFunctions = {} function communicator (functionName, ...) resourceFunctions[functionName](...) end function resourceFunctions.getCommunicationFunctions (communicationFunctions) loadstring(communicationFunctions)() end local connected = call( getResourceFromName ("missionManager"), "connect", {communicator = "communicator", communicationFunctions = true}) iprint(connected) reConnect("hmm does this work???") Damn it is brain fu... while writing this example without any testing.
-
In case of a local-server. JavaScript + browser might do the trick as well: https://wiki.multitheftauto.com/wiki/ExecuteBrowserJavascript https://stackoverflow.com/questions/189430/detect-the-internet-connection-is-offline if (navigator.onLine == true) { console.log("This might work"); } (no guarantees for this browser) https://wiki.multitheftauto.com/wiki/Resource_Web_Access !important
-
local playerTable = {} local player = playerTable[math.random(#playerTable)] https://stackoverflow.com/questions/2988246/choose-a-random-item-from-a-table As extend of N3xT his comment.
-
Just to be clear: Offset position = a world position (which is calculated by an offset value) Offset = a distance value (not a position) To calculate offset from two positions: Position:1 [435, 6577, 3457] position:2 [325, 7657, 5686] (Position:1 [435, 6577, 3457]) - (position:2 [325, 7657, 5686]) = offset:1 (position:2 [325, 7657, 5686]) - (Position:1 [435, 6577, 3457]) = offset:2 The main issue is of course if getElementPosition doesn't work on attached elements.(which I would consider as a MTA bug, but afaik they fixed this...) < If this function doesn't work correctly and the rotation in attachElements is used, it will be indeed a bit complex and getPositionFromElementOffset will not be helpful.
-
With the matrix of course: (the offset can be received with the function in @MrTasty his replied) function getPositionFromElementOffset(element,offX,offY,offZ) local m = getElementMatrix ( element ) -- Get the matrix local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1] -- Apply transform 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 -- Return the transformed point end https://wiki.multitheftauto.com/wiki/GetElementMatrix or https://wiki.multitheftauto.com/wiki/Matrix
-
My purpose here is teaching and not free scripting. Please help yourself: https://wiki.multitheftauto.com/wiki/GuiCreateButton https://wiki.multitheftauto.com/wiki/AddEventHandler
-
addEventHandler("onClientGUIClick", GUIEditor.button[15], fly, false) The table reference inside of the variable GUIEditor.button[15] doesn't contain the reference of a button[element]. With other words, the there is no button (yet) created when the line 12 is executed. This might solve the problem, if the issue is caused by a wrong code execution order: addEventHandler("onClientResourceStart", resourceRoot, function () addEventHandler("onClientGUIClick", GUIEditor.button[15], fly, false) end, true, "low") If the button doesn't exist, this code will not solve your problem.
-
Where is your dxDrawText function in your code?
-
The IIYAMA rule: Scale EVERYTHING only over the Y as. Except for the X position. We are very lucky that they hardly design monitors with a portrait orientation... else it would have blown off my mind. This could be one of your issues, an absolute value: dxDrawRectangle(s*0.008,y*0.957, length + 55,y*0.030, tocolor ( 0, 266, 0, 250 ) ) dxDrawRectangle(s*0.008,y*0.957,length + resY(55),y*0.030, tocolor ( 0, 266, 0, 250 ) )
-
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.
-
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.
-
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.
-
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)
-
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 )
-
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)
-
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... ]]
-
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.
-
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.
-
Code can't correct itself. Even stupid @IIYAMA knows that.
-
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)
-
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
-
The answer to your question is already in YOUR comments. local fegyverPed = createPed(111, fegyverPedP[randompos][1], fegyverPedP[randompos][2], fegyverPedP[randompos][3])
