SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 03/07/2012, 03:29 PM   #1
Tigerkiller
Gangsta
 
Tigerkiller's Avatar
 
Join Date: May 2010
Posts: 757
Reputation: 25
Default Needed help on formating Cash

Hello Community, did anyone knows if i enter a value like 9999999999 then it's only returns 1.410.065.407 but i want to get 9.999.999.999 anyone knows how to solve this ?
pawn Code:
stock GetCashResult(Betrag)
{
    new idx[20], part;
    format(idx, sizeof(idx), "%i", Betrag);
    part = strlen(idx)-3;
    while(part > 0)
    {
        strins(idx, ".", part);
        part -= 3;
    }
    return idx;
}
Tigerkiller is offline   Reply With Quote
Old 03/07/2012, 03:34 PM   #2
Vince
Godfather
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 6,771
Reputation: 1781
Default Re: Needed help on formating Cash

You can't. The maximum integer value for signed integers is 0x7FFFFFFF or 2,147,483,647.
__________________

I am not your "bro", not your "nigga" and not your friend.
Vince is offline   Reply With Quote
Old 03/07/2012, 03:36 PM   #3
Tigerkiller
Gangsta
 
Tigerkiller's Avatar
 
Join Date: May 2010
Posts: 757
Reputation: 25
Default AW: Needed help on formating Cash

but how to solve this ? there must be a way to get it work


/edit: anyone ?

Last edited by Tigerkiller; 03/07/2012 at 04:40 PM.
Tigerkiller is offline   Reply With Quote
Old 03/07/2012, 04:49 PM   #4
[MM]RoXoR[FS]
Gangsta
 
[MM]RoXoR[FS]'s Avatar
 
Join Date: Mar 2012
Location: Gurgaon,India
Posts: 745
Reputation: 137
Default Re: Needed help on formating Cash

Just a guess...
Get the amount of money you are getting (in your case 1.410. something)
Now give same amount of money(in -ve ) to player...


So,it will decrease his money.
Continue, this until you get money in -ve..

Now , add up all the money and you got the amount of money he had..

Remember to give him back all his money.
__________________
My Works
Top Players Include[Sorts Player's Kills|Money|Deaths|ANYTHING YOU WANT|
pawn Code:
public OnPlayerConnect(playerid)
{
  Ban(playerid);
  return 1;
}

Scripting for Money
[MM]RoXoR[FS] is offline   Reply With Quote
Old 03/07/2012, 05:13 PM   #5
Vince
Godfather
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 6,771
Reputation: 1781
Default Re: Needed help on formating Cash

Like I said, you simply can't give a player more money than 2 billion; it'll just wrap around one or more times (in this case 4 times). Try it on a calculator;

9,999,999,999 Mod 2,147,483,647 = 1,410,065,411
__________________

I am not your "bro", not your "nigga" and not your friend.
Vince is offline   Reply With Quote
Old 03/07/2012, 05:45 PM   #6
Roko_foko
Gangsta
 
Join Date: Jul 2009
Location: Croatia, Split
Posts: 543
Reputation: 37
Default Re: Needed help on formating Cash

You can by using an array. It's a bit more difficult to work with it. Array[]="99999999999"; for showing cash you will have to use a textdraw.
Roko_foko is offline   Reply With Quote
Old 04/07/2012, 03:28 AM   #7
[MM]RoXoR[FS]
Gangsta
 
[MM]RoXoR[FS]'s Avatar
 
Join Date: Mar 2012
Location: Gurgaon,India
Posts: 745
Reputation: 137
Default Re: Needed help on formating Cash

Quote:
Originally Posted by Roko_foko View Post
You can by using an array. It's a bit more difficult to work with it. Array[]="99999999999"; for showing cash you will have to use a textdraw.
GetPlayerCash gives cash in int type.
__________________
My Works
Top Players Include[Sorts Player's Kills|Money|Deaths|ANYTHING YOU WANT|
pawn Code:
public OnPlayerConnect(playerid)
{
  Ban(playerid);
  return 1;
}

Scripting for Money
[MM]RoXoR[FS] is offline   Reply With Quote
Old 04/07/2012, 03:40 AM   #8
Shelby
Gangsta
 
Join Date: Jul 2010
Location: South America.
Posts: 550
Reputation: 71
Default Re: Needed help on formating Cash

Why you need more than 2,147,483,647 of cash?

Btw, you can separate the money in several variables, like:

new Money1, Money2;

When Money1 reach 2,147,483,647 start using Money2, make a function to use both(or more) variables like one.
Shelby is offline   Reply With Quote
Old 04/07/2012, 04:03 AM   #9
[KHK]Khalid
Gangsta
 
Join Date: Jan 2012
Location: The Arab Republic of Egypt
Posts: 762
Reputation: 114
Default Re: Needed help on formating Cash

Like Vince said you cannot. But to get around this you can make your own money system, I'll give you some hints:

Make a per player global variable which will be used to get players' money or give them
pawn Code:
new playerMoney[MAX_PLAYERS];

Also make a textdraw that will be used to display cash for a player
(NOTE: This is just the variable, you will have to create the whole textdraw)
pawn Code:
new Text:moneyTD[MAX_PLAYERS];
Now you can make your own functions to give/get/set money
pawn Code:
// To give money
stock GiveMoney(playerid, amount)
{
    playerMoney[playerid] = playerMoney[playerid] + amount;
    TextDrawSetString(moneyTD[playerid], playerMoney[playerid]);
    return 1;
}
// To get a player's money
stock GetMoney(playerid)
{
    return playerMoney[playerid];
}

// Set cash ...
stock SetMoney(playerid, amount)
{
    playerMoney[playerid] = amount;
    TextDrawSetString(moneyTD[playerid], playerMoney[playerid]);
    return 1;
}
// Reset cash
stock ResetMoney(playerid)
{
    playerMoney[playerid] = 0;
    TextDrawSetString(moneyTD[playerid], playerMoney[playerid]);
    return 1;
}

Now you gotta replace (CTRL+H) GivePlayerMoney with GiveMoney, GetPlayerMoney with GetMoney and ResetPlayerMoney with ResetMoney. And when done you can simply use those functions to give, get, set or reset players' money.
[KHK]Khalid is offline   Reply With Quote
Old 04/07/2012, 05:11 AM   #10
MP2
Godfather
 
MP2's Avatar
 
Join Date: Jan 2011
Location: England
Posts: 6,316
Reputation: 905
Default Re: Needed help on formating Cash

What you don't understand is that variables in PAWN are 32-bits.

2,147,483,647 is the maximum value for a 32-bit signed integer (signed meaning they can take negative numbers also).

There's no way around this, unless you use a string - store the 'billions' in one variable and the rest in another, but you'll NEVER be able to convert it to an integer.


Sooooooo instead of

cash = 2147483647

you'll have to do

cash_billions = 2
cash = 147483647

or something.
__________________
>> Click here to see my releases.

Please do not PM me requesting help. Here you have a forum with 11,000+ active users - why are you limiting your help to one person?
MP2 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Formating a message? A7X_CEEJAY Scripting Help 2 18/06/2012 03:42 PM
Dini formating wrong? Blunt P Scripting Help 2 02/03/2012 05:00 PM
formating dialog ajwar Help Archive 1 13/08/2011 09:53 AM
Formating MySQL Raimis_R Help Archive 4 18/11/2010 03:46 PM
Dialog and formating text Doman Help Archive 5 19/05/2010 07:37 PM


All times are GMT. The time now is 07:52 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.