Thiefs stealing from players.

Got any custom JavaScript additions/tweaks you think other people would like to see? Post 'em here!
Post Reply
Grimson
Developer
Posts: 802
Joined: Sat Jun 04, 2005 1:52 am
Location: Germany
Has thanked: 0
Been thanked: 0

Thiefs stealing from players.

Post by Grimson »

A little script so thiefs steal from players when they talk to them:

First edit the malehumans.dfn and femalehumans.dfn, there go to the m_thief and f_thief sections, remove the "NPCAI=2" line, so that the thiefs won't attack you from the beginning. Also change the "SCRIPT=3000" line into "SCRIPT=3001".

Now open jse_fileassociations.scp, search for this line:

Code: Select all

3000=npc/speech/speech_001.js
add this directly after the searched line:

Code: Select all

3001=custom/thief.js
Copy the speech_001.js into the custom folder and rename it to thief.js, now open the thief.js and search for:

Code: Select all

	var i = 0, currObj = 0;
add this directly after the searched line:
    var mItem;
    var trySteal = RandomNumber( 0, 1 );
    var stealItem = null;
    var goldFound = 0;
   
    if( trySteal == 1 ) {
        for( mItem = myPlayer.pack.FirstItem(); !myPlayer.pack.FinishedItems(); mItem = myPlayer.pack.NextItem() )
        {
            if( mItem != null )
            {
                if( mItem.id == 0x0eed )
                {
                    var stealAmount = RandomNumber( 10, 50 );
                    if(mItem.amount < stealAmount)
                    {
                        mItem.container = myNPC.pack;
                    } else {
                        var itemMade = CreateDFNItem( myNPC.socket, myNPC, "0x0eed", stealAmount, "ITEM", true );
                        mItem.amount = mItem.amount - stealAmount;
                    }
                    goldFound = 1;
                }
                else if( stealItem == null && (RandomNumber( 0, 1 )) == 1 )
                {
                    stealItem = mItem;
                }      
            }
        }
        if( goldFound == 0 && stealItem != null )
        {
            stealItem.container = myNPC.pack;
        }
   
    }
Every time a player talks to a thief there is a 50% chance that the thief trys to steal something from him. Thiefs first look after gold, if the player has gold in his backpack the thief steals between 10 and 50 coins. If the player has no gold the thief steals a random item from the backpack.

This script is still in a very early stage, what is needed to make it better:
  • Inlcude a possibility that a player with higher skills detects the steal attempt (I'm still looking for a skill that might fit that purpose), and turn the thief into a criminal if he got detected (is this even possible with a jscript?).
  • Let thiefs try to steal when they collide with a player (can't do that until onCollide works again).
When the inRange event is working again (according to the docs it's broken) it might also nice to have a thief follow a player char, trying to run into him or provoking the player into talking, for example by offering a (faked) quest ;).
giwo
Developer
Posts: 1780
Joined: Fri Jun 18, 2004 4:17 pm
Location: California
Has thanked: 0
Been thanked: 0

Post by giwo »

Looks great, Grimson.

Btw, if inRange is broken (and I have no idea, though I thought it worked), can we get a verified bug report on it? :)
Scott
User avatar
Xuri
Site Admin
Posts: 3704
Joined: Mon Jun 02, 2003 9:11 am
Location: Norway
Has thanked: 48 times
Been thanked: 8 times
Contact:

Post by Xuri »

Nice idea, and nicely done script =)

To make the thief a criminal upon detection, try

Code: Select all

myNPC.criminal = true;
I'm not sure if it works on NPCs, but if it does, it will probably make the NPC permanently "grey", so you'll have to use a timer of your own if you want it to wear off.

And you might want to limit what kind of items the thieves take to items that might be "acceptable" for players to loose. Won't be too happy if some random NPC just steals their Magic Weapon of L33t, and they can't even get it back if they didn't detect the crime so the NPC becomes a criminal =)

giwo: I quote from the Javascript Docs:
Notes objType == 0 indicates objInRange is a character
objType == 1 indicates objInRange is an item
CURRENTLY BROKEN!!!
:D
-= Ho Eyo He Hum =-
Grimson
Developer
Posts: 802
Joined: Sat Jun 04, 2005 1:52 am
Location: Germany
Has thanked: 0
Been thanked: 0

Post by Grimson »

giwo wrote:Btw, if inRange is broken (and I have no idea, though I thought it worked), can we get a verified bug report on it? :)
I have just tried it. I added the followinf to the thief.js:

