Player id problem
#1

PHP код:
CMD:givecash(playeridparams[])
{
    new 
targetidamountname[MAX_PLAYER_NAME], tname[MAX_PLAYER_NAME], string[128], string1[128];
    
GetPlayerName(playeridnamesizeof(name));
    
GetPlayerName(targetidtnamesizeof(tname));
    if (
sscanf(params"ud"targetidamount)) SendClientMessage(playerid, -1"SERVER(S): /givecash <playerid/name> <amount>");
    else if(!
IsPlayerConnected(targetid) || targetid == playerid) return SendClientMessage(playerid, -1"SERVER{ff0000}(E){FFFFFF}: Target ID is offline/yourself.");
    else if (
amount GetPlayerMoney(playerid)) SendClientMessage(playerid, -1"SERVER{ff0000}(E){FFFFFF}: You don't have enough money to send.");
    else if (
amount 100000SendClientMessage(playerid, -1"SERVER{ff0000}(E){FFFFFF}: You can't send more than $100,000 at once!");
    else if (
amount 1SendClientMessage(playerid, -1"SERVER{ff0000}(E){FFFFFF}: Your amount value should be between 1 to 100,000.");
    else
    {
        
GivePlayerMoney(targetidamount);
        
GivePlayerMoney(playerid, -amount);
          
format(stringsizeof(string), "~g~+%d$"amount);
        
GameTextForPlayer(playeridstring30001);
        
format(stringsizeof(string), "- {FFF2E7}%s(%d) has sent you '%d$'."nameplayeridamount);
        
SendClientMessage(targetid, -1string);
        
format(stringsizeof(string), "~r~-%d$"amount);
        
GameTextForPlayer(playeridstring30001);
        
format(string1sizeof(string1), "- {FFF2E7}You've sent '%d$' to %s(%d)"amounttnametargetid);
        
SendClientMessage(playerid, -1string1);
    }
    return 
1;

Log (from ID 1):
- You've sent Peyote (0) 1$.
- Peyote (0) has sent you 100$.

Log (from ID 0):
- Airmesh(1) has sent you 1$.
- You've sent Peyote(1) 1$.

ID is showing correctly but name is having problems from ID 0.
Reply
#2

First you need to use sscanf, verify the targetid is connected and then get the name.

If you get the name before the sscanf line, targetid is 0 by default.
Reply
#3

Try using a stock for getting the player's name, useful for further scripts

PHP код:
stock ReturnName(playerid)
{
    new 
string[MAX_PLAYER_NAME];
    
GetPlayerName(playeridstringsizeof(string));
    return 
string;

Then you can simply ReturnName(playerid) || ReturnName(targetid)
Reply
#4

PHP код:
CMD:givecash(playeridparams[]) 

    if(
sscanf(params"ud"params[0], params[1])) return SendClientMessage(playerid, -1"SERVER(S): /givecash <playerid/name> <amount>"); 
    if(!
IsPlayerConnected(params[0]) || playerid == params[0]) return SendClientMessage(playerid, -1"SERVER{ff0000}(E){FFFFFF}: Target ID is offline/yourself.");
    if(
params[1] > 100000 || params[1] <= 0) return SendClientMessage(playerid, -1"SERVER{ff0000}(E){FFFFFF}: Your amount value should be between $1 to $100,000.");
    if(
params[1] > GetPlayerMoney(playerid)) return SendClientMessage(playerid, -1"SERVER{ff0000}(E){FFFFFF}: You don't have enough money to send.");
    
GivePlayerMoney(playerid, -params[1]);
    
GivePlayerMoney(params[0], params[1]);
    
    new 
string[145];
    
format(stringsizeof(string), "~g~+%d$"params[1]);
    
GameTextForPlayer(params[0], string30001);
    
format(stringsizeof(string), "~r~-%d$"params[1]);
    
GameTextForPlayer(playeridstring30001);
    
    
format(stringsizeof(string), "- {FFF2E7}%s(%d) has sent you '%d$'."GetName(playerid), playeridparams[1]);  SendClientMessage(params[0], -1string); 
    
format(stringsizeof(string), "- {FFF2E7}You've sent '%d$' to %s(%d)"params[1], GetName(params[0]), params[0]); SendClientMessage(playerid, -1string); 
    return 
1
}
stock GetName(playerid)
{
    new 
playername[MAX_PLAYER_NAME];
    
GetPlayerName(playeridplayernameMAX_PLAYER_NAME);
    return 
playername;

Reply
#5

PHP код:
GetPlayerNameEx(playerid)
{
 new 
pname[25];
 
GetPlayerName(playeridpnamesizeof(pname));
 return 
pname;
}
CMD:givecash(playeridparams[]) 

    new 
targetidamountstring[128]; 
    if (
sscanf(params"ud"targetidamount)) SendClientMessage(playerid, -1"SERVER(S): /givecash <playerid/name> <amount>"); 
    if(!
IsPlayerConnected(targetid) || targetid == playerid) return SendClientMessage(playerid, -1"SERVER{ff0000}(E){FFFFFF}: Target ID is offline/yourself."); 
    if (
amount GetPlayerMoney(playerid)) SendClientMessage(playerid, -1"SERVER{ff0000}(E){FFFFFF}: You don't have enough money to send."); 
    if (
amount && amount 100000SendClientMessage(playerid, -1"SERVER{ff0000}(E){FFFFFF}: Your amount value should be between 1 to 100,000."); 
    
    
GivePlayerMoney(targetidamount); 
    
GivePlayerMoney(playerid, -amount); 
    
    
format(stringsizeof(string), "~g~+%d$"amount); 
    
GameTextForPlayer(targetidstring30001); 
    
    
format(stringsizeof(string), "~r~-%d$"amount); 
    
GameTextForPlayer(playeridstring30001); 
    
    
format(stringsizeof(string), "- {FFF2E7}%s(%d) has sent you '%d$'."GetPlayerNameEx(playerid), playeridamount); 
    
SendClientMessage(targetid, -1string); 
    
    
format(stringsizeof(string), "- {FFF2E7}You've sent '%d$' to %s(%d)"amountGetPlayerNameEx(targetid), targetid); 
    
SendClientMessage(playerid, -1string); 
    return 
1

Reply
#6

Quote:
Originally Posted by CaptainBoi
Посмотреть сообщение
PHP код:
GetPlayerNameEx(playerid)
{
 new 
pname[25];
 
GetPlayerName(playeridpnamesizeof(pname));
 return 
pname;
}
CMD:givecash(playeridparams[]) 

    new 
targetidamountstring[128]; 
    if (
sscanf(params"ud"targetidamount)) SendClientMessage(playerid, -1"SERVER(S): /givecash <playerid/name> <amount>"); 
    if(!
IsPlayerConnected(targetid) || targetid == playerid) return SendClientMessage(playerid, -1"SERVER{ff0000}(E){FFFFFF}: Target ID is offline/yourself."); 
    if (
amount GetPlayerMoney(playerid)) SendClientMessage(playerid, -1"SERVER{ff0000}(E){FFFFFF}: You don't have enough money to send."); 
    if (
amount && amount 100000SendClientMessage(playerid, -1"SERVER{ff0000}(E){FFFFFF}: Your amount value should be between 1 to 100,000."); 
    
    
GivePlayerMoney(targetidamount); 
    
GivePlayerMoney(playerid, -amount); 
    
    
format(stringsizeof(string), "~g~+%d$"amount); 
    
GameTextForPlayer(targetidstring30001); 
    
    
format(stringsizeof(string), "~r~-%d$"amount); 
    
GameTextForPlayer(playeridstring30001); 
    
    
format(stringsizeof(string), "- {FFF2E7}%s(%d) has sent you '%d$'."GetPlayerNameEx(playerid), playeridamount); 
    
SendClientMessage(targetid, -1string); 
    
    
format(stringsizeof(string), "- {FFF2E7}You've sent '%d$' to %s(%d)"amountGetPlayerNameEx(targetid), targetid); 
    
SendClientMessage(playerid, -1string); 
    return 
1

Why copy something I've done before? If it is already solved, you do not need to respond simply for wanting to attract attention.
Reply
#7

Quote:
Originally Posted by Undef1ned
Посмотреть сообщение
PHP код:
CMD:givecash(playeridparams[]) 

    if(
sscanf(params"ud"params[0], params[1])) return SendClientMessage(playerid, -1"SERVER(S): /givecash <playerid/name> <amount>"); 
    if(!
IsPlayerConnected(params[0]) || playerid == params[0]) return SendClientMessage(playerid, -1"SERVER{ff0000}(E){FFFFFF}: Target ID is offline/yourself.");
    if(
params[1] > 100000 || params[1] <= 0) return SendClientMessage(playerid, -1"SERVER{ff0000}(E){FFFFFF}: Your amount value should be between $1 to $100,000.");
    if(
params[1] > GetPlayerMoney(playerid)) return SendClientMessage(playerid, -1"SERVER{ff0000}(E){FFFFFF}: You don't have enough money to send.");
    
GivePlayerMoney(playerid, -params[1]);
    
GivePlayerMoney(params[0], params[1]);
    
    new 
string[145];
    
format(stringsizeof(string), "~g~+%d$"params[1]);
    
GameTextForPlayer(params[0], string30001);
    
format(stringsizeof(string), "~r~-%d$"params[1]);
    
GameTextForPlayer(playeridstring30001);
    
    
format(stringsizeof(string), "- {FFF2E7}%s(%d) has sent you '%d$'."GetName(playerid), playeridparams[1]);  SendClientMessage(params[0], -1string); 
    
format(stringsizeof(string), "- {FFF2E7}You've sent '%d$' to %s(%d)"params[1], GetName(params[0]), params[0]); SendClientMessage(playerid, -1string); 
    return 
1
}
stock GetName(playerid)
{
    new 
playername[MAX_PLAYER_NAME];
    
GetPlayerName(playeridplayernameMAX_PLAYER_NAME);
    return 
playername;

Spoonfeeding!

Quote:
Originally Posted by CaptainBoi
Посмотреть сообщение
PHP код:
GetPlayerNameEx(playerid)
{
 new 
pname[25];
 
GetPlayerName(playeridpnamesizeof(pname));
 return 
pname;
}
CMD:givecash(playeridparams[]) 

    new 
targetidamountstring[128]; 
    if (
sscanf(params"ud"targetidamount)) SendClientMessage(playerid, -1"SERVER(S): /givecash <playerid/name> <amount>"); 
    if(!
IsPlayerConnected(targetid) || targetid == playerid) return SendClientMessage(playerid, -1"SERVER{ff0000}(E){FFFFFF}: Target ID is offline/yourself."); 
    if (
amount GetPlayerMoney(playerid)) SendClientMessage(playerid, -1"SERVER{ff0000}(E){FFFFFF}: You don't have enough money to send."); 
    if (
amount && amount 100000SendClientMessage(playerid, -1"SERVER{ff0000}(E){FFFFFF}: Your amount value should be between 1 to 100,000."); 
    
    
GivePlayerMoney(targetidamount); 
    
GivePlayerMoney(playerid, -amount); 
    
    
format(stringsizeof(string), "~g~+%d$"amount); 
    
GameTextForPlayer(targetidstring30001); 
    
    
format(stringsizeof(string), "~r~-%d$"amount); 
    
GameTextForPlayer(playeridstring30001); 
    
    
format(stringsizeof(string), "- {FFF2E7}%s(%d) has sent you '%d$'."GetPlayerNameEx(playerid), playeridamount); 
    
SendClientMessage(targetid, -1string); 
    
    
format(stringsizeof(string), "- {FFF2E7}You've sent '%d$' to %s(%d)"amountGetPlayerNameEx(targetid), targetid); 
    
SendClientMessage(playerid, -1string); 
    return 
1

Spoonfeeding!

Quote:
Originally Posted by Undef1ned
Посмотреть сообщение
Why copy something I've done before? If it is already solved, you do not need to respond simply for wanting to attract attention.
Still, spoon feeding!
Reply
#8

Quote:
Originally Posted by TheToretto
Посмотреть сообщение
Try using a stock for getting the player's name, useful for further scripts

PHP код:
stock ReturnName(playerid)
{
    new 
string[MAX_PLAYER_NAME];
    
GetPlayerName(playeridstringsizeof(string));
    return 
string;

Then you can simply ReturnName(playerid) || ReturnName(targetid)
Never suggest that again.
Reply
#9

Quote:
Originally Posted by J0sh...
Посмотреть сообщение
Never suggest that again.
Why shouldn't I?
Reply
#10

Quote:
Originally Posted by TheToretto
Посмотреть сообщение
Why shouldn't I?
https://sampforum.blast.hk/showthread.php?tid=570635
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)