12.08.2012, 13:07
Olб gostava que alguйm me pudesse dizer como й que se faz um comando de transferencia de Dinheiro entre jogadores. Do gйnero /transferкncia [id do player] [quantidade de grana]
CMD:transferencia(playerid, params[])
{
new id;
new grana;
if(GetPlayerMoney(playerid) >= grana)
{
GivePlayerMoney(playerid, -grana);
GivePlayerMoney(id, grana);
}
SendClientMessage(playerid, -1, "Voce nao tem essa Grana");
return 1;
}
pawn Code:
|
if(strcmp(cmd, "/givecash", true) == 0) {
new tmp[256];
tmp = strtok(cmdtext, idx);
if(!strlen(tmp)) {
SendClientMessage(playerid, COLOR_WHITE, "USAGE: /givecash [playerid] [amount]");
return 1;
}
giveplayerid = strval(tmp);
tmp = strtok(cmdtext, idx);
if(!strlen(tmp)) {
SendClientMessage(playerid, COLOR_WHITE, "USAGE: /givecash [playerid] [amount]");
return 1;
}
moneys = strval(tmp);
//printf("givecash_command: %d %d",giveplayerid,moneys);
if (IsPlayerConnected(giveplayerid)) {
GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
GetPlayerName(playerid, sendername, sizeof(sendername));
playermoney = GetPlayerMoney(playerid);
if (moneys > 0 && playermoney >= moneys) {
GivePlayerMoney(playerid, (0 - moneys));
GivePlayerMoney(giveplayerid, moneys);
format(string, sizeof(string), "You have sent %s(player: %d), $%d.", giveplayer,giveplayerid, moneys);
SendClientMessage(playerid, COLOR_YELLOW, string);
format(string, sizeof(string), "You have recieved $%d from %s(player: %d).", moneys, sendername, playerid);
SendClientMessage(giveplayerid, COLOR_YELLOW, string);
printf("%s(playerid:%d) has transfered %d to %s(playerid:%d)",sendername, playerid, moneys, giveplayer, giveplayerid);
}
else {
SendClientMessage(playerid, COLOR_YELLOW, "Invalid transaction amount.");
}
}
else {
format(string, sizeof(string), "%d is not an active player.", giveplayerid);
SendClientMessage(playerid, COLOR_YELLOW, string);
}
return 1;
}
YCMD:transferencia(playerid, params[], help)
{
new targetid, value;
if(sscanf(params, "ud", targetid, value))
return SendClientMessage(playerid, -1, "* /transferencia [playerid] [quantia]");
if(targetid == INVALID_PLAYER_ID || !IsPlayerConnected(targetid))
return SendClientMessage(playerid, -1, "* Jogador nгo conectado.");
if(GetPlayerMoney(playerid) < value)
return SendClientMessage(playerid, -1, "* Vocк nгo tem essa quantia.");
GivePlayerMoney(playerid, -value);
GivePlayerMoney(targetid, value);
return 1;
}
CMD:transferir(playerid, params[]){
new Grana, pname[45], gname[45],Xd;
GetPlayerName(playerid, gname, sizeof(pname));
GetPlayerName(playerid, pname, sizeof(pname));
if(sscanf(params, "dd", Xd, Grana)) return SendClientMessage(playerid, -1, "Use: /Transferir [ID]);
if(GivePlayerMoney < Grana) return SendClientMessage(playerid, -1, "Erro: Voce Nгo Tem Essa Grana");
GivePlayerMoney(playerid, -Grana);
GivePlayerMoney(Xd, Grana);
format(string, sizeof(string), "Voce Transferiu Grana Para O Jogador %s", gname);
SendClientMessage(playerid, -1, string);
format(string, sizeof(string), "Voce Recebeu Grana Do Jogador %s", pname);
SendClientMessage(Xd, -1, string);
return 1;
}
YCMD:transferencia(playerid, params[], help)
{
new targetid, value, str[128], str1[128];
if(sscanf(params, "ud", targetid, value))
return SendClientMessage(playerid, -1, "* /transferencia [playerid] [quantia]");
if(targetid == INVALID_PLAYER_ID || !IsPlayerConnected(targetid))
return SendClientMessage(playerid, -1, "* Jogador nгo conectado.");
if(GetPlayerMoney(playerid) < value)
return SendClientMessage(playerid, -1, "* Vocк nгo tem essa quantia.");
GivePlayerMoney(playerid, -value);
GivePlayerMoney(targetid, value);
format(str, sizeof(str), "[Transferкncia] O jogador %s transferiu %d de dinheiro para sua conta", GetPlayerName(playerid), value);
format(str1, sizeof(str1), "[Transferкncia] Vocк transferiu %d de dinheiro para a conta de %s", value, GetPlayerName(targetid);
SendClientMessage(playerid, -1, str1);
SendClientMessage(targetid, -1, str);
return 1;
}
Los, fiz uma alteraзгo em seu codigo:
pawn Code:
|
YCMD:transferencia(playerid, params[], help)
{
new targetid, value, str[128];
if(sscanf(params, "ud", targetid, value))
return SendClientMessage(playerid, -1, "* /transferencia [playerid] [quantia]");
if(targetid == INVALID_PLAYER_ID || !IsPlayerConnected(targetid))
return SendClientMessage(playerid, -1, "* Jogador nгo conectado.");
if(GetPlayerMoney(playerid) < value)
return SendClientMessage(playerid, -1, "* Vocк nгo tem essa quantia.");
GivePlayerMoney(playerid, -value);
GivePlayerMoney(targetid, value);
format(str, sizeof(str), "[Transferкncia] O jogador %s transferiu %d de dinheiro para sua conta", GetPlayerName(playerid), value);
SendClientMessage(playerid, -1, str);
format(str, sizeof(str), "[Transferкncia] Vocк transferiu %d de dinheiro para a conta de %s", value, GetPlayerName(targetid);
SendClientMessage(targetid, -1, str);
return 1;
}
Nгo precisa criar 2 string. Basta usar apenas 1.
Vejб: pawn Code:
|
Los, fiz uma alteraзгo em seu codigo:
pawn Code:
|
YCMD:transferencia(playerid, params[], help)
{
new targetid, value;
if(sscanf(params, "ud", targetid, value))
return SendClientMessage(playerid, -1, "* /transferencia [playerid] [quantia]");
if(targetid == INVALID_PLAYER_ID || !IsPlayerConnected(targetid))
return SendClientMessage(playerid, -1, "* Jogador nгo conectado.");
if(GetPlayerMoney(playerid) < value)
return SendClientMessage(playerid, -1, "* Vocк nгo tem essa quantia.");
GivePlayerMoney(playerid, -value);
GivePlayerMoney(targetid, value);
new targetname[MAX_PLAYER_NAME]; GetPlayerName(targetid, targetname, MAX_PLAYER_NAME);
new playername[MAX_PLAYER_NAME]; GetPlayerName(playerid, playername, MAX_PLAYER_NAME);
new str[128], str2[128];
format(str, sizeof(str), "[Transferкncia] O jogador %s transferiu $%d para sua conta", playername, value);
format(str2, sizeof(str2), "[Transferкncia] Vocк transferiu $%d para a conta de %s", value, targetname);
SendClientMessage(targetid, -1, str);
SendClientMessage(playerid, -1,str2);
return 1;
}