Page 1 of 1

Beggar V. 1.5

Posted: Thu Dec 27, 2007 3:57 pm
by stranf
This script is a modification of Xuri's Wandering Healer Script. (There really is a lot you can do with that script)

Basically a Beggar will respond to a PC depending on how much gold the PC is carrying. The PC can give a begger any amount of gold by typing in "give ##" where # is the numerical value of gold he/she wishes to give the beggar.

Karma is given depending on the amount of gold, and karma is taken if the PC promises to give any amount greater than he/she is carrying.

Enjoy!
// Begger edit of Xuri's Wandering Healer Script
// By Stranf
// V1.5
// Wandering Healer
// v1.00
// by Xuri (xuri@sensewave.com)

// Beggar will beg for gold based on the amount the PC is carrying.  Gold is given to beggars by typing "beggar give ##"
// Gold given increases karma, If a PC dosen't have the correct amount of gold to give, karma is lost.
// DON'T CHANGE THIS VALUE:
var i = 0;

// searchAmount = Number of times healer will look around for chars to heal/resurrect before stopping
// searchInterval = The interval at wihch the healer looks around for chars to heal/resurrect after having started searching
// searchRange = The radius in which the healer searches for wounded people
// searchTimer = Amount of time between each time the healer initiates his searches
// resTimer = Minimum time that must pass before healer will resurrect same char again (1000 = 1 second)
// healTimer = Minimum time that must pass before healer will heal same char again (1000 = 1 second)
// manaCostHeal = the amount of mana the NPC uses for healing
// manaCostRes = the amount of mana the NPC uses for resurrecting
var searchAmount = 3;
var searchInterval = 5000;
var searchRange = 4;
var searchTimer = 15000;
var resTimer = 30000;
var healTimer = 30000;
var manaCostHeal = 11;
var manaCostRes = 50;

// These variables can be customized or commented out if you don't want to use them
var healSoundFX = 0x01f2;
var healGFXEffect = 0x376A;
var resSoundFX = 0x376A;
var resGFXEffect = 0x376A;

// These messages can be customized. If you don't want to use them at all, comment them out
var startSearchEmote = "Spare a coin friend?";
var endSearchEmote = "My family will starve!";


function inRange( pCharacter, objInRange )
{
   if( objInRange.isChar )
   {
      // 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> iTime )))
      {
        // pCharacter.TextMessage( initSearchTime + " " + iTime + " " + searchTimer );
        // 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, Beggar )
{
   
    var splitString = strSaid.split( " ", 2 );
    var uKey    = splitString[0].toUpperCase();
    var nVal    = StringToNum( splitString[1] );
    var gold =  pTalking.ResourceCount( 0xEED, 0 );    

    switch( uKey )
    {
    case "GIVE":
{
    if (gold <nVal> 999)
        {
    Beggar.EmoteMessage("*Speechlessly looks at the gold*");
    Beggar.EmoteMessage("With tears streaming, the beggar quickly puts the gold in his pouch");
    pTalking.karma =pTalking.karma + 300;  
    break;
        }
   
    if (nVal > 499)
        {
    Beggar.EmoteMessage("*looks speechless* Th...th...ank thee!");
    pTalking.karma =pTalking.karma + 125;
    break;
        }
       
    if (nVal > 99)
        {
    Beggar.EmoteMessage("Oh Thank thee!  Oh Thank thee!");
    pTalking.karma =pTalking.karma + 30;
    break;
        }

    if (nVal > 49)
        {
    Beggar.EmoteMessage("Thank thee gracious one!");
    pTalking.karma =pTalking.karma + 15;
    break;
        }
       
    if (nVal > 4)
        {
    Beggar.EmoteMessage("A blessing upon thee!");
    pTalking.karma =pTalking.karma + 4;
    break;
        }      
       
    Beggar.EmoteMessage("*grunts*  *takes the gold and nods*");
    pTalking.karma =pTalking.karma + 2;
    break;
       
    }
    break;
}
break;     







   }
   
}    






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

//This function iterates through all characters within the specified radius in AreaCharacterFunction
//It then checks to make sure they are valid for receiving healing or resurrection.
function searchForWounded( srcChar, trgChar, pSock )
{

 var gold =  trgChar.ResourceCount( 0xEED, 0 );        
    if( gold <1> 1 && gold <200> 200 && gold <500> 500 && gold <2000> 2000 )
      {
         
               srcChar.EmoteMessage( "*stares at coinpurse*  Surley you can spare hundreds of coins for my sick baby?  Potions are expensive these days!"  );
         
      }

   
}

Posted: Thu Dec 27, 2007 6:51 pm
by Xuri
Nice one, stranf! :)

One suggestion: How about changing the karma of the giver based on the percentage of gold he gives (of the total amount he's carrying) instead of specific amounts? Or make it even more complex and involve the contents of the players bankbox as well, somehow, to better determine the true quality of the player's compassion. *grin*

There would still be ways to work around that, of course, but.. *shrug*

Posted: Fri Dec 28, 2007 5:03 pm
by stranf
That's a good idea and an easy fix. The reason the Karma amounts are set in stone is that originally you could only give beggars a set amount. I just forgot to change the rewards...