View previous topic :: View next topic |
Author |
Message |
scarface
Joined: 12 Jun 2005 Posts: 94 Location: Sweden
|
Posted: Sat Aug 29, 2009 23:15 Post subject: Party struct |
|
|
I came up with this to create 2 parties from a single party, but it doesn't work properly (it's leaving 1 member behind) and I'm having a hard time testing it as no players are really offering to help and I cannot force them to.
Code: | struct Team
{
object blue;
object red;
};
struct Team SF_CreateTeams( object player )
{
struct Team Leader;
Leader.blue = OBJECT_INVALID;
Leader.red = OBJECT_INVALID;
int partyCount = SF_GetPartyMemberCount( player );
object partyMember = GetFirstFactionMember( player );
while ( GetIsObjectValid( partyMember ) )
{
if ( partyCount % 2 )
{
if ( Leader.red == OBJECT_INVALID )
{
Leader.red = partyMember;
SetLocalObject( GetModule( ), "redLeader", partyMember );
}
SetLocalString( partyMember, "eventTeam", "Red" );
}
else
{
if ( Leader.blue == OBJECT_INVALID )
{
Leader.blue = partyMember;
SetLocalObject( GetModule( ), "blueLeader", partyMember );
}
SetLocalString( partyMember, "eventTeam", "Blue" );
}
partyCount --;
partyMember = GetNextFactionMember( player );
}
partyMember = GetFirstFactionMember( player );
while ( GetIsObjectValid( partyMember ) )
{
if (partyMember != player )
{
RemoveFromParty( partyMember );
}
partyMember = GetNextFactionMember( player );
}
object area = GetArea( player );
int count = 1;
object obj = GetNearestCreature( CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC, OBJECT_SELF, count );
string team;
while ( GetIsObjectValid( obj ) )
{
team = GetLocalString( obj, "eventTeam" );
if ( team == "Blue" && obj != Leader.blue )
{
AddToParty( obj, Leader.blue );
}
else
if ( team == "Red" && obj != Leader.red )
{
AddToParty( obj, Leader.red );
}
count ++;
obj = GetNearestCreature( CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC, OBJECT_SELF, count );
}
return Leader;
} |
Any help would be appreciated. |
|
Back to top |
|
|
Gryphyn
Joined: 20 Jan 2005 Posts: 431
|
Posted: Sun Aug 30, 2009 1:46 Post subject: |
|
|
To start with I think you need some code to ONLY deal with PC's.
Pets/Familiars/Summons would be caught up in your looping.
You might want to check for a minimum party count - say 6 or more. (otherwise it's easier to get the players to manage it)
Wouldn't it be easier to leave the original party (Red), and take every 2nd player and put them in party Blue (remove/add) with the first member (2nd player) being the blue leader.
- loop through party
- - assign team# (not limited to 2) <randomize here?>
- loop through party (again)
- - if not team 1
- - - if no party leader
- - - - remove -> mark as team leader <relocate>
- - - else
- - - - remove -> add (team leader) <relocate>
- - - endif
- - endif
Cheers
Gryphyn |
|
Back to top |
|
|
scarface
Joined: 12 Jun 2005 Posts: 94 Location: Sweden
|
Posted: Sun Aug 30, 2009 13:32 Post subject: |
|
|
Gryphyn wrote: | To start with I think you need some code to ONLY deal with PC's.
Pets/Familiars/Summons would be caught up in your looping.
You might want to check for a minimum party count - say 6 or more. (otherwise it's easier to get the players to manage it)
Wouldn't it be easier to leave the original party (Red), and take every 2nd player and put them in party Blue (remove/add) with the first member (2nd player) being the blue leader.
- loop through party
- - assign team# (not limited to 2) <randomize here?>
- loop through party (again)
- - if not team 1
- - - if no party leader
- - - - remove -> mark as team leader <relocate>
- - - else
- - - - remove -> add (team leader) <relocate>
- - - endif
- - endif
Cheers
Gryphyn |
The GetFirst/NextFactionMember function only includes PCs unless the second default parameter is changed to FALSE, the conversation that calls this function aölready checks for party count and makes sure it's even, and your proposed proceedure is basically what the struct already does so this hasn't really helped.
I think the struct is ok just has a bug that I am unable to see or test at this time, can anyone spot what might be the problem? |
|
Back to top |
|
|
Gryphyn
Joined: 20 Jan 2005 Posts: 431
|
Posted: Mon Aug 31, 2009 2:10 Post subject: |
|
|
scarface wrote: |
The GetFirst/NextFactionMember function only includes PCs unless the second default parameter is changed to FALSE, the conversation that calls this function aölready checks for party count and makes sure it's even, and your proposed proceedure is basically what the struct already does so this hasn't really helped. |
Yes, it's similar - that's what you wanted isn't it?
The main difference is that I'm suggesting you only deal with two factions not three. You're taking the original party, removing every member and separating them into a two new parties (Red & Blue). My suggestion is to take every 2nd player, and move them to a new party. (only 2 parties)
In this case the struct doesn't add much. It allows you notate a pair of players (the red/blue leaders) *you could break that loop after both red & blue are assigned, or avoid a loop all together
Leader.red = GetFirstFactionMember( player );
Leader.blue = GetNextFactionMember( player );
I'm a little confused why you change to GetNearestCreature() to add party members. (and area doesn't seem to be used)
Code: | struct Leaders
{
object One;
object Two;
};
struct Leaders AssignTeams(object oLeader) //OriginalLeader
{
struct Leaders leaderOfTeam;
leaderOfTeam.One = GetFirstFactionMember(oLeader);
SetLocalString(leaderOfTeam.One,"TeamLeader","One");
leaderOfTeam.Two = GetNextFactionMember(oLeader);
SetLocalString(leaderOfTeam.Two,"TeamLeader","Two");
RemoveFromParty(leaderOfTeam.Two);
object oTeamMember = GetNextFactionMember(oLeader);
while (GetIsObjectValid(oTeamMember))
{
//TeamOnePlayers
SetLocalString(oTeamMember,"Team",GetLocalString(leaderOfTeam.One,"TeamLeader"));
oTeamMember = GetNextFactionMember(oLeader);
if (GetIsObjectValid(oTeamMember))
{
//TeamTwoPlayers
SetLocalString(oTeamMember,"Team",GetLocalString(leaderOfTeam.Two,"TeamLeader"));
RemoveFromParty(oTeamMember);
AddToParty(oTeamMember, leaderOfTeam.Two);
oTeamMember = GetNextFactionMember(oLeader);
}
}
return leaderOfTeam;
} |
**I can't recall if the 'chain' of First/Next is broken if an item is 'removed' before the set-scan is complete. |
|
Back to top |
|
|
scarface
Joined: 12 Jun 2005 Posts: 94 Location: Sweden
|
Posted: Mon Aug 31, 2009 4:36 Post subject: |
|
|
Gryphyn wrote: |
**I can't recall if the 'chain' of First/Next is broken if an item is 'removed' before the set-scan is complete. |
Pretty sure it is or I would have done it all within a single loop. |
|
Back to top |
|
|
ShaDoOoW
Joined: 20 Aug 2005 Posts: 584
|
Posted: Tue Sep 01, 2009 0:13 Post subject: |
|
|
Code: | object PVP_GetTeamLeader(int nTeam)
{
object oPC = GetFirstPC();
while(GetIsObjectValid(oPC))
{
if(PVP_GetTeam(oPC)==nTeam)
{
return GetFactionLeader(oPC);
}
oPC = GetNextPC();
}
return OBJECT_INVALID;
}
void AddToTeam(object oPC, int nTeam)
{
ForceRest(oPC);
object oLeader = PVP_GetTeamLeader(nTeam);
RemoveFromParty(oPC);
AdjustAlignment(oPC,nTeam == PVP_TEAM_GOOD ? ALIGNMENT_GOOD : ALIGNMENT_EVIL,100,FALSE);
if(GetIsObjectValid(oLeader))
{
AddToParty(oPC,oLeader);
}
PVP_SetTeam(oPC,nTeam);//this sets local int for PVP_GetTeam and print string
SetEnemies(oPC,FALSE);//sets dislikes
AssignCommand(oPC,ClearAllActions());
AssignCommand(oPC,JumpToObject(PVP_GetTeamStartPoint(nTeam)));
} |
Thats how I accomplished it. Of course its not exactly what you want, but you can base it upon this, im pretty sure there isnt need to change much.
Btw my arena is under construction atm, porting to linux, is hosted at technical support, you can have a look in... _________________ Community Patch / NWNX Patch / NWNX Files / NWNX Connect |
|
Back to top |
|
|
scarface
Joined: 12 Jun 2005 Posts: 94 Location: Sweden
|
Posted: Tue Sep 01, 2009 0:32 Post subject: |
|
|
ShaDoOoW wrote: | Code: | object PVP_GetTeamLeader(int nTeam)
{
object oPC = GetFirstPC();
while(GetIsObjectValid(oPC))
{
if(PVP_GetTeam(oPC)==nTeam)
{
return GetFactionLeader(oPC);
}
oPC = GetNextPC();
}
return OBJECT_INVALID;
}
void AddToTeam(object oPC, int nTeam)
{
ForceRest(oPC);
object oLeader = PVP_GetTeamLeader(nTeam);
RemoveFromParty(oPC);
AdjustAlignment(oPC,nTeam == PVP_TEAM_GOOD ? ALIGNMENT_GOOD : ALIGNMENT_EVIL,100,FALSE);
if(GetIsObjectValid(oLeader))
{
AddToParty(oPC,oLeader);
}
PVP_SetTeam(oPC,nTeam);//this sets local int for PVP_GetTeam and print string
SetEnemies(oPC,FALSE);//sets dislikes
AssignCommand(oPC,ClearAllActions());
AssignCommand(oPC,JumpToObject(PVP_GetTeamStartPoint(nTeam)));
} |
Thats how I accomplished it. Of course its not exactly what you want, but you can base it upon this, im pretty sure there isnt need to change much.
Btw my arena is under construction atm, porting to linux, is hosted at technical support, you can have a look in... |
I don't really see how this does anything that the default AddToParty GetFactionLeader functions don't already do.
The above code doesn't do anything like waht I want, but thanks. |
|
Back to top |
|
|
KMdS
Joined: 23 Dec 2009 Posts: 5
|
Posted: Wed Dec 23, 2009 18:18 Post subject: What is calling the function? |
|
|
SF, there are a couple of things I see that you have in the script, but the one that may be causing your problem is simple. What is calling the function? Is the function called by a player? If so that player never gets assigned a team.
See if this code works for you.
Code: | struct Team
{
object blue;
object red;
};
struct Team SF_CreateTeams( object player )
{
struct Team Leader;
Leader.blue = OBJECT_INVALID;
Leader.red = OBJECT_INVALID;
int partyCount = SF_GetPartyMemberCount( player );
object partyMember = GetFirstFactionMember( player );
while ( GetIsObjectValid( partyMember ) )
{
if ( partyCount % 2 )
{
if ( Leader.red == OBJECT_INVALID )
{
Leader.red = partyMember;
SetLocalObject( GetModule( ), "redLeader", partyMember );
}
SetLocalString( partyMember, "eventTeam", "Red" );
}
else
{
if ( Leader.blue == OBJECT_INVALID )
{
Leader.blue = partyMember;
SetLocalObject( GetModule( ), "blueLeader", partyMember );
}
SetLocalString( partyMember, "eventTeam", "Blue" );
}
partyCount --;
partyMember = GetNextFactionMember( player );
}
partyMember = GetFirstFactionMember( player );
while ( GetIsObjectValid( partyMember ) )
{
if (partyMember != player )
{
RemoveFromParty( partyMember );
}
partyMember = GetNextFactionMember( player );
}
object area = GetArea( player );
int count = 1;
object obj = GetNearestCreature( CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC, OBJECT_SELF, count );
string team;
while ( GetIsObjectValid( obj ) )
{
team = GetLocalString( obj, "eventTeam" );
if ( team == "Blue" && obj != Leader.blue )
{
AddToParty( obj, Leader.blue );
}
else
if ( team == "Red" && obj != Leader.red )
{
AddToParty( obj, Leader.red );
}
count ++;
obj = GetNearestCreature( CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC, OBJECT_SELF, count );
}
//lets make sure to assign a team to the initial player OBJECT_SELF...KMdS
team = GetLocalString( OBJECT_SELF, "eventTeam" );
if ( team == "Blue")
{
AddToParty( OBJECT_SELF, Leader.blue );
}
else
if ( team == "Red" )
{
AddToParty( OBJECT_SELF, Leader.red );
}
return Leader;
} |
Mind you, I would rewrite this code and change out the OBJECT_SELF references if this does the trick and reassign all references to OBJECT_SELF to "player". |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|