Hostages use keys to save

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 use keys to save

Post by dragon slayer »

I figured people like my first script so i made a second one that uses keys to save the hostages.

keys.dfn

Code: Select all

[jailkey]
{
get=base_item
NAME=prisoner key
ID=0x1013
COLOR=0x0387
}
keyhostage.js
// 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= "Free me from this horriable chains!";
var hostageMsg2 = "Please save me!";
var hostageMsg3 = "Find they key to unlock my 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 )
{
   var numKeys = pUser.ResourceCount( 0x1013, 0x0387 );
   pUser.tempObj = targChar;
   if( !targChar.InRange( pUser, 4 ) )
   {
      pUser.SysMessage( "Not close enough" );
      return false;
   }
   if ( numKeys < 1 )
   {
       pUser.SysMessage( "You do not have any keys on you to unlock the chains." );
       return false;
   }
   if( numKeys >= 1)
   {
      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 );
      pUser.UseResource( 1,  0x1013, 0x0387 );
      pUser.SoundEffect( 0x011c, true );
      targChar.Delete();
      return false;
   }
   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 );
   }
}
enjoy die hard fans :_)
Post Reply