I suck at scripting...

Here you can post threads requesting help on the official POL Ultima Online Emulator Core 095. Note: Core 095 is no longer officially supported.
Post Reply
Breg
New User
Posts: 27
Joined: Sat Dec 09, 2006 11:58 am

I suck at scripting...

Post by Breg »

Okay heres my dealio now peeps.. I need Theivery as in Snooping and Stealing to function like this,

1. Dbl click the snooping gloves
2. Target the victim
3. Open their backpack containers within the pack also resulting in seperate skillchecks for each container opened via snooping
4. Using stealing to click the items and voila!
5. Feel free to remove the weird steal from guards/npc thingy I'd prefer it to be player interactionable to increase roleplay.
And here is my crappy messy coding.. goodluck and may god save your soul!

SNOOPING

Code: Select all

use uo;
use os;
use util;

include "include/client";
include "include/attributes";
include "../pkg/character/virtue/virtue";
include "include/class";
include "include/trainingskill";

program snooping( who )

        var data := {};
        data[1] := "snooping";
        data[2] := ReadGameClock();
        data[3] := 28;
        SetObjProperty(who, "LastUsedSkill", data );
        TrainingSkill(who, data);

	SendSysMessage(who,"choose victim");

	var victim := Target(who, TGTOPT_CHECK_LOS);
	if (!victim)
		SendSysMessage(who,"Canceled");
		return;
	endif

	if (!CheckLosAt(who, victim.x, victim.y, victim.z))
           SendSysMessage(who, "You can't see that.");
	   return 0;
	endif

	if ( Distance(who, victim) > 2 )
		SendSysMessage(who,"A bit far away, don't you think?");
		return;
	endif

        var diff := GetDiff(who, victim);
        if (!CheckSkill(who, SKILLID_SNOOPING, diff, modify_points(who, SKILLID_SNOOPING, 100)))
	
	endif

	AddVirtue(who, -1);


endprogram

function GetDiff(who, victim)

        var skill := GetEffectiveSkill( who, SKILLID_SNOOPING );
        var whoskill := CInt(skill/4) + CInt(GetDexterity(who)/4);                     // max 60
        var victimskill := CInt(GetDexterity(victim)/6) + CInt(GetIntelligence(victim)/4) + 10; // max 60
        var chance := victimskill - whoskill + 50;
        return chance;

endfunction
STEALING

Code: Select all

use uo;
use os;
use util;

include "include/client";
include "include/attributes";
include "include/objtype";
include "include/eventid";
include "../pkg/character/virtue/virtue";
include "include/class";
include "include/trainingskill";

program textcmd_dmg( who )

        var data := {};
        data[1] := "stealing";
        data[2] := ReadGameClock();
        data[3] := 33;
        SetObjProperty(who, "LastUsedSkill", data );
        TrainingSkill(who, data);

	SendSysMessage(who,"Steal from whom?");

	var victim := Target(who, TGTOPT_CHECK_LOS);
	if (!victim)
		SendSysMessage(who,"Canceled");
		return;
	endif

	if ( Distance(who,victim)>2 )
		SendSysMessage(who,"A bit far away, don't you think?");
		return;
	endif

	var diff := CanStealFrom(victim);
	if ( (!diff) || ( diff > (GetEffectiveSkill(who, SKILLID_STEALING)+20) ) )
		SendSysMessage(who,"You'd be caught red handed!");
		SendSysMessage(who,"Canceled");
		return;
	endif

        if (!CheckSkill(who,SKILLID_STEALING,diff,modify_points(who, SKILLID_STEALING, 0)))
		Busted(who, victim);
		return;
	endif

	if ( GetObjProperty(victim,"#robbed") )
		if ( ReadGameClock() < GetObjProperty(victim,"#robbed") )
			SendSysMessage(who,"Doesn't look like they have any money.");
			return;
		endif
	endif

	SetObjProperty( victim, "#robbed", ReadGameClock()+1800 );
	AddVirtue(who,-2);

	var lootbag := who.backpack;
	if ( GetObjProperty(who,"grabbag") )
		var bagserial := GetObjProperty(who,"grabbag");
		foreach item in EnumerateItemsInContainer(who.backpack)
			if ( item.serial == bagserial )
				lootbag := item;
				break;
			endif
		endforeach
	endif

	if (RandomInt(100) < diff )
		SendSysMessage(who,"Ooh!  Gems!");
		var gem := gemtype(diff);
		var amount := RandomInt(2) + 1;
		foreach item in EnumerateItemsInContainer(who.backpack)
			if (item.objtype == gem)
				if (AddAmount(item, amount))
					return;
				endif
			endif
		endforeach
		CreateItemInContainer(lootbag, gem, amount);
	else
		SendSysMessage(who,"You successfully pilfer a few coins.");
		CreateItemInContainer(lootbag, UOBJ_GOLD_COIN, RandomInt(diff)+(diff*2));
	endif

