Jump to content

[HELP]How to ignore numbers in value?


Enkanet

Recommended Posts

Posted

Hello everyone. I need to show a picture for my item but I need to show the pictures of the item by the value of the item. I have skin items and ids. So, if the skin item's value is 1 so when I use the item I get a skin with the id of 1. I have a folder for them which is called "img" folder. There're skin pictures inside it and they are ordered from "1.png" to "299.png" (example) I want to show that pictures with my item by using the value. I am using that code and it works. "return ":img/" .. ("%03d"):format(itemValue) .. ".png"" but sometimes I have item value like 120:1 so the game tries to find an image with name of 120:1.png but it can't. Now I want to ignore the numbers after ":" this syntax. So if the item's value is 120:1 the game should show me a picture of 120. Sorry if I made mistakes with my English. I am writing this at 4:30AM and I am so sleepy. So forgive me if I made a mistake. Thanks.

Regards.

  • MTA Team
Posted
value = "120:1" 
number = tonumber(value:match("%d+")) 

I don't recommend using that on each render call, but it should work.

Posted

First of all thanks for your time and comments. I am using that to draw a dximage and value is not given manually. It is but it is given manually in game item by item. So I can't do value = "120:1" All I need is ignore :1 from 120:1. Thanks

  • MTA Team
Posted

You shouldn't do heavy operations on each frame render. You could save a string with the file path for each item.

Posted

Still will be same because I can not write it for each skin because it is not only 120:1 whenever you add a new skin like it, it'll make another value like 120:2 and people will continue adding. Anymore way? There should be.

Posted

Thanks everyone! I solved the problem. I did value:gsub(":" .. "%d", "") and it worked. Thanks to everyone for their time, comments, helps..

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...