dcmd_transferir(playerid,params[])
{
new Index;
new tmp[256]; tmp = strtok(params,Index);
new tmp2[256]; tmp2 = strtok(params,Index);
new player1 = ReturnUser(tmp);
if(IsPlayerConnected(player1))
{
new cash = strval(tmp2);
if(player1 == playerid) return SendClientMessage(playerid,COLOR_RED,"No te puedes transferir a ti mismo");
if(!IsRangeToBank(playerid)) return SendClientMessage(playerid,COLOR_RED,"No estas en un banco");
if(pInfo[playerid][Balance] < cash) return SendClientMessage(playerid,COLOR_RED,"No tienes esa cantidad en el banco");
if(!strlen(tmp) || !strlen(tmp2) || !IsNumeric(tmp2)) return SendClientMessage(playerid,COLOR_RED,"Usa: /transferir [ID/Nombre] [Cantidad]");
pInfo[playerid][Balance] -= cash;
pInfo[player1][Balance] += cash;
new string[128];
format(string,sizeof(string),"Transferiste %d$ a %s ",cash, pName(player1));
SendClientMessage(playerid,COLOR_YELLOW,string);
new file[100];
dini_IntSet(file,"Deposit",pInfo[playerid][Balance]);
new string2[128]; format(string2,128,"Tu nuevo balance es %d$",pInfo[playerid][Balance]);
SendClientMessage(playerid,color,string2);
new string3[128]; format(string3,128,"%s (%d) te transfiriу $%d a tu cuenta",pName(playerid),playerid,cash);
SendClientMessage(player1,COLOR_YELLOW,string3);
new string4[128]; format(string4,128,"Tu nuevo balance es: %d$",pInfo[chosenpid][Balance]);
SendClientMessage(player1,color,string4);
}
else return SendClientMessage(playerid,COLOR_RED,"Jugador no conectado o nombre no encontrado.");
return 1;
}
stock ReturnUser(text[], playerid = INVALID_PLAYER_ID)
{
new pos = 0;
while (text[pos] < 0x21) // Strip out leading spaces
{
if (text[pos] == 0) return INVALID_PLAYER_ID; // No passed text
pos++;
}
new userid = INVALID_PLAYER_ID;
if (IsNumeric(text[pos])) // Check whole passed string
{
// If they have a numeric name you have a problem (although names are checked on id failure)
userid = strval(text[pos]);
if (userid >=0 && userid < MAX_PLAYERS)
{
if(!IsPlayerConnected(userid))
{
userid = INVALID_PLAYER_ID;
}
else
{
return userid; // A player was found
}
}
}
// They entered [part of] a name or the id search failed (check names just incase)
new len = strlen(text[pos]);
new count = 0;
new name[MAX_PLAYER_NAME];
for (new i = 0; i < MAX_PLAYERS; i++)
{
if (IsPlayerConnected(i))
{
GetPlayerName(i, name, sizeof (name));
if (strcmp(name, text[pos], true, len) == 0) // Check segment of name
{
if (len == strlen(name)) // Exact match
{
return i; // Return the exact player on an exact match
}
else // Partial match
{
count++;
userid = i;
}
}
}
}
if (count != 1)
{
if (playerid != INVALID_PLAYER_ID)
{
if (count)
{
SendClientMessage(playerid, 0xFF0000AA, "Multiple users found, please narrow search.");
}
else
{
SendClientMessage(playerid, 0xFF0000AA, "No matching user found.");
}
}
userid = INVALID_PLAYER_ID;
}
return userid; // INVALID_PLAYER_ID for bad return
}
Es verdad, te recomiendo usar el plugin sscanf y zcmd que son mбs sencillos que el strcmp, strtok y todo eso.
|
if(strcmp(cmd, "/dardinero", true) == 0) {
new tmp[256];
tmp = strtok(cmdtext, idx);
if(!strlen(tmp)) {
SendClientMessage(playerid, COLOR_WHITE, "USO: /dardinero [playerid] [Cantidad]");
return 1;
}
giveplayerid = strval(tmp);
tmp = strtok(cmdtext, idx);
if(!strlen(tmp)) {
SendClientMessage(playerid, COLOR_WHITE, "USO: /dardinero [playerid] [Cantidad]");
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), "Has enviado a %s (id: %d)la cantidad de $%d.", giveplayer,giveplayerid, moneys);
SendClientMessage(playerid, COLOR_YELLOW, string);
format(string, sizeof(string), "Tu has recivido $%d de %s (id: %d).", moneys, sendername, playerid);
SendClientMessage(giveplayerid, COLOR_YELLOW, string);
printf("%s(playerid:%d) has transferido %d a %s(playerid:%d)",sendername, playerid, moneys, giveplayer, giveplayerid);
}
else {
SendClientMessage(playerid, COLOR_YELLOW, "Transaccion invalida.");
}
}
else {
format(string, sizeof(string), "El jugador %d no esta conectado.", giveplayerid);
SendClientMessage(playerid, COLOR_YELLOW, string);
}
return 1;
}