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.0temp.players.size(); temp.c++ )
      {
        if ( 
players[temp.c].guild == "Convict" )
          
temp.countCons++;
      }
      
      
serverr.numStartCons temp.countCons;

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

        
//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 )
        {
          
temp.counter 0;
          
temp.conxwarp this.conStartTopx;
          
temp.conywarp this.conStartTopy;

          for ( 
temp.0temp.players.size(); temp.p++ )
          {
            if ( 
players[temp.p].guild == "Convict" )
            {
              if ( 
temp.counter )
              {
                
players[temp.p].setlevel2("era_prison-cellroom_" serverr.pbmapsize ".nw"temp.conxwarptemp.conywarp);
                
temp.conxwarp+=8;
                if ( 
temp.counter == )
                  
temp.conxwarp this.conStartBottomx;
              }
              else if ( 
temp.counter 10 )
              {
                
temp.conywarp this.conStartBottomy;
                
players[temp.p].setlevel2("era_prison-cellroom_" serverr.pbmapsize ".nw"temp.conxwarptemp.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 = { getPercentOftotalCount.6 ), getPercentOftotalcount.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] )
    {
      
pl.guild guilds[0];
    }
    else
    {
      
pl.guild guilds[1];
    }
  }
}
function 
getPercentOftotalCountpercent )
{
  
temp.inttotalCount percent );
  return 
<= 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.NULLtemp.players.size(); temp.++) {
  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.NULLtemp.players.size(); temp.++) {
  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},
                           { 
"leve2.nw"x}
                       };
  
temp.loc_Guard = {
                     { 
"level.nw"x},
                     { 
"leve2.nw"x}
                   };
  
temp.( @ "loc_Events Team" ) = { { "level.nw"x} };
  
  
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.temp.( @ "count_" pl.guild );
      
temp.( @ "count_" pl.guild ) = >= location.size() - 1;
      
temp.( @ "count_" pl.guild );
    
      
pl.setlevel2location[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 08:42 AM.

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