Skip to content

Save Henchman and Inventory

SeverumSeverum Member Posts: 16
edited February 2019 in Builders - Scripting
Hi.

I'm trying to get the PCs to keep their Henchmans for the next time they reconnect to the server to serve them directly again.

To do this I have created a campaign BDD in the OnModuleLoad:

 
 SetLocalString (GetModule (), "X0_CAMPAIGN_DB", "Henchmen");

Then calling the function "StoreCampaignHenchman" to save the Henchmen in several situations, for example in the OnRest and in the OnLeave of the properties of the module:
object oPC = GetLastPCRested ();
    StoreCampaignHenchman (oPC);
object oPC = GetExitingObject();
StoreCampaignHenchman (oPC);

This seems to be working since it records variables of the characters in the database created.
The used code of the "StoreCampaignHenchman" is:
void StoreCampaignHenchman(object oPC)
{
    object oHench;
    string sHench;
    int ret, iSlot, iMax = GetMaxHenchmen();
 
    for (iSlot = 1; iSlot <= iMax; iSlot++)
    {
        oHench = GetHenchman(oPC, iSlot);
        if (!GetIsObjectValid(oHench))
            DBG_msg("No valid henchman to store");
        else
        {
            DBG_msg("Storing henchman: " + GetTag(oHench));
            sHench = "Henchman" + IntToString(iSlot);
            ret = StoreCampaignDBObject(oPC, sHench, oHench);
            if (!ret)
                DBG_msg("Error attempting to store henchman " + GetName(oHench));
            else
                DBG_msg("Henchman " + GetName(oHench) + " stored successfully");
        }
    }
}


The problem is when I want to recover the Henchman when the player reconnects to the server. For that I use the variable "RetrieveCampaignHenchman" for example in the OnEnter of the properties of the module:
 object oPC = GetEnteringObject ();
    if (GetLocalInt (oPC, "LOAD_HENCHMAN") == 1)
        return;
 
    if (! GetIsPC (oPC))
        return;
 
    RetrieveCampaignHenchman (oPC);
    SetLocalInt (oPC, "LOAD_HENCHMAN", 1);

The RetrieveCampaignHenchman function is:
void RetrieveCampaignHenchman(object oPC)
{
    string sHench;
    object oHench, oDupe;
    location lLoc = GetLocation(oPC);
    int iSlot, iMax = GetMaxHenchmen();
 
    for (iSlot = 1; iSlot <= iMax; iSlot++)
    {
        sHench = "Henchman" + IntToString(iSlot);
        oHench = RetrieveCampaignDBObject(oPC, sHench, lLoc);
        DelayCommand(0.5, DeleteCampaignDBVariable(oPC, sHench));
        if (GetIsObjectValid(oHench))
        {
            DelayCommand(0.5, HireHenchman(oPC, oHench));
            oDupe = GetNearestObjectByTag(GetTag(oHench), oHench);
            if ((oDupe != OBJECT_INVALID) && (oDupe != oHench))
            {
                AssignCommand(oDupe, SetIsDestroyable(TRUE));
                SetPlotFlag(oDupe,FALSE);
                SetImmortal(oDupe,FALSE);
                DestroyObject(oDupe);
            }
        }
        else
            DBG_msg("No valid henchman retrieved");
    }
}

But for some reason it is not working.

Does anyone have any ideas?

Thank you

Comments

  • HimmelweissHimmelweiss Member Posts: 72
    edited March 2019
    If you instantly call RetrieveCampaignHenchman (oPC); on the OnClientEnter script of the Module then the location of oPC will be invalid as oPC hasn't loaded the Area yet. That's why it probably isn't working.

    Call it in the OnEnter event of the Area instead.

    Ofc. you could also just DelayCommand() the call within OnClientEnter but that's not really secure since you never know how long the player needs to load.
  • SeverumSeverum Member Posts: 16
    If you instantly call RetrieveCampaignHenchman (oPC); on the OnClientEnter script of the Module then the location of oPC will be invalid as oPC hasn't loaded the Area yet. That's why it probably isn't working.

    It is! Thanks a lot!! I use RetrieveCampaignHenchman in spell and works!

    Thanks again.

  • L0BSTERL0BSTER Member Posts: 2
    Severum wrote: »
    If you instantly call RetrieveCampaignHenchman (oPC); on the OnClientEnter script of the Module then the location of oPC will be invalid as oPC hasn't loaded the Area yet. That's why it probably isn't working.

    It is! Thanks a lot!! I use RetrieveCampaignHenchman in spell and works!

    Thanks again.

    This seems like an amazing idea and I really like it.. is it possible to get a copy for my module Diablo II ? plus I will add you as the maker/designer :)

    hear from you soon.

    L0BSTER
  • SeverumSeverum Member Posts: 16
    edited March 2019
    No problem L0BSTER.
    U have this code in x0_i0_henchmen.nss

    Greetings.
    Post edited by Severum on
Sign In or Register to comment.