Author Topic: Input event - OnPlayerHasAllChests  (Read 953 times)

/title, Basicly an input event if you opened all the chests.
Would be super cool, But would it even be possible?

Yes please!

OnPlayerHasAllChests >> Minigame >> Win

Why has nobody else actually thought about this?

Very easy.

Wait a few minutes.

package ChestsEvents
{
   function serverCmdAddEvent(%client, %enabled, %inputEventIdx, %delay, %targetIdx, %NTNameIdx, %outputEventIdx, %par1, %par2, %par3, %par4)
   {
      Parent::serverCmdAddEvent(%client, %enabled, %inputEventIdx, %delay, %targetIdx, %NTNameIdx, %outputEventIdx, %par1, %par2, %par3, %par4);

      if(!isObject(%client.wrenchBrick))
         return;

      if(%input == $ChestsEvents::onChestFound_Idx)
      {
         $ChestsEvents::onChestFound_List = addItemToList($ChestsEvents::onChestFound_List, %client.wrenchBrick);
      }
      else if(%input == $ChestsEvents::onChestFoundAll_Idx)
      {
         $ChestsEvents::onChestFoundAll_List = addItemToList($ChestsEvents::onChestFoundAll_List, %client.wrenchBrick);
      }
   }

   function serverCmdClearEvents(%client)
   {
      Parent::serverCmdClearEvents(%client);

      $ChestsEvents::onChestFound_List = removeItemFromList($ChestsEvents::onChestFound_List, %client.wrenchBrick);

      $ChestsEvents::onChestFoundAll_List = removeItemFromList($ChestsEvents::onChestFoundAll_List, %client.wrenchBrick);
   }

   function fxDtsBrick::onDeath(%brick)
   {
      $ChestsEvents::onChestFound_List = removeItemFromList($ChestsEvents::onChestFound_List, %brick);

      $ChestsEvents::onChestFoundAll_List = removeItemFromList($ChestsEvents::onChestFoundAll_List, %brick);

      Parent::onDeath(%brick);
   }

   function brickTreasureChestData::openTreasureChest(%data, %obj, %player)
   {
      Parent::openTreasureChest(%data, %obj, %player);

      for(%i = 0; %i < getWordCount($ChestsEvents::onChestFound_List); %i++)
      {
         %brick = getWord($ChestsEvents::onChestFound_List, %i);

         if(isObject(%brick))
         {
            $inputTarget_Self = %brick;
            $inputTarget_Player = %player;
            $inputTarget_Client = %player.client;
            $inputTarget_Minigame = getMinigameFromObject(%player);

            %brick.processInputEvent("onChestFound", %client);
         }
      }

      if(%player.client.numFoundTreasureChests >= $TreasureChest::NumChests)
      {
         for(%i = 0; %i < getWordCount($ChestsEvents::onChestFoundAll_List); %i++)
         {
            %brick = getWord($ChestsEvents::onChestFoundAll_List, %i);

            if(isObject(%brick))
            {
               $inputTarget_Self = %brick;
               $inputTarget_Player = %player;
               $inputTarget_Client = %player.client;
               $inputTarget_Minigame = getMinigameFromObject(%player);

               %brick.processInputEvent("onChestFound", %client);
            }
         }
      }
   }
};
activatePackage(ChestsEvents);

registerInputEvent("onChestFound", "onSearchFindBrick", "Self fxDTSBrick\tTargetBrick fxDTSBrick\tPlayer Player\tClient GameConnection\tMinigame Minigame");
registerInputEvent("onChestFoundAll", "onSearchFindBrick", "Self fxDTSBrick\tTargetBrick fxDTSBrick\tPlayer Player\tClient GameConnection\tMinigame Minigame");

$ChestsEvents::onChestFound_Idx = inputEvent_GetInputEventIdx("onChestFound");
$ChestsEvents::onChestFoundAll_Idx = inputEvent_GetInputEventIdx("onChestFoundAll");

function addItemToList(%string,%item)
{
   if(hasItemOnList(%string,%item))
      return %string;

   if(%string $= "")
      return %item;
   else
      return %string SPC %item;
}

function hasItemOnList(%string,%item)
{
   for(%i=0;%i<getWordCount(%string);%i++)
   {
      if(getWord(%string,%i) $= %item)
         return 1;
   }
   return 0;
}

function removeItemFromList(%string,%item)
{
   for(%i=0;%i<getWordCount(%string);%i++)
   {
      if(getWord(%string,%i) $= %item)
      {
         if(%i $= 0)
            return getWords(%string,1,getWordCount(%string));
         else if(%i $= getWordCount(%string)-1)
            return getWords(%string,0,%i-1);
         else
            return getWords(%string,0,%i-1) SPC getWords(%string,%i+1,getWordCount(%string));
      }
   }
}


Not tested.
« Last Edit: June 20, 2014, 01:46:03 PM by Zeblote »

-snip-
You might want to include the addItemToList and removeItemFromList functions as they are not default.

I thought there was a default counter for found treasure chests?

I thought there was a default counter for found treasure chests?
There is, but it's not implemented into the eventing system.

I made a script that adds the variables <var:client:foundChests>, <var:client:chestsLeft>, and <var:global:numChests> into VCE.

I made a script that adds the variables <var:client:foundChests>, <var:client:chestsLeft>, and <var:global:numChests> into VCE.
So stop flaunting it around and just release it.

So stop flaunting it around and just release it.
I didn't know anyone wanted it, as the request was for an event. And I released it quite some time ago.
http://forum.blockland.us/index.php?topic=243057.0#post_ChestVars

I didn't know anyone wanted it, as the request was for an event. And I released it quite some time ago.
http://forum.blockland.us/index.php?topic=243057.0#post_ChestVars
Oh, thanks.