Author Topic: How bad are Pseudo HB's?  (Read 3041 times)

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
How bad are Pseudo HB's?
« Reply #30 on: June 25, 2011, 09:33:34 pm »


               

FunkySwerve wrote...
Anyway, we should probably continue this in pms, to prevent further sidetrackig of the thread. I'll put future responses there, unless they have  more direct bearing on the topic.


If the Original Poster or others asks me to desist I will. Otherwise, writing only for your benefit doesn't seem worth it, as the back and forth is likely to benefit someone else as well. If it is not worth it for you to post here, thats fine, but I'd rather not go back and forth in PMs.

Generally, though, this [TMI] shouldn't be an issue, and you can always avoid it by AssignCommanding problem segments of code to start the TMI count over.


thats useful. thanks. didn't realize.

Game dev tools like what, exactly?


Torque is the perfect example. I was not speaking of NWN.

I'm only pointing out that religiously using certain techniques because they were put there by the designers will lead to some very bad results, given the options available. I don't see how that in any way supports the use of 'terrible game dev tools'. Good ones, sure.


You misunderstood me. Nowhere am I laying down hard and fast rules nor am I calling NWN a terrible game dev tool. Rather I am stating a preference to use the tool as intended, and judge it on those merits. I also said that making a few exceptions here and there is fine. If the engine does not function as intended in most cases however, its good to be aware of that as NWN is not the only usable game dev tool anymore.

Also accepting the engine's limitations, because of one's attachment to it is just as much of a problem especially if you let it influence the way you think about and write code. Its a good way to develop bad habits. Perhaps thats not a problem for you. But it is for me. And since NWN isn't the only engine I use, I'm not going to let it define the way I work and think. I don't think anyone else should either if they want to keep making games.
               
               

               
            

Legacy_Rolo Kipp

  • Hero Member
  • *****
  • Posts: 4349
  • Karma: +0/-0
How bad are Pseudo HB's?
« Reply #31 on: July 26, 2011, 10:53:34 pm »


               <peeking through the aether>

henesua wrote...

... as the back and forth is likely to benefit someone else as well. 


It does :-)

<goes back to taking notes silently>
               
               

               
            

Legacy_Taino

  • Sr. Member
  • ****
  • Posts: 268
  • Karma: +0/-0
How bad are Pseudo HB's?
« Reply #32 on: July 27, 2011, 07:23:36 pm »


               

GhostOfGod wrote...

I was planning on putting a blank HB script in all areas as I'm building them just in case I want to put something in later. Now I'm not sure if I should. How much of a resource difference are we talking here?

I would like to know this as well...

Also what about the Module's Event Heartbeat? The less the better or make sure it is clean and smooth sailing.
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
How bad are Pseudo HB's?
« Reply #33 on: July 27, 2011, 09:36:15 pm »


               

Taino wrote...

GhostOfGod wrote...

I was planning on putting a blank HB script in all areas as I'm building them just in case I want to put something in later. Now I'm not sure if I should. How much of a resource difference are we talking here?

I would like to know this as well...

No one in their right mind is going to have an answer to that question based on prior experience, because it's a consumately foolhardy thing to do - no gain in ease of use or modularity, and added cost in cpus. If you want to put somehthing in later, use the Module heartbeat if you want it in all areas, or an area-enter pseudo if you just want it in one (or just the module hearbeat, if you're uncomfortable with pseudos - having multiple area heartbeats is...silly, to put it politely).

Also what about the Module's Event Heartbeat? The less the better or make sure it is clean and smooth sailing.

Both. We actually loop pcs multiple times in ours because the loop is fast, and we wanted to keep the different parts distinct (or 'clean' as you put it). A single loop would be slightly faster, but the difference is negligible. This is our mod heartbeat, and it's very quick, despite how it looks. Everything area-specific requiring heartbeat behavior is done via pseudoheartbeats launched from our universal area-enter script, which Executes an area-specific script if the proper var is set on the area, for modularity and ease of use.


#include "hg_inc"

