Ferry Masters

Got any custom JavaScript additions/tweaks you think other people would like to see? Post 'em here!
Post Reply
dragon slayer
UOX3 Guru
Posts: 776
Joined: Thu Dec 21, 2006 7:37 am
Has thanked: 4 times
Been thanked: 26 times

Ferry Masters

Post by dragon slayer »

Here is code for ferry master creation on your shard.

in your jse_fileassociation.scp

add this
50156=custom/ferrymaster.js
in the commands part
1066=custom/spawnferrymaster.js

prices go by how much ferry master is used each one is different also prices change every 23 hours
function CommandRegistration()
{
    RegisterCommand( "spawnferrymasters", 2, true );
    RegisterCommand( "ferrymastersetup", 2, true);
}

function command_SPAWNFERRYMASTERS( socket, cmdString )
{
    var pUser = socket.currentChar;
    FerrymasterSpawnGump( pUser );
}

function command_FERRYMASTERSETUP(socket, cmdString)
{
    var pUser = socket.currentChar;
    FerrymasterSpawnGump(pUser);
}

function FerrymasterSpawnGump(pUser)
{
    var socket = pUser.socket;
    var uox3gump = new Gump;
    uox3gump.AddPage(0);

    uox3gump.AddBackground(30, 30, 224, 196, 1755);
    uox3gump.AddGump(40, 40, 299);
    uox3gump.AddPicture(130, 100, 5364);
    uox3gump.AddHTMLGump(70, 186, 200, 100, false, false, "<basefont color=#ffffff>Spawn Ferry Masters</basefont>");
    uox3gump.AddButton(50, 190, 1209, 1210, 1, 0, 1);

    uox3gump.Send(pUser);
    uox3gump.Free();
}

function onGumpPress(pSock, pButton, gumpData)
{
    var pUser = pSock.currentChar;
    switch (pButton)
    {
        case 1:
            if (!pUser.GetTag("Createdfm"))
            {
                CreateFerryMaster();
                pUser.SetTag("Createdfm", true);
                pSock.SysMessage("All Ferry Masters Spawned.");
            }
            else
                pSock.SysMessage("You have already created the ferry masters.");
            break;
        default: break;
    }
}

function CreateFerryMaster()
{
    // Coordinates for each ferry master location
    var locations = [
        { x: 2058, y: 2856, z: -2 },  // Trinsic
        { x: 1481, y: 1753, z: -2 },  // Britain
        { x: 2252, y: 1191, z: -2 },  // Cove
        { x: 2527, y: 349, z: -2 },   // Minoc
        { x: 4406, y: 1048, z: -2 },  // Moonglow
        { x: 3801, y: 1279, z: 6 },   // Nujelm
        { x: 3649, y: 2657, z: -2 },  // Ocllo
        { x: 2948, y: 3400, z: 1 },   // Serpent's Hold
        { x: 1489, y: 3696, z: -2 },  // Jhelom
        { x: 521, y: 803, z: -2 }     // Yew
    ];

    for (var i = 0; i < locations.length; i++)
    {
        var loc = locations[i];
        var ferrymaster = SpawnNPC("ferrymaster", loc.x, loc.y, loc.z, 0, 0);
        ferrymaster.wandertype = 0;  // Set to stationary
        ferrymaster.frozen = true;   // Prevent movement
        ferrymaster.direction = 0;   // Set facing direction (0 = North)
    }
}
Here is the ferry master script
function onCreateDFN(objMade, objType)
{
    if (objType == 1)
    {
        if (!objMade.GetTag("init"))
        {
            UpdateCityCosts(objMade);
            objMade.StartTimer(82800000, 1, true);// start the timer for 23 hours
        }
    }
}

function onCharDoubleClick(pUser, FerryMaster)
{
    if (!FerryMaster.GetTag("init"))
    {
        UpdateCityCosts(FerryMaster);
        FerryMaster.StartTimer(82800000, 1, true);// start the timer for 23 hours
    }

    if (!FerryMaster.InRange(pUser, 1))
    {
        pUser.SysMessage("You are too far away from ferry master");
        return false;
    }
    else
    {
        FerryMasterGump(pUser, FerryMaster);
        pUser.SetTag("FerryMasterSerial", (FerryMaster.serial).toString());
    }
}

function FerryMasterGump(pUser, FerryMaster)
{
    var socket = pUser.socket;

    // Retrieve the costs from the tag
    var costTag = FerryMaster.GetTag("cityCosts");
    if (!costTag)
    {
        // Default values if tag doesn't exist
        costTag = "500,500,500,500,500,500,500,500,500,500";
        FerryMaster.SetTag("cityCosts", costTag);
    }

    // Split the costs into an array
    var costs = costTag.split(",");
    var FerryGump = new Gump;
    FerryGump.AddPage(0);

    FerryGump.AddBackground(30, 20, 465, 484, 1755);
    FerryGump.AddPicture(60, 40, 5364);
    FerryGump.AddPicture(440, 40, 5363);
    FerryGump.AddPicture(440, 430, 5369);
    FerryGump.AddButton(180, 30, 100, 248, 0, 0, 0);
    FerryGump.AddText(210, 70, 197, "Ferry Master");
    FerryGump.AddGump(10, 270, 12);
    FerryGump.AddGump(8, 244, 64021);
    FerryGump.AddGumpColor(10, 270, 50920, 2435);
    FerryGump.AddGumpColor(10, 270, 61201, 2435);
    FerryGump.AddGumpColor(10, 270, 61686, 2435);
    FerryGump.AddGump(10, 270, 64341);
    FerryGump.AddGump(10, 270, 64189);
    FerryGump.AddHTMLGump(80, 150, 110, 70, false, false, "<basefont color=#ffffff>Minoc</basefont>");
    FerryGump.AddHTMLGump(80, 180, 110, 70, false, false, "<basefont color=#ffffff>Yew</basefont>");
    FerryGump.AddHTMLGump(80, 210, 110, 70, false, false, "<basefont color=#ffffff>Britain</basefont>");
    FerryGump.AddHTMLGump(80, 240, 110, 70, false, false, "<basefont color=#ffffff>Cove</basefont>");
    FerryGump.AddHTMLGump(80, 270, 110, 70, false, false, "<basefont color=#ffffff>Serpents Hold</basefont>");
    FerryGump.AddHTMLGump(300, 150, 110, 70, false, false, "<basefont color=#ffffff>Nujelm</basefont>");
    FerryGump.AddHTMLGump(300, 180, 110, 70, false, false, "<basefont color=#ffffff>Ocllo</basefont>");
    FerryGump.AddHTMLGump(300, 210, 110, 70, false, false, "<basefont color=#ffffff>Jhelom</basefont>");
    FerryGump.AddHTMLGump(300, 240, 110, 70, false, false, "<basefont color=#ffffff>Moonglow</basefont>");
    FerryGump.AddHTMLGump(300, 270, 110, 70, false, false, "<basefont color=#ffffff>Trinsic</basefont>");
    FerryGump.AddGump(200, 340, 299);
    FerryGump.AddButton(50, 150, 1209, 1210, 1, 0, 1);
    FerryGump.AddButton(50, 180, 1209, 1210, 1, 0, 2);
    FerryGump.AddButton(50, 210, 1209, 1210, 1, 0, 3);
    FerryGump.AddButton(50, 240, 1209, 1210, 1, 0, 4);
    FerryGump.AddButton(50, 270, 1209, 1210, 1, 0, 5);
    FerryGump.AddButton(270, 150, 1209, 1210, 1, 0, 6);
    FerryGump.AddButton(270, 180, 1209, 1210, 1, 0, 7);
    FerryGump.AddButton(270, 210, 1209, 1210, 1, 0, 8);
    FerryGump.AddButton(270, 240, 1209, 1210, 1, 0, 9);
    FerryGump.AddButton(270, 270, 1209, 1210, 1, 0, 10);

    // Add cost text
    FerryGump.AddText(170, 150, 55, costs[0]); // Minoc
    FerryGump.AddText(170, 180, 55, costs[1]); // Yew
    FerryGump.AddText(170, 210, 55, costs[2]); // Britain
    FerryGump.AddText(170, 240, 55, costs[3]); // Cove
    FerryGump.AddText(170, 270, 55, costs[4]); // Serpents Hold
    FerryGump.AddText(370, 150, 55, costs[5]); // Nujelm
    FerryGump.AddText(370, 180, 55, costs[6]); // Ocllo
    FerryGump.AddText(370, 210, 55, costs[7]); // Jhelom
    FerryGump.AddText(370, 240, 55, costs[8]); // Moonglow
    FerryGump.AddText(370, 270, 55, costs[9]); // Trinsic

    FerryGump.Send(pUser);
    FerryGump.Free();
}

function onGumpPress(pSock, pButton, gumpData)
{
    var pUser = pSock.currentChar;

    var FerryMaster = CalcCharFromSer(parseInt(pUser.GetTag("FerryMasterSerial")));

    var goldInPack = pUser.ResourceCount(0x0EED, 0);
    var bankBox = pUser.FindItemLayer(29);
    var goldInBank = TriggerEvent(3201, "CountGoldInBank", pUser, bankBox);

    // Retrieve the costs stored in the FerryMaster's tag
    var costString = FerryMaster.GetTag("cityCosts");
    var costs = costString.split(",");

    // Determine the cost based on the button pressed
    var amount = parseInt(costs[pButton]);

    // Check if the player has enough gold
    var totalGold = goldInPack + goldInBank;
    if (totalGold >= amount)
    {
        // Deduct the gold from the player's pack and bank as necessary
        if (goldInPack >= amount)
        {
            pUser.UseResource(amount, 0x0EED); // Deduct from pack
        }
        else
        {
            pUser.UseResource(goldInPack, 0x0EED); // Use all gold in pack
            var remainingAmount = amount - goldInPack;
            bankBox.UseResource(remainingAmount, 0x0EED); // Deduct the remaining amount from the bank
        }

        // Call onRouteUsed to increase the cost based on usage
        switch (pButton)
        {
            case 1: // Minoc
                onRouteUsed(FerryMaster, 0);
                TeleportToDock(pUser, 2509, 326, -2);
                break;
            case 2: // Yew
                onRouteUsed(FerryMaster, 1);
                TeleportToDock(pUser, 522, 771, -2);
                break;
            case 3: // Britain
                onRouteUsed(FerryMaster, 2);
                TeleportToDock(pUser, 1469, 1768, -2);
                break;
            case 4: // Cove
                onRouteUsed(FerryMaster, 3);
                TeleportToDock(pUser, 2256, 1169, -2);
                break;
            case 5: // Serpents Hold
                onRouteUsed(FerryMaster, 4);
                TeleportToDock(pUser, 2936, 3414, -2);
                break;
            case 6: // Nujelm
                onRouteUsed(FerryMaster, 5);
                TeleportToDock(pUser, 3806, 1279, -2);
                break;
            case 7: // Ocllo
                onRouteUsed(FerryMaster, 6);
                TeleportToDock(pUser, 3619, 2655, -2);
                break;
            case 8: // Jhelom
                onRouteUsed(FerryMaster, 7);
                TeleportToDock(pUser, 2509, 326, -2);
                break;
            case 9: // Moonglow
                onRouteUsed(FerryMaster, 8);
                TeleportToDock(pUser, 4406, 1035, -2);
                break;
            case 10: // Trinsic
                onRouteUsed(FerryMaster, 9);
                TeleportToDock(pUser, 2084, 2855, -2);
                break;
            default: break;
        }

        // Perform ferry transportation logic here (e.g., teleporting the player to the destination)
    }
    else
    {
        pUser.SysMessage("You don't have enough gold for the ferry ride.");
    }

    // Clear the FerryMasterSerial tag
    pUser.SetTag("FerryMasterSerial", null);
}

function TeleportToDock(pUser, x, y, z)
{
    // Teleport player's pets to dock
    var followerList = pUser.GetFollowerList();
    for (var i = 0; i < followerList.length; i++)
    {
        var tempFollower = followerList[i];
        if (ValidateObject(tempFollower) && tempFollower.wandertype == 1 && tempFollower.InRange(pUser, 24))
        {
            tempFollower.Teleport(x, y, z);
            tempFollower.Follow(pUser);
        }
    }

    // Teleport player to dock
    pUser.Teleport(x, y, z);
}

function onTimer(FerryMaster, timerID)
{
    if (timerID == 1)
    { // Timer ID 1 for the daily cost randomization
        UpdateCityCosts(FerryMaster);
        FerryMaster.StartTimer(82800000, 1, true);// Reset the timer for another 23 hours
    }
}

