-
Posts
6,089 -
Joined
-
Last visited
-
Days Won
216
Everything posted by IIYAMA
-
getElementsByType("gui-staticimage", resourceRoot) Maybe you get other resource elements as well?
-
@Xwad Master this loop and all possibility will open up to you. local theTable = {[0] = 0, 1,2,3,4,5,6,7} local index = 1 for i=0, #theTable, 2 do print("position: ", index * 10) index = index + 1 print("index: ", theTable[i]) print("index: ", theTable[i + 1]) print("---") end
-
Instead of true save the gui element you entered. Then you can compare it to the destroyed element later.
-
Yes, tables (and functions) are not saved in the variables. They are objects/things that are saved at a different place in the memory. (Not that far, they are neighbours...) The only thing that is saved in those variables are a kind of references to the thing itself. Because it is not saved in to those variables directly, we are able to do this: a = {} b = a a[1] = "I love it" print(b[1]) -- I love it This should really make clear that a table is not just a value, but a thing that can pretend that it exist at multiple places at the same time. `a` and `b` share the same reference to the same table. When both reference are delete, the table becomes unreachable* and the garbage collector will automatically deal with it: http://lua-users.org/wiki/GarbageCollectionTutorial
-
Not sure, Doesn't blob help you out? But it shouldn't be an issue. At the end they both represents NO in most lua conditions. This method is in most scenarios just asking for trouble: if a == nil then This one works just 99% of the time: if not a then
-
A (local) table would probably not faster than a global variable. Because instead of doing 1 thing, you are actually doing 2 things. Requesting the local variable. Indexing in the table with a string. That is also the reason why OOP is not very fast. But as I said many times before, read-ability is also performance. If you want performance then please consider to only apply it selective at places in the code which are used a lot. (by for example a loop or onClientRender) If we look for example at the function callNextFrame: (shared: client/server) It is very well optimised. But not 100%. What would you want to improve of this code to optimise it to a 100%? local tableRemove = table.remove local serverSide = triggerClientEvent and true or false --[[ -- callNextFrame function ]] do local nextFrameCalls = {} local serverSideTimer local processing = false local function process () --[[ Do an empty check at the beginning of the function, this will make sure to make an extra run in case of heavy work load. If the timer is killed or the addEventHandler is removed, then this has to be re-attached again every frame. This is not very healthy... ]] if #nextFrameCalls == 0 then if serverSide then if serverSideTimer then if isTimer(serverSideTimer) then killTimer(serverSideTimer) end serverSideTimer = nil end else removeEventHandler("onClientRender", root, process) end processing = false return end -- In case of calling the function callNextFrame within the process, the loop type `repeat until` is required. repeat local item = nextFrameCalls[1] item.callback(unpack(item.content)) tableRemove(nextFrameCalls, 1) until #nextFrameCalls == 0 end function callNextFrame (callback, ...) if type(callback) == "function" then local newIndex = #nextFrameCalls + 1 nextFrameCalls[newIndex] = {callback = callback, content = {...}} if not processing then if serverSide then serverSideTimer = setTimer(process, 50, 0) else addEventHandler("onClientRender", root, process) end processing = true end return true end return false end end This code does: Moving a function call to the next possible frame. Example: callNextFrame(outputChatBox, "Hey next frame, I love you!")
-
Best practice to synchronize server/client caches
IIYAMA replied to Sorata_Kanda's topic in Scripting
1. Yea, this will also prioritise the request over the network. 2. The entity you will be using to update the main data is a table. MTA objects/elements are secondary. Ofcourse this doesn't mean you can't use an object to fake the updates before they are actually applied. (Data reduction) 3. A boolean or a custom function in between. The default MTA functions do not have such a feature without creating errors. -
If something doesn't exist anymore, then there is nothing to leave from. In fact it will only cause more problems for the onClientMouseLeave event. An event can't just trigger without it's source.
-
A file counts also as a function.
-
No your can't use that function as it blocked. This is more or less how a require_once module works. So you can also make your own. (NOTE: it is not exactly the same as require, just the logic of it) Untested, if it works or not is irrelevant for now. modules = {["module1"] = {loaded = false}} function requireThis (name) local thisModule = modules[name] if thisModule then if thisModule.loaded then return thisModule.container else local fileName = name .. ".lua" if fileExists ( fileName ) then local theFile = fileOpen(fileName, true) if theFile then local count = fileGetSize(theFile) local data = fileRead(theFile, count) thisModule.container = loadstring(data)() thisModule.loaded = true end fileClose(theFile) return true end end end return false end requireThis("module1") File: module1.lua local thisModule = { collection = {} } function thisModule:add (...) local data = {...} if data[1] then local collection = self.collection collection[#collection + 1] = data return true end return false end return thisModule
-
Best practice to synchronize server/client caches
IIYAMA replied to Sorata_Kanda's topic in Scripting
Server should be in control at all times. So yes caches on serverside to reduce impact on the database. But keep in mind that if a query fails, it is important that the data is reset. In case of more users are editing the same data. > No caches recommended on clientside. (until the instructions from clientside are perfect) While there are changes made, it is recommended that the client his GUI is disabled until the server is finished. Else the data might not be mirrored correctly, that being said it is not impossible. You can use caches clientside, but it is important that the identifiers remain unique at all cost. The server is in control of the identifiers. Else there is a VERY HIGH risk of data corruption. Clientside should only send retrace able instructions of the modifications and not the modified data. Else there is a risk of VERSION corruption. Instructions also allows you to mirror without freezing the GUI. Each instruction should be validated on both serverside as well as clientside. In case of a failed data-update/query clientside should be restored to it's previous data-structure. It is VERY important to block new instructions and freeze the GUI until both sides are mirrored again. It is not that easy after all And use or build a tool like this: https://gitlab.com/IIYAMA12/mta-communication-enchantment/tree/master/ -
nvm that is probably not going to work.
-
local posX, posY, posZ = getElementPosition(hitElement) local offsetX, offsetY, offsetZ = getOffsetFromXYZ(getElementMatrix(hitElement), posX - hitX, posY - hitY, posZ - hitZ) The matrix is already containing the position of the vehicle. Untested and not even sure if this is the right approach. @Xwad P.s this function can return the surface position:https://wiki.multitheftauto.com/wiki/ProcessLineOfSight normalX, normalY, normalZ
-
Command with space characters!!! Help with team names!
IIYAMA replied to Razor70538's topic in Scripting
function functionName (player, cmd, ...) local name = table.concat({...}, " ") end @Razor70538 -
@Overkillz dxSetRenderTarget( myRenderTarget, true ) Syntax: bool dxSetRenderTarget ( [ element renderTarget, bool clear = false ] ) The stuff you have drawn before on the paper, will not just clear itself. A render target is like a piece of paper of the REAL WORLD. Once you have drawn on it, you need an eraser to clean it. There are two things you can do. Clear the render target Or paint it black again with a rectangle. If it is just text on it, clearing the render target will do the job. But if you have multiple components on it, which you do not want to re-draw very frame on the render-target, then it might be handy to paint selected area's black. See also blend mode: overwrite : The source textures are overwritten. This can be useful for clearing render targets https://wiki.multitheftauto.com/wiki/DxSetBlendMode (Haven't used it before.) Also keep in minder that you can also use two render targets. One you can update when the text changes and one to move the frame.
- 1 reply
-
- 1
-
-
Or you can use this function: https://wiki.multitheftauto.com/wiki/IsElementVisibleTo Within the donegobeach function. It is a little bit dirty, but it should do it's job.
-
Ah yea true, my bad. But afaik that doesn't work for new joined players. Experimental. local normaliseVisibility = createElement("normaliseVisibility") addEventHandler("onPlayerJoin", root, function () setElementVisibleTo(normaliseVisibility, source, false) end) markergobeach = createMarker ( 2945.4387207031, -2053.7338867188, 2.8984375, "cylinder", 2, 255, 0, 0, 50, thePlayer ) BlipDiver = createBlipAttachedTo ( markergobeach , 41, 2, 255, 0, 0, 255, 0, 99999.0, thePlayer ) setElementParent(markergobeach, normaliseVisibility) setElementParent(BlipDiver, normaliseVisibility)
-
version 1.6 How to use a function that only exists in the future?
IIYAMA replied to Lord Henry's topic in Scripting
I am the one that requested this function. They moved it to 1.6 after my request. It was finished and added to 1.6 within a few days. @IIYAMA still wondering why, when it could have been easily added to 1.5.6. -
@GodKraken Because there is nothing in the code that sets the marker and blip only available for a specific person. With the function setElementVisibleTo you can make specific elements visible/invisible for some players. https://wiki.multitheftauto.com/wiki/SetElementVisibleTo Or you can create the marker and blip clientside. (Marker created on the CLIENT/PLAYER computer) But you will need to learn to communicate between serverside and clientside. Learn the MTA way: Or a tool you can use to make this easier: https://gitlab.com/IIYAMA12/mta-communication-enchantment Examples Syntax Set-up
-
Good. No visible issues here except for some missing resource information, which are not required to run code. Now please debug your code Use this tutorial:
-
How can you start this without a meta.xml?
-
show all files.
-
Yea you can't, OBVIOUS!!!!!, because that is goal of your first iteration of YOUR code. \/
-
@ArcAngeL Changed root to localPlayer. addEventHandler ( "onClientPlayerDamage", localPlayer, function( attacker, weapon, bodypart ) And attacker exist + attacker isn't the same as the localPlayer. if attacker and attacker ~= localPlayer and getElementType(attacker) == "player" then
-
Probably a resource with commands that is attached to a database. A way to counter this, be picky: And download only resources that look a bit more professional. But where is the fun in that? ? Highly secret + being honest here: @IIYAMA ? That is something similar to what those guys did to your server. But your server was the victim, instead of the ?.
- 1 reply
-
- 2
-
-
