SA-MP Forums Archive
is this command wrong? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: is this command wrong? (/showthread.php?tid=360655)



is this command wrong? - ZBits - 18.07.2012

pawn Код:
CMD:dice(playerid,params[])
{
new rand = random(12);
new sendername[MAX_PLAYER_NAME], message[128];
format(message, sizeof(message), "%s(%d) tries his luck and throws the dice, The dice landed on the number %d",sendername,playerid,rand);
ProxDetector(30.0, playerid, message,COLOR_LAWNGREEN,COLOR_LAWNGREEN,COLOR_LAWNGREEN,COLOR_LAWNGREEN,COLOR_LAWNGREEN);
return 1;
}
CMD:ad(playerid,params[])
{
new sendername[MAX_PLAYER_NAME], string[28];
format(string, sizeof(string),"ADVERTIESMENT: %s, contact %s (ID:%d)",params,sendername,playerid);
SendClientMessageToAll(COLOR_ORANGE,string);
return 1;
}
guys tell me is this code wrong

it does compile but it does not show my name, in the commad /ad it does not show my name and id,and in command /dice it shows only the ID

need help in this


Re: is this command wrong? - LukeStephens - 18.07.2012

Seems legit


Re: is this command wrong? - Andi_Evandy - 18.07.2012

Add this after variables (or before the "format")
pawn Код:
GetPlayerName(playerid, sendername, sizeof(sendername));



Re: is this command wrong? - Larceny - 18.07.2012

Edit: /\

You are not getting player's name.

pawn Код:
CMD:ad(playerid,params[])
{
    new sendername[MAX_PLAYER_NAME], string[28];
    GetPlayerName(playerid, sendername, MAX_PLAYER_NAME);//<<<<<
    format(string, sizeof(string),"ADVERTIESMENT: %s, contact %s (ID:%d)",params,sendername,playerid);
    SendClientMessageToAll(COLOR_ORANGE,string);
    return 1;
}
Obs. Your string array is too short, will not print all characters.


Re: is this command wrong? - Dan. - 18.07.2012

Yes, you forgot to get the player's name + on the AD command, you used "params" in the format, but I dont see it defined anywhere. For this code to work you need also sscanf2.

pawn Код:
CMD:dice(playerid,params[])
{
    new rand = random(12);
    new sendername[MAX_PLAYER_NAME], message[128];
    GetPlayerName(playerid, sendername, sizeof(sendername));
    format(message, sizeof(message), "%s(%d) tries his luck and throws the dice, The dice landed on the number %d",sendername,playerid,rand);
    ProxDetector(30.0, playerid, message,COLOR_LAWNGREEN,COLOR_LAWNGREEN,COLOR_LAWNGREEN,COLOR_LAWNGREEN,COLOR_LAWNGREEN);
    return 1;
}

CMD:ad(playerid,params[])
{
    new sendername[MAX_PLAYER_NAME], string[64], ad[64];
    GetPlayerName(playerid, sendername, sizeof(sendername));
    if(sscanf(params,"s[64]", ad)) return SendClientMessage(playerid, FFFFFF, "Usage: /ad [text]");
   
    format(string, sizeof(string),"ADVERTISEMENT: %s, contact %s (ID:%d)", ad, sendername, playerid);
    SendClientMessageToAll(COLOR_ORANGE, string);
    return 1;
}



Re: is this command wrong? - ZBits - 18.07.2012

@dan,and @Ruigy your code is complying but when i type a message like

/ad Cops are after me trying to catch me

it only displays like

ADVERTISEMESNT: Cops are

in short it does not display the whole message


Re: is this command wrong? - Larceny - 18.07.2012

Quote:
Originally Posted by RuiGy
Посмотреть сообщение
Obs. Your string array is too short, will not print all characters.
pawn Код:
CMD:ad(playerid,params[])
{
    new sendername[MAX_PLAYER_NAME], string[144];// <<<<
    GetPlayerName(playerid, sendername, MAX_PLAYER_NAME);
    format(string, sizeof(string),"ADVERTIESMENT: %s, contact %s (ID:%d)",params,sendername,playerid);
    SendClientMessageToAll(COLOR_ORANGE,string);
    return 1;
}



Re: is this command wrong? - Dan. - 18.07.2012

pawn Код:
CMD:ad(playerid,params[])
{
    new sendername[MAX_PLAYER_NAME], string[64], ad[144];
    GetPlayerName(playerid, sendername, sizeof(sendername));
    if(sscanf(params,"s[64]", ad)) return SendClientMessage(playerid, FFFFFF, "Usage: /ad [text]");
   
    format(string, sizeof(string),"ADVERTISEMENT: %s, contact %s (ID:%d)", ad, sendername, playerid);
    SendClientMessageToAll(COLOR_ORANGE, string);
    return 1;
}



Re: is this command wrong? - ZBits - 18.07.2012

here you go it outcomes like this




Re: is this command wrong? - Dan. - 18.07.2012

pawn Код:
CMD:ad(playerid,params[])
{
    new sendername[MAX_PLAYER_NAME], string[128], ad[128];
    GetPlayerName(playerid, sendername, sizeof(sendername));
    if(sscanf(params,"s[64]", ad)) return SendClientMessage(playerid, FFFFFF, "Usage: /ad [text]");
   
    format(string, sizeof(string),"ADVERTISEMENT: %s, contact %s (ID:%d)", ad, sendername, playerid);
    SendClientMessageToAll(COLOR_ORANGE, string);
    return 1;
}