Skip to content

Trying To Give All PCs a reward

I'm trying to make a multiplayer module and the part I'm struggling with right now is giving the quest reward. It's a short adventure so there isn't much else going on.

When the quest is finished each player is supposed to receive the following: 1000 experience, a special ring, and a unique quest reward. Don't worry about determining the unique quest reward. I'll worry about coding that later. I have something similar working elsewhere.

The problem is I need to be able to give each PC the items. I haven't tested it yet but supposedly the XP reward is working just fine (using the GiveXPToAll function). I'll use module settings to force everyone into the same party.

The way I imagine this working is we make a list (or array?) of the PCs in the party (not their familiars, animal companions, and summons). Then we run a for loop that gives the item rewards listed above (like I said, I've got the unique rewards figured elsewhere). I don't know how to write a list (or array?) and run the for loop. I also don't know how to "get every PC in the party or in the module".

Thank you for reading all this! I appreciate your help!

Comments

  • TerrorbleTerrorble Member Posts: 179
    NWScript didn't really have actual arrays as I understand it - so, loops are the go to. GetFirstPC() and GetNextPC() should work well with a while-loop for this.

    I'm guessing that this code might be run from a conversation with someone who gave you a quest. After completing the quest and talking to them, this script could go on the "Actions Taken" tab of a conversation line.
    object oPC = GetFirstPC();//gets the first PC in the module
    
    while( GetIsObjectValid(oPC) )//check if oPC is valid each time before repeating the loop
    {
        if( GetLocalInt(oPC,"Quest_A_Rewards") != 1 )//If the PC doesn't have this variable set to 1 already, then we need to do this stuff
        {
    
            //1.
            if( GetItemPossessedBy(oPC,"special_ring") == OBJECT_INVALID )//GetItemPossessedBy() will check if they have an item with the TAG special_ring. It == OBJECT_INVALID if they do not have it.
            {
                CreateItemOnObject("special_ring",OPC);//Create an item with the resref special_ring on the player.  (Note: I'm saying special_ring is both the TAG and resref of the item.)
            }
    
    
            //2.
            GiveXPToCreature(oPC,1000);
    
    
            //3.
            if( GetItemPossessedBy(oPC,"unique_reward") == OBJECT_INVALID )
            {
                CreateItemOnObject("unique_reward",OPC);
            }
    
    
            //4.
            SetLocalInt(oPC,"Quest_A_Rewards",1);//Set the Int on the PC to indicate they've already received the rewards.
        }
    
    oPC = GetNextPC();//Get the next player and do this again.
    
    }
    
  • Dragonfolk2000Dragonfolk2000 Member Posts: 388
    Thank you! This is what I was looking for!

    I noticed that we are setting a local int on the PC. Do those local variables remain on characters who are exported out?
  • TerrorbleTerrorble Member Posts: 179
    Vars set on a PC do not export and do not last across resets, but vars on an inventory item do.
    A non-droppable, plot-marked "database item" is an easy way to track quests, whether players have spoken to NPCs or opened unique chests, visited areas, their status with sanity, curses, hunger, disease, kill counts, deaths, etc.
Sign In or Register to comment.