1K instead of 1000 - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: 1K instead of 1000 (
/showthread.php?tid=657671)
1K instead of 1000 -
AzaMx - 13.08.2018
Can anyone give me example how to make like
/pay 1k instead of /pay 1000
Re: 1K instead of 1000 -
CodeStyle175 - 13.08.2018
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;
}
Re: 1K instead of 1000 -
jlalt - 13.08.2018
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 = 0, len = strlen(vals);
if(len != 0 && (len % 2))
len--;
for(new i = 0, j = strlen(str); i < j; i++)
{
if(str[i] >= '0' && val <= '9')
{
val *= 10;
val += str[i] - '0';
}
else
{
for(new q = 0; q < len; q += 2)
{
if(tolower(str[i]) == tolower(vals[q]))
{
val *= vals[q + 1];
}
}
}
}
return val;
}
Re: 1K instead of 1000 -
AzaMx - 14.08.2018
Damn, that's long ass code, but how do I use it?ї
Re: 1K instead of 1000 -
OneDay - 14.08.2018
http://forum.sa-mp.com/showpost.php?...38&postcount=3
Re: 1K instead of 1000 -
AzaMx - 14.08.2018
I tried the sscanf version, but I received $0?
Re: 1K instead of 1000 -
Crystallize - 15.08.2018
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.
Re: 1K instead of 1000 -
AzaMx - 15.08.2018
How to use it tho?
Re: 1K instead of 1000 -
Gammix - 15.08.2018
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.
Re: 1K instead of 1000 -
AzaMx - 16.08.2018
ok, working now, thanks guys!