#include "fky_chat_inc"
#include "hg_client_inc"

#include "ac_effect_inc"
#include "ac_itemprop_inc"


void SendResetBroadcast (string sMessage, int bTell, object oMessenger) {
    sMessage = "<cþ þ>" + sMessage + "</c>";

    object oPC = GetFirstPC();

    while (GetIsObjectValid(oPC)) {
        SendChatLogMessage(oPC, sMessage, oMessenger, (bTell ? 4 : 5));
        oPC = GetNextPC();
    }
}


void main() {
    object oMod = GetModule();
    object oMes = GetMessenger();
    int nUptime = GetLocalInt(oMod, "uptime");
    int nMemory = GetProcessMemoryUsage();
    int nMessages = 0, nPlayers = 0;
    string sServer = GetLocalString(oMod, "ServerNumber");
    string sBootTime = IntToString(GetLocalInt(oMod, "boottime"));

    {
        object oPC;

        for (oPC = GetFirstPC(); GetIsObjectValid(oPC); oPC = GetNextPC()) {
            nPlayers++;
            RecalculateMovementRate(oPC);
            RecalculateDexModifier(oPC);

            int nAlarm = GetLocalInt(oPC, "AlarmUptime");
            if (nAlarm > 0 && nAlarm <= nUptime) {
                DeleteLocalInt(oPC, "AlarmUptime");
                SendChatLogMessage(oPC, C_PINK + "[Alarm] " + GetLocalString(oPC, "AlarmMessage") + C_END, oMes, 4);
            }
        }

        SetLocalInt(oMod, "ServerPlayers", nPlayers);
    }

    SQLExecDirect("SELECT UNIX_TIMESTAMP() - " + sBootTime + ", UTC_TIMESTAMP(), UNIX_TIMESTAMP(), " +
        "COUNT(*) FROM user_messages WHERE um_recipient = '*" + sServer + "'");

    if (SQLFetch() == SQL_SUCCESS) {
        nUptime = StringToInt(SQLGetData(1));
        nMessages = StringToInt(SQLGetData(4));

        SetLocalInt(oMod, "uptime", nUptime);
        SetLocalInt(oMod, "realtime", StringToInt(SQLGetData(3)));
        SetLocalString(oMod, "utctime", SQLGetData(2));

        SQLExecDirect("UPDATE server_list SET srv_utime = " + IntToString(nUptime) + ", srv_memory = " +
            IntToString(nMemory) + ", srv_players = " + IntToString(nPlayers) + " WHERE srv_id = '" + sServer + "'");

        SQLExecDirect("SELECT COUNT(*) FROM user_list WHERE u_active > 0");
        if (SQLFetch() == SQL_SUCCESS)
            SetLocalInt(oMod, "GlobalPlayers", StringToInt(SQLGetData(1)));

        SQLExecDirect("SELECT COUNT(*) FROM user_list WHERE u_active > 0 AND u_server_name REGEXP '" + GetStringLeft(sServer, 1) + ".[1-8]'");
        if (SQLFetch() == SQL_SUCCESS) {
            int nHubPlayers = StringToInt(SQLGetData(1));

            SetLocalInt(oMod, "HubPlayers", nHubPlayers);

            if (GetStringLeft(sServer, 1) != "1" && GetStringRight(sServer, 1) == "1")
                SetNumberOfPlayers(nHubPlayers);
        }
    }


    /* check for server messages if available */
    if (nMessages > 0) {
        int nGuild;
        string sMessage;
        string sSQL = "SELECT um_id, um_guild, um_text FROM user_messages WHERE um_recipient = '*" + sServer + "'";

        SQLExecDirect(sSQL);

        sSQL = "";

        while (SQLFetch() != SQL_ERROR) {
            if (sSQL == "")
                sSQL = "um_id = " + SQLGetData(1);
            else
                sSQL += " OR um_id = " + SQLGetData(1);

            nGuild   = StringToInt(SQLGetData(2));
            sMessage = SQLDecodeSpecialChars(SQLGetData(3));

            if (nGuild == -2) {
                object oPC = GetFirstPC();

                while (GetIsObjectValid(oPC)) {
                    if (!(GetPCFilter(oPC, PCFILTER_CHANNELS) & 1))
                        SendChatLogMessage(oPC, sMessage, oMes);

                    oPC = GetNextPC();
                }
            } else if (nGuild == -3) {
                object oPC = GetFirstPC();

                while (GetIsObjectValid(oPC)) {
                    if (!(GetPCFilter(oPC, PCFILTER_CHANNELS) & 2))
                        SendChatLogMessage(oPC, sMessage, oMes);

                    oPC = GetNextPC();
                }
            } else if (nGuild == -4) {
                object oPC = GetFirstPC();

                while (GetIsObjectValid(oPC)) {
                    if (!(GetPCFilter(oPC, PCFILTER_CHANNELS) & 4))
                        SendChatLogMessage(oPC, sMessage, oMes);

                    oPC = GetNextPC();
                }
            } else if (nGuild < 0) {
                SendMessageToDMDMs(sMessage);
                SendMessageToPCDMs(sMessage);
                SendMessageToDMAdmins(sMessage);
                SendMessageToPCAdmins(sMessage);
            } else if (nGuild > 0) {
                object oPC = GetFirstPC();

                while (GetIsObjectValid(oPC)) {
                    if (GetLocalInt(oPC, "Guild") == nGuild && !(GetPCFilter(oPC, PCFILTER_GUILD) & 1))
                        SendChatLogMessage(oPC, sMessage, oMes);

                    oPC = GetNextPC();
                }
            } else
                AssignCommand(oMod, SpeakString(sMessage, TALKVOLUME_SHOUT));
        }

        if (sSQL != "")
            SQLExecDirect("DELETE FROM user_messages WHERE " + sSQL);
    }


    /* scan players for inter-server messages every minute; also check for auto-reset */
    if (nUptime >= GetLocalInt(oMod, "LastMessageCheck") + 60) {
        SetLocalInt(oMod, "LastMessageCheck", nUptime);

        if (nMemory > GetLocalInt(oMod, "resetmemory") && !GetLocalInt(oMod, "resetforce")) {
            SetLocalInt(oMod, "resetforce", 1);

            if (GetLocalInt(oMod, "resetuptime") > nUptime)
                SetLocalInt(oMod, "resetuptime", nUptime - 1);
        }


        /* update PCs in the user list */
        UpdateAllClients(sServer, sBootTime, oMes);


        /* check for automatic reset */
        int nResetUptime = GetLocalInt(oMod, "resetuptime");
        if (nResetUptime > 0 && nUptime > nResetUptime) {

            if (!GetIsObjectValid(GetFirstPC()))
                SetLocalString(oMod, "NWNX!RESETPLUGIN!SHUTDOWN", "1");

            if (nUptime > nResetUptime + 900) {
                SendResetBroadcast("SERVER RESET IN 10 SECONDS - SERVER REBOOT IS NOW COMMITTED - CANCELLATION " +
                    "IS NO LONGER POSSIBLE - PLEASE STAY OUT OF BANK CHESTS - HAVE A NICE DAY!", 1, oMes);
                DelayCommand(10.0, SetLocalString(oMod, "NWNX!RESETPLUGIN!SHUTDOWN", "1"));
            } else {
                int bTell = 0;
                int nSeconds = (nResetUptime + 900) - nUptime;
                string sMinutes = IntToString((nSeconds / 60) + 1);

                if (sMinutes == "1" || sMinutes == "5" || sMinutes == "10" || sMinutes == "15")
                    bTell = 1;

                if (GetLocalInt(oMod, "resetforce"))
                    SendResetBroadcast("AUTOMATIC SERVER RESET IN " + sMinutes + " MINUTE" +
                        (sMinutes != "1" ? "S" : "") + " - THIS CANNOT BE ABORTED DUE TO A LOW MEMORY CONDITION", bTell, oMes);
                else
                    SendResetBroadcast("AUTOMATIC SERVER RESET IN " + sMinutes + " MINUTE" +
                        (sMinutes != "1" ? "S" : "") + " - USE !delayreset TO DELAY THE RESET", bTell, oMes);
            }
        }
    }


    /* scan players for epic buffs every minute */
    if (nUptime >= GetLocalInt(oMod, "LastImmunityBuffCheck") + 60) {
        int i;
        object oCreator, oArea, oItem, oPC = GetFirstPC();

        while (GetIsObjectValid(oPC)) {
            oArea = GetArea(oPC);

            if (GetIsDead(oPC)           ||
                !GetIsObjectValid(oArea) ||
                GetHasEffectOfType(EFFECT_TYPE_CONFUSED, oPC)) {
                oPC = GetNextPC();
                continue;
            }


            if (GetHasSpellEffect(HGSPELL_EPIC_AEGIS, oPC)) {
                oCreator = GetLocalObject(oPC, "EpicCreator_Aegis");

                if (!GetIsObjectValid(oCreator) || GetArea(oCreator) != oArea || !GetFactionEqual(oCreator, oPC)) {
                    if (GetLocalInt(oPC, "EpicCollapse_Aegis") > 1) {
                        RemoveEffectsFromSpell(HGSPELL_EPIC_AEGIS, oPC);
                        FloatingTextStringOnCreature(
                            "* The Aegis spell on you collapses without the support of its caster! *",
                            oPC, FALSE);
                    } else
                        AddLocalInt(oPC, "EpicCollapse_Aegis", 1);
                } else
                    DeleteLocalInt(oPC, "EpicCollapse_Aegis");
            }


            if (GetHasSpellEffect(HGSPELL_EPIC_CHANT_OF_WARDING, oPC)) {
                oCreator = GetLocalObject(oPC, "EpicCreator_Chant");

                if (!GetIsObjectValid(oCreator) || GetArea(oCreator) != oArea || !GetFactionEqual(oCreator, oPC)) {
                    if (GetLocalInt(oPC, "EpicCollapse_Chant") > 1) {
                        RemoveEffectsFromSpell(HGSPELL_EPIC_CHANT_OF_WARDING, oPC);
                        FloatingTextStringOnCreature(
                            "* The Chant of Warding spell on you collapses without the support of its caster! *",
                            oPC, FALSE);
                    } else
                        AddLocalInt(oPC, "EpicCollapse_Chant", 1);
                } else
                    DeleteLocalInt(oPC, "EpicCollapse_Chant");
            }


            if (GetHasSpellEffect(HGSPELL_EPIC_ELEMENTAL_SHUNT, oPC)) {
                oCreator = GetLocalObject(oPC, "EpicCreator_Shunt");

                if (!GetIsObjectValid(oCreator) || GetArea(oCreator) != oArea || !GetFactionEqual(oCreator, oPC)) {
                    if (GetLocalInt(oPC, "EpicCollapse_Shunt") > 1) {
                        RemoveEffectsFromSpell(HGSPELL_EPIC_ELEMENTAL_SHUNT, oPC);
                        FloatingTextStringOnCreature(
                            "* The Elemental Shunt spell on you collapses without the support of its caster! *",
                            oPC, FALSE);
                    } else
                        AddLocalInt(oPC, "EpicCollapse_Shunt", 1);
                } else
                    DeleteLocalInt(oPC, "EpicCollapse_Shunt");
            }


            if (GetHasSpellEffect(HGSPELL_EPIC_SHROUD_OF_NATURE, oPC)) {
                oCreator = GetLocalObject(oPC, "EpicCreator_Shroud");

                if (!GetIsObjectValid(oCreator) || GetArea(oCreator) != oArea || !GetFactionEqual(oCreator, oPC)) {
                    if (GetLocalInt(oPC, "EpicCollapse_Shroud") > 1) {
                        RemoveEffectsFromSpell(HGSPELL_EPIC_SHROUD_OF_NATURE, oPC);
                        FloatingTextStringOnCreature(
                            "* The Shroud of Nature spell on you collapses without the support of its caster! *",
                            oPC, FALSE);
                    } else
                        AddLocalInt(oPC, "EpicCollapse_Shroud", 1);
                } else
                    DeleteLocalInt(oPC, "EpicCollapse_Shroud");
            }


            oPC = GetNextPC();
        }

        SetLocalInt(oMod, "LastImmunityBuffCheck", (nUptime - 5) + Random(11));
    }


    if (nUptime >= GetLocalInt(oMod, "LastEquipmentBuffCheck") + 60) {
        int i;
        object oCreator, oArea, oItem, oPC = GetFirstPC();

        while (GetIsObjectValid(oPC)) {
            oArea = GetArea(oPC);

            if (GetIsDead(oPC)                                 ||
                !GetIsObjectValid(oArea)                       ||
                GetHasEffectOfType(EFFECT_TYPE_POLYMORPH, oPC) ||
                GetHasEffectOfType(EFFECT_TYPE_CONFUSED, oPC)) {
                oPC = GetNextPC();
                continue;
            }

            if ((GetLevelByclass(class_TYPE_BLACKGUARD, oPC) + GetLevelByclass(class_TYPE_PALADIN, oPC)) >= 40) {
                if (GetKnowsFeat(FEAT_SMITE_EVIL, oPC))
                    IncrementRemainingFeatUses(oPC, FEAT_SMITE_EVIL);
                if (GetKnowsFeat(FEAT_SMITE_GOOD, oPC))
                    IncrementRemainingFeatUses(oPC, FEAT_SMITE_GOOD);
            }

            if (GetHasSpellEffect(HGSPELL_EPIC_GIRDING_OF_THE_FAITHFUL, oPC)) {
                oCreator = GetLocalObject(oPC, "EpicCreator_Gird");

                if (!GetIsObjectValid(oCreator) || GetArea(oCreator) != oArea || !GetFactionEqual(oCreator, oPC)) {
                    if (GetLocalInt(oPC, "EpicCollapse_Gird") > 1) {
                        RemoveEffectsFromSpell(HGSPELL_EPIC_GIRDING_OF_THE_FAITHFUL, oPC);
                        DelayCommand(0.1, VoidRemoveAllItemPropertiesFromSpell(HGSPELL_EPIC_GIRDING_OF_THE_FAITHFUL, oPC));

                        FloatingTextStringOnCreature(
                            "* The Girding of the Faithful spell on you collapses without the support of its caster! *",
                            oPC, FALSE);
                    } else
                        AddLocalInt(oPC, "EpicCollapse_Gird", 1);
                } else
                    DeleteLocalInt(oPC, "EpicCollapse_Gird");
            }


            if (GetHasSpellEffect(HGSPELL_EPIC_INSTRUMENTS_OF_FAITH, oPC)) {
                oCreator = GetLocalObject(oPC, "EpicCreator_Instr");

                if (!GetIsObjectValid(oCreator) || GetArea(oCreator) != oArea || !GetFactionEqual(oCreator, oPC)) {
                    if (GetLocalInt(oPC, "EpicCollapse_Instr") > 1) {
                        RemoveEffectsFromSpell(HGSPELL_EPIC_INSTRUMENTS_OF_FAITH, oPC);
                        DelayCommand(0.1, VoidRemoveAllItemPropertiesFromSpell(HGSPELL_EPIC_INSTRUMENTS_OF_FAITH, oPC));

                        FloatingTextStringOnCreature(
                            "* The Instruments of Faith spell on you collapses without the support of its caster! *",
                            oPC, FALSE);
                    } else
                        AddLocalInt(oPC, "EpicCollapse_Instr", 1);
                } else
                    DeleteLocalInt(oPC, "EpicCollapse_Instr");
            }


            oPC = GetNextPC();
        }

        SetLocalInt(oMod, "LastEquipmentBuffCheck", (nUptime - 5) + Random(11));
    }
}

Funky