Aller au contenu

Photo

Get the Player's PC who interacted with GUI?


  • Veuillez vous connecter pour répondre
7 réponses à ce sujet

#1
_Knightmare_

_Knightmare_
  • Members
  • 643 messages
How do you get the PC of the player who just interacted with a GUI? I have a GUI that sends a player input back to the game (string variable). How do I set up the script so that it knows which PC the interacting player controls?

object oPC = ???????

Multi-player compliant preferred. It is possible that multiple players will be interacting with the GUI at the same time (though the GUI itself is seperate per player, so each player is on a "copy" of the GUI). Script itself is fired by the player pressing a GUI button - OnLeftClick=UIObject_MISC_ExecuteServerScript()

Thanks.

#2
MasterChanger

MasterChanger
  • Members
  • 686 messages
When a script is called from a GUI (a gui_<scriptname> script) the PC that interacted with it is OBJECT_SELF. I've verified this through testing in single-player, at least, but I'm pretty sure it applies to all environments.

Modifié par MasterChanger, 03 octobre 2011 - 11:39 .


#3
painofdungeoneternal

painofdungeoneternal
  • Members
  • 1 799 messages
quote i use the following for the event i fire off when characters are swapped ( i put a little delay in to make sure it's accurate.)
object oPC = OBJECT_SELF;  //Despite who the player controls OBJECT_SELF is the person that opened the GUI.
	object oCurrentCharacter = GetControlledCharacter(oPC); // this is the actual character now controlled

Might want to describe more about what you are doing, but it is technically OBJECT_SELF, but there are some outlier situations where the above, or things like getMaster are useful.

OBJECT_SELF is going to be sent from the gui, from the players computer, and be the player that sent it in. If more than one player, it would send in more than one event, one for each player, each one being OBJECT_SELF.

#4
_Knightmare_

_Knightmare_
  • Members
  • 643 messages
Thanks for the replies. Basically when the player hits the button on the GUI, the script will jump them to another area. Just want to be sure that I am in fact jumping the character of the player that actually hit the button and not somebody else's/random PC. It is possible that two or more players are using the GUI at the same time, hit the button at the same time, but get jumped to different areas (based on variables within the script itself).

#5
painofdungeoneternal

painofdungeoneternal
  • Members
  • 1 799 messages
If two hit at the same time, then two events fire and OBJECT_SELF is for each event the particular player who clicked the button. It basically handles it all for you.

#6
_Knightmare_

_Knightmare_
  • Members
  • 643 messages
Sweet, that makes thing a lot easier. Thanks. :)

#7
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
Thanks for the info. I've been eavesdropping and this is very useful.

#8
MasterChanger

MasterChanger
  • Members
  • 686 messages
As Pain notes, each player has a separate instance of the GUI, which calls a separate instance of the script. In this way, it's no different than if ten players simultaneously used Rage. In each instance of the impact script, OBJECT_SELF is the character that used the feat.

How the engine keeps track of which instance is being run for which object is beyond me. As Pain points out, the engine just works that way, which is how we are able to create custom scripts at all.