DMH-Online

Dungeon Masters Helper · Est. 2005

PCs Scripts

NWN Script: voting.htm

Author Sticky: Post Working Scripts Here
Syrinx Posted: Monday, 08 July 02:01AM
Name: Voting System Script, v0.92 beta

What it does: Allows you to add voting system to your server/module, so that PCs can vote on game settings or kick obnoxious players.

Temporary download: http://www.csee.usf.edu/~ledwith/nwnvote.zip
Should be up on Neverwinter Vault shortly.

Check out the example module and read vt_system_h for more information on how to use.

Here's vt_pass:

NWScript:
//::////////////////////////////////////////////////////////////////////////////
//:: Name: Voting System Script for Neverwinter Nights
//:: FileName: vt_pass
//:: Version: 0.92 (BETA)
//:: Copyright (c) 2002 Chris M. Ledwith
//::////////////////////////////////////////////////////////////////////////////
/*
    See vt_system_h for more information.
*/
//::////////////////////////////////////////////////////////////////////////////
//:: Created By: Chris M. Ledwith
//:: Created On: July 7, 2002
//::////////////////////////////////////////////////////////////////////////////
// Dependencies:
// vt_system_h, vt_debug, vt_misc, array_api_int
// Function declarations
void DecideVote();
int WillVotePass(int nYes, int nNo, int nAbstain);
void PassVote();
// Decide the vote
// USER: Your module MUST call this via OnHeartBeat after voting time has elapsed.
////////////////////////////////////////////////////////////////////////////////
void DecideVote()
{
    int nCast;
    int nYes, nNo, nAbstain;
    // Tally the votes
    object oPC = GetFirstPC();
    while (GetIsObjectValid(oPC)) {
        nCast = GetLocalInt(oPC, VT_STR_MYVOTE);
        if (nCast == VT_YES)
            nYes++;
        else if(nCast == VT_NO)
            nNo++;
        else if(nCast == VT_ABSTAIN)
            nAbstain++;
        oPC = GetNextPC();
    }
    // Determine the vote
    if (WillVotePass(nYes, nNo, nAbstain)) {
        // Pass it
        PassVote();
        Announce("Vote passed (" + IntToString(nYes) + " to " + IntToString(nNo) + " with " + IntToString(nAbstain) + " abstentions).");
    } else {
        // Don't pass it
        Announce("Vote did not pass (" + IntToString(nYes) + " to " + IntToString(nNo) + " with " + IntToString(nAbstain) + " abstentions).");
    }
}
// Determines whether the vote will pass or not.
// USER: You may want to make this function determine the vote in a different way.
//       By default, it simply checks whether the number of yes votes exceeds the number of no and abstain votes.
//       You could set up different requirements for each type of vote to pass.
////////////////////////////////////////////////////////////////////////////////
int WillVotePass(int nYes, int nNo, int nAbstain)
{
    DebugMessage("entered WillVotePass");
    return (nYes > (nNo + nAbstain));
}
// Pass the vote and take necessary actions
// USER: This is the Really Important Function (tm).
//       Here's where you put changes into effect when a vote passes.
////////////////////////////////////////////////////////////////////////////////
void PassVote()
{
    DebugMessage("entered PassVote");
    // Set the key's new value
    int nKey = GetLocalInt(oModule, VT_STR_KEY);
    int nValue = GetLocalInt(oModule, VT_STR_VALUE);
    SetIntArray(VT_STR_KEYSARRAY, nKey, nValue, oModule);
    // Take action
    if (nKey == VT_SAMPLE) {
        ExecuteScript("vt_sample", oModule);
        Announce("Sample script has executed");
    }
    else if (nKey == VT_KICK) {
        string sName = GetLocalString(oModule, VT_STR_KICKTARGET);
        object oPC = GetPCByName(sName);
        if (GetIsObjectValid(oPC)) {
            DebugMessage("Attempting to kick player " + GetPCPlayerName(oPC) + "(" + sName + ").");
            DebugMessage("This won't work if they are the only PC.");
            BootPC(oPC);
        }
        else
            DebugMessage("No such player");
    }
    //else if (nKey == VT_MYKEY) {              <<<EXAMPLE USAGE<<<
    //    <do something>
    //}
    else {
        Announce(VT_STR_NOIMP);
    }
}
⌂ All Scripts ← Previous 👁 Category List

All PCs Scripts

📄 adjust_faction 📄 alt_idle_pc_anim 📄 bleeding 📄 bleeding_002 📄 bleeding_003 📄 bleeding_004 📄 creature_item 📄 drop_items 📄 force_zone 📄 give_pc_item 📄 inspect_inv 📄 limited_druid 📄 move_items_to_container 📄 notify_of_loot 📄 pc_respawn 📄 pc_respawn_002 📄 pc_respawn_003 📄 pc_respawn_004 📄 pc_respawn_005 📄 pc_respawn_006 📄 pc_respawn_007 📄 remove_neg 📄 save_spots 📄 strip_inv_give_gold 📄 strip_inv_plot 📄 subraces 📄 subraces_002 📄 voting