Code: Select all

function inRange( myNPC, objInRange, objType )
{
	if( objType == 0 )
	{
		if( !objInRange.npc )
		{
			myNPC.TurnToward( objInRange );
			myNPC.TextMessage( "Hey "+objInRange.name+" wait I have to talk to you." );
		}
	}	
}
But I can run around a thief or stand right in front of his eyes without anything happening.

Edit:

Code: Select all

myNPC.criminal = true;
Doesn't seem to work. I guess you can only read out the criminal status, but not change it via script.
giwo
Developer
Posts: 1780
Joined: Fri Jun 18, 2004 4:17 pm
Location: California
Has thanked: 0
Been thanked: 0

Post by giwo »

Well inRange is only triggered when you first come within visual range of the character or item.

Likely what the problem is, though, is that one would think you would want it to trigger this way.

Char x is running around

Char x comes in visual range of Char y

Char y is triggered, yelling at Char x



How it currently works

Char x is runing around

Char x comes in visual range of Char y

Char x is triggered, nothing happens because Char y had the script assigned to it.

Let me switch it around, so it runs the proper way, and we'll see how it looks.
Scott
giwo
Developer
Posts: 1780
Joined: Fri Jun 18, 2004 4:17 pm
Location: California
Has thanked: 0
Been thanked: 0

Post by giwo »

On second thought, you should be able to be triggered when you walk near something if you have a script assigned. But it should be able to be triggered as well.

Thus we should have it both ways :)
Scott
Grimson
Developer
Posts: 802
Joined: Sat Jun 04, 2005 1:52 am
Location: Germany
Has thanked: 0
Been thanked: 0

Post by Grimson »

Grimson wrote:

Code: Select all

myNPC.criminal = true;
Doesn't seem to work. I guess you can only read out the criminal status, but not change it via script.
I just had a bit of time and looked into it. As far as I can tell the attempt to set an NPC criminal with the above fails in the "setcharflag( CChar *c )" function in "uox3.cpp". It get's called but doesn't set an NPC criminal, it does work on players though. So is it just a bug, or aren't NPCs supposed to become criminals?

Edit:
Seems like criminal NPCs weren't planned in the first place. So I made up a dirty hack for them to work: viewtopic.php?p=2749#2749
giwo
Developer
Posts: 1780
Joined: Fri Jun 18, 2004 4:17 pm
Location: California
Has thanked: 0
Been thanked: 0

Post by giwo »

NPC's should be able to become criminals. I suppose it has just been an oversight that they currently aren't able to (never having an NPC actually change status mid-game, it wasn't noticed).

I'll take a look at your changes on the other post when I get home this afternoon, and see what I can come up with to allow fully-featured Criminal NPC's.
Scott
karther77
UOX3 Newbie
Posts: 8
Joined: Wed Nov 08, 2006 5:19 am
Location: California
Has thanked: 0
Been thanked: 0
Contact:

Post by karther77 »

Could this not be changed to make the NPC thief search for players like the wandering healers do and when they find a PC (player) then he tries to snoop bag then random steal gold first then item as possible. Instead of trying this on being talked to.? THis would make a better thief.?

It would be like searching for player. Once found target player then snoop bag then try steal gold 50 or if not found try random item in bag.

Thanks just wondering if this was another possible fix for this to make it a better NPC thief in town....
Karther-Ranger of Yew
(NuFf SaId)
Post Reply