Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Dark Dreams of Furiae - a new module for NWN:EE! Buy now
Attention, new and old users! Please read the new rules of conduct for the forums, and we hope you enjoy your stay!

help setting random local int

I want to check for item when PC opens door then set random of 4 chooses local int on pc and party.
Here's what I have so far.

void main()
{



object oPC = GetLastOpenedBy();

if (!GetIsPC(oPC)) return;

if (GetItemPossessedBy(oPC, "mg_key1")== OBJECT_INVALID)
return;
object oPartyM = GetFirstFactionMember(oPC);
// If not in party avoid loop
if(!GetIsObjectValid(oPartyM))
{
SetLocalInt(oPartyM,"randomport",1);
return;
}
while(GetIsObjectValid(oPartyM))
{
SetLocalInt(oPartyM,"randomport",1);
oPartyM = GetNextFactionMember(oPC);
}
}

thnx in advance as always

Comments

  • CalgacusCalgacus Member Posts: 272
    edited November 2020
    You can use the Random function to get a random number. You also do not need one of those "if" blocks, I removed it.
    You also need to make one pass to get PCs and one to get the NPCs in the party.

    Does this look like what you are going for?
    void main()
    {
    
    	object oPC = GetLastOpenedBy();
    	
    	if ( !GetIsPC(oPC) ) { return; }
    	
    	if ( GetItemPossessedBy(oPC, "mg_key1") == OBJECT_INVALID) { return; }
    	
    	object oPartyM = GetFirstFactionMember(oPC, FALSE);
    	int rnum =  Random(4) +1;  // yields 1 to 4, or do you want the same randomly generated number on every party member?  if so put this line inside the loop as the first line 
    	//We stop when there are no more valid NPC's in the party.
    	while( GetIsObjectValid(oPartyM) )
    	{
    		SetLocalInt(oPartyM,"randomport", rnum);
    		oPartyM = GetNextFactionMember(oPC, FALSE);
    	}
    	
    	object oPartyMember = GetFirstFactionMember(oPC, TRUE);
    	// We stop when there are no more valid PC's in the party.
    	while(GetIsObjectValid(oPartyMember) == TRUE)
    	{
    	        // Do something to party member
    	        SetLocalInt(oPartyM,"randomport", rnum);
    	        // Get the next PC member of oPC's faction.
    	        // If we put anything but oPC into this, it may be a totally
    	        // unreliable loop!
    	        oPartyMember = GetNextFactionMember(oPC, TRUE);
    	}
    
    }
    



  • Knight_ShieldKnight_Shield Member Posts: 45
    Thanks...I will give it a go. :)

Sign In or Register to comment.