Needing help on a script
#1

hello,
its me yvoms,
I need a little bit of help

i have this code :

Код:
CMD:transfer(playerid,params[])
{
	new string[128],ID,cmdreason;
	if(sscanf(params, "dd", ID, cmdreason))
	{
	    SendClientMessage(playerid,COLOR_ERROR,"USAGE: /transfer (id) (Amount)");
	    return 1;
	}
	if(PlayerInfo[playerid][Spawned] != 1)
    {
        SendClientMessage(playerid,COLOR_ERROR,"You must be alive and spawned in order to be able to use this command.");
        return 1;
	}
	if(PlayerInfo[playerid][IsKidnapped] == 1)
	{
	    SendClientMessage(playerid,COLOR_ERROR,"You are kidnapped. You cannot use this command.");
	    return 1;
	}
	if(!IsPlayerInDynamicCP(playerid,CP_BankMain) )
	{
	    SendClientMessage(playerid,COLOR_ERROR,"You must be in the bank checkpoint in order to transfer money to someone's account.");
	    return 1;
	}
	if(!IsPlayerConnected(ID))
	{
		format(string,sizeof(string),"The Player ID (%d) is not connected to the server. You cannot tranfer money to them.",ID);
        SendClientMessage(playerid,COLOR_ERROR,string);
		return 1;
	}
	if(ID == playerid)
	{
	    SendClientMessage(playerid,COLOR_ERROR,"You cannot transfer funds to your own bank account. Why would you waste my time?");
	    return 1;
	}
	if(BankCash[playerid] < cmdreason)
	{
	    SendClientMessage(playerid,COLOR_ERROR,"You do not have the sufficient funds in your bank account to transfer this amount.");
	    return 1;
	}
	BankCash[ID] +=cmdreason;
	format(string,sizeof(string),"[BANK ACTION] %s(%d) has transfered $%d to your bank account. Your new balance is $%d.",PlayerName(playerid),playerid,cmdreason,BankCash[ID]);
	SendClientMessage(ID,COLOR_LIGHTBLUE,string);

	BankCash[playerid] -=cmdreason;
	format(string,sizeof(string),"Account Holder: %s(%d).\nBranch Location: San Fierro.\nFunds Transfered: $%d.\nTransfered to: %s(%d).\nNew Balance: $%s.",PlayerName(playerid),playerid,cmdreason,PlayerName(ID),ID,BankCash[playerid]);
	ShowPlayerDialog(playerid,DIALOG_BANK_BALANCE,DIALOG_STYLE_MSGBOX,"Bank Balance",string,"Ok","Cancel");
	return 1;
}
Its for transferring money. (scanffd)
But it seems that players are possible to send Negative amounts of money,
Someone help me on this one please
Reply
#2

For example,
I type /transfer 1 1000
Then it sends 1000 to the player with id 1,
But if i type /transfer 1 -1000
Then it takes 1000 from the playerid's account
and puts it on my account.
Reply
#3

Can't you just check if cmdreason < 0? If so don't allow transaction.

pawn Код:
CMD:transfer(playerid,params[])
{
    new string[128],ID,cmdreason;
    if(sscanf(params, "ud", ID, cmdreason))
    {
        SendClientMessage(playerid,COLOR_ERROR,"USAGE: /transfer (id/name) (Amount)");
        return 1;
    }
   
    if( cmdreason < 0 )
    {
        SendClientMessage(playerid,COLOR_ERROR,"ERROR: Cannot tranfer negative amount.");
        return 1;
    }
   
    //... rest of stuff
   
    return 1;
}
EDIT: Changed your sscanf line to use the 'u' specifier too. Now you can do /transfer [name][amount] aswell as id.
Reply
#4

Im new to pawno mate,
I didn't get a thing of what you just told me xD
Reply
#5

In other words, check to see if the money the player is typing is less than zero by doing this.
pawn Код:
if(cmdreason < 0) // If the money the player typed is less than Zero.
{
    // Then it sends them a message and stops processing the command.
    SendClientMessage(playerid, -1, "You cannot give negative amounts.");
    return 1;
}
Reply
#6

so it would be like this?

Код:
CMD:transfer(playerid,params[])
{
	new string[128],ID,cmdreason;
	if(sscanf(params, "ud", ID, cmdreason))
	{
	    SendClientMessage(playerid,COLOR_ERROR,"USAGE: /transfer (id) (Amount)");
	    return 1;
	}
	if(PlayerInfo[playerid][Spawned] != 1)
    {
        SendClientMessage(playerid,COLOR_ERROR,"You must be alive and spawned in order to be able to use this command.");
        return 1;
	}
	if(PlayerInfo[playerid][IsKidnapped] == 1)
	{
	    SendClientMessage(playerid,COLOR_ERROR,"You are kidnapped. You cannot use this command.");
	    return 1;
	}
	if(!IsPlayerInDynamicCP(playerid,CP_BankMain) )
	{
	    SendClientMessage(playerid,COLOR_ERROR,"You must be in the bank checkpoint in order to transfer money to someone's account.");
	    return 1;
	}
	if(!IsPlayerConnected(ID))
	{
		format(string,sizeof(string),"The Player ID (%d) is not connected to the server. You cannot tranfer money to them.",ID);
        SendClientMessage(playerid,COLOR_ERROR,string);
		return 1;
	}
	if(ID == playerid)
	{
	    SendClientMessage(playerid,COLOR_ERROR,"You cannot transfer funds to your own bank account. Why would you waste my time?");
	    return 1;
	}
	if(BankCash[playerid] < cmdreason)
	{
	    SendClientMessage(playerid,COLOR_ERROR,"You do not have the sufficient funds in your bank account to transfer this amount.");
	    return 1;
	}
	if(cmdreason < 0) // If the money the player typed is less than Zero.
	{
    // Then it sends them a message and stops processing the command.
    SendClientMessage(playerid, -1, "You cannot give negative amounts.");
    return 1;
	}
	BankCash[ID] +=cmdreason;
	format(string,sizeof(string),"[BANK ACTION] %s(%d) has transfered $%d to your bank account. Your new balance is $%d.",PlayerName(playerid),playerid,cmdreason,BankCash[ID]);
	SendClientMessage(ID,COLOR_LIGHTBLUE,string);

	BankCash[playerid] -=cmdreason;
	format(string,sizeof(string),"Account Holder: %s(%d).\nBranch Location: San Fierro.\nFunds Transfered: $%d.\nTransfered to: %s(%d).\nNew Balance: $%s.",PlayerName(playerid),playerid,cmdreason,PlayerName(ID),ID,BankCash[playerid]);
	ShowPlayerDialog(playerid,DIALOG_BANK_BALANCE,DIALOG_STYLE_MSGBOX,"Bank Balance",string,"Ok","Cancel");
	return 1;
}
Reply
#7

Bump?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)