[Tutorial] Usages for OnPlayerClickPlayer
#1

I'm not seeing this callback used frequently. OnPlayerClickPlayer is called when somebody double-clicks a name in the online list (TAB), yet most people don't see how easy it can be.

I'll give a small demonstration today of what you can do with it.

So here's the callback:
pawn Код:
public OnPlayerClickPlayer(playerid,clickerplayerid,source)
{
  return 1;
}
Playerid - The player who (double) clicks on that name.
Clickedplayerid - The player ID who got clicked on by 'playerid'
Source - The way of clicking. The only possible way at the moment is '0', which is reach by clicking on the scoreboard.

Now I'll show an example of doing a PM system. You might've seen some of those things on the forums though, here's how it works (I didn't looked at the code of a PM system).

First off, we'll need to show the 'playerid' an input dialog, and save 'clickedplayerid'. We're saving 'clickedplayerid' because this is the only time we know it's value.

pawn Код:
public OnPlayerClickPlayer(playerid,clickedplayerid,source)
{
  SetPVarInt(playerid,"ClickedPlayer",clickedplayerid); // Save clickedplayerid in a PVar.
  ShowPlayerDialog(playerid,0,DIALOG_STYLE_INPUT,"PM","Type a message to send to the clicked player!","Send","Cancel");
 /* If you don't know what the ShowPlayerDialog parameters are, I'll list them here:
playerid - The player to show the dialog to
dialog id (0) - The ID of the dialog. NOTE: If you're already using dialogs, you might wish to change the ID to something different. I don't know if they can cause problems.
style (DIALOG_STYLE_INPUT) - The dialog style. There are 3 styles, a message dialog, an input dialog and a list dialog (Choose from the list).
caption ("PM") - The name of the dialog
info ("Type a.. ..clicked player!") - The text to show in the dialog. For dialog lists, this is different.
button1 ("Send!") - The primary button. Clicking this will set the 'response' variable in OnDialogResponse to 'true'.
button2 ("Cancel") - The secondary button. Clicking this will set the 'response' variable in OnDialogResponse to 'fase'. */

  return 1;
}
Hope you understood that, questions may be asked.

To continue, we'll need to do this last part: OnDialogResponse. This callback is called when a player responds to a dialog. Note that 'inputtext' is the text the player typed in the dialog.

pawn Код:
public OnDialogResponse(playerid,dialogid,response,listitem,inputtext[])
{
  if(dialogid == 0 && response == 1) // Checks if the dialog ID is the same as we sent him when he double-clicked the player. Reponse checks if the player hits the primary button, in this case the "Send!" button. If he would click "Cancel", nothing would happen.
  {
    new pName[MAX_PLAYER_NAME],gName[MAX_PLAYER_NAME],string[128];
    new giveplayerid = GetPVarInt(playerid,"ClickedPlayer"); // Gets the clicked player's ID.
    GetPlayerName(playerid,pName,sizeof pName); // Get the player's name and save it in 'pName';
    GetPlayerName(giveplayerid,gName,sizeof gName); // Get the name of the player we've clicked on.
    format(string,sizeof string,"PM From %s: %s",pName,inputtext); // Formats a string with the PM
    SendClientMessage(giveplayerid,0x00ff00ff,string); // Send the string to the giveplayerid
    format(string,sizeof string,"PM Send to %s: %s",gName,inputtext); // Formats another string, this time to confirm the playerid that the string has been sent.
    SendClientMessage(playerid,0x00ff00ff,string); // Send the confirmation to the playerid.
    return 1; // Kills the callback. Or that's how I call it.
  }
  //rest
  return 1;
}
PasteBin of what we've made:
http://pastebin.com/GT5dyPEp

Here's what I made: http://www.youtube.com/watch?v=5t5gpUa8RHA
Don't forget to put the Vuvuzela sound on!
PS: That RCON extension download link is in the vid, don't ask here.
Use your imagination, you can perform a lot of things easier and faster this way.


Feel free to ask questions.
Reply


Messages In This Thread
Usages for OnPlayerClickPlayer - by Hiddos - 09.07.2010, 14:18
Re: Usages for OnPlayerClickPlayer - by Grim_ - 09.07.2010, 14:20
Re: Usages for OnPlayerClickPlayer - by Hiddos - 09.07.2010, 14:21
Re: Usages for OnPlayerClickPlayer - by [XST]O_x - 09.07.2010, 14:25
Re: Usages for OnPlayerClickPlayer - by Basicz - 22.09.2010, 13:30
Re: Usages for OnPlayerClickPlayer - by HyperZ - 22.09.2010, 14:51
Re: Usages for OnPlayerClickPlayer - by Hoss - 03.05.2011, 17:14
Re: Usages for OnPlayerClickPlayer - by justsomeguy - 03.05.2011, 19:12
Re: Usages for OnPlayerClickPlayer - by Ash. - 12.06.2011, 15:45
Re: Usages for OnPlayerClickPlayer - by PCheriyan007 - 20.06.2011, 15:35

Forum Jump:


Users browsing this thread: 2 Guest(s)