PDA

View Full Version : is this command wrong?


ZBits
18/07/2012, 03:36 PM
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_LAWN GREEN,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

LukeStephens
18/07/2012, 03:38 PM
Seems legit

Andi_Evandy
18/07/2012, 03:40 PM
Add this after variables (or before the "format")
GetPlayerName(playerid, sendername, sizeof(sendername));

Larceny
18/07/2012, 03:41 PM
Edit: /\

You are not getting player's name.

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.

Dan.
18/07/2012, 03:44 PM
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.

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_LAWN GREEN,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;
}

ZBits
18/07/2012, 04:07 PM
@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

Larceny
18/07/2012, 04:12 PM
Obs. Your string array is too short, will not print all characters.

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;
}

Dan.
18/07/2012, 04:13 PM
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;
}

ZBits
18/07/2012, 04:19 PM
here you go it outcomes like this

http://img715.imageshack.us/img715/750/samp006im.png

Dan.
18/07/2012, 04:25 PM
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;
}

Aprezt
18/07/2012, 04:38 PM
And you can use string much more size...


new
string[ 256 ]
;

ZBits
18/07/2012, 04:39 PM
Thanks +rep

Dan.
18/07/2012, 04:40 PM
And you can use string much more size...


new
string[ 256 ]
;


Why should he make it bigger than 128? SA:MP chat max input is 128, so no need to make it bigger.

The SA:MP chat box has a maximum line length of 128, if someone types something you know it will never be longer than 128 ever. This includes text and commands, so why use a buffer twice that length to process the input?