Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
guidelines:adding_message_to_gamebots [2012/02/08 16:47]
martin.cerny
guidelines:adding_message_to_gamebots [2012/02/08 21:27]
martin.cerny
Line 1: Line 1:
-======Introduction======+======Adding new GameBots message and commands (UnrealScript)======
  
 GameBots messages are text strings exported from Unreal Tournament through socket connection. GameBots commands are text strings sent from Pogamut to Unreal Tournament. Here we will provide you with some basic information on how to create a new GameBots message or command. Afterwards you may also want to check the topic: [[Adding GameBots message to Pogamut JAVA|Adding new GameBots message to Pogamut JAVA]]. GameBots messages are text strings exported from Unreal Tournament through socket connection. GameBots commands are text strings sent from Pogamut to Unreal Tournament. Here we will provide you with some basic information on how to create a new GameBots message or command. Afterwards you may also want to check the topic: [[Adding GameBots message to Pogamut JAVA|Adding new GameBots message to Pogamut JAVA]].
Line 62: Line 62:
 <code> <code>
 static function SendNotifyMessage(){ static function SendNotifyMessage(){
- local Controller C; 
- local GBClientClass G; 
- local string message; 
- local WorldInfo worldInfo; 
-  
- worldInfo = class'WorldInfo'.static.GetWorldInfo(); 
- 
  message = "MYMESSAGE {StringParam bagr}";  message = "MYMESSAGE {StringParam bagr}";
  
- foreach worldInfo.AllControllers(class'Controller', C) +        SendMessageToAll("MYMESSAGE {StringParam bagr}"); 
- { +        SendMessageToAllBots("BOTMESSAGE {IntParam 23}"); 
- if( C.IsA('RemoteBot') ) +        SendMessageToAllControlConnections("CONTROLMESSAGE {FloatParam 1.5}");
-+
- RemoteBot(C).myConnection.SendLine(message); +
- +
-+
- +
-    if (GBGameInterface(worldInfo.Game).GetGameHandler().theControlServer != None) +
- { +
- for (G = GBGameInterface(worldInfo.Game).GetGameHandler().theControlServer.ChildListG != None; G = G.Next ) +
- { +
- G.SendLine(message); +
-+
- }+
  
 } }
  
 </code> </code>
-This method sends the message to all bot and control server connections.+This method sends the one message to all bot and control server connections, another only to all bots and yet another only to control connections. Note that while this method is quite simple it is good practice not to embed this in your action code, but keep it in the connection class so that the vocabulary of gamebots commands and messages is not scattered in many classes. 
 + 
 +Of course you might want to have a message that is sent for example only to the bot that triggered something. Than you need to get the bot object from the event and use it's connection.
  
 ====== Receiving commands from Pogamut ====== ====== Receiving commands from Pogamut ======
Line 96: Line 79:
 Except for special messages (handshake with server, password), the message handling is done in ''BotConnection.ProcessRegularAction'' method. If you are extending Gamebots core you write a handler function and add another case to the switch statement in this method. If you are adding project specific command, you should subclass BotConnection and override this method in your subclass and delegate parsing to super implementation if you cannot recognize the message. Example of such an overriden method follows: Except for special messages (handshake with server, password), the message handling is done in ''BotConnection.ProcessRegularAction'' method. If you are extending Gamebots core you write a handler function and add another case to the switch statement in this method. If you are adding project specific command, you should subclass BotConnection and override this method in your subclass and delegate parsing to super implementation if you cannot recognize the message. Example of such an overriden method follows:
  
-<code>+<code php>
 function ProcessRegularAction(string cmdType) function ProcessRegularAction(string cmdType)
 { {
Line 113: Line 96:
 In your handler method, you are free to use method GetArgVal(argName) to parse command arguments (it is automagically filled with arguments from most recent command.  In your handler method, you are free to use method GetArgVal(argName) to parse command arguments (it is automagically filled with arguments from most recent command. 
  
 +====== Triggering Kismet event with a command ======
 +
 +One nice thing to do with a message is to fire a custom Kismet event when a command is received. Here is an example of such a handler function (from SpyVsSpy project).
 +
 +<code php>
 +function ReceivedChangeDoorState(){
 +    local Sequence GameSeq;
 +    local array<SequenceObject> AllDoorEvents;
 +    local array<int> ActivateIndices;
 +    local int i;
 + local string doorFrom;
 + local string doorTo;
 + local bool open;
 + local SeqEvent_ExternalDoorStateChange doorChangeEvent;
 +
 + doorFrom = GetArgVal("DoorFrom");
 + doorTo = GetArgVal("DoorTo");
 + open = bool(GetArgVal("Open"));
 +
 +
 +
 +    GameSeq = WorldInfo.GetGameSequence();
 +    if (GameSeq != None)
 +    {
 +
 +        // find all instance of our event
 +        GameSeq.FindSeqObjectsByClass(class'SeqEvent_ExternalDoorStateChange', true, AllDoorEvents);
 +
 +        //choose the right activation link number
 +        if(open){
 +                ActivateIndices[0] = 0; 
 +        } else {
 +                ActivateIndices[0] = 1;
 +        }
 +        for (i = 0; i < AllDoorEvents.Length; i++)
 +        {
 + doorChangeEvent = SeqEvent_ExternalDoorStateChange(AllDoorEvents[i]); //convert to appropriate class
 +                        //Check custom activation condition
 + if( (doorChangeEvent.DoorFrom == doorFrom && doorChangeEvent.DoorTo == doorTo) 
 + || (doorChangeEvent.DoorFrom == doorTo && doorChangeEvent.DoorTo == doorFrom)
 + ){
 +                                 //trigger the event
 + doorChangeEvent.CheckActivate(WorldInfo, None, false, ActivateIndices);
 + }
 +        }
 +    }
 +}
 +</code>
 +
 +Here we have a custom kismet event with two output links.
 +This method gets all event object of appropriate class, performs custom checking, whether the message should trigger the event and then triggers the appropriate activation link on them.
  
 ====== Adding project-specific messages and commands ====== ====== Adding project-specific messages and commands ======
guidelines/adding_message_to_gamebots.txt · Last modified: 2012/02/08 21:34 by martin.cerny