1K instead of 1000
#1

Can anyone give me example how to make like

/pay 1k instead of /pay 1000
Reply
#2

PHP код:
cmd:pay(pid,p[]){
    if(
sscanf(p,"s[10]",p))return scm(pid,-1,"/pay [amount]");
    new 
amount=strval(p);
    if(
strfind(p,"k",true) != -1)amount*=1000;
    
User[pid][Money]+=amount;
    return 
1;

Reply
#3

Just wrote a simple function see if it fit your need : p
PHP код:
public OnFilterScriptInit()
{
    new 
str[] = { 'M'1000000'K'1000 };
    new 
value GetValue("126MK"str);
    
printf("%d"value);
}
GetValue(str[], const vals[])
{
    new 
val 0len strlen(vals);
    if(
len != && (len 2))
        
len--;
    for(new 
0strlen(str); ji++)
    {
        if(
str[i] >= '0' && val <= '9')
        {
               
val *= 10;
            
val += str[i] - '0';
        }
        else
        {
            for(new 
0len+= 2)
            {
                if(
tolower(str[i]) == tolower(vals[q]))
                {
                    
val *= vals[1];
                }
            }
        }
    }
    return 
val;

Reply
#4

Damn, that's long ass code, but how do I use it?ї
Reply
#5

http://forum.sa-mp.com/showpost.php?...38&postcount=3
Reply
#6

I tried the sscanf version, but I received $0?
Reply
#7

Quote:
Originally Posted by AzaMx
Посмотреть сообщение
I tried the sscanf version, but I received $0?
That code is trash.
If you do /pay 5k it will still send 1k.

Use the code jalt posted.
Reply
#8

How to use it tho?
Reply
#9

PHP код:
// take this as parameters of your command like "/pay 100k"
new string[] = "100k";
// working on getting real amount
new amount strval(string);
if (
strfind(string"m"true) != -1) {
    
amount *= 1000000;
}
if (
strfind(string"k"true) != -1) {
    
amount *= 1000;
}
// result
printf("amount is $%i"amount); 
Nobody writes like "100k100k", the abbreviations are always in the end like "100k", "100m". So this is the easiest and fastest approach i posted.
Reply
#10

ok, working now, thanks guys!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)