function UpdateCityCosts(FerryMaster)
{
    // Retrieve the current costs and usage counts from the tags
    var costTag = FerryMaster.GetTag("cityCosts");
    var usageTag = FerryMaster.GetTag("cityUsage");

    if (!costTag) {
        costTag = "500,500,500,500,500,500,500,500,500,500"; // Default costs
        FerryMaster.SetTag("cityCosts", costTag);
    }

    if (!usageTag) {
        usageTag = "0,0,0,0,0,0,0,0,0,0"; // Default usage counts
        FerryMaster.SetTag("cityUsage", usageTag);
    }

    var costStrings = costTag.split(",");
    var usageStrings = usageTag.split(",");

    var costs = [];
    var usage = [];

    // Convert the string arrays to number arrays
    for (var i = 0; i < costStrings.length; i++)
    {
        costs[i] = parseInt(costStrings[i], 10);
        usage[i] = parseInt(usageStrings[i], 10);
    }

    var newCosts = [];

    for (var i = 0; i < 10; i++)
    {
        // Adjust the cost based on usage:
        // - Increase cost if the usage is high
        // - Decrease cost if the usage is low
        // - Ensure the cost stays within a reasonable range

        var adjustmentFactor = 1 + (usage[i] / 100); // Increase cost by a percentage based on usage
        var randomAdjustment = Math.floor(Math.random() * 100) - 50; // Random adjustment factor (-50 to +49)
        var newCost = Math.max(500, Math.min(2000, costs[i] * adjustmentFactor + randomAdjustment));

        newCosts.push(Math.floor(newCost));

        // Reset usage for the next period
        usage[i] = 0;
    }

    // Manually concatenate the new costs into a comma-separated string
    var costString = "";
    for (var j = 0; j < newCosts.length; j++)
    {
        costString += newCosts[j];
        if (j < newCosts.length - 1) {
            costString += ",";
        }
    }

    // Store the updated costs and reset usage counts in the tags
    FerryMaster.SetTag("cityCosts", costString);

    var usageString = "0,0,0,0,0,0,0,0,0,0"; // Reset all usage counts
    FerryMaster.SetTag("cityUsage", usageString);

    // Initialize the FerryMaster with a tag if not already done
    if (!FerryMaster.GetTag("init")) {
        FerryMaster.SetTag("init", true);
    }
}

// Function to be called when a player uses a route, updating the usage count
function IncrementUsage(FerryMaster, routeIndex)
{
    var usageTag = FerryMaster.GetTag("cityUsage");
    if (!usageTag) {
        usageTag = "0,0,0,0,0,0,0,0,0,0";
    }

    var usageStrings = usageTag.split(",");
    var usage = [];

    // Convert the string array to a number array
    for (var i = 0; i < usageStrings.length; i++)
    {
        usage[i] = parseInt(usageStrings[i], 10);
    }

    usage[routeIndex]++;

    // Manually concatenate the updated usage into a comma-separated string
    var usageString = "";
    for (var i = 0; i < usage.length; i++)
    {
        usageString += usage[i];
        if (i < usage.length - 1)
        {
            usageString += ",";
        }
    }

    // Store the updated usage counts in the tag
    FerryMaster.SetTag("cityUsage", usageString);
}

// Example usage: Call this function whenever a player uses a ferry route
function onRouteUsed(FerryMaster, routeIndex)
{
    IncrementUsage(FerryMaster, routeIndex);
}
jhere is the fery master npc
[ferrymaster]
{
GET=basehuman
NAMELIST=1
TITLE=the ferry master
ID=0x0190
EQUIPITEM=listobject13
HAIRCOLOR=15
EQUIPITEM=listobject14
COLORMATCHHAIR
EQUIPITEM=0x13b6
EQUIPITEM=listobject20
COLORLIST=11
EQUIPITEM=listobject31
COLORLIST=11
EQUIPITEM=listobject32
COLORLIST=11
EQUIPITEM=listobject33
COLORLIST=11
EQUIPITEM=listobject34
COLORLIST=11
EQUIPITEM=listobject36
COLORLIST=11
STR=86 100
DEX=66 100
INT=71 85
MAGICRESISTANCE=490 580
PARRYING=250 480
SWORDSMANSHIP=640 1000
TACTICS=650 880
WRESTLING=260 580
TOPEACE=605 5
NPCWANDER=0
FX2=10
NOTRAIN
SCRIPT=50156
}
Post Reply