CMD:transfer(playerid, params[]){
new id, amount, cash;
if(sscanf(params,"ui", id, amount))
return SendClientMessage(playerid, 0xCECECEFF, "CMD: /transfer [player] [amount]");
if(!IsPlayerConnected(id))
return SendClientMessage(playerid, 0xCECECEFF, "Player is not connected");
cash = GetPlayerMoney(playerid);
if(amount > cash)
return SendClientMessage(playerid, 0xCECECEFF, "You do not have that much!");
if(amount < 1)
return SendClientMessage(playerid, 0xCECECEFF, "You can not transfer funds under 1!");
GivePlayerMoney(playerid, -amount);
GivePlayerMoney(id, amount);
SendClientMessage(playerid, 0xCECECEFF, "You sent the money.");
SendClientMessage(id, 0xCECECEFF, "You got given money.");
return 1;
}
stock IsNumeric(const string[]) { for (new i = 0, j = strlen(string); i < j; i++) if (string[i] > '9' || string[i] < '0') return 0; return 1; } ReturnUser(text[], playerid = INVALID_PLAYER_ID) { new pos = 0; while (text[pos] < 0x21) { if (text[pos] == 0) return INVALID_PLAYER_ID; pos++; } new userid = INVALID_PLAYER_ID; if (IsNumeric(text[pos])) { userid = strval(text[pos]); if (userid >=0 && userid < MAX_PLAYERS) { if(!IsPlayerConnected(userid)) userid = INVALID_PLAYER_ID; else return userid; } } new len = strlen(text[pos]); new count = 0; new pname[MAX_PLAYER_NAME]; for (new i = 0; i < MAX_PLAYERS; i++) { if (IsPlayerConnected(i)) { GetPlayerName(i, pname, sizeof (pname)); if (strcmp(pname, text[pos], true, len) == 0) { if (len == strlen(pname)) return i; else { count++; userid = i; } } } } if (count != 1) { if (playerid != INVALID_PLAYER_ID) { if (count) SendClientMessage(playerid, 0xFF0000AA, "Please type the player's full name."); else SendClientMessage(playerid, 0xFF0000AA, "The Player's name has not been found."); } userid = INVALID_PLAYER_ID; } return userid; } stock strvalEx( const string[] ) { //Register Protection if( strlen( string ) >= 50 ) return 0; return strval(string); } stock strtok(const string[], &index) { new length = strlen(string); while ((index < length) && (string[index] <= ' ')) { index++; } new offset = index; new result[20]; while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1))) { result[index - offset] = string[index]; index++; } result[index - offset] = EOS; return result; } public OnPlayerCommandText(playerid, cmdtext[]) { new cmd[256],string[248]; new tmp[256]; new idx; cmd = strtok(cmdtext, idx); if(strcmp(cmd, "/pay", true) == 0) { tmp = strtok(cmdtext,idx); if(strlen(tmp)) { new giveplayerid = ReturnUser(tmp); if(IsPlayerConnected(giveplayerid) && !IsPlayerNPC(giveplayerid)) { if(giveplayerid == playerid) { SendClientMessage(playerid,0xFF0000AA," You can't pay yourself."); return 1; } tmp = strtok(cmdtext,idx); new cash = strvalEx(tmp); if(cash < 1 || cash > 999999) { SendClientMessage(playerid,0xFFFFFFAA," Given cash can't be lower than 1 or above 10.000$."); return 1; } if(GetPlayerMoney(playerid) >= cash) { new pName[MAX_PLAYER_NAME], giveplayername[MAX_PLAYER_NAME]; GetPlayerName(playerid, pName,sizeof(pName)); GetPlayerName(giveplayerid, giveplayername, sizeof(giveplayername)); format(string,sizeof(string)," You have received {58A624}%d$ {FFFFFF}from {58A624}%s{FFFFFF}.",cash,pName); SendClientMessage(giveplayerid,0xFFFFFFAA,string); format(string,sizeof(string)," You have given {58A624}%d$ {FFFFFF}to {58A624}%s{FFFFFF}.",cash,giveplayername); SendClientMessage(playerid,0xFFFFFFAA,string); GivePlayerMoney(playerid,-cash); GivePlayerMoney(giveplayerid,cash); } else { SendClientMessage(playerid,0xFF0000AA," You don't have that money."); } } else { SendClientMessage(playerid,0xFF0000AA," The Player is not connected."); } } else { SendClientMessage(playerid,0xFF0000AA," Usage: /pay [playerid/playername] [money]"); } return 1; } return 0; }
What errors? You have to add everything I pasted you, not only the OnPlayerCommandText.
|
public OnPlayerCommandText(playerid, cmdtext[]) {
if(!strcmp(cmdtext, "transfer", true)) {
new
id,
amount,
cash;
if(sscanf(params,"ui", id, amount))
return SendClientMessage(playerid, 0xCECECEFF, "CMD: /transfer [player] [amount]");
if(!IsPlayerConnected(id))
return SendClientMessage(playerid, 0xCECECEFF, "Player is not connected");
cash = GetPlayerMoney(playerid);
if(amount > cash)
return SendClientMessage(playerid, 0xCECECEFF, "You do not have that much!");
if(amount < 1)
return SendClientMessage(playerid, 0xCECECEFF, "You can not transfer funds under 1!");
GivePlayerMoney(playerid, -amount);
GivePlayerMoney(id, amount);
SendClientMessage(playerid, 0xCECECEFF, "You sent the money.");
SendClientMessage(id, 0xCECECEFF, "You got given money.");
return 1;
}
return 0;
}
Why are you promoting the use of even more deprecated, outdated and inefficient functions than OnPlayerCommandText? Sure, it's good to know about them, but the use of them should be avoided at all times!
Use this: PHP код:
|