Hostages

Got any custom JavaScript additions/tweaks you think other people would like to see? Post 'em here!
Post Reply
dragon slayer
UOX3 Guru
Posts: 776
Joined: Thu Dec 21, 2006 7:37 am
Has thanked: 4 times
Been thanked: 26 times

Hostages

Post by dragon slayer »

You every wanted to be like bruce Willis and save poeple. well here is your chance to be part of him.

save them hostages and become hero :)
// DON'T CHANGE THIS VALUE:
var i = 0;
var searchAmount = 3;
var searchInterval = 2500;
var searchRange = 4;
var searchTimer = 7500;

// these scripts are activated when the PC says "news"
var hostageMsg1= "Help me out of this chains";
var hostageMsg2 = "Please save me.";
var hostageMsg3 = "Cut them chains.";
var hostageMsg4 = "HELP!";

// This message is fired if the PC is criminal.
var criminalReply = "Thou art a criminal and I will go with thee!";

// These two messages start and begin when the pc approaches the crier.
var startSearchEmote = "*HELP! HELP!";
var endSearchEmote = "Some one save me.";

function onCreateDFN( objMade, objType )
{
   if( objType == 1 )
   {
    objMade.frozen = 1;
        objMade.vulnerable = 0;
   }
}

function onCharDoubleClick( pUser, targChar )
{
   pUser.tempObj = targChar;
   if( !targChar.InRange( pUser, 4 ) )
   {
      pUser.SysMessage( "Not close enough" );
      return false;
   }
   else
      pUser.DoAction( 0x22 );
      var goldToGive = 0;
      switch( RandomNumber( 0, 2 ) )
      {
      case 0:      goldToGive = 50;      break;
      case 1:      goldToGive = 100;      break;
      case 2:      goldToGive = 150;      break;
      }
      CreateDFNItem( pUser.socket, pUser, "0x0EED", goldToGive, "ITEM", true );
      pUser.SysMessage( "Thank you for saving me here is your reward." );
      pUser.StaticEffect( 0x376A, 9, 9 );
      targChar.Delete();
      return false;
}

function inRange( pCharacter, objInRange, objType )
{
   if( objType == 0 )
   {
      // Get the current server clock, and if it exists, the time for when the last search was started
      // Compare the two, and the script will see if enough time has passed to initiate a new search
      // This also ensures that the script stays working even if the server saves in the middle of a
      // search, but crashes before the next save.
      var iTime = GetCurrentClock();
      var initSearchTime = pCharacter.GetTag( "initSearchTime" );
      //If search has already been initiated, don't start a new search, unless an abnormal amount of time has passed
      if(( initSearchTime != null && initSearchTime != 0 ) && ((( iTime - initSearchTime ) < searchTimer ) && !( initSearchTime > iTime )))
         return;
      else if((( iTime - initSearchTime ) > searchTimer ) || initSearchTime > iTime )
      {
         pCharacter.SetTag( "initSearchTime", iTime );
         if( startSearchEmote )
            pCharacter.EmoteMessage( startSearchEmote );
         pCharacter.StartTimer( searchInterval, 1, true );
      }
   }
}

// This triggers the keyword-based healing/resurrection
function onSpeech( strSaid, pTalking, npcHostage )
{
   if( strSaid == "news" )
   {
      npcHostage.TurnToward( pTalking );
      doYell( pTalking, npcHostage );
   }
   return false;
}

// This is the general function for healing characters
function doYell( mChar, npcHostage )
{
   var dice;
   dice = RollDice(1,20,0);

   if (dice < 6)
   {
     npcHostage.TextMessage(hostageMsg1);
     return;
   }
   if (dice < 11)
   {
     npcHostage.TextMessage(hostageMsg2);
     return;
   }
   if (dice < 16)
   {
     npcHostage.TextMessage(hostageMsg3);
     return;
   }
     npcHostage.TextMessage(hostageMsg4);
}


function onTimer( srcChar, timerID )
{
   if( timerID == 1 )
   { //Search for nearby wounded characters the specified amount of times
      if( i < searchAmount )
      {
         AreaCharacterFunction( "searchForPeople", srcChar, searchRange );
         srcChar.StartTimer( searchInterval, 1, true );
         i++;
      }
      else
      {
         i = 0;
         if( endSearchEmote )
            srcChar.EmoteMessage( endSearchEmote );
      }
   }
}

function searchForPeople( srcChar, trgChar, pSock )
{
   if( trgChar.serial != srcChar.serial )
   {
         doYell( trgChar, srcChar );
   }
}
Blue Dragon
UOX3 Apprentice
Posts: 159
Joined: Mon Jan 09, 2012 1:43 am
Has thanked: 0
Been thanked: 0

Post by Blue Dragon »

HaHaHa. Nice! Funny the text you posted to display the script.
Post Reply