Jump to content

Addlibs

Members
  • Posts

    1,052
  • Joined

  • Last visited

  • Days Won

    7

Everything posted by Addlibs

  1. The only way this would work is if download priority was set higher for the resource with this code, otherwise this code won't execute until everything downloads and thus voice will be heard until download completes.
  2. addEventHandler("onClientMarkerHit", getJobMarker, hitMarkerWindow) -- should be changed to addEventHandler("onClientMarkerHit", getJobMarker, function(hitPlayer, matchingDimension) if (hitPlayer == localPlayer and matchingDimension) then hitMarkerWindow() end end ) This protects the window from being created when any element hits the marker, instead only triggering if the element that hits the marker is the client that is running this client-side script.
  3. Addlibs

    [HELP]

    You should carefully rethink your code design -- this may work for 1 or 2 car options, but as you add the 3rd, 4th, 5th etc, it gets really complicated unnecessarily. Instead, consider reusing existing code with iterations through a table and extracting parts of the code into their own functions. Here's a much more flexible version of your code, which does not rely on adding numbers to variable names, writing a cascade of if blocks and bind handlers within bind handlers, etc. local models = { 411, 478, 240 -- add as many models here as you want, and the code will work without any other changes } local displayVehicle, index -- declaring variables as local ahead of time allows to get the speed benefits of `local` while having variables accessible thoughout the current script file (not accessible in other scripts of the same resource though) local function updateDisplayVehicle() if (isElement(displayVehicle)) then -- to prevent generating errors when the vehicle doesn't exist destroyElement(displayVehicle) -- delete the existing vehicle if it exists end local vehModel = models[index] -- get the vehicle model corresponding to the current index displayVehicle = createVehicle(vehModel, 2154.45996, -1153.21362, 23.87550) -- spawns a vehicle with the correct vehicle model end local function tryChangeIndex(newIndex) if (models[newIndex]) then -- if the given index is valid (i.e. table `models` contains a value for that index) index = newIndex -- set current index to the given index updateDisplayVehicle() -- and update the currently spawned vehicle end end local function nextVehicle() tryChangeIndex(index + 1) end bindKey("arrow_r", "down", nextVehicle) local function previousVehicle() tryChangeIndex(index - 1) end bindKey("arrow_l", "down", previousVehicle) I've tried to provide comments that should help you understand what I'm doing in the code. I hope this helps.
  4. What nonsense is that? Root is an element sui generis that represents the top of the element tree, that is, all elements descend from it. Most, if not all, functions are recursive down the element tree (except where propagation is disabled), so setVehicleColor(root, ...) would, while returning false (because the function makes no sense on its principal element, root), set the color of every vehicle that descends from it, or in other words, every vehicle in the world. Then there's resource root, from which all elements spawned by one resource descend. These elements can be recalled with getRootElement and getResourceRootElement (and the pre-defined variables root and resourceRoot). You can read more about this on the MTA wiki page for the Element tree. Source is the element on which an event is triggered, an element that is the source of that event. Typically this will be the subject of the event name, for example, in the event onPlayerEnterVehicle, the player is the grammatical subject, and is therefore the source of the event. In an event handler -- that is, the function that is called when the event triggers (registered with addEventHandler) -- MTA defines a local variable called source that references said element. For example, in onPlayerEnterVehicle, the source variable references the player element of the player that entered a vehicle. The vehicle's element will be in the event handler's parameters. To look up what the source of an event is, and the parameters of each event, look up the wiki page for that event.
  5. These errors mean you're attempting to compare incomparable values, for example, a bool with a number. Is true > 1, < 1? It doesn't make sense. getElementData returns a 'false' value when there is no data stored under the given key -- all you have to do is prevent the comparison from happening if the returned value is not a number: local returnedValue = getElementData(someElement, "someKey") -- options: if (returnedValue) then if (returnedValue > 5) then -- valid end end if (returnedValue and returnedValue > 5) then -- valid end -- the following two will also work if the returned value is a string that contains arabic numbers in base-10, e.g. ("1000" (string) => 1000 (number)) if (tonumber(returnedValue) and tonumber(returnedValue) > 5) then -- valid end local returnedValue = tonumber(getElementData(someElement, "someKey")) if (returnedValue and returnedValue > 5) then -- valid end
  6. Please use the Portuguese section if you need help in Portuguese. Por favor utilize a secção portuguesa se precisar de ajuda em português. This post, translated with DeepL: sqlite.db "error loading data I think". <code> theoretically when entering the marker it should display the amount of fuel available in the station but it is displaying ( Could not get the amount of gasoline for the set ) any idea how to make it work correctly
  7. First issue: Lua is parsed and executed from top to bottom; by the time of the setTimer call, timerJail has not been declared or defined. You need to move the setTimer call after the timerJail function definition. Second issue: addEventHandler requires an element to bind onto (2nd argument) -- this means which element (and its children if propagation is enabled, which it is by default) should the event fire for -- and in your code it is an nil-value variable source, hence the error. source is defined within an event handler function, so getElementData(source, "jailLoc") is fine, source is the player that spawned. source outside that function, such as in the arguments passed to addEventHandler, it is undefined/nil. Change this to something like root (this is a pre-defined synonym for the value returned by getRootElement()).
  8. You can use Telegram's Bot API. First, if you haven't already, create a bot (by messaging BotFather on Telegram) and use callRemote or fetchRemote (only do this on the server side, for security reasons -- never send the bot's token to a client) to utilize the API. Bots cannot initiate conversations, but you can prompt users to start a conversation by displaying a URL (or preferably a QR code) that a user can scan and open the conversations. You can also use a parameter in the QR code that would allow the bot to correlate the Telegram user with the MTA player if you need that. You can also create a group chat or a channel and invite the bot into it, and use it to let users read and write to the ingame chat out-of-game.
  9. The commands you listed are incredibly easy to implement yourself (beginner level stuff, may be difficult if you have absolutely not idea what you're doing but once you learn the basics it should be easy), have you even tried? If so, show us your progress/attempts and what your specific issue is. We're not here to script for you.
  10. The callback function for bindKey callback function does not receive a player element. The client-side bindKey's player can only ever be the localPlayer, so you need to change this function signature: function burnoutTheTires(player,key) -- into this function burnoutTheTires(key) and likewise for unpressedTheKeys, function unpressedTheKeys(player) -- into this function unpressedTheKeys() You could have discovered this yourself with a very simply debug methodology: debug outputs. See outputDebugString and iprint, (and less frequently used for this purpose but still usable: outputChatBox, outputConsole). And get rid of the burnoutTimer table, it is unnecessary, since it only ever stores one value, always under the key equivalent to the localPlayer element. Simply declare a local value (tip: local values, aka upvalues are faster in write and read speed over globals which are actually entries in the _G table and table lookups aren't as fast as upvalues) local burnoutTimer --- ... elsewhere in the code burnoutTimer = setTimer(...) -- ... in another place if isTimer(burnoutTimer) then killTimer(burnoutTimer) end -- etc. You may choose to search-and-replace all occurrences of "player" with "localPlayer" since that's pre-defined, but it's fine to leave as since it's just a local value pointing to the localPlayer element. The following part seems to be remnant of a time when this script was supposed to be serverside? for i,v in ipairs(getElementsByType("player")) do --bindKey("accelerate","down",burnoutTheTires) --bindKey("brake_reverse","down",burnoutTheTires) bindKey("accelerate","up",unpressedTheKeys) bindKey("brake_reverse","up",unpressedTheKeys) end Anyway, completely unnecessary -- onClientResourceStart is triggered for a running client (at the time of resource start on the server) as well as a joining client (aka resource start on the client at time of join), so this results in duplicated bind calls.
  11. Do you possess the server-side for the given script? Or are you attempting to use someone else's client-side script files? This event name seems suspicious, like the author intended it to not work without the server-side files, even if they might not be required.
  12. I'd point out @Shady1's solution does not scale well as the whitelist gets bigger. It would be more ideal to, on start-up, and then periodically (or on command like refreshwhitelist) download the list, store it in a Lua table in a [serial] = bool structure and look-up that table onPlayerConnect, and cancelEvent(true) if serial not present (which also benefits the server process as a good part of player join sequence is aborted earlier, including the construction of a player element). This way you don't download the whole list every time a player joins, parse it every time a player joins, and iterate thought it every time a player joins. Lua table look-ups benefit from hashing, leading to much faster lookup speeds than iterating thought the list, provided the list is large enough (could be as little as 5 entries for benefits to show up but I haven't tested it) (otherwise hashing could be more expensive).
  13. if capacete1 then This checks whether a value is assigned to capacete1 (this value could be anything -- a string, number, userdata, coroutine, element, etc.), not whether it is a valid value for the purposes of your script. If the warning message you get says "expected element", it means you've passed it something that isn't an element (for instance, it could be a userdata reference to an element that's been destroyed by another script). A solution that gets rid of the warning is if isElement(capacete1) then
  14. Pretty sure the most important part is slots[i] = {screenW * x, screenH * (y - scroll), screenW * 0.0483, screenH * 0.0872} replacing table.insert(slots, {screenW * x, screenH * (y - scroll), screenW * 0.0483, screenH * 0.0872}) The table.insert version was continuously adding new entries into the table rather than updating existing values as you scroll.
  15. First of all, admin/staff_manager is not part of the default set of resources for MTA, so next time, tell us exactly what sort of resource you're using, where you got it from, a link to the documentation/user guide if you read it yourself beforehand) Also, please tell us what you've already tried doing to resolve your issue. So far, the error message suggests there's an issue with the resource 'integration' -- is it started? Does it have any errors when it starts? Have you tried restarting it?
  16. Addlibs

    API

    Edit: I've misread the question; the following is an answer to how to create an API that lists the players on your server. There are a number of ways to do this: Query the ASE port (123 above the server port, e.g. 22126 for a server running on 22003) for the information (I'm not sure how the ASE protocol works, you'd have to research it), or Query the server via its HTTP port (here you would need to create a HTTP web access resource which responds with the list of players in an encoding the API client expects, e.g. JSON) (can trigger anti-flood/anti-spam countermeasures on MTA server side if IP is not whitelisted in mtaserver.conf, as it would try to request a fresh list every time anyone loads a page; ideas for cached storage of fetched data below) this requires allowing guest HTTP access to the server (can expose admin functionality to everyone if not careful, so limit admin/webadmin resource access to authenticated users only), or setting up a dedicated user and logging in with it (password is sent via HTTP authenticate headers in plaintext, unencrypted; can expose admin functionality to eavesdropper on network between API client and MTA server; so limit this users ACL/RPC to read only access) or Have the server regularly send updates to a web server and the web server keep a copy of the latest list of players, or Have the server track players on it and update a MySQL database that the webserver connects to. The answer to your question is generally no, unless you plan to run surveillance on the MTA global server masterlist, query every server's player list and create a comprehensive database of who plays on what servers, and then query such a database.
  17. It's a syntax issue -- you're not supposed to use a colon to separate the key from the value in a table. The correct character is an equals sign: local messages = { message1 = " Some message", message2 = " Some message2", } I believe "<name> expected" is referencing OOP style calls like SomeObject:someMethod(), (the only use of the colon in Lua that I can recall of the top of my head), as if you wrote :someMethod() without any object name in front, but Lua expects a object name there.
  18. Can you provide a screenshot/video of what your code currently produces, and an annotated screenshot of what you want to achieve? I tried running the code you provided to get an idea of what you're trying to do but the code is incomplete, lacks the definition of the render target (i.e. its size is missing), uses non-standard drawing functions, etc. I don't understand the use of string.len(core) here. String length = number of characters, which suggests horizontal scrolling but the positions scrolled indicate vertical scrolling. I also don't understand the variables used (please, name your variables, it makes helping so much easier): what are x2, y2, z1, z2?
  19. Because the code uses get, credentials should be in the meta.xml like so: <settings> <setting name="hostname" value="" /> <setting name="username" value="" /> <setting name="password" value="" /> <setting name="database" value="" /> <setting name="port" value="" /> </settings> Now onto the code problem: mysql_connect is not a built-in MTA function, but rather a server module which you need to install to be able to use that function. Most modules today are quite deprecated because most of their functionality can be found built-in into MTA, for example, mysql_connect can be replaced with dbConnect. Indeed, all of the mysql_* functions in the code you provide can be replaced with appropriate db* functions. If you choose not to rewrite the code, you can try to install the module, https://wiki.multitheftauto.com/wiki/Modules/MTA-MySQL, but be aware, it was last updated in 2012. It is really old and may not even work anymore with the latest versions of MTA.
  20. Setting their initial velocity appears to work mostly, however, missiles gain speed very quickly on their own, try spawning one with 0 initial velocity, to a speed between 0.5 to 2 greater than target speed - I've tested with the target aircraft at default max speed of 1.5, the missiles follow with just around 2.8 speed. If the target aircraft is at speed 3, missiles follow it with velocity of up to 4.5. If you want to target a missile at a particular location, you can, as you said yourself, calculate that from two positions: local initialPosition = Vector3(0, 0, 0) local targetPosition = Vector(300, 300, 0) local differenceVector = targetPosition-initialPosition local directionVector = differenceVector.normalized local missileInitialSpeed = 1 local missileDirectionVector = directionVector * missileInitialSpeed You do not necessarily need any callbacks, you can change any element's velocity at any point. If you want to implement your own guidance system, you can adjust missile positions on the client side every frame, every 2 frames, etc. with onClientRender and either a loop of all missiles, a loop of missiles in a table, or just selecting a particular missile with single variable. Projectiles can also store element data if necessary.
  21. The wiki's arguments list suggests setControlState only works on players, not any ped. Have you tried setPedControlState client-side? You can trigger it by firing off an event from the server that's handled on the client side. This may need a lot of synchronisation code though, as a client won't receive this event when connecting after the resource was started, nor if the resource starts and triggers onResourceStart before the client side is ready.
  22. Likely caused by the line if not (Team.isInTeam(target)) then return false end The two options you have is to either return an empty table, or to verify the return value of getTeamPlayers when putting it as an argument to setPlayerVoiceBroadcastTo, ensuring it is indeed a table before passing it.
  23. This is because you're explicitly checking if row 1's status column is equal to 2, rather than making this check per-row. If you want it per row, you need to iterate over each returned record like so for i = 1, #checkpedingQuery do local row = checkpedingQuery[i] if row.status == 2 then -- or row["status"] (this is entirely equivalent, just different syntax, but the second one lets you plug a variable in there instead of a static string, the first version only works with static compile-time -- i.e. when the script loads -- strings) iprint(row) end end -- or for index, row in pairs(checkpedingQuery) do if row.status == 2 then -- same remark as above iprint(row) end end
  24. guiCreateButton is a persistent button - it creates a button element, not renders a button for a frame -- you should never call it in onClientRender except in if-statements which you know will only execute once when necessary (i.e. not every frame, and only if the previously created button was destroyed). Setting elementd to false in your code merely stops creating new buttons -- it does not delete the previously created buttons (yes, buttons, plural. You're creating hundreds of buttons every couple seconds depending on the FPS of the client). This code event = guiCreateButton(16, 20, 250, 40, "Take", false) addEventHandler ( "onClientGUIClick", event, Tokens ) and this code function eventshows () if elementd == false then dxDrawImage(500*sW, 120*sH, 370*sW, 470*sH, "img/event.png", 0, 0, 0, tocolor(255, 255, 255, 255), true) end end addEventHandler ( "onClientRender", getRootElement(), eventshows ) should generally never exist in the same function
  25. A sizable chunk of ACL rights are function rights-- these rights only matter for resources, as player cannot invoke functions directly. All these functions are documented on the wiki on pages named after them. For players, commands rights are the main way to control access. Each command in the list is implemented either in MTA or in a resource. The MTA commands are outlined in Server Commands on the wiki. The remaining commands are from resources, such as admin (the default admin panel). In the case of the admin panel, command rights also control the enabled/disabled state of GUI buttons corresponding to those commands, i.e. the Ban button is not clickable if the user has no right to command.ban. There are some additional ACL rights such as general rights, these may control things like access to particular functionality of a resource, e.g. general.tab_resources controls the access to the Resources tab of the admin panel. For the rights related to particular resources, you need to check if the resource has documentation of these commands, or infer the purpose from the code.
×
×
  • Create New...