Jump to content

Addlibs

Members
  • Posts

    1,060
  • Joined

  • Last visited

  • Days Won

    9

Everything posted by Addlibs

  1. You're setting everyone's look-at coordinates to the centre of the localPlayer's screen, not the respective player's screen. Also, last time I used setPedLookAt, it didn't work for remote players correctly. Also, read the Wiki notices (specifically the first one - don't run this on onClientRender): Note: Avoid calling setPedLookAt every frame as this can cause bugs like being invincible to burning. Note: For remote players, you have to use setPedAimTarget before setPedLookAt.
  2. Share the code that you need help with, or at least tell us which script it is if it's from MTASA community resources website.
  3. Using setAccountData you run the risk that items may get duplicated, since there is no protection against an item being listed in the account data of two accounts. Using a central MySQL (external) or sqlite (internal) database table, you could avoid this by having one list of items and who they belong to, rather than seperate lists per account.
  4. https://wiki.multitheftauto.com/wiki/Serial#Notes I wouldn't recommend relying on serials as the sole authentication factor, as serials can be faked, they are not guarenteed to be unique (two players can have the same serial, it's just very unlikely). Indeed, under European privacy rules, if another user gets logged into someone else's account though serial collision, and gains the ability to view the account owner's information, you would probably be violating GDPR (I'm not a lawyer so don't quote me on that, but it definitely sounds like a violation of GDPR).
  5. You cannot return information from the server side this way. You need the server to trigger a client event back with the balance amount. The client should be something like this: -- ... triggerServerEvent("bank-hajs-panel", localPlayer) -- request balance from the server addEventHandler("onClientBrowserDocumentReady", theBrowser, function () bank = triggerServerEvent("bank-hajs-panel", localPlayer) executeBrowserJavascript(source, "document.getElementById('gotowka').innerHTML = '"..getPlayerMoney(localPlayer).."$';") executeBrowserJavascript(source, "document.getElementById('Witamy__nazwa_gracza').innerHTML = 'Witamy "..getPlayerName(localPlayer).."!';") executeBrowserJavascript(source, "document.getElementById('bank').innerHTML = 'Loading...';") -- display a placeholder while we're waiting for the server to return the balance end ) -- ... -- this should be at top level scope, outside any functions addEvent("bank-hajs-balans", true) addEventHandler("bank-hajs-balans", localPlayer, -- server triggers this event sending over the balance function(bank) if initBrowser then -- we only want to continue if the player hasn't hid the panel in the meantime local theBrowser = guiGetBrowser(initBrowser) executeBrowserJavascript(theBrowser, "document.getElementById('bank').innerHTML = '$"..tostring(bank).."';") -- update player's displayed balance end end ) The server should look like this: function bank() local konto = getPlayerAccount(client) -- account of the client who sent the event to the server if konto then triggerClientEvent(client, "bank-hajs-balans", client, getAccountData(konto, "bank.balance")) end end addEvent("bank-hajs-panel", true) addEventHandler("bank-hajs-panel", root, bank)
  6. Addlibs

    [HELP] BAN

    getPlayerID isn't an MTA function; could you show us it's code as well? Also, did you add the resource into admin ACL too? It needs to be privileged to use the function banPlayer.
  7. math.randomseed can affect the RNG of internal MTA logic, yes, but it also works the other way round too -- your math.randomseed can be overridden by internal MTA logic. This could affect seed-based generation if it happens to be interrupted by a map resource with XML vehicle definitions starting for example, which invokes MTA's internal RandomizeRandomSeed function which overrides srand (and by extension math.randomseed)
  8. Addlibs

    Question

    When set to "true", it will make the resource show up in resourcebrowser, which is a resource that handles the server's HTTP webserver, available at http://<server ip>:<http port>/resourcebrowser/ (http port is by default 22005). It will list all resources that are set to "showInResourceBrowser". It is an advanced feature honestly, and if you don't understand HTTP web access programming, you shouldn't worry about it. Unless you're making a resource which has a server-side HTTP page (not related to CEF) then you should set it to "false" or not include "showInResourceBrowser" attribute at all.
  9. Regarding specifically Lua-tables, they generally don't shrink as you nil values inside them (but nil'ing the reference to the table itself will clean up the memory at some point when GC runs, same for whatever is being referenced in the table, will be cleaned up, just that the space for its reference in the table will not be cleaned up), as table rehashing only occurs when adding new elements. A messy workaround is to add a lot of nil entries (about twice as much as the table had data at last rehash) to trigger a new rehash, which will shrink the table and remove the original and newly added nil elements. But the process of adding those nils will most likely cost you more in performance than you save up in memory space. You can still opt to nil out any table values regularly as good practice, just know that it probably won't reduce the table size in memory unless you are adding and nil'ing entries regularly.
  10. If you have OOP enabled, you can use the matrix forward vector multiplied by a scalar coefficient of the magnitude (i.e. strength of the velocity) local magnitude = 0.5 local rocket = createProjectile(ped, 19, x, y, z, 1.0, nil, 0, 0, 0, ped.matrix.forward * magnitude) Otherwise you can use local m = getElementMatrix(ped) local forward = Vector3(m[2][1], m[2][2], m[2][3]) -- offset from player position to position 1m ahead of them taking into account the rotation local magnitude = 0.5 local rocket = createProjectile(ped, 19, x, y, z, 1.0, nil, 0, 0, 0, forward * magnitude) Or, if you prevent to avoid using Vector3 local m = getElementMatrix(ped) local forwardX, forwardY, forwardZ = m[2][1], m[2][2], m[2][3] -- offset from player position to position 1m ahead of them taking into account the rotation local magnitude = 0.5 local rocket = createProjectile(ped, 19, x, y, z, 1.0, nil, 0, 0, 0, forwardX * magnitude, forwardY * magnitude, forwardZ * magnitude)
  11. Client-side variant of setVehicleHandling can only modify handling of vehicles which are local only, i.e. client-side vehicles that don't exist on the server side, which a player cannot enter.
  12. Cause you're only rendering onto a render-target. After you've rendered the contents in your render-target, you need to render the render-target itself as well. -- add this somewhere at the top in outermost scope local screenX, screenY = guiGetScreenSize() -- add this right after setting rendering target to screen (line 27) dxDrawImage(0, screenY - hud.przez, hud.szer, hud.przez, minimap)
  13. loadstring loads Lua code from a string into a function than you can call (to execute the loaded code). Looking at the loadstring error message, it does not appear that you're putting code into that, but rather a string of text, not code. You have two options: Either change line 65 to memo = guiCreateMemo(241, 24, 450, 437, "Bem vindo/a ao RPG City Reallife. Use o menu á esquerda para navegar pela documentação do servidor.\n\nRegras do Servidor:\n\n"..rules, false, window) and remove line 28 through 34 (the safer option, since you remove the ability for arbitrary code execution in your script) Or the second option, is to change the rules.txt file to contain valid code which this script expects. It appears to expect a table named theRules with a string of rules under the key "English", so your rules.txt should be local theRules = { ["English"] = "Art 1° - Não praticar Power Gaming: Mínimo (10H) Máximo(24H ..." } and it should load correctly. However, this is less safe, since it can allow someone with access to editing rules.txt to insert malicious code into the file, which is then executed on through clients' Lua interpreters.
  14. First of all, to clarify, onVehicleEnter, onClientClick etc. are native events, not native functions. resourceRoot contains all the elements created by thisResource. If you want to handle all objects created by this resource, you'll want to bind the events on resourceRoot. If you want to handle foreign elements (from other resources), you'll need to use root. If you're only interested in handling a specific element or elements, use (multiple) bind(s) to single element(s). onVehicleEnter on resourceRoot will only trigger for any player or ped who enters a vehicle created by this resource. onVehicleEnter on root will trigger for players or peds entering any vehicle, regardless of which resource created it. onClientClick's source is always root, so I don't think it will trigger for resourceRoot at all. You have to look at the wiki pages for each event, check what the source of the event is, and determine what element to attach the handler to. Root attaches onto everything (unless you set propagate to false), resourceRoot attaches to everything created by your resource. It goes down the element tree.
  15. According to what I found on mybb github , t, their hashing method is md5 of salt and md5 of password concatenated together and md5 hashed again, this time together. local passHash -- comes from the database local passSalt -- comes from the database local password -- user input if passHash == md5( md5(passSalt) .. md5(password) ) then -- password is correct else -- password is incorrect end
  16. -- make these accessible throughout this file local shader = nil local terrain = nil local active = false function toggleShader(state) if state == active then return false -- don't do anything if it's already in the desired state end if state then engineApplyShaderToWorldTexture(shader, 'cj_rubbish1') engineApplyShaderToWorldTexture(shader, 'sf_junction2') engineApplyShaderToWorldTexture(shader, ':Oroad01_law') engineApplyShaderToWorldTexture(shader, 'des_1line256') engineApplyShaderToWorldTexture(shader, 'concretebig4256128') active = true else engineRemoveShaderFromWorldTexture(shader, 'cj_rubbish1') engineRemoveShaderFromWorldTexture(shader, 'sf_junction2') engineRemoveShaderFromWorldTexture(shader, ':Oroad01_law') engineRemoveShaderFromWorldTexture(shader, 'des_1line256') engineRemoveShaderFromWorldTexture(shader, 'concretebig4256128') active = false end return true end addEventHandler('onClientResourceStart', resourceRoot, function() shader = dxCreateShader('shader.fx') terrain = dxCreateTexture('img/road.jpg') dxSetShaderValue(shader, 'gTexture', terrain) toggleShader(true) -- toggle on at start end ) addCommandHandler("shadertogglecmd", function() toggleShader(not active) -- invert toggle on command end )
  17. cancelEvent() cancels an event from happening. Prevents default behaviour. Return simply exits a function and sends a return value. CancelEvent can be used to prevent GTA hardcoded behaviour, whilst return can only prevent your own Lua code from any further execution in the current context.
  18. Have you tried dimensions? setElementDimension You can put all objects into dimensions -1, making them visible in every dimension, but keep players in seperate dimensions. Alternatively, you can manage the visibility of the objects manually through clientside scripts: Keep players in seperate dimensions but put the objects into the dimension of the localPlayer, on the client.
  19. Are you trying to store player money? I'd suggest you use an XML styled more like this: <accounts> <account name="playername1" balance="1000"></account> <account name="playername2" balance="1500"></account> </accounts> And use the Lua table associatively (like a directory) instead of as an array. local moneyT = { ["playername1"] = 1000, ["playername2"] = 1500, } Generally, the way you were trying to tackle this problem is over-complicated. You're storing two related values in seperate arrays when you can use associative arrays and additionally avoid having to loop over every value searching for someone's account - if you use associative arrays, you can just index it by the player's name. --Tabele accountsT = { -- [playername] = balance } --Funkcja zczytująca zapisane tabele addEventHandler("onResourceStart", root, function() -- Open the XML local xml = xmlLoadFile("accounts.xml") if xml then local accounts = xmlNodeGetChildren(xml, "account") -- Loop through the accounts for i, node in ipairs(accounts) do local name = xmlNodeGetAttribute(node, "name") local balance = xmlNodeGetAttribute(node, "balance") -- Store `balance` in accountsT table under key `name` accountsT[name] = balance end -- Unload the XML xmlUnloadFile(xml) else -- Create XML, save and unload local xml = xmlCreateFile("accounts.xml", "accounts") xmlSaveFile(xml) xmlUnloadFile(xml) end end ) --Funkcja zapisująca tabele addEventHandler("onResourceStop", root, function() -- Create the XML local xml = xmlCreateFile("accounts.xml", "accounts") -- Loop through each account for name, balance in ipairs(accountsT) do -- Create <account> node and store account number and balance as attributes local account = xmlCreateChild(xml, "account") xmlNodeSetAttribute(account, "name", name) xmlNodeSetAttribute(account, "balance", balance) end -- Save the XML xmlSaveFile(xml) xmlUnloadFile(xml) end ) --Reszta skryptu (komendy) --Funkcja do przelewów addCommandHandler("przelew", function(player, command, pname, amount) local target = getPlayerFromName(pname) if not target then outputChatBox("ERROR_TARGET_DOES_NOT_EXIST", player, 255, 0, 0) return end -- be sure to translate this yourself -- Check if target is yourself if target == player then outputChatBox("ERROR_CANT_SENT_TO_YOURSELF", player, 255, 0, 0) return end -- be sure to translate this yourself -- Check if amount is valid amount = tonumber(amount) or 0 -- default to zero to give invalid amount error but allow math.floor to work amount = math.floor(amount) -- make sure players aren't sending non-integers if not amount or amount <= 0 then outputChatBox("ERROR_INVALID_AMOUNT", player, 255, 0, 0) return end -- be sure to translate this yourself -- If trying to send more than you have if amount > getPlayerMoney(player) then outputChatBox("ERROR_INSUFFICIENT_FUNDS", player, 255, 0, 0) return end -- be sure to translate this yourself takePlayerMoney(player, amount) givePlayerMoney(target, amount) outputChatBox("#09ff00Przelew ukończony pomyślnie!", player, 255, 255, 255, true) outputChatBox("#ffffff" .. getPlayerName(player) .. "#09ff00 przelał Ci #ffffff$" .. amount .. "#09ff00 do twojego portfela!", target, 255, 255, 255, true) end ) --Funkcja do wpłacania pieniędzy addCommandHandler("wplac", function(player, command, amount) amount = tonumber(amount) or 0 -- default to zero to given invalid amount error but allow math.floor to work amount = math.floor(amount) if not amount or amount <= 0 then outputChatBox("ERROR_INVALID_AMOUNT", player, 255, 0, 0) return end -- be sure to translate this yourself -- If trying to send more than you have if amount > getPlayerMoney(player) then outputChatBox("ERROR_INSUFFICIENT_FUNDS", player, 255, 0, 0) return end -- be sure to translate this yourself local name = getPlayerName(player) -- Create player's account if it doesn't exist yet if not accountsT[name] then accountsT[name] = 0 end takePlayerMoney(player, amount) -- take player's money accountsT[name] = accountsT[name] + amount -- and add it onto his account outputChatBox("#09ff00Wpłaciłeś na konto bankowe #ffffff$" .. amount .. "#09ff00!", player, 255, 255, 255, true) end ) --Funkcja do wypłacania pieniędzy addCommandHandler("wyplac", function(player, command, amount) amount = tonumber(amount) or 0 -- default to zero to given invalid amount error but allow math.floor to work amount = math.floor(amount) if not amount or amount <= 0 then outputChatBox("ERROR_INVALID_AMOUNT", player, 255, 0, 0) return end -- be sure to translate this yourself local name = getPlayerName(player) -- Create player's account if it doesn't exist yet if not accountsT[name] then accountsT[name] = 0 end local balance = accountsT[name] -- If trying to send more than you have if amount > balance then outputChatBox("ERROR_INSUFFICIENT_FUNDS_ON_ACCOUNT", player, 255, 0, 0) return end -- be sure to translate this yourself accountsT[name] = accountsT[name] - amount -- reduce player's account balance givePlayerMoney(player, amount) -- and give him the amount outputChatBox("#09ff00Wpypłaciłeś z konta bankowego #ffffff$" .. amount .. "#09ff00!", player, 255, 255, 255, true) end ) I haven't tested the code above, but should it not work, hopefully you'll be able to fix whatever minor bugs I've got there. Don't forget to add your translations. I've restructured it to use returns to escape out of a function to avoid indentation leading to pyramids of doom. I have also removed XML saving on player quit, since it's kinda redundant. As long as the server doesn't crash, you're safe just saving the XML when the resource is stopped.
  20. For weapons held in a ped/player's hand, you use "ped" because a weapon held by a ped is part of the ped in GTASA. You'll need to apply the shader to the world texture named exactly like the weapon object's texture, and have the ped/player as the target element.
  21. You need to use getPedTask or getPedSimplestTask but I'm not sure what task you'd be looking for. Try displaying the tasks of the local player on screen for debugging, find out what tasks are active while aiming, then remove the debug displays since they're no longer needed, and check if these tasks are active before rendering the healthbar.
  22. Are you asking for any particular help or just dumping a lot of code and letting others figure out you're trying to do or what the problem is?
  23. It's likely that the execution of the code is aborted by the Lua interpreter when it wants to store the result of guiCreateStaticImage(0, 0, 1280, 960, ":loginG/imagenes/ap.png", false) into a non-existant table. You need to add the following before any other code you may have: local GUIEditor = {} GUIEditor.staticimage = {} GUIEditor.label = {} GUIEditor.edit = {} GUIEditor.button = {} -- or (simply a matter of preference) local GUIEditor = { staticimage = {}, label = {}, edit = {}, button = {}, }
  24. Line 10 has a typo - it's removeEventHandler not removEventHandler. Besides, that line is unnecessary. The if-line above it already calls that function and its side-effects are executed (i.e. handler gets removed from the function or a false is returned because it's not attached anyway, so calling it again won't work - it'll either be removed or it wasn't attached in the first place)
  25. Is GUIEditor table defined? Are the sub-tables GUIEditor.staticimage, GUIEditor.label, GUIEditor.edit and GUIEditor.button defined? Also please use code tags next time, it's the <> button on the rich text editor toolbar.
×
×
  • Create New...