[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
#2

Did I ever tell you that you have no life

(Nice tut).
Reply
#3

Quote:
Originally Posted by Grim_
Посмотреть сообщение
Did I ever tell you that you have no life

(Nice tut).
Me no life? Where'd you get that idea.
Reply
#4

Great job my mate!
You helped me a lot,and I'm now working on an edited version of Easy Registration by Grim_,using OnPlayerClickPlayer,I think it'll be good.
Thanks for the tutorial
Reply
#5

Nice tutorial Hiddos!
Reply
#6

Nice tutorial!
Reply
#7

OMG.Good job!
It helped me!
Reply
#8

nice i never realy knew what to do with it thanks!
Reply
#9

Nice! I was considering writing something like this.

Just incase you wanted an extra idea(?)

I used to use mine for administration commands/dialogs.

An administrator would click a player, and be presented with a dialog (list) which contained all the things the admin could do to that player. The only reason I don't include it now is because I use the OnPlayerClickPlayer for an advanced PM system (which isn't active yet)
Reply
#10

Quote:
Originally Posted by Hiddos
Посмотреть сообщение
Me no life? Where'd you get that idea.
Off Topic - I lol'd

Back on Topic - Thanks for making this tutorial. Now I'm probably going to start working on making some stuffs for OnPlayerClickPlayer.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)