Advertisement
Guest User

Support_MultiSourceEvents

a guest
Jan 2nd, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // +-------------------------------------------+
  2. // |  ___   _     _____   __  __  ____   ____  |
  3. // | | __| | |   | /_\ |  \ \/ / | ___| | /\ | |
  4. // | |__ | | |_  |  _  |   \  /  | __|  | \/ / |
  5. // | |___| |___| |_| |_|   |__|  |____| |_| \\ |
  6. // |  Greek2me              Blockland ID 11902 |
  7. // +-------------------------------------------+
  8.  
  9. if($Support_MultiSourceEvents::Version > 1)
  10.     return;
  11. $Support_MultiSourceEvents::Version = 1;
  12.  
  13. //Processes an event which occurs on multiple sources, normally bricks.
  14. //@param    string inputEvent   The name of the input event.
  15. //@param    GameConnection client   The client that activated the event.
  16. //@param    ScriptObject minigame   Optional. Only bricks within this minigame will be processed.
  17. function processMultiSourceInputEvent(%inputEvent, %client, %minigame)
  18. {
  19.     %group = "multiSourceEventGroup" @ inputEvent_GetInputEventIdx(%inputEvent);
  20.  
  21.     if(!isObject(%group))
  22.         return;
  23.  
  24.     for(%i = 0; %i < %group.getCount(); %i ++)
  25.     {
  26.         %obj = %group.getObject(%i);
  27.  
  28.         if(!%minigame || %minigame == getMinigameFromObject(%obj))
  29.         {
  30.             $InputTarget_["Self"] = %obj;
  31.             %obj.processInputEvent(%inputEvent, %client);
  32.         }
  33.     }
  34. }
  35.  
  36. //Registers a multiple-source input event. Use this in place of registerInputEvent.
  37. //@param    string class    The object class that this event is far.
  38. //@param    string inputEvent   The name of the input event.
  39. //@param    string targets  A tab-delimited list of targets. See the link below.
  40. //@link http://forum.blockland.us/index.php?topic=40631.0
  41. function registerMultiSourceInputEvent(%class, %inputEvent, %targets, %adminOnly)
  42. {
  43.     registerInputEvent(%class, %inputEvent, %targets, %adminOnly);
  44.  
  45.     //for whatever reason, this doesn't take a class parameter
  46.     %inputEventIdx = inputEvent_GetInputEventIdx(%inputEvent);
  47.    
  48.     if(%inputEventIdx != -1)
  49.         $InputEvent_MultiSource[%class, %inputEventIdx] = true;
  50. }
  51.  
  52. package Support_MultiSourceEvents
  53. {
  54.     function serverCmdAddEvent(%client, %enabled, %inputEventIdx, %delay, %targetIdx, %namedTargetNameIdx, %outputEventIdx, %par1, %par2, %par3, %par4)
  55.     {
  56.         %obj = %client.wrenchBrick;
  57.         %class = %obj.getClassName();
  58.  
  59.         parent::serverCmdAddEvent(%client, %enabled, %inputEventIdx, %delay, %targetIdx, %namedTargetNameIdx, %outputEventIdx, %par1, %par2, %par3, %par4);
  60.  
  61.         if($InputEvent_MultiSource[%class, %inputEventIdx])
  62.         {
  63.             %group = "multiSourceEventGroup" @ %inputEventIdx;
  64.             if(!isObject(%group))
  65.             {
  66.                 new SimSet(%group);
  67.                 missionCleanup.add(%group);
  68.             }
  69.             %group.add(%obj);
  70.         }
  71.     }
  72.  
  73.     function SimObject::clearEvents(%this)
  74.     {
  75.         %class = %this.getClassName();
  76.         for(%i = 0; %i < %this.numEvents; %i ++)
  77.         {
  78.             %inputEventIdx = %this.eventInputIdx[%i];
  79.             if(!%removed[%inputEventIdx] && $InputEvent_MultiSource[%class, %inputEventIdx])
  80.             {
  81.                 %removed[%inputEventIdx] = true;
  82.                 %group = "multiSourceEventGroup" @ %inputEventIdx;
  83.                 %group.remove(%this);
  84.             }
  85.         }
  86.         return parent::clearEvents(%this);
  87.     }
  88. };
  89. activatePackage(Support_MultiSourceEvents);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement