Colored armor Gump

Got any custom JavaScript additions/tweaks you think other people would like to see? Post 'em here!
Post Reply
Inkvisitor
UOX3 Newbie
Posts: 4
Joined: Thu Feb 02, 2006 7:42 pm
Has thanked: 0
Been thanked: 0

Colored armor Gump

Post by Inkvisitor »

I'm not sure that this script will work on the latest release but here goes.

Can someone point out how to modify AR after creation ?
The skill check probably needs a bit more work too...
// Version 0.1 written by Inkvisitor
// Makes a GUMP for any player triggered by a special blacksmith tool.
// This script enables the ability to make colored armors.  

var myColor = 0;
var myName = 0;
var colorAddon = 0;
var colorName = 0;

function onUseChecked( pUser, iUsed )
{
    var srcSock = pUser.socket;
    var iPackOwner = GetPackOwner( iUsed, 0 );
        if( iPackOwner == null )
        {
                srcSock.SysMessage( "This has to be in your backpack!" );
                return;
        }
    srcSock.CustomTarget( 0, "What ingots do you wish to use ?" );
}
function onCallback0( tSock, targSerial )
{
    var tItem = CalcTargetedItem( tSock );
    // tSock.SysMessage( "targserial:"+targSerial+":"+tSock); //if (targSerial == 0 || titem == null)
    if (tItem == null)
    {
        tSock.SysMessage("You didn't target anything.");
        return;
    }
    myName = tItem.name;
   
    // tSock.SysMessage("target item value is "+tItem); tSock.SysMessage("target item name is "+tItem.name);
   
    if (myName == "Mythril Ingot" || myName == "Adamantium Ingot" || myName == "Merkite Ingot"
    || myName == "Agapite Ingot" || myName == "Bronze Ingot" || myName == "Verite Ingot"
    || myName == "Gold Ingot" || myName == "Silver Ingot" || myName == "Copper Ingot")
    {
        myColor = tItem.colour; // tSock.SysMessage("c:"+myColor);
    }
    else {
        tSock.SysMessage("You cannot make anything from that material");
        return;
    }
    var srcChar = tSock.currentChar;
    var iMakeResource = srcChar.ResourceCount( 0x1bf2, myColor );   // is there enough resources to use
        if( iMakeResource <25> 110 ) {
                srcChar.socket.SysMessage("You successfully create the "+colorName+" Chestplate.");
                var itemMade = SpawnItem( srcChar.socket, srcChar, "0x1416"+colorAddon, false );
                itemMade.name = colorName + " PlateMail Chest";
                itemMade.name2 = "crafted by " + srcChar.name ;
            }
            else {
                srcChar.socket.SysMessage("You fail to create the item, destroying some material");
            }
            break;
        }
        case 2:
        {
            srcChar.SoundEffect( 0x0140, true);  srcChar.DoAction(0x000b );
            srcChar.UseResource( 20, 0x1bf2, myColor); //amount, itemID, colorID
            srcChar.CheckSkill(7,1,200);
            if ( pull + (srcChar.skills[7]/10) > 110 ) {
                srcChar.socket.SysMessage("You successfully create a pair of "+colorName+" Leggings."  );
                var itemMade = SpawnItem( srcChar.socket, srcChar, "0x141a"+colorAddon, false );
                itemMade.name = colorName + " PlateMail Leggings";
                itemMade.name2 = "crafted by " + srcChar.name ;
            }
            else {
                srcChar.socket.SysMessage("You fail to create the item, destroying some material");
            }
            break;
        }
        case 3:
        {
            srcChar.SoundEffect( 0x0140, true);  srcChar.DoAction(0x000b );
            srcChar.UseResource( 17, 0x1bf2, myColor); //amount, itemID, colorID
            srcChar.CheckSkill(7,1,200);
            if ( pull + (srcChar.skills[7]/10) > 110 ) {
                srcChar.socket.SysMessage("You successfully create a pair of "+colorName+" Sleeves." );
                var itemMade = SpawnItem( srcChar.socket, srcChar, "0x1410"+colorAddon, false );
                itemMade.name = colorName + " PlateMail Sleeves";
                itemMade.name2 = "crafted by " + srcChar.name ;
            }
            else {
                srcChar.socket.SysMessage("You fail to create the item, destroying some material");
            }
            break;
        }
        case 4:
        {
            srcChar.SoundEffect( 0x0140, true);  srcChar.DoAction(0x000b );
            srcChar.UseResource( 16, 0x1bf2, myColor); //amount, itemID, colorID
            srcChar.CheckSkill(7,1,200);
            if ( pull + (srcChar.skills[7]/10) > 110 ) {
                srcChar.socket.SysMessage("You successfully create a "+colorName+" Helm." );
                var itemMade = SpawnItem( srcChar.socket, srcChar, "0x1419"+colorAddon, false );
                itemMade.name = colorName + " PlateMail Helm";
                itemMade.name2 = "crafted by " + srcChar.name ;
            }
            else {
                srcChar.socket.SysMessage("You fail to create the item, destroying some material");
            }
            break;
        }
        case 5:
        {
            srcChar.SoundEffect( 0x0140, true);  srcChar.DoAction(0x000b );
            srcChar.UseResource( 10, 0x1bf2, myColor); //amount, itemID, colorID
            srcChar.CheckSkill(7,1,200);
            if ( pull + (srcChar.skills[7]/10) > 110 ) {
                srcChar.socket.SysMessage("You successfully create a pair of "+colorName+" Gloves." );
                var itemMade = SpawnItem( srcChar.socket, srcChar, "0x1414"+colorAddon, false );
                itemMade.name = colorName + " PlateMail Gloves";
                itemMade.name2 = "crafted by " + srcChar.name ;
            }
            else {
                srcChar.socket.SysMessage("You fail to create the item, destroying some material");
            }
            break;
        }
        case 6:
        {
            srcChar.SoundEffect( 0x0140, true);  srcChar.DoAction(0x000b );
            srcChar.UseResource( 10, 0x1bf2, myColor); //amount, itemID, colorID
            srcChar.CheckSkill(7,1,200);
            if ( pull + (srcChar.skills[7]/10) > 110 ) {
                srcChar.socket.SysMessage("You successfully create a "+colorName+" Gorget." );
                var itemMade = SpawnItem( srcChar.socket, srcChar, "0x1413"+colorAddon, false );
                itemMade.name = colorName + " PlateMail Gorget";
                itemMade.name2 = "crafted by " + srcChar.name ;
            }
            else {
                srcChar.socket.SysMessage("You fail to create the item, destroying some material");
            }
            break;
        }
        case 7:
        {
            srcChar.SoundEffect( 0x0140, true);  srcChar.DoAction(0x000b );
            srcChar.UseResource( 18, 0x1bf2, myColor); //amount, itemID, colorID
            srcChar.CheckSkill(7,1,200);
            if ( pull + (srcChar.skills[7]/10) > 110 ) {
                srcChar.socket.SysMessage("You successfully create a "+colorName+" Tower Shield.");
                var itemMade = SpawnItem( srcChar.socket, srcChar, "0x1b76"+colorAddon, false );
                itemMade.name = colorName + " Tower Shield";
                itemMade.name2 = "Crafted by " + srcChar.name ;
            }
            else {
                srcChar.socket.SysMessage("You fail to create the item, destroying some material");
            }
            break;
        }
        case 8:
        {
            srcChar.SoundEffect( 0x0140, true);  srcChar.DoAction(0x000b );
            srcChar.UseResource( 18, 0x1bf2, myColor); //amount, itemID, colorID
            srcChar.CheckSkill(7,1,200);
            if ( pull + (srcChar.skills[7]/10) > 110 ) {
                srcChar.socket.SysMessage("You successfully create a "+colorName+" Chainmail Tunic." );
                var itemMade = SpawnItem( srcChar.socket, srcChar, "0x13c4"+colorAddon, false );
                itemMade.name = colorName + " Chainmail Tunic";
                itemMade.name2 = "crafted by " + srcChar.name ;
            }
            else {
                srcChar.socket.SysMessage("You fail to create the item, destroying some material");
            }
            break;
        }
        case 9:
        {
            srcChar.SoundEffect( 0x0140, true);  srcChar.DoAction(0x000b );
            srcChar.UseResource( 18, 0x1bf2, myColor); //amount, itemID, colorID
            srcChar.CheckSkill(7,1,200);
            if ( pull + (srcChar.skills[7]/10) > 110 ) {
                srcChar.socket.SysMessage("You successfully create a pair of "+colorName+" Chainmail Leggings.");
                var itemMade = SpawnItem( srcChar.socket, srcChar, "0x13c3"+colorAddon, false );
                itemMade.name = colorName + " Chainmail Leggings";
                itemMade.name2 = "crafted by " + srcChar.name ;
            }
            else {
                srcChar.socket.SysMessage("You fail to create the item, destroying some material");
            }
            break;
        }
        case 10:
        {
            srcChar.SoundEffect( 0x0140, true);  srcChar.DoAction(0x000b );
            srcChar.UseResource( 18, 0x1bf2, myColor); //amount, itemID, colorID
            srcChar.CheckSkill(7,1,200);
            if ( pull + (srcChar.skills[7]/10) > 110 ) {
                srcChar.socket.SysMessage("You successfully create a "+colorName+" Chainmail Coif." );
                var itemMade = SpawnItem( srcChar.socket, srcChar, "0x13bb"+colorAddon, false );
                itemMade.name = colorName + " Chainmail Coif";
                itemMade.name2 = "crafted by " + srcChar.name ;
            }
            else {
                srcChar.socket.SysMessage("You fail to create the item, destroying some material");
            }
            break;
        }
    }
}
Last edited by Inkvisitor on Fri Feb 03, 2006 2:06 pm, edited 1 time in total.
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 »

To modify AR after creation, the .def item property comes to mind, though I'm not 100% certain.

Also note that you might want to include a version number in the script somewhere, to make it easier for people to identify changes to your script, as well as any specific instructions needed to set it up (what's scripttrigger = 11001, for instance?). :)
-= Ho Eyo He Hum =-
Inkvisitor
UOX3 Newbie
Posts: 4
Joined: Thu Feb 02, 2006 7:42 pm
Has thanked: 0
Been thanked: 0

Post by Inkvisitor »

To get it working, add the line "11001 js/blacksmithing/blacksmithing.js" to scripts/scpTrig.scp. Then the trigger should be added to the item definition.

Other activities are blocked while using the smithing skill, that makes it impossible to "que up" entire sets of armor.
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 »

scpTrig.scp would be jse_fileassociations.scp, I assume? :)
-= Ho Eyo He Hum =-
Maarc
Developer
Posts: 576
Joined: Sat Mar 27, 2004 6:22 am
Location: Fleet, UK
Has thanked: 0
Been thanked: 0
Contact:

Post by Maarc »

Couple of comments, apart from the obvious that Xuri mentioned :) And some of this may not necessarily be documented.

1) You're explicitly setting a character's scripttrigger. This is generally a bad thing, because once you're finished using them, you're resetting it back to 0 (and you cannot guarantee the scripttrigger before the call was 0). By and large, it makes it sort of non-portable, or hard to reuse.

