help please!
#1

hi i made a /givescore and it works but the string doesn't work

Код:
CMD:givescore(playerid,params[])
{
if(!IsPlayerAdmin(playerid))return SendClientMessage(playerid, COLOR_ERROR,"[ERROR]:you are not rcon admin");
new targetid,str[75],pname[MAX_PLAYER_NAME],score;
GetPlayerName(targetid);
if(sscanf(params,"ud",targetid,score)) return SendClientMessage(playerid,COLOR_ERROR,"[ERROR]:Usage(playerid)");
if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_ERROR, "[ERROR]:Player is not connected.");
GetPlayerScore(targetid);
SetPlayerScore(targetid,score);
format(str, sizeof(str), "admin has given you %d score.",score);
SendClientMessage(playerid,COLOR_YELLOW,"you have given %d score to %i",score,targetid);
SendClientMessage(targetid,COLOR_PURPLE,str);
return 1;
}
the string gives me random numbers!
Reply
#2

Quote:
Originally Posted by ahameed4755
Посмотреть сообщение
hi i made a /givescore and it works but the string doesn't work

Код:
CMD:givescore(playerid,params[])
{
if(!IsPlayerAdmin(playerid))return SendClientMessage(playerid, COLOR_ERROR,"[ERROR]:you are not rcon admin");
new targetid,str[75],pname[MAX_PLAYER_NAME],score;
GetPlayerName(targetid);
if(sscanf(params,"ud",targetid,score)) return SendClientMessage(playerid,COLOR_ERROR,"[ERROR]:Usage(playerid)");
if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_ERROR, "[ERROR]:Player is not connected.");
GetPlayerScore(targetid);
SetPlayerScore(targetid,score);
format(str, sizeof(str), "admin has given you %d score.",score);
SendClientMessage(playerid,COLOR_YELLOW,"you have given %d score to %i",score,targetid);
SendClientMessage(targetid,COLOR_PURPLE,str);
return 1;
}
the string gives me random numbers!
Your command looks fine to me but you can use this

PHP код:
CMD:setscore(playeridparams[])
{
    
//check if the player is a admin
    
CheckPlayerAdminLevel(playerid3);
    new 
targetamount;
    if(
sscanf(params"ui"targetamount)) return SendClientMessagef(playeridX11_THISTLE_1"USAGE: /setscore [player] [amount]");
    if(! 
IsPlayerConnected(target)) return SendClientMessage(playeridX11_FIREBRICK"ERROR: The specified player is not conected.");
    if(
GetPlayerGAdminLevel(playerid) < GetPlayerGAdminLevel(target)) return SendClientMessage(playeridX11_FIREBRICK"ERROR: You cannot use this command on higher level admin.");
    
SetPlayerScore(targetamount);
    
PlayerPlaySound(target10570.00.00.0);
    
PlayerPlaySound(playerid10570.00.00.0);
    
SendClientMessagef(targetX11_DODGER_BLUE"Admin %s[%i] have set your score to %i."ReturnPlayerName(playerid), playeridamount);
    
SendClientMessagef(playeridX11_DODGER_BLUE"You have set %s[%i]'s score to %i."ReturnPlayerName(target), targetamount);
    return 
1;

Reply
#3

Well, its because the message that was sent to the cmd user (Admin) wasn't formatted. You only formatted the message that was sent to the target player. Also, i saw that you have fetched target player's name but didn't utilize it at all.

PHP код:
CMD:givescore(playeridparams[])
{
    if(!
IsPlayerAdmin(playerid))
        return 
SendClientMessage(playeridCOLOR_ERROR"[ERROR]: You are not an admin!");

    new 
targetidscore;
    
    if(
sscanf(params"ud"targetidscore))
        return 
SendClientMessage(playeridCOLOR_ERROR"[ERROR]: Usage /givescore [playerid] [amount]");

    if(
targetid == INVALID_PLAYER_ID)
        return 
SendClientMessage(playeridCOLOR_ERROR"[ERROR]: Player is not connected.");

    new 
str[75], pname[MAX_PLAYER_NAME];
    
GetPlayerName(targetidpnameMAX_PLAYER_NAME);
    
    
SetPlayerScore(targetidGetPlayerScore(targetid) + score);
    
    
format(strsizeof(str), "Admin has given you %d score."score);
    
SendClientMessage(targetidCOLOR_PURPLEstr);
    
    
format(strsizeof(str), "you have given %d score to %s(%d)"scorepnametargetid);
    
SendClientMessage(playeridCOLOR_YELLOWstr);
    return 
1;

Reply
#4

Quote:
Originally Posted by Sjn
Посмотреть сообщение
Well, its because the message that was sent to the cmd user (Admin) wasn't formatted. You only formatted the message that was sent to the target player. Also, i saw that you have fetched target player's name but didn't utilize it at all.

PHP код:
CMD:givescore(playeridparams[])
{
    if(!
IsPlayerAdmin(playerid))
        return 
SendClientMessage(playeridCOLOR_ERROR"[ERROR]: You are not an admin!");
    new 
targetidscore;
    
    if(
sscanf(params"ud"targetidscore))
        return 
SendClientMessage(playeridCOLOR_ERROR"[ERROR]: Usage /givescore [playerid] [amount]");
    if(
targetid == INVALID_PLAYER_ID)
        return 
SendClientMessage(playeridCOLOR_ERROR"[ERROR]: Player is not connected.");
    new 
str[75], pname[MAX_PLAYER_NAME];
    
GetPlayerName(targetidpnameMAX_PLAYER_NAME);
    
    
SetPlayerScore(targetidGetPlayerScore(targetid) + score);
    
    
format(strsizeof(str), "Admin has given you %d score."score);
    
SendClientMessage(targetidCOLOR_PURPLEstr);
    
    
format(strsizeof(str), "you have given %d score to %s(%d)"scorepnametargetid);
    
SendClientMessage(playeridCOLOR_YELLOWstr);
    return 
1;

ty! +rep!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)