SA-MP Forums Archive
how to send messages? - 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: how to send messages? (/showthread.php?tid=641820)



how to send messages? - Mobtiesgangsa - 21.09.2017

Код:
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


Re: how to send messages? - Toroi - 21.09.2017

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)


Re: how to send messages? - Logic_ - 21.09.2017

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.


Re: how to send messages? - Bolex_ - 21.09.2017

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



Re: how to send messages? - Mobtiesgangsa - 21.09.2017

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


Re: how to send messages? - Toroi - 21.09.2017

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?


Re: how to send messages? - Mobtiesgangsa - 21.09.2017

Код:
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


Re: how to send messages? - Toroi - 21.09.2017

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