onplayertext value? -
Admigo - 28.11.2011
Heey all,
How can i make if you enter a value(onplayertext) and you are in menu(variable) you can deposit money?
So when i am at menu and i enter 6642 , i am depositing 6642 dollar to the bank.
Thanks Admigo
Re: onplayertext value? -
Ash. - 28.11.2011
How are you storing the fact that the player is in a menu? (Aside from it being in a variable)
+ How do you deposit money to the bank in the first place?
Re: onplayertext value? -
Admigo - 28.11.2011
This is my deposit command:
Код:
dcmd_deposit(playerid,params[])
{
new deposit;
new file[100],Name[MAX_PLAYER_NAME]; GetPlayerName(playerid,Name,sizeof(Name)); format(file,sizeof(file),PlayerFile,Name);
if(sscanf(params,"d",deposit)) return SendClientMessage(playerid,COLOR_RED,"USAGE:/deposit [Amount]");
else if(deposit > GetPlayerMoney(playerid)) return SendClientMessage(playerid,COLOR_RED,"You Don't Have That Amount!");
else if(deposit < 0) return SendClientMessage(playerid,COLOR_RED,"Invalid Amount!");
{
}
GivePlayerMoney(playerid,-deposit);
pInfo[playerid][Deposit] += deposit;
dini_IntSet(file,"Deposit",pInfo[playerid][Deposit]);
SendClientMessage(playerid,COLOR_GREEN,"BANK");
new string[128]; format(string,sizeof(string),"You Have Deposited : %d$",deposit);
SendClientMessage(playerid,COLOR_LIGHTBLUE,string);
dini_IntSet(file,"Deposit",pInfo[playerid][Deposit]);
new string2[128]; format(string2,128,"Your New Balance Is : %d$",pInfo[playerid][Deposit]);
SendClientMessage(playerid,COLOR_LIGHTBLUE,string2);
return 1;
}
I just want to let it store if you are in bankmenu.if(Bankmenu[playerid]==1) and you enter a amount in text ,not in command.
Re: onplayertext value? -
Ash. - 28.11.2011
Well, instead of re-creating that and all text, you could actually just pass the text recieved from OnPlayerText to the command when Bankmenu[playerid] is equal to 1.
Like so:
pawn Код:
public OnPlayerText(playerid, text[])
{
if(Bankmenu[playerid] && IsNumeric(text)) dcmd_deposit(playerid, text);
else SendClientMessage(playerid, COLOUR, "You need to enter a numeric value that is above 0.");
//Rest of OPT
}
You will need IsNumeric, for that though. (To check if it is numeric and doesn't contain letters aswell - ie, "asforg213")
pawn Код:
/*IsNumeric, by Slice*/
stock IsNumeric( const szString[ ] )
{
if ( !szString[ 0 ] )
return false;
new
iLength = strlen( szString ),
i
;
if ( szString[ 0 ] == '-' && szString[ 1 ] )
i = 1;
for ( ; i < iLength; i++ )
{
if ( !( '0' <= szString[ i ] <= '9' ) )
return false;
}
return true;
}
Re: onplayertext value? -
Admigo - 28.11.2011
If i typ something if i am not in menu i get the error message that the num needs to be higher then 0.
Re: onplayertext value? -
Ash. - 28.11.2011
Ah..
Try this instead:
pawn Код:
public OnPlayerText(playerid, text[])
{
if(Bankmenu[playerid])
{
if(!IsNumeric(text)) return SendClientMessage(playerid, COLOUR, "You need to enter a numeric value that is above 0.");
dcmd_deposit(playerid, text);
return 0; //Don't allow OPT to continue any further.
}
//Rest of OPT
}
I should of noticed that!
Re: onplayertext value? -
Admigo - 28.11.2011
Thnks dude,if bankmenu[playerid]=0 you can deposit anymore?
Re: onplayertext value? -
Ash. - 28.11.2011
Quote:
Originally Posted by admigo
Thnks dude,if bankmenu[playerid]=0 you can deposit anymore?
|
Nope, you will have to make Bankmenu[playerid] equal to 1 to deposit any more!
Edit: You may want to make Bankmenu[playerid] equal 0 after the command is called, just realised that you don't neutralize it in the command.
Re: onplayertext value? -
Admigo - 28.11.2011
Thank you dude for your help! This works great!
Re: onplayertext value? -
Ash. - 28.11.2011
No problem
Here to help!