Lockpick & Locks

Archive of posts related to former distro versions. Be aware that posts here do not refer to the current distro and may not work.

Moderators: POL Developer, Distro Developer

Locked
User avatar
ELSoft
Journeyman Poster
Posts: 61
Joined: Sun Jun 18, 2006 7:45 pm

Lockpick & Locks

Post by ELSoft »

Today i was watching the scripts of lockpicking in distro 095 and the scripts migrated by Yukiko and i think that i found a bug.

lockpicking.src

Code: Select all

function PickLockedItem(who, tool, chest)

	var lvl := CInt(GetObjProperty(chest,"lockable" ));

	if (!lvl)

		SendSysMessage(who,"That cannot be picked");

		return;

	endif

	if (!chest.locked)

		SendSysMessage(who,"That doesn't appear to be locked");

		return;

	endif

	PlaySoundEffect(chest,SFX_LOCKPICK);

	Sleepms(1500);

	var diff := lvl + 10;

	if ( SkillCheck(who, LOCKPICKING, diff) > 0 )

		PlaySoundEffect(chest,SFX_UNLOCK);

		chest.locked := 0;

	else

		SendSysMessage(who,"You fail to pick the lock.");

		if (diff < 10)

			diff := 0;

		else

			diff := diff -10;

		endif

		if ((RandomDiceRoll("1d99")+1) >= GetAttribute(who, LOCKPICKING))

			PlaySoundEffect(chest,0xef);

			SendSysMessage(who,"Your pick breaks!");

			SubtractAmount(tool,1);

		endif

		return;

	endif

endfunction



If we watch in the entire distro the property "Lockable" always was "1". I think that the correct code maybe

var lvl := CInt(GetObjProperty(chest,"LockPickDiff" ));

Besides this, I think that this implementation is not best. So i propose this way

Code: Select all

enum LOCK_TYPE
             MAGIC_LOCK          := 0x1,
             KEY_LOCK              := 0x2,
             TREASURE_LOCK   := 0x3
endenum

//For Carpentry & Tinkering
var lock := struct{ "type"    := KEY_LOCK,
                           "level"   := AP_GetSkill(who, TINKERING),
                           "lockid" := CreateLockID()};
SetObjProperty(theitem,"Lock", lock);

//For Magic Lock
var lock := struct{ "type"    := MAGIC_LOCK,
                           "level"   := AP_GetSkill(who, MAGERY)};

//For Treasures
var lock := struct{ "type"    := TREASURE_LOCK,
                           "level"   := ¿¿¿¿????};

SetObjProperty(theitem,"Lock", lock);

For a better reusable code ....

Code: Select all

function MakeKeyLock(theitem, craftskill )
       var thekey := CreateItemInContainer(theitem, 0x100E, 1 );
       thekey.SetLockId( CreateLockID() );
       MakeLock(theitem, KEY_LOCK, level, thekey.GetLockId());
       return thekey;
endfunction

function MakeMagicLock(theitem, mageryskill )
       MakeLock(theitem, MAGIC_LOCK, level);
endfunction

function MakeTreasureLock(theitem, level)
       MakeLock(theitem, TREASURE_LOCK, level);
endfunction

function MakeLock(theitem, type, level, lockid:=-1)
      var lock := struct{ "type"    := type,
                                "level"    := level};
     if( lockid >= 0)
              lock.+lockid := lockid;
     endif
     SetObjProperty(theitem,"Lock", lock);
endfunction
If I have the ok of the community, i can making the code for the distro
Yukiko
Distro Developer
Posts: 2825
Joined: Thu Feb 02, 2006 1:41 pm
Location: San Antonio, Texas
Contact:

Re: Lockpick & Locks

Post by Yukiko »

I'm not opposed to improving the script. The reason I left the three different CProps for lockpicking was because some developers might want different events to occur upon successfully picking a certain type of lock. For example on some shards big nasty "guardian" beats will appear when a treasure chest is picked but not when a spawned chest is picked. I thought providing the three different lock types would allow individual flexibility. I have no doubt you can improve on the script. As I mentioned I did convert from POL 0.95.

By "MAGIC_LOCK" are you referring to the magic lock spell? If so I'm not sure how "magic lock" comes into play with lockpicking. It was my understanding that magic lock and magic unlock were complementary spells but I didn't know that a "magic locked" item could be picked. I thought the only way to unlock a "magic locked" item was by casting magic unlock spell and that would be handled in the spell scripts. Maybe you meant some other kind of magic lock that I am not familiar with.

Anyway, please feel free to make it better.
User avatar
ELSoft
Journeyman Poster
Posts: 61
Joined: Sun Jun 18, 2006 7:45 pm

Re: Lockpick & Locks

Post by ELSoft »

With "MAGIC_LOCK" I'm referring to the magic lock spell
http://www.uoguide.com/Lockpicking
http://www.uoguide.com/Magic_Lock
http://www.uoguide.com/Unlock
http://uo.stratics.com/php-bin/show_con ... tent=30684

