-
Posts
1,060 -
Joined
-
Last visited
-
Days Won
9
Everything posted by Addlibs
-
If you want someone to "give" you a script, you're in the wrong place. This section is for getting help in scripting. Please read the rules.
-
This is a very easy script, you really shouldn't have any issues writing this yourself. Seriously? You ask him to give you a script every time? How about you read the rules of this forum section? We're not here to give scripts, but to give advice and help resolving issues which you come across. function tpCommand(plr, cmd, target) local trgt = Player.getFromName(target) if not isElement(trgt) then -- if target player was NOT found from the name plr:outputChat("No player named "..target.." found.") return end local acc = plr.account if acc.guest or (not ACLGroup.get("Admin"):doesContainObject("user."..acc.name)) then -- if its a guest account or doesn't exist in Admin acl group plr:outputChat("You do not have permission to use this command.") return -- abort the function here end plr.position = trgt.position -- set your position to their position plr:outputChat("Teleported to "..trgt.name..".") trgt:outputChat("Admin "..plr.name.." has teleported to you.") end addCommandHandler("teleport", tpCommand) This code requires you to set <oop>true</oop> in meta.xml. If you don't want to use OOP, you're gonna have to try to convert this code to non-OOP yourself, as a little learning exercise.
-
It doesn't seem like you've posted the part with line 34, or if you did, please tell us which of the snippet is line 34.
-
I don't believe you can externally access a database through the client via fetchRemote or callRemote unless you put that through a web-server run PHP code or a Lua-parsed server http file (https://wiki.multitheftauto.com/wiki/Resource_Web_Access). An easier option would be to have the server serve the data by accessing and collecting the data directly from the database, and sending it through a event (preferable a latent one, that is, triggerLatentClientEvent) to the client.
-
function wordWrap(text, maxwidth, scale, font, colorcoded) local lines = {} local words = split(text, " ") local line = 1 local word = 1 while (words[word]) do -- while there are still words to read repeat lines[line] = (lines[line] and (lines[line] .. " ") or "") .. words[word] word = word + 1 until ((not words[word]) or dxGetTextWidth(lines[line] .. " " .. words[word], scale, font, colorcoded) >= maxwidth) -- stop if next word doesn't exist to text width would exceed maxwidth if next word was added line = line + 1 end -- jumps back to while(words[word]) return lines end You can use this function similarly to multiLineForText from MTASAPLAYER, or use table.concat(wordWrap(...), "\n") to concatenate the lines into one string separated with newline characters. Note: This function removes consecutive space characters, so four spaces will be shortened to one space due to how split words.
-
You need to add resource.Login to the Admin ACL group in acl.xml ... <group name="Admin"> ... <object name="resource.Login"></object> ... </group> ...
-
The snippet of the code you've sent does not include any setElementData that the error message mentions.
-
Image doesn't work, and you haven't even bothered describing/explaining the issue a bit more, or what your desired outcome is.
-
You're not passing player nor attacker into the function, leading to getElementPositions to fail, returning false, which means you don't have actual XYZ positions to compare distance off - you're plugging a bool (false) into what was supposed to be a number (or Vector3)
-
Line 13 should be local team = getTeamFromName(equipos[math.random(#equipos)][1])
-
addCommandHandler('spoiler', function() local theVeh = getPedOccupiedVehicle(localPlayer) if (theVeh) then -- if theVeh exists local components = getVehicleComponents(theVeh) if components['movspoiler_23.5_1800'] then -- if this component exists in theVeh local x, y, z = getVehicleComponentPosition(theVeh, 'movspoiler_23.5_1800') setVehicleComponentPosition(theVeh, 'movspoiler_23.5_1800', x+1, y+1, z+1) --outputChatBox(k) end end end )
-
I'd like to point out that MTA didn't invent Lua. Lua is its own independent language used for a plethora of applications, including MTA. It seems to be that the only thing you're complaining about is that the MTA API is outputting errors into the console to let you know that you write bad code, and you're getting mad at MTA and Lua for it. It's your own fault. I can imagine you dereferencing a null pointer and complaining that you get a memory access violation but you willfully refuse to check whether the pointer is null before attempt to dereference because "it's not my fault the language is bad wah wah," or complaining that math is broken because you can't divide by 0. If you don't like it, you should just go back to PAWN and the only software that uses it - SAMP.
-
But you just said you're getting errors. That means it doesn't work "perfectly". When an API error returns an error, it does not stop the execution of the code, it simply fails. That call fails, it does nothing, and the code continues on. This does not mean it works perfectly. It continues - not perfectly, but at least it works.
-
If you think this is a problem of this scripting language or the API, I honestly don't know how you want to have any success in writing code. Literally any weak-typed language will give you these runtime errors when you try to add an integer to a boolean, or when you attempt to destroyElement a false/nil. The error message LITERALLY tells you the problems. You're attempting to perform arithmetic (addition, subtraction, etc) on a BOOLEAN, most likely a false value (that's what getElementData returns when there is not data set) local countCheckpoint = getElementData(player, "countCheckpoitBusRoad") -- you could also add "or 0" afterwards to make it default to a 0 when it's false/nil if (countCheckpoint) then countCheckpoint = countCheckpoint + 1 -- attempt arithmetic ONLY WHEN YOU KNOW IT'S NOT false/nil to avoid errors end You're attempting to use destroyElement to destroy a BOOLEAN, most likely a false value (that's what getElementData returns when there is no data set). The function name even tells you that the function's purpose is to destroy an ELEMENT, not a BOOLEAN. local elem = getElementData(player, "elementCheckpointBus") if (isElement(elem)) then destroyElement(elem) -- attempt to destroy it ONLY IF YOU KNOW IT'S AN ELEMENT to avoid errors end
-
Lua patterns are not the same thing as regular expressions. Firstly, Lua patterns don't have quantifiers {n} I believe, so you have to expand the pattern: ^(\\d{3})(\\d{3})(\\d{3})(\\d{2}) into ^(\\d\\d\\d)(\\d\\d\\d)(\\d\\d\\d)(\\d\\d) Secondly, Lua patterns use different notation (%d rather than \d): ^(%d%d%d)(%d%d%d)(%d%d%d)(%d%d) and to use the captures you also use % rather than $ local cpf = string.format("%011d", 09551130401) -- format the number into an 11 digit number (makes sure the leading zeros are there) print(string.gsub(cpf, '^(%d%d%d)(%d%d%d)(%d%d%d)(%d%d)', '%1.%2.%3.%4')) -- "095.511.304.01" print(cpf) -- "09551130401" Read more about Lua patterns on the Lua manual and lua-users.org
-
As far as I'm aware, you need to add a trailing slash after the resource name to prevent it from redirecting to resource browser. E.g. http://serverip:port/runcode will redirect to http://serverip:port/resourcebrowser/, but http://serverip:port/runcode/ won't redirect. All client-downloadable files from meta.xml are cached into the resource-cache/http-client-files on the server which are accessible through http://serverip:port/resourcename/filename.ext but only those which were added in the meta.xml and thus consequently copied to http-client-files by the server. Files not in meta.xml or those which cache="false" option cannot be downloaded through a web browser nor through fetchRemote as they are not located in the http-client-files directory.
-
Race gamemode is a resource called "race" - load it instead of "play" and remove "freeroam" as well.
-
mtaserver.conf has all those options.
-
You can do that using a Shader, and a Render Target along with getSoundFFTData and dxDraw* (see Visualiser)
-
If you want the image to be truly 3D, you can either use a Shader or dxDrawMaterialLine3D/dxDrawImage3D (the latter is useful function that you need to embed into your code yourself) or, if you simply want a 2D image placed on the screen covering or above where the object appears to be on screen, you'd use getScreenFromWorldPosition and dxDrawImage.
-
function removePlayerMedkits(player) for _,plrs in ipairs(getElementsByType("player")) do if ( getElementDimension (plrs) == 336 ) then removeCommandHandler("usemedkit") removeCommandHandler("acceptmedkit") removeEventHandler("meds.giveMedKit", root, giveMedKit) removeEventHandler("meds.useMedKitOnOther", root, usemedkitanother) end -- [...] end end addCommandHandler("empm", removePlayerMedkits) You do realise that this code, specifically lines 4 and 5, completely remove the handling of the command for ANY player (if server side) or the client (if client side), and lines 6 and 7 remove the handling of events for ANY player (if server side) or the client (if client side), if the last person of the loop is in dimension 336 (as every other iteration is simply overruled by the next). You don't want to remove the handler - you want the handler to determine how the command/event should be handled - whether you want it to do anything or to ignore the command/event in case the source player or the target player is in the wrong dimension. Note: the following is written assuming this is server-side Use the handler to determine whether to do anything or to ignore the command: function usethemedkit(sourcePlayer, command, ...) -- /usemedkit if getElementDimension(sourcePlayer) == 336 then return false -- abort function here, player is in wrong dimension end -- [...] continue doing whatever this function was meant to do end function healOthers(sourcePlayer, command, ...) -- /acceptmedkit if getElementDimension(sourcePlayer) == 336 then return false -- abort here, player is in wrong dimension end -- here assumes there's a table pendingMedRequests that stores the user as key and healer as value (e.g. pendingMedRequests[whoToHeal] = healedByWho) local healer = pendingMedRequests[sourcePlayer] if not healer then return false -- no awaiting medkit request to accept end if getElementDimension(healer) == 336 then return false -- abort here, healer is in wrong dimension end -- [...] continue doing whatever this function was meant to do end -- and so on And add these only once and keep them: addCommandHandler("usemedkit", usethemedkit) addCommandHandler("acceptmedkit", healOthers) addEventHandler("meds.giveMedKit", root, giveMedKit) addEventHandler("meds.useMedKitOnOther", root, usemedkitanother)
-
Timer10 = setTimer( function () for _,plrs in ipairs(getElementsByType("player")) do if ( getElementDimension(plrs) == 0 ) then addCommandHandler("usemedkit", usethemedkit) addCommandHandler("acceptmedkit", healOthers) addEventHandler("meds.giveMedKit", root, giveMedKit) addEventHandler("meds.useMedKitOnOther", root, usemedkitanother) end end end, 1000, 0) I don't really understand why would you put these handlers (especially the event handlers attached to root) inside a loop? Just add the handlers once at initialisation. On the server, command and event (attached to root) handlers are bound to all players, even those who join later on, and on the client, well, they're bound when the script starts so pretty much on every client. Also, you really do not have to use a timer for the dimension check, you can have the dimension checked inside the usethemedkit, healOthers, giveMedKit, and usemedkitanother functions.
-
Possible through getEventHandlers. The following is (part) of the example usage from the wiki: function isEventHandlerAdded( sEventName, pElementAttachedTo, func ) if type( sEventName ) == 'string' and isElement( pElementAttachedTo ) and type( func ) == 'function' then local aAttachedFunctions = getEventHandlers( sEventName, pElementAttachedTo ) if type( aAttachedFunctions ) == 'table' and #aAttachedFunctions > 0 then for i, v in ipairs( aAttachedFunctions ) do if v == func then return true end end end end return false end
-
Something like this should work -- on the client triggerServerEvent("addNewZone", localPlayer, zonename, zonecost, x, y, w, d) -- on the server addEvent("addNewZone", true) addEventHandler("addNewZone", root, function(title,cost,x,y,w,d) if client ~= source then return end -- make sure the client sending this event isn't trying to frame someone into it by using a different source element. `client` cannot be faked, `source` can be. local zone = { id = __, name = title, owner = getPlayerName(client), ctrl = __, price = cost, objects = __, radio = __, x = x, y = y, sx = w, sy = d } table.insert(zones, zone) outputChatBox(getPlayerName(client).." added a new zone.", root, 255, 127, 0, true) end )