Hunger, Thirst, and Disease System



  • void main()
    {
    object oPlayer;
    object oFetchedFirstPC;
    object oFetchedNextPC;
    int iFetchedThirst;
    int iFetchedHunger;
    string sConvertedThirst;
    string sConvertedHunger;
    int iFetchedTimer = GetLocalInt(OBJECT_SELF, "iTimer");
    string sFetchedIsDead;
    object oTarget;
    location lTarget;
    string sConvertedTarget;
    object oFetchedArea;
    string sConvertedArea;
    int iFetchedDisease;
    string sConvertedDisease;
    int iFetchedCurrentHP;
    int iFetchedMaxHP;

    SetLocalInt(OBJECT_SELF, "iTimer", iFetchedTimer + 1);

    if (iFetchedTimer == 30)
    {
    SetLocalInt(OBJECT_SELF, "iTimer", 0);

    oFetchedFirstPC = GetFirstPC();
    oPlayer = oFetchedFirstPC;

    while(GetIsObjectValid(oPlayer))
    {
    GiveXPToCreature(oPlayer, 1);
    SendMessageToPC(oPlayer, "You gained some survivor experience!");

    iFetchedThirst = GetCampaignInt("ThirstAndHunger", "iThirst", oPlayer);
    SetCampaignInt("ThirstAndHunger", "iThirst", iFetchedThirst + 1, oPlayer);
    sConvertedThirst = IntToString(iFetchedThirst);
    SendMessageToPC(oPlayer, "Your Thirst Is:");
    SendMessageToPC(oPlayer, sConvertedThirst);
    SendMessageToPC(oPlayer, "Don't Let It Reach 100.");

    iFetchedHunger = GetCampaignInt("ThirstAndHunger", "iHunger", oPlayer);
    SetCampaignInt("ThirstAndHunger", "iHunger", iFetchedHunger + 1, oPlayer);
    sConvertedHunger = IntToString(iFetchedHunger);
    SendMessageToPC(oPlayer, "Your Hunger Is:");
    SendMessageToPC(oPlayer, sConvertedHunger);
    SendMessageToPC(oPlayer, "Don't Let It Reach 100.");

    iFetchedDisease = GetCampaignInt("ThirstAndHunger", "iDisease", oPlayer);
    sConvertedDisease = IntToString(iFetchedDisease);
    SendMessageToPC(oPlayer, "Your disease level is:");
    SendMessageToPC(oPlayer, sConvertedDisease);
    SendMessageToPC(oPlayer, "Don't Let It Reach 10.");

    if (iFetchedDisease >= 1)
    {
    iFetchedCurrentHP = GetCurrentHitPoints(oPlayer);
    iFetchedMaxHP = GetMaxHitPoints(oPlayer);
    int iFortSave = FortitudeSave(oPlayer, 14 + iFetchedDisease, SAVING_THROW_TYPE_DISEASE);
    if (iFortSave == 0 && iFetchedCurrentHP != iFetchedMaxHP)
    {
    SetCampaignInt("ThirstAndHunger", "iDisease", iFetchedDisease + 1, oPlayer);
    iFetchedDisease = GetCampaignInt("ThirstAndHunger", "iDisease", oPlayer);
    sConvertedDisease = IntToString(iFetchedDisease);
    SendMessageToPC(oPlayer, "The disease continues to spread!:");
    SendMessageToPC(oPlayer, sConvertedDisease);
    SendMessageToPC(oPlayer, "Don't Let It Reach 10.");
    }
    else
    {
    iFetchedDisease = GetCampaignInt("ThirstAndHunger", "iDisease", oPlayer);
    sConvertedDisease = IntToString(iFetchedDisease);
    SendMessageToPC(oPlayer, "You fought off the disease for now!.");
    SetCampaignInt("ThirstAndHunger", "iDisease", iFetchedDisease - 1, oPlayer);
    SendMessageToPC(oPlayer, "Your disease level is: " + sConvertedDisease);
    }
    }

    if (iFetchedThirst >= 100 || iFetchedHunger >= 100 || iFetchedDisease >= 10)
    {
    SetCampaignString("ThirstAndHunger", "sIsDead", "sDead", oPlayer);
    }

    sFetchedIsDead = GetCampaignString("ThirstAndHunger", "sIsDead", oPlayer);
    oFetchedArea = GetArea(oPlayer);
    oTarget = GetWaypointByTag("RealmOfTheDead");

    string sFetchedTagOfCurrentArea = GetTag(oFetchedArea);
    if (sFetchedTagOfCurrentArea == "RealmoftheDead" || sFetchedTagOfCurrentArea == "LabyrinthofHopeLevel1" || sFetchedTagOfCurrentArea == "LabyrinthofHopeLevel2" || sFetchedTagOfCurrentArea == "LabyrinthofHopeLevel3")
    {
    SendMessageToPC(oPlayer, "You are dead.");
    int iFetchedIsDead = GetIsDead(oPlayer);
    if (iFetchedIsDead == TRUE)
    {
    ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectResurrection(), oPlayer, 0.0f);

    lTarget = GetLocation(oTarget);
    AssignCommand(oPlayer, ClearAllActions());
    AssignCommand(oPlayer, ActionJumpToLocation(lTarget));
    }
    }
    else
    {
    if (sFetchedIsDead == "sDead")
    {
    ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectResurrection(), oPlayer, 0.0f);

    lTarget = GetLocation(oTarget);
    AssignCommand(oPlayer, ClearAllActions());
    AssignCommand(oPlayer, ActionJumpToLocation(lTarget));
    }
    }
    oFetchedNextPC = GetNextPC();
    oPlayer = oFetchedNextPC;
    }
    }
    }



  • #include "x3_inc_horse"

    void main()
    {
    object oPC=GetEnteringObject();

    string sFetchedPlayerName = GetPCPlayerName(oPC);
    string sFetchedPCPublicCDKey = GetPCPublicCDKey(oPC, FALSE);
    object oFetchedPlayerValidation = GetItemPossessedBy(oPC, "PlayerValidation");
    if (oFetchedPlayerValidation == OBJECT_INVALID)
    {
    CreateItemOnObject("pv", oPC, 1, "PlayerValidation");
    oFetchedPlayerValidation = GetItemPossessedBy(oPC, "PlayerValidation");
    SetName(oFetchedPlayerValidation, sFetchedPlayerName + sFetchedPCPublicCDKey);
    }
    string sFetchedItemName = GetName(oFetchedPlayerValidation, FALSE);
    if (sFetchedItemName != sFetchedPlayerName + sFetchedPCPublicCDKey)
    {
    BootPC(oPC);
    }

    string sConvertedThirst;
    int iFetchedThirst = GetCampaignInt("ThirstAndHunger", "iThirst", oPC);
    if (iFetchedThirst > 0)
    {
    sConvertedThirst = IntToString(iFetchedThirst);
    SendMessageToPC(oPC, "Your Thirst Is:");
    SendMessageToPC(oPC, sConvertedThirst);
    SendMessageToPC(oPC, "Don't Let It Reach 100.");
    }
    else
    {
    SetCampaignInt("ThirstAndHunger", "iThirst", 0, oPC);
    }
    string sConvertedHunger;
    int iFetchedHunger = GetCampaignInt("ThirstAndHunger", "iHunger", oPC);
    if (iFetchedHunger > 0)
    {
    sConvertedHunger = IntToString(iFetchedHunger);
    SendMessageToPC(oPC, "Your Hunger Is:");
    SendMessageToPC(oPC, sConvertedHunger);
    SendMessageToPC(oPC, "Don't Let It Reach 100.");
    }
    else
    {
    SetCampaignInt("ThirstAndHunger", "iHunger", 0, oPC);
    }
    string sConvertedDisease;
    int iFetchedDisease = GetCampaignInt("ThirstAndHunger", "iDisease", oPC);
    if (iFetchedDisease > 0)
    {
    sConvertedDisease = IntToString(iFetchedDisease);
    SendMessageToPC(oPC, "Your Disease Level Is:");
    SendMessageToPC(oPC, sConvertedDisease);
    SendMessageToPC(oPC, "Don't Let It Reach 10.");
    }
    else
    {
    SetCampaignInt("ThirstAndHunger", "iDisease", 0, oPC);
    }
    ExecuteScript("x3_mod_pre_enter",OBJECT_SELF); // Override for other skin systems
    if ((GetIsPC(oPC)||GetIsDM(oPC))&&!GetHasFeat(FEAT_HORSE_MENU,oPC))
    { // add horse menu
    HorseAddHorseMenu(oPC);
    if (GetLocalInt(GetModule(),"X3_ENABLE_MOUNT_DB"))
    { // restore PC horse status from database
    DelayCommand(2.0,HorseReloadFromDatabase(oPC,X3_HORSE_DATABASE));
    } // restore PC horse status from database
    } // add horse menu
    if (GetIsPC(oPC))
    { // more details
    // restore appearance in case you export your character in mounted form, etc.
    if (!GetSkinInt(oPC,"bX3_IS_MOUNTED")) HorseIfNotDefaultAppearanceChange(oPC);
    // pre-cache horse animations for player as attaching a tail to the model
    HorsePreloadAnimations(oPC);
    DelayCommand(3.0,HorseRestoreHenchmenLocations(oPC));
    } // more details
    }



  • Just some scripts I've been working on for my module, figured I would share them though if anything ever happened to my backups. I also have a cheap and lowly player validation tool, but I'm looking for a better one if anyone can help me out.



  • #include "dmfi_plychat_inc"

    const string DMFI_PLAYERCHAT_SCRIPTNAME = "dmfi_plychat_exe";

    ////////////////////////////////////////////////////////////////////////
    void main()
    {
    object oFetchedSpeaker = GetPCChatSpeaker();
    string sFetchedLastChatMessage = GetPCChatMessage();

    if (sFetchedLastChatMessage == "-Search")
    {
    object oFetchedWeaponsAndArmorTrigger = GetNearestObjectByTag("WeaponsAndArmor", oFetchedSpeaker, 1);
    int iFetchedIsInSubArea = GetIsInSubArea(oFetchedSpeaker, oFetchedWeaponsAndArmorTrigger);
    if (iFetchedIsInSubArea == TRUE)
    {
    int iFetchedSearchDC = GetLocalInt(oFetchedWeaponsAndArmorTrigger, "iSearchDC");
    int iFetchedIsSearchSuccessful = GetIsSkillSuccessful(oFetchedSpeaker, SKILL_SEARCH, iFetchedSearchDC);
    if (iFetchedIsSearchSuccessful == TRUE)
    {
    SetLocalInt(oFetchedWeaponsAndArmorTrigger, "iSearchDC", iFetchedSearchDC + 1);
    SendMessageToPC(oFetchedSpeaker, "You Found Something!");
    int iRandomOne = Random(53) + 1;
    if (iRandomOne == 1)
    {
    CreateItemOnObject("paddedarmor", oFetchedSpeaker, 1, "");
    }
    else if (iRandomOne == 2)
    {
    CreateItemOnObject("leatherarmor", oFetchedSpeaker, 1, "");
    }
    else if (iRandomOne == 3)
    {
    CreateItemOnObject("studdedleather", oFetchedSpeaker, 1, "");
    }
    else if (iRandomOne == 4)
    {
    CreateItemOnObject("chainshirt", oFetchedSpeaker, 1, "");
    }
    else if (iRandomOne == 5)
    {
    CreateItemOnObject("chainmail", oFetchedSpeaker, 1, "");
    }
    else if (iRandomOne == 6)
    {
    CreateItemOnObject("scalemail", oFetchedSpeaker, 1, "");
    }
    else if (iRandomOne == 7)
    {
    CreateItemOnObject("breastplate", oFetchedSpeaker, 1, "");
    }
    else if (iRandomOne == 😎
    {
    CreateItemOnObject("prismaticfull001", oFetchedSpeaker, 1, "");
    }
    else if(iRandomTwo == 9)
    {
    CreateItemOnObject("fullplateofthevo", oFetchedSpeaker, 1, "");
    }
    else if(iRandomTwo == 10)
    {
    CreateItemOnObject("ArchmagesStaff", oFetchedSpeaker, 1, "");
    }
    else if(iRandomTwo == 11)
    {
    CreateItemOnObject("telridianlongswo", oFetchedSpeaker, 1, "");
    }
    else if(iRandomTwo == 12)
    {
    CreateItemOnObject("terrorofthenight", oFetchedSpeaker, 1, "");
    }
    else if(iRandomTwo == 13)
    {
    CreateItemOnObject("shockinglongbowo", oFetchedSpeaker, 1, "");
    }
    else if(iRandomTwo == 14)
    {
    CreateItemOnObject("bowofelementalfu", oFetchedSpeaker, 1, "");
    }
    else if(iRandomTwo == 15)
    {
    CreateItemOnObject("arrowofundeadsla", oFetchedSpeaker, 1, "");
    }
    else if(iRandomTwo == 16)
    {
    CreateItemOnObject("salamander", oFetchedSpeaker, 1, "");
    }
    else if(iRandomTwo == 17)
    {
    CreateItemOnObject("heavenandhell", oFetchedSpeaker, 1, "");
    }
    else if(iRandomTwo == 18)
    {
    CreateItemOnObject("aegisoftheoracle", oFetchedSpeaker, 1, "");
    }
    else if(iRandomTwo == 19)
    {
    CreateItemOnObject("woodentowershiel", oFetchedSpeaker, 1, "");
    }
    else if(iRandomTwo == 20)
    {
    CreateItemOnObject("smallshieldofthe", oFetchedSpeaker, 1, "");
    }
    else if(iRandomTwo == 21)
    {
    CreateItemOnObject("telridianstealth", oFetchedSpeaker, 1, "");
    }
    else if(iRandomTwo == 22)
    {
    CreateItemOnObject("hoodofconcealing", oFetchedSpeaker, 1, "");
    }
    else if(iRandomTwo == 23)
    {
    CreateItemOnObject("helmofintellect", oFetchedSpeaker, 1, "");
    }
    else if(iRandomTwo == 24)
    {
    CreateItemOnObject("stealthybootsofd", oFetchedSpeaker, 1, "");
    }
    SendMessageToPC(oFetchedSpeaker, "You Found Something!");
    }
    else
    {
    SendMessageToPC(oFetchedSpeaker, "You Didn't Find Anything!");
    }
    }
    }

    int nVolume = GetPCChatVolume();
    object oShouter = GetPCChatSpeaker();

    int bInvoke;
    string sChatHandlerScript;
    int maskChannels;
    // int bListenAll;
    object oRunner;
    int bAutoRemove;
    int bDirtyList = FALSE;
    int iHook;
    object oMod = GetModule();
    // SendMessageToPC(GetFirstPC(), "OnPlayerChat - process hooks");
    int nHooks = GetLocalArrayUpperBound(oMod, DMFI_CHATHOOK_HANDLE_ARRAYNAME);
    for (iHook = nHooks; iHook > 0; iHook–) // reverse-order execution, last hook gets first dibs
    {
    // SendMessageToPC(GetFirstPC(), "OnPlayerChat -- process hook #" + IntToString(iHook));
    maskChannels = GetLocalArrayInt(oMod, DMFI_CHATHOOK_CHANNELS_ARRAYNAME, iHook);
    // SendMessageToPC(GetFirstPC(), "OnPlayerChat -- channel heard=" + IntToString(nVolume) + ", soughtmask=" + IntToString(maskChannels));
    if (((1 << nVolume) & maskChannels) != 0) // right channel
    {
    // SendMessageToPC(GetFirstPC(), "OnPlayerChat --- channel matched");

    bInvoke = FALSE;
    if (GetLocalArrayInt(oMod, DMFI_CHATHOOK_LISTENALL_ARRAYNAME, iHook) != FALSE)
    {
    bInvoke = TRUE;
    }
    else
    {
    object oDesiredSpeaker = GetLocalArrayObject(oMod, DMFI_CHATHOOK_SPEAKER_ARRAYNAME, iHook);
    if (oShouter == oDesiredSpeaker) bInvoke = TRUE;
    }
    if (bInvoke) // right speaker
    {
    // SendMessageToPC(GetFirstPC(), "OnPlayerChat --- speaker matched");
    sChatHandlerScript = GetLocalArrayString(oMod, DMFI_CHATHOOK_SCRIPT_ARRAYNAME, iHook);
    oRunner = GetLocalArrayObject(oMod, DMFI_CHATHOOK_RUNNER_ARRAYNAME, iHook);
    // SendMessageToPC(GetFirstPC(), "OnPlayerChat --- executing script '" + sChatHandlerScript + "' on object '" + GetName(oRunner) +"'");
    ExecuteScript(sChatHandlerScript, oRunner);
    bAutoRemove = GetLocalArrayInt(oMod, DMFI_CHATHOOK_AUTOREMOVE_ARRAYNAME, iHook);
    if (bAutoRemove)
    {
    // SendMessageToPC(GetFirstPC(), "OnPlayerChat --- scheduling autoremove");
    bDirtyList = TRUE;
    SetLocalArrayInt(oMod, DMFI_CHATHOOK_HANDLE_ARRAYNAME, iHook, 0);
    }
    }
    }
    }

    if (bDirtyList) DMFI_ChatHookRemove(0);

    // always execute the DMFI parser
    ExecuteScript(DMFI_PLAYERCHAT_SCRIPTNAME, OBJECT_SELF);

    }



  • That one is a search system based on the on player chat to find items using a character's search skill. Also some DMFI stuff. I could also use some tutorials on while loops, or loops in general as I struggle with them sometimes.


Log in to reply