Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Looping problems (https://forums.graalonline.com/forums/showthread.php?t=81448)

Understood 08-26-2008 04:56 AM

Looping problems
 
1 Attachment(s)
Hi, I'm relatively new to GS2 and have been trying to get this player-sorting script to work...I'm getting closer, and I -think- I have an idea what the problem is, but I can't quite figure it out.
Basically, what is supposed to happen is the first 6 players are warped on a top level, 8 tiles apart from eachother, and the next 4 are warped below them...However, it only seems to sort the first 10. (I haven't had a chance to test it with 20+, so I don't know if it's only sorting the first 10, or in sets of 10)

I included a picture in this post..the red squares are where people are being warped...just not everyone.

PHP Code:

function onCreated()
{
  
//starting x,y for top and bottom rows
  
this.conStartTopx = 8.5;
  
this.conStartBottomx = 23.5;  
  
this.conStartTopy = 10;
  
this.conStartBottomy = 20;
}

function 
onPlayerChats()
{
  if ( 
player.guild == "Events Team" )
  {
    if ( 
player.chat == ":start" )
    {
      
temp.countCons = 0;

      for ( 
temp.c = 0; temp.c < players.size(); temp.c++ )
      {
        if ( 
players[temp.c].guild == "Convict" )
          
temp.countCons++;
      }
      
      
serverr.numStartCons = temp.countCons;

      if ( !(
serverr.pbmapsize = null) )
      {
        for ( 
temp.pl = 0; temp.pl < players.size(); temp.pl++ )
        {
          if ( 
players[temp.pl].guild == "Guard" )
          {
            
players[temp.pl].setlevel2("era_prison-entrance_" @ serverr.pbmapsize @ ".nw", 30, 40);
          }
        }

        
//This is supposed to determine the number of times 
        //the while loop should execute
        
if (serverr.numStartCons%10 != 0)
        {
          
temp.numloop = int(serverr.numStartCons/10) + 1;
        }
        else
        {
          
temp.numloop = serverr.numStartCons/10;
        }

        while ( 
temp.numloop > 0 )
        {
          
temp.counter = 0;
          
temp.conxwarp = this.conStartTopx;
          
temp.conywarp = this.conStartTopy;

          for ( 
temp.p = 0; temp.p < players.size(); temp.p++ )
          {
            if ( 
players[temp.p].guild == "Convict" )
            {
              if ( 
temp.counter < 6 )
              {
                
players[temp.p].setlevel2("era_prison-cellroom_" @ serverr.pbmapsize @ ".nw", temp.conxwarp, temp.conywarp);
                
temp.conxwarp+=8;
                if ( 
temp.counter == 5 )
                  
temp.conxwarp = this.conStartBottomx;
              }
              else if ( 
temp.counter < 10 )
              {
                
temp.conywarp = this.conStartBottomy;
                
players[temp.p].setlevel2("era_prison-cellroom_" @ serverr.pbmapsize @ ".nw", temp.conxwarp, temp.conywarp);
                
temp.conxwarp+=8;
              }
              
temp.counter++;
            }
          }
          
temp.numloop--;
        }

      }
      else
      {
        
player.chat = "I need to set the map!";
      }
    }
  }
} 


cbk1994 08-26-2008 05:19 AM

Could always do something like this:
PHP Code:

function sortPlayers()
{
  
temp.totalCount = 0;
  
  for ( 
temp.pl : players )
  {
    if ( 
pl.guild == "Events Team" )
    {
      continue;
    }
    
    
totalCount ++;
  }
  
  
temp.needed = { getPercentOf( totalCount, .6 ), getPercentOf( totalcount, .4 ) }; // { needed convicts, needed convicts }
  
temp.guilds = { "Convict", "Guard" };
  
temp.totalCount = 0;
 
  for ( 
temp.pl : players )
  {
    if ( 
pl.guild == "Events Team" )
    {
      continue;
    }
  
    if ( 
totalCount ++ > needed[ 0 ] )
    {
      
pl.guild = guilds[0];
    }
    else
    {
      
pl.guild = guilds[1];
    }
  }
}
function 
getPercentOf( totalCount, percent )
{
  
temp.p = int( totalCount * percent );
  return 
p <= 0 ? 0 : p;
} 

Haven't tested this, but I think it should work. I'm open to new ways to do this as well.

Formatting got messed up when I pasted it in, but I think I fixed it.

Understood 08-26-2008 05:39 AM

Quote:

Originally Posted by cbk1994 (Post 1417563)
Could always do something like this:
PHP Code:

//stuff 

Haven't tested this, but I think it should work. I'm open to new ways to do this as well.

Formatting got messed up when I pasted it in, but I think I fixed it.

...I guess I didn't really explain my problem that well, and my wording was incorrect. The teams are sorted properly (I don't think I even included that part of the script in my post), but the problem is when I try to start the game, the entire "Convict" team isn't warped, only 10 of them...

xXziroXx 08-26-2008 08:37 AM

Scratch that while loop, you're over complicating things. Try something like this instead:

PHP Code:

for (temp.i = NULL; temp.i < players.size(); temp.i ++) {
  if (
temp.i%10 < 6) {
    
// The top 6 spots
  
} else if (temp.i%10 < 10) {
    
// The other 4 spots
  
}

  
// Current 'player object' would be read as:
  // players[temp.i]
} 


Understood 08-26-2008 07:45 PM

Oh wow, I tend to overcomplicate things...I don't know why I didn't even think to do that z.z

Thanks a lot, I'll test it out now.

cbk1994 08-27-2008 12:07 AM

Quote:

Originally Posted by xXziroXx (Post 1417772)
Scratch that while loop, you're over complicating things. Try something like this instead:

PHP Code:

for (temp.i = NULL; temp.i < players.size(); temp.i ++) {
  if (
temp.i%10 < 6) {
    
// The top 6 spots
  
} else if (temp.i%10 < 10) {
    
// The other 4 spots
  
}

  
// Current 'player object' would be read as:
  // players[temp.i]
} 


That's going to include Events Team members, though.

For your problem, maybe something like this:
PHP Code:

function warpPlayers()
{
    
temp.loc_Convict = {
                           { 
"level.nw", x, y },
                           { 
"leve2.nw", x, y }
                       };
  
temp.loc_Guard = {
                     { 
"level.nw", x, y },
                     { 
"leve2.nw", x, y }
                   };
  
temp.( @ "loc_Events Team" ) = { { "level.nw", x, y } };
  
  
temp.count_Convict = 0;
  
temp.count_Guard = 0;
  
temp.( @ "count_Events Team" ) = 0;
  
  for ( 
temp.pl : players )
  {
      
temp.location = temp.( @ "loc_" @ pl.guild );
      
      if ( 
location == null || pl.guild == null )
      {
          continue; 
// No location specified
      
}
      
      
temp.n = temp.( @ "count_" @ pl.guild );
      
temp.( @ "count_" @ pl.guild ) = n >= location.size() - 1 ? 0 : n + 1;
      
n = temp.( @ "count_" @ pl.guild );
    
      
pl.setlevel2( location[n][0], location[n][1], location[n][2] );
  }
} 

(sorry for the weird formatting, TextMate does that, and I can't get on RC at the moment)

Understood 08-27-2008 01:08 AM

Yea, I noticed that too, but I just checked for the "Convict" tag, and added a separate counter...works now, finally! Thanks for all your help.


All times are GMT +2. The time now is 04:57 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.