how to send messages?
#1

Код:
dcmd_poke(playerid, params[])
{
	new id;
	if(sscanf(params, "u", id)) SendClientMessage(playerid, COLOR_YELLOW, "[USAGE]:[/]poke <id>");
	else if(id == INVALID_PLAYER_ID) SendClientMessage(playerid, COLOR_RED, "[ERROR] player is not connected!");
	else SendClientMessage(playerid, COLOR_RED, "[ERROR] You can't poke yourself?");
	return 1;
}
example

You Poked player1
player1 has poked you
Reply
#2

What else do you need? You're using all the functions you need already.
Add a SendClientMessage to each one of the ids (playerid and id) with the respective message on it.

Also, for the records: INVALID_PLAYER_ID is translated to 65535 or some number like that after compiling. That means you're checking if id equals to 65535, dumb, right? Use IsPlayerConnected(id) instead. (False statement as pointed in Logic_'s totally friendly reply)
Reply
#3

Quote:
Originally Posted by Toroi
Посмотреть сообщение
Also, for the records: INVALID_PLAYER_ID is translated to 65535 or some number like that after compiling. That means you're checking if id equals to 65535, dumb, right? Use IsPlayerConnected(id) instead.
What the fuck are you even saying... When a player is not connected, the Sscanf returns the value of 'playerid' as INVALID_PLAYER_ID (65535) which is constant at all conditions and it's far more easier and faster to compare two values rather than using a different function, which will absolutely do the same.
Reply
#4

Just change what do you need

Код:
dcmd_poke(playerid,params[])
{
    new ID;
    if(sscanf(params, "u",ID)) return SendClientMessage(playerid, -1, "/poke [PlayerID]");
    if(!IsPlayerConnected(ID)) return SendClientMessage(playerid, -1, "Player is not connected.");
    if(playerid == ID) return SendClientMessage(playerid, -1, "Dumbass, you can't poke yourself..");

    new string[128]; // Limit is 128 characters, ofc you can reduce it
    format(string,sizeof(string),"Ouch, %s has poked you", GetName(playerid));
    SendClientMessage(ID, -1, string);

    format(string,sizeof(string),"[INFO] You have poked %s", GetName(ID));
    SendClientMessage(playerid, -1, string);
    return 1;
}
Reply
#5

Toroi if i use IsPlayerConnected i will do it on strtok instead but i choose not to the point is i want to combinw dcmd and sscanf for in my opinion is the best option for me also forgot to mention about Bolex_ help ty so much bro i tested it out with my friend and it worked 100% no bug no crash no nothing it wasnt hard to make this command i madi it fast
Reply
#6

Quote:
Originally Posted by Logic_
Посмотреть сообщение
What the fuck are you even saying... When a player is not connected, the Sscanf returns the value of 'playerid' as INVALID_PLAYER_ID (65535) which is constant at all conditions and it's far more easier and faster to compare two values rather than using a different function, which will absolutely do the same.
Well, thank you for the info i guess?
Reply
#7

Код:
dcmd_poke(playerid, params[])
{
	new id;
	if(sscanf(params, "u", id)) SendClientMessage(playerid, COLOR_YELLOW, "[USAGE]:[/]poke <id>");
	else if(id == INVALID_PLAYER_ID) SendClientMessage(playerid, COLOR_RED, "[ERROR] player is not connected!");
	else if(playerid != id)
	{
	    new string[128];
	    new pName[24];
	    new iName[24];
	    format(string, sizeof(string), "you poked %s (%d)", iName, id);
	    format(string, sizeof(string), "%s (%d) has poked you", pName, playerid);
	    SendClientMessage(id, COLOR_PPINK, string);
	    SendClientMessage(playerid, COLOR_PPINK, string);
	    return 1;
	}
	else SendClientMessage(playerid, COLOR_RED, "You can't poke yourself");
	return 1;
}
SORRY FOR DOUBLE POST I IMPROVED MY COMMAND FOR POKE
Reply
#8

Quote:
Originally Posted by Mobtiesgangsa
Посмотреть сообщение
Код:
dcmd_poke(playerid, params[])
{
	new id;
	if(sscanf(params, "u", id)) SendClientMessage(playerid, COLOR_YELLOW, "[USAGE]:[/]poke <id>");
	else if(id == INVALID_PLAYER_ID) SendClientMessage(playerid, COLOR_RED, "[ERROR] player is not connected!");
	else if(playerid != id)
	{
	    new string[128];
	    new pName[24];
	    new iName[24];
	    format(string, sizeof(string), "you poked %s (%d)", iName, id);
	    format(string, sizeof(string), "%s (%d) has poked you", pName, playerid);
	    SendClientMessage(id, COLOR_PPINK, string);
	    SendClientMessage(playerid, COLOR_PPINK, string);
	    return 1;
	}
	else SendClientMessage(playerid, COLOR_RED, "You can't poke yourself");
	return 1;
}
SORRY FOR DOUBLE POST I IMPROVED MY COMMAND FOR POKE
Not likely, the first format function won't have effect as you're formatting the same string again in the next line.

The order you should follow is the following:

Код:
Format the string > send the message to the respective ID > format the string again > send the message to the other ID
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)