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 16:59]
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 96: Line 96:
 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 113:
 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