In (http://www.uoguide.com/Magic_Lock)
Duration Until picked with Lockpicking or magically unlocked with magic Unlock

But in (http://www.uoguide.com/Lockpicking)
Although a Mage may open some locked chests by way of the Unlock spell .......
On the other hand, only a Mage can unlock a chest barred with the Magic Lock spell.

is confuse =S


I think that, instead of using "chest.locked := 0;" in the lockpicking skill or in unlock spell, it is necessary use some functions like:

( this is an example )

Code: Select all

function OpenLockWithMagic(who, theitem)
       var lock := GetObjProperty(theitem,"Lock");
       if( !lock )
              SendSysMessage(who,"There is no lock in that item.");
              return 0;
       endif
       case ( lock.type )
             MAGIC_LOCK:          
                                             if ( SkillCheck(who, MAGERY, lock.level ) > 0 )
                                                        theitem.locked := 0;
                                             else
                                                        SendSysMessage(who,"The lock is too powerful.");
                                                        return 0;
                                             endif
                                             break;
             KEY_LOCK:              
                                             SendSysMessage(who,"The item cannot be unlock with magic.");
                                             return 0;
             TREASURE_LOCK:   
                                             ..... // Like MAGIC_LOCK but with treasures
                                             break;
             default:                     
                                             return 0;
       endcase
       return 1;
endfunction

function OpenLockWithLockpick(who, theitem)
       var lock := GetObjProperty(theitem,"Lock");
       if( !lock )
              SendSysMessage(who,"There is no lock in that item.");
              return 0;
       endif
       case ( lock.type )
             MAGIC_LOCK:          
                                             SendSysMessage(who,"The lock cannot be open by a mundane way.");
                                             return 0;
             KEY_LOCK:              
                                             .....   // check the skill of lockpick
                                             return 0;
             TREASURE_LOCK:   
                                             .....   // check the skill of lockpick
                                             break;
             default:                     
                                             return 0;
       endcase
       return 1;
endfunction

function OpenLockWithKey(who, theitem, key)
       var lock := GetObjProperty(theitem,"Lock");
       if( !lock )
              SendSysMessage(who,"There is no lock in that item.");
              return 0;
       endif
       case ( lock.type )
             MAGIC_LOCK:          
                                             SendSysMessage(who,"The key doesn't match.");
                                             return 0;
             KEY_LOCK:              
                                            // check if the lockid of the key match with lock.lockid
                                             return 0;
             TREASURE_LOCK:   
                                             SendSysMessage(who,"The key doesn't match.");
                                             break;
             default:                     
                                             return 0;
       endcase
       return 1;
endfunction

This is more simple, flexible and centralize the management of the locks in all scripts.

PD: This could also be used in doors, adding a DOOR_LOCK or something similar, referring to a lock that cannot by unlock using magic or lockpicking. The only way is using the key.
Yukiko
Distro Developer
Posts: 2825
Joined: Thu Feb 02, 2006 1:41 pm
Location: San Antonio, Texas
Contact:

Re: Lockpick & Locks

Post by Yukiko »

By default in the current lockpicking script a locked item without the CProps "spawnchest", "lockable" or "level" would not be able to be picked. Obviously this could be expanded. I was going to create a settings file with settings for DoorsPickable etc. but I figured I'd add that a bit later once I get a few more skills working. To be honest, I am just working on getting some skills atleast functional for now. Naturally I'm trying to adhere to the general format of the Distro.

I'm seriously thinking about starting fresh with my shard and I want to start running the Distro as my base set of scripts while slowly incorporating my custom scripts into it. Naturally I can't do that unless it is feature complete. So my goal here is to try to get skills working, have the POLitburo, ie. the developers, either accept and patch them into the Distro or have them tell me to try again if they are not up to the minimal features that they want.

As far as adding the ability to pick a magic lock and some of the more advanced things like that, it is my understanding that goes beyond the scope originally intended for the Distro. I think, and the Lord knows I could be way off track here, that the Distro is supposed to be a complete working set of scripts that allows game play at a basic level; a foundation which developers can build upon and customize.

I have asked about adding advanced features to the Distro in the past and was given the above explanation.

However, feel free to submit your improvements. I don't mind. I'm just glad the lockpicking skill is now implemented.
User avatar
ELSoft
Journeyman Poster
Posts: 61
Joined: Sun Jun 18, 2006 7:45 pm

Re: Lockpick & Locks

Post by ELSoft »

I agree with what you say, but writing this for a future improvement of the Distro I think good idea :)
Yukiko
Distro Developer
Posts: 2825
Joined: Thu Feb 02, 2006 1:41 pm
Location: San Antonio, Texas
Contact:

Re: Lockpick & Locks

Post by Yukiko »

Certainly.
Locked