2) You've got a fair chunk of common sort of code, at least in the make stuff. Notably ...

Code: Select all

srcChar.scripttrigger = 11001; 
srcChar.StartTimer( 3 * 1000, 6 ); 
srcChar.SoundEffect( 0x002a, true);  srcChar.DoAction( 0x000b ); 
Apart from the 6 on the StartTimer, the rest is the same. You could throw this in a custom function, and call it with parameters. eg

Code: Select all

function myUpdate( srcChar, timerVal )
{
srcChar.scripttrigger = 11001; 
srcChar.StartTimer( 3 * 1000, timerVal ); 
srcChar.SoundEffect( 0x002a, true);  srcChar.DoAction( 0x000b ); 
}
And then just call it earlier on like ...

Code: Select all

myUpdate( srcChar, 6 );
Makes it a little more readable, and also makes it easier. You could do something very similar with the code in onTimer too, btw.

3) You could use the skillsused property, if you're trying to stop people from queueing up. Basically, the create menu (and, by exposure, the JS engine) allows for the flagging of a skill to be in use or not. And you can block on that action. So for instance, you could use something like.

Code: Select all

if( srcChar.skillsused[7] )
{
  srcChar.TextMessage( "I'm a noob, because I'm already using a skill!" );
}
And later on, when you begin the actual crafting process, you could do

Code: Select all

srcChar.skillsused[7] = true;
To flag it as being on. Make sure you do turn it off at some stage though! Otherwise you'll block that skill until the server restarts :)

Though actually, I'm not sure if we support indexing like that anymore (you'd have to ask giwo). The general way of doing it now, is usually along the lines of

Code: Select all

if( pull + ( srcChar.skills.blacksmithing / 10 ) > 110 )
And so on. Though the call to srcChar.CheckSkill() still uses the number. Perhaps that should be updated at some stage.

Just a few items for thought, hope it's helpful to you (and it might expose something others may not realise exists).
giwo
Developer
Posts: 1780
Joined: Fri Jun 18, 2004 4:17 pm
Location: California
Has thanked: 0
Been thanked: 0

Post by giwo »

Oh we support all kinds of indexing. Skills always go back to the basic numbers the client acknowledges, and thus if skillused[] was a valid parameter at one time, it should still be now (not looking at the moment).

What we DON'T index anymore, is items and characters (along with some other objects). And this is because the only number that should directly relate to these objects is their serial (which is constant), rather than their index (which changes every time you load the server)
Scott
Inkvisitor
UOX3 Newbie
Posts: 4
Joined: Thu Feb 02, 2006 7:42 pm
Has thanked: 0
Been thanked: 0

Post by Inkvisitor »

As I now have latest UOX3 compiled for linux, the testing can commence ! The script is written for 0.97 so it doesn't surprise me that things are changed. I will try to make the suggested changes and then report back. I'll paste the new script as an edit.

Thanks for the good feedback :)
stranf
UOX3 Guru
Posts: 939
Joined: Wed Jan 04, 2006 3:59 pm
Has thanked: 0
Been thanked: 0

Post by stranf »

Hey Inkvisitor?

Does this script allow you to use the tongs on colored ingots and make the armor relative to the ingot color?

Or does it rather work, where I bind it to a hammer, and that hammer only makes black armor regardless of ingot color?

either way is fine for me, just wondering.
Post Reply