Jump to content

Tails

Members
  • Posts

    740
  • Joined

  • Days Won

    16

Everything posted by Tails

  1. From http://lua-users.org/wiki/FormattingNumbers, slightly simplified: function comma_value(n) return tostring(n):reverse():gsub('(%d%d%d)','%1,'):reverse() end print(comma_value(4024910100)) --> 4,024,910,100 Hope this helps
  2. You need to use givePlayerMoney: https://wiki.multitheftauto.com/wiki/GivePlayerMoney
  3. Also make sure you have disabled "Always show download window" in the mta settings.
  4. You can simply keep track of the ids by adding them to a table and then check against that table to see if it's already seen that id. local ids = {} for i,v in ipairs(getElementsByType("blips")) do local id = getBlipIcon(v) if not ids[id] then ids[id] = true outputChatBox("ID Icon : "..id) end end ids = {} -- clear it if necessary (depends on your application) You'll probably want to put this inside a function so that you can trigger it again later, or have the function return the unique ids. But this all depends on the application.
  5. Tails

    [HELP]

    You need to add a if statement and check for the player's model with getElementModel Example: if getElementModel(localPlayer) == 0 then -- do your thing end
  6. Just use triggerServerEvent. It's not player related that's why it's not a player method.
  7. My guess is it's because it's not really player related, unlike with triggerClientEvent you can specifically target a player (in the 1st parameter) that's why there's a oop method. Also, you should avoid passing the local player by argument or source as the wiki states, you should use the global client variable on the serverside instead that will be available within every event handler. Read the warning here: https://wiki.multitheftauto.com/wiki/TriggerServerEvent
  8. You just need to add the event with addEvent and set the second arg to true. https://wiki.multitheftauto.com/wiki/AddEvent
  9. Tails

    Chat

    Use isTransferBoxActive to check if the client is downloading Cancel onClientChatMessage
  10. You need to whitelist the domain with requestBrowserDomains https://wiki.multitheftauto.com/wiki/RequestBrowserDomains
  11. Try clearing your cache, if that doesn't help then it's probably a bug in the resource where it sends something to the client only when the resource starts. Your best bet is to contact the author to see if they can fix it.
  12. Tails

    Help, Marker

    You can use getVehicleTowedByVehicle to get the trailer attached to a truck. https://wiki.multitheftauto.com/wiki/GetVehicleTowedByVehicle First create your marker (serverside) local myMarker = createMarker(0, 0, 0, 'cylinder', 1, 255, 0, 0, 150) setElementID(myMarker, 'myMarker') Listen for hit event and check for petrol trailer for example (serverside) addEventHandler('onMarkerHit', myMarker, function(hitElement) if getElementType(hitElement) == 'vehicle' then local driver = getVehicleOccupant(hitElement) if driver then local trailer = getVehicleTowedByVehicle(hitElement) if trailer and getElementModel(trailer) == 584 then outputChatBox('You have a petrol trailer', driver, 0, 255, 0) else outputChatBox('You do not have a petrol trailer.', driver, 255, 0, 0) end end end end) Or listen for key press while inside the marker (clientside) addEventHandler('onClientKey', root, function(key, p) if key == 'e' and p then local vehicle = getElementVehicle(localPlayer) local myMarker = getElementByID('myMarker') if vehicle and isElementWithinColShape(vehicle, getElementColShape(myMarker)) then local trailer = getVehicleTowedByVehicle(vehicle) if trailer and getElementModel(trailer) == 584 then outputChatBox('You have a petrol trailer.', 0, 255, 0) else outputChatBox('You do not have a petrol trailer.', 255, 0, 0) end end end end) Hope this helps!
  13. Hi, there are already scripts that do this. Here's a couple: Zday by Dutchman101 Slothbot: https://community.multitheftauto.com/index.php?p=resources&s=details&id=672
  14. Hotfix has been uploaded! New bugs may be introduced with this version, however, playing videos should work again for the most part. Consider this is a temporary fix until we find a new and better solution. I also replaced the switch browser button with a Skip Ads button. This is basically a refresh button which will help you skip ads. Download the latest version here: https://community.multitheftauto.com/index.php?p=resources&s=details&id=12950
  15. We're currently looking at solutions right now. We may just have to use the default youtube page now and crop the image a bit. There are some issues though with popups and ads covering the video, but we could put the screen browser in the panel so you can interact with it and remove any popups shown or skip ads. Stay tuned.
  16. Instead of sending a PM, please clarify it here in this thread, so others can help too such as myself.
  17. Make sure you put lang.lua before client.lua in the meta file so it loads first.
  18. You can use table.sort for sorting, but first you have to extract the data you want from the table and place it in another to make it iterable. For instance: local sorted = {} for itemId, itemData in pairs(myItems) do table.insert(sorted, itemId) -- extract item ids end -- sort the items table.sort(sorted, function(a, b) return a < b end) iprint(sorted) You can also sort it by the item count local sorted = {} for itemId, itemData in pairs(myItems) do table.insert(sorted, itemData) -- extract the item data instead end table.sort(sorted, function(a, b) return a.count < b.count end) As you can see you can extract any data from your tables and sort them however you like.
  19. Don't use metatables just for simple table lookups, that's only asking for problems and will decrease performance. In your case (response to original post) an int loop would be faster: for i=1, #playerTable.playerItems do local v = playerTable.playerItems[i] outputChatBox("item: "..v[1]..", count: "..v[2]) -- item: Item, count: 1 end However I can imagine that with a list of 1000's of items you wouldn't really want to loop this table over and over. What you're doing is, you're inserting a new table for every item and there isn't really any way to get the "Item" from the table with a single lookup other than looping the entire thing. What you could do is change the structure of the table to something like this: -- a fixed table that contains all the item ids and information local items = { ['apple'] = {desc = 'A green apple', name = 'apple'} -- an item with id 'apple' } local myItems = { ['apple'] = {count = 10}, -- player has an item with id 'apple' and has 10 of them } Now you'd still have to loop it if you wanted to get all the items at once but if you want to get the count of a specific item you can access it according to the item id. -- say you know the item id, all you do is local item = myItems['apple'] if item then print(item.count) end -- for instance function takeItem(id, count) local item = myItems[id] if item then if item.count >= count then item.count = item.count - count end end end -- if you want to get all then you loop it for id, item in pairs(myItems) do print('ID:', id, 'Count:', item.count, 'Description:', items[id].desc) end Notice you don't have to loop it in the takeItem function which will help with performance. So instead of table.insert you keep a key table where the id's are fixed and don't change so that you can access them by their key/id. Hope this helps.
  20. Tails

    Expected account

    @1LoL1 cause getAccountPlayer expects an 'account' element but getAccount returns false cause it didn't find the account. All you need to do is add a check, for example: if account then -- continue here end Next time you use a function check the wiki page for it, it explains exactly what it will return and what it returns in case there's a mistake. In your case it didn't find the account so it returned false. Hope this helps.
  21. Or listen for the resourceBlocked event and request each blocked domain to be unblocked. addEventHandler('onClientBrowserResourceBlocked', browser, function(url) requestBrowserDomains({url}, true, function(accepted) if accepted then reloadBrowserPage(browser) end end) end)
  22. @Sorata_Kanda you can't pass any sort of functions or metatables unfortunately. However as IIYAMA said you can use loadstring to inject code into your scripts. I wrote this a while back: function load() return [[ function import(name) if type(name) ~= 'string' then error("bad arg #1 to 'import' (string expected)", 3) end local content = exports.import:getFileContents(name) if not content then error("can't import '"..name.."' (doesn't exist)", 2) end return loadstring('return function() '..content..' end')()() end ]] end function getFileContents(name) if not name then return end local path = 'exports/'..name..'.lua' if fileExists(path) then local f = fileOpen(path) local content = f:read(f.size) f:close() return content end return false end If you put this in a resource called "import" then you'd use it like this: loadstring(import.exports:load())() local utils = import('utils') iprint(utils) This loads files directly into a variable in your script. Ofcourse you can easily modify this to load files from different resources. Also in said files you will have to return the class or function or whatever you need to return just like real modules.
  23. not supported, however you can do this... local link = "https://media.rockstargames.com/rockstargames-newsite/img/global/downloads/buddyiconsconavatars/sanandreas_truth_256x256.jpg" local pix requestBrowserDomains({link}, true, function(accepted) if not accepted then return end fetchRemote(link, function(data, err) if err > 0 then error('Error: ', err) end pix = dxCreateTexture(data) end) end) function teste() if pix then dxDrawImage(0, 0, 256, 256, pix, 0, 0, 0, tocolor(255, 255, 255, 255), false) end end addEventHandler("onClientRender", root, teste) I didn't test it but it should work
  24. I found both movement and camera speed to be really slow, especially the camera. It takes 3-4 seconds for me to rotate the camera 360 degrees, unless I crank up the dpi on my mouse, which I rarely do. There should be an option to change the camera speed. Here's what the UI looks like: https://imgur.com/a/hcKVmV0
×
×
  • Create New...