Jump to content

Addlibs

Members
  • Posts

    1,060
  • Joined

  • Last visited

  • Days Won

    9

Everything posted by Addlibs

  1. The error is telling you that mysql_ping function is not defined. Either this script wasn't written for MTA, or it was written to be used with a server module (modules allow server-side Lua to call functions implemented in C or C++). This code in particular appears to want to handle a MySQL connection; this is very deprecated way of doing things as MTA has built-in support for SQLite and MySQL connections though the dbConnect and other db* functions. To fix your issue, you either need to find the module for which this code was written (not recommended, MySQL modules are old and outdated nowadays), or redesign the code to use MTA's built-in db* functions.
  2. Have you tried attachElements?
  3. Actually, code_descriptions is neither a string nor a number, it is an array type. Meaning if you want to print its string, you need to add [1] to the variable that holds the array, to get the first (and only) value in that array, or use a for each loop to iterate over all strings in that array if there can conceivably be more than one in the actual data. tonumber on a string that does not contain a correctly formed number returns nil, which is the case in your original code; also I'm pretty sure fromJSON takes care of returning numbers correctly from a JSON where they're written as number literals rather than strings, so you shouldn't need to use tonumber unless your input data sometimes returns the number within a string.
  4. No need to disable the HS system if you can modify it, simply add checks like the ones above within the system.
  5. You can either use getTickCount() which counts milliseconds since the client/server started, or you can use setTimer to manually increment a variable until it reaches your desired value. getTickCount requires a tiny bit of basic math, but ultimately more efficient than a creating timer.
  6. You can augment the original weapon system if you replace original weapons with empty meshes and attach custom objects to player hands, however, this won't give you new IDs on its own and you'll need to code in a system to refer to and switch between these weapons yourself.
  7. Have you checked using toggleBrowserDevTools DOM inspector whether the JS executes correctly and updates the DOM, that is, whether the element #orghomelogo's src parameter is indeed what you expect it to be?
  8. You need to base64Encode the output of dxGetTexturePixels(texture) not just texture itself, and you need to prepend "data:image/png;base64," to the encoded base64 if you want it to be interpreted as raw data rather than a URL.
  9. You're missing libssl.so in your shared libraries path (typically /usr/local/lib, /usr/local/lib64, /usr/lib and/or /usr/lib64), which is required by dbconmy.so (the shared library responsible for database functionality in MTA). You might be missing the packages openssl-1.1 and openssl-solibs-1.1. If you are your system administrator, you should be able to easily add these packages using apt-get or yum depending on your distro; if you don't know how to do that you can find tons of information about installing packages on Linux on Google. If you don't have access to the root user and/or sudo, you might need to get in contact with your system administrator or service provider and ask them for assistance.
  10. You don't seem to be using the result of local check = exports.mysql:mysql_query_single("SELECT * FROM `players` WHERE `login` = ?", login) anywhere in the snippet, you might want to move it closer to where you use it for more readability, and either way, its not relevant to this snippet so it could have been omitted. Now if you want to do a case insensitive comparison between people's logins, your best bet is to lowercase or uppercase both sides of the comparison, or ensure one of the sides is always lowercase/uppercase and case fold the other side: -- turn both sides to lowercase if(string.lower(getElementData(p, "login")) == string.lower(login)) then -- ... end -- or -- lowercase the user input local lowercaseLogin = string.lower(login) for _, p in --[[...]] do if(getElementData(p, "login") == lowercaseLogin) then -- compare stored -- ... end end --- ... -- ensure the login value in element data is always stored in lowercase setElementData(p, "login", lowercaseLogin) The second option is slightly more efficient since you only need to lowercase it once per player when logging in, rather than for every player when one player logs in, essentially a O(1) vs O(n) difference.
  11. local arg1Colors = { ["pink"] = pink_1, ["blue"] = blue_1, ["yellow"] = yellow_1, ["red"] = red_1 } local arg2Colors = { ["pink"] = pink, ["blue"] = blue, ["yellow"] = yellow, ["red"] = red } local arg3Colors = { ["pink"] = pink_2, ["blue"] = blue_2, ["yellow"] = yellow_2, ["red"] = red_2 } function getColorToImage(arg1, arg2, arg3) -- dont check anything if arg1 is nil if (not arg1) then return false end -- return with nil-coalescing 'or' functionality in order of arg2, then arg1 and lastly arg3 return arg2Colors[arg2] or arg1Colors[arg1] or arg3Colors[arg3] or nil end This is one way of simplifying the function, a tiny bit more readable and maintainable, but still unfortunately cryptic with these argument names.
  12. Addlibs

    ScoreBoard

    You cannot hide players from the MTA server browser player list, but you could disguise all players with non-identifying nicknames but use more identifiable nicknames in chat messages, etc. If you want to hide yourself from the ingame scoreboard (the one you get when holding tab), you can modify the scoreboard resource, or whichever resource you use for scoreboards if you have a custom one, to hide the rows of “hidden” players
  13. Addlibs

    HTML script

    HTML is not a "script" language, but you can use HTML on the client-side for user interface / rendering through Lua and the CEF browser functions.
  14. Additionally, it seems Chassi is suposed to be unique, yet the database contains the following duplicates: ID,Conta,Vehiculo,Chassi 379,fynkffx,Mercedes AMG 63,6762 483,mercenario,Impala 1967,6762 665,Kryvios,GTR R35,31969 666,CireloPlay,GTR R35,31969 279,Nirvana,Civic Type R,61810 667,Gabriel665,Civic Type R,61810 244,Nirvana,Nissan GTR,77690 337,relmen,GTR R35,77690 513,NINJATV22,Audi R8,83450 646,michael,Shineray,83450 Some of these duplicates appear to be the same vehicle, others not. You should probably mark the column as UNIQUE in the database to prevent this from being allowed by the database. Also, this is the wrong way to do what you're setting out to do local sucess = dbExec(database, "DELETE FROM playersConce WHERE Model = ? AND Chassi = ?", tonumber(model), qChassi) local sucess1 = dbExec(database, "INSERT INTO playersConce (Conta,Model,Veiculo,Chassi) VALUES (?,?,?,?)", getAccountName(getPlayerAccount(pID)), tonumber(model), Config.VEICULOS.CARROS.nome, Chassi) What you probably want is local sucess = dbExec(database, "UPDATE playersConce SET Conta = ? WHERE Chassi = ?", getAccountName(getPlayerAccount(pID)), qChassi) which changes the vehicle's owner by modifying the row, instead of deleting the old one and inserting a new one.
  15. A screenshot of /debugscript 3 when attempting to sell a vehicle would be a good start.
  16. I don't need the whole file, I need the debug script logs, to see which debug statements (iprint) get printed.
  17. Could you put the code into code tags please? Also, I see a number of iprints, can you share the debugscript log as well? Does dxMsg(player, "Você vendeu seu veículo com sucesso.", "success") dxMsg(pID, "Você recebeu um veículo.", "success") ever get executed? What is this supposed to do, and why? local query = dbPoll(dbQuery(database, "SELECT * FROM playersConce WHERE Model = ?", tonumber(model)), -1) It appears to check if there are any vehicles in the database of that model ID, but it feels redundant to check, if you could later go on to check if query["Chassi"] == getElementData(vehicleConces[player], "Yammy.vehicleBank") then local Chassi = query["Chassi"] local query_02 = dbPoll(dbQuery(database, "SELECT * FROM playersConce WHERE Model = ? AND Chassi = ?", tonumber(model), query["Chassi"]), -1) This could be shortened to just one query, similar to the latter one, but in place of query["Chassi"] it would just be getElementdata(vehicleConces[player], "Yammy.vehicleBank") The way your current code is structured is to execute a SELECT statement checking Model and Chassi for every record in playersConce where Model is tonumber(model). This means if you have 3000 records with model = 429 (Banshee), your code executes 3000 searches, x, for matching Model = 429 and Chassi = x["Chassi"] = getElementData(vehicleConces[player], "Yammy.vehicleBank")), where just one would suffice: SELECT search for Model = 429 and Chassi = getElementData(vehicleConces[player], "Yammy.vehicleBank")
  18. What is countArgs being used for? I don't think you need any of the variadic parameters. Your current code takes target as the first argument, and packs the rest of the arguments into args, and then you tested it for count of 1, meaning you had to provide two arguments, the target name and any string afterwards which is just discarded. function locatePlayer( source, command, target ) if (not target) then -- if target wasn't specified outputChatBox("Usage: /pos <name>", source) return -- return (nil) early, makes code cleaner -- less nesting. Control doesn't proceed beyond here if the if-case was true end local targetPlayer = getPlayerFromName(target) if (targetPlayer) then outputChatBox(target) else outputChatBox("Target '" .. target .. "' not found.") end end addCommandHandler ("pos", locatePlayer)
  19. local function tableToString(table, bIgnoreKey) -- if bIgnoreKey is true, the function won't print the key name, useful only in list-like tables where -- the key is sequential and/or unused local str = "" for k, v in pairs(table) do if (type(k) == "string" or type(k) == "number") and (type(v) == "string" or type(v) == "number") then -- only add to string if both key and value are printable strings or numbers -- this ignores userdata, tables, elements, etc, so if you want them, you'll have to extend this -- function yourself if type(v) == "string" then -- add double quotation marks (" ... ") before and after a string value v = '"' .. v .. '"' end -- append key followed by colon and space if not ignored, then the value, a comma and space to the draft string str = str .. (bIgnoreKey and "" or (k .. ": ")) .. v .. ", " end end -- return the draft string with last two characters omitted (trailing comma and space) return str:sub(0, -2) end Does this function produce strings that you're looking for? Given you seem to want to print data out of a SQL query, I'm assuming you don't need functionality for printing userdata, elements, etc. only the standard printable types like string and number, right? local theTable = { CapturePoints = 1002 } outputChatBox(tableToString(theTable)) -- CapturePoints: 1002 local theTable = { CapturePoints = 1002, anotherKey = "someValue", ["key with spaces"] = 53.2 } outputChatBox(tableToString(theTable)) -- key with spaces: 53.2, anotherKey: "someValue", CapturePoints: 1002 -- note that the order is not guaranteed and can be different everytime the table changes and at different -- run times While this answers your question, it does seem a little over-engineered if all you're interested in is printing a single value out of the table, in which case it would be much simpler and faster to simply write if rezultat and rezultat.CapturePoints then outputChatBox("CapturePoints: " .. rezultat.CapturePoints) else outputChatBox("Failed to get CapturePoints") end
  20. There is no built-in functions (perhaps other than inspect but that works recursively and returns a string with brackets) which does what you want; so, you must write your own. What you'll want in such function is to create a string, and concatenate/append to it each key and value pair that meets certain conditions (i.e. that it's a printable value, such as a string or number, not a table) separated by a colon and a space, and return the finalised string; then the caller function can print out the return.
  21. Does the entire thing not work? Is the code file included in the meta.xml? It should be a <script ... />. Have you tried a top-level outputChatBox call to see if the script gets loaded? If it prints, then that means the script loads. Then try adding an outputChatBox call in the handler function for onClientBrowserCreated. If that works, its probably your HTML that's the problem. Is it included in the meta.xml? It should be a <file ... />. Once you get the browser to show up, you can set download_priority_group in the meta.xml to a high value (anything greater than 0 will load before resources without an explicitly set priority group as it defaults to 0), if you want it to load and start earlier than the rest of resources.
  22. The error you're getting means Lua is expecting a function name on line 2, between function and (getPlayerName). But that's only the currently detected syntax error. There's a lot of other syntax and semantic errors in your code besides that one. addCommandHandler (which you misspelled as addComamandHandler) takes two arguments, the command name and a function that will handle it. You want to remove the ending bracket on line 1 and replace it with a comma, so that the function on the lower lines is an argument of addCommandHandler. Secondly, you take as parameter a value that you store in a variable called getPlayerName, thereby overriding the MTA function called getPlayerName with whatever value is sent to this function -- which, as it is a command handler, the parameters are source player and the command on the server side, just the command on the client side, plus extra arguments passed through the command by the player. Thirdly, on line 3, you attempt to get two returns out of the function getPlayerName which only returns one string. Fourthly, you never end the function and instead had two end brackets one on the first line and the other on the last line. Lastly, within the if-block, you create a string containing the text "Ez .. getPlayerName .. járműve!" literally when you likely wanted to concatenate getPlayerName variable between the strings "Ez" and "járműve!" addCommandHandler ( "playerInTheCar", -- no bracket at the end here function (player) -- anonymous function with corrected parameter name local playerName = getPlayerName ( player ) -- corrected return variables if playerInTheCar then -- this variable is not set and I am unsure what it was meant to be outputChatBox ("Ez ".. playerName .. " járműve!") end end -- end the anonymous function ) -- end of addCommandHandler arguments
  23. It acts differently depending on whether you're using a MySQL or sqlite connection; specifically, this is the escaping function for MySQL and this is the one for sqlite.
  24. Well, you have a couple options 1) A single timer using setTimer, generally the duration is not modifiable after it's been created but you can get current remaining time and set a new one with a different time if necessary. The callback is triggered when the timer runs out. 2) A timer set using setTimer that triggers every second (1000ms period) and increments or decrements a variable of how many seconds passed or are remaining, respectively; this way you get to change time remaining without having to deal with new timers (but this may be a bit more resource-hungry than the option above). Use the timer's callback and compare it against the remaining time to determine if the timer elapsed. 3) Use the missontimer resource packed with default MTA resources, as used by gamemodes like the default deathmatch. Using that you can abstract most of the internal timers and how to change durations using them, instead get exported functions that deal with it; and it takes care of rendering for you. onMissionTimerElapsed is triggered when the time runs out. When it comes to options 1 and 2, you need to render the remaining time yourself. Ideally, the server should have an authoritative timer while clients get a very close approximation through data sending using triggerClientEvent and triggerServerEvent. Clients should only have math that controls the display of the timer, not the actual timer.
  25. Either that or Installing and Configuring Nginx as an External Web Server should be helpful. The built-in HTTP server in MTA that takes care of downloading is a very simple server, and can't do things like transmission compression. Nginx or Squid (maybe? I haven't ever used it so I'm not entirely sure) should be able to compress the transmission and thus make it faster and use less bandwidth.
×
×
  • Create New...