endprogram

function Busted(who, victim)

	PrintTextAbove(victim,"Stop!  Help!  A thief!");
	who.criminal := 1;

	var ev := array;
	ev.+type;
	ev.+source;
	ev.source := who;
	ev.type := EVID_DAMAGED;
	SendEvent(victim,ev);

	foreach guard in ListMobilesNearLocation(victim.x, victim.y, victim.z, 20)
		if ( guard.npctemplate == "townguard" )
			SendEvent(guard,ev);
		endif
	endforeach

endfunction

function CanStealFrom(victim)

	if (victim.npctemplate == "person")
		return 20;
	elseif (victim.npctemplate == "townperson")
		return 40;
	elseif (victim.npctemplate == "questie")
		return 60;
	elseif (victim.npctemplate == "warrior" && !GetObjProperty(victim, "master"))
		return 80;
	elseif (victim.npctemplate["townguard"] || victim.script["merchant"])
		return 100;
	else
		return 0;
	endif

endfunction

function gemtype(diff)

	var d := RandomInt(2);
	var tone, ttwo;

	case (diff)
	100:
		tone := 0x0f30;//diamond
		ttwo := 0x0f0f;//starsapphire
	80:
		tone := 0x0f10;//emerald
		ttwo := 0x0f11;//sapphire
	60:
		tone := 0x0f13;//ruby
		ttwo := 0x0f16;//amethyst
	40:
		tone := 0x0f15;//citrine
		ttwo := 0x0f18;//tourmaline
	default:
		tone := 0x0f25;//amber
		ttwo := 0x0f25;//amber
	endcase

	if (d)
		return tone;
	else
		return ttwo;
	endif

endfunction
Yukiko
Distro Developer
Posts: 2826
Joined: Thu Feb 02, 2006 1:41 pm

Re: I suck at scripting...

Post by Yukiko »

We all sucked at scripting in the beginning.
I still do so I don't have an excuse.
*grins*

Now just to get things rolling I looked at the snooping script and I think I found the place where you want the success and/or failure to occur and the backpack to open. I think it's here:

Code: Select all

var diff := GetDiff(who, victim);
if (!CheckSkill(who, SKILLID_SNOOPING, diff, modify_points(who, SKILLID_SNOOPING, 100)))
   
endif
It's been a long time since I worked with those scripts but if you want the backpack to open you'll have to use SendViewContainer( who, victim.backpack) or SendOpenSpecialContainer( who, victim.backpack) upon successful snooping. I suppose you'd change the script to the following:

Code: Select all

var diff := GetDiff(who, victim);
if (!CheckSkill(who, SKILLID_SNOOPING, diff, modify_points(who, SKILLID_SNOOPING, 100))) // I'm guessing this means they failed.
   //Notify the victim someone is trying to snoop if you want to that is.
   return 0;
elseif
   SendViewContainer( who, victim.backpack);
endif
Be sure you understand the ramifications of using the SendOpenSpecialContainer function if you do end up uding it. Read the docs because it allows the player to alter the contents of containers and may not be the one you need to use. I was never too ot on snooping and stealing so I can't remember what we did to get that script to actually work on our shard. I think I ended up disabling it later in fact.
Post Reply