Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 08-26-2008, 04:56 AM
Understood Understood is offline
Registered User
Join Date: Jun 2006
Location: Orlando, FL
Posts: 120
Understood is on a distinguished road
Looping problems

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!";
      }
    }
  }

Attached Thumbnails
Click image for larger version

Name:	explanation.png
Views:	129
Size:	56.9 KB
ID:	45687  
Reply With Quote
  #2  
Old 08-26-2008, 05:19 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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.
__________________
Reply With Quote
  #3  
Old 08-26-2008, 05:39 AM
Understood Understood is offline
Registered User
Join Date: Jun 2006
Location: Orlando, FL
Posts: 120
Understood is on a distinguished road
Quote:
Originally Posted by cbk1994 View Post
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...
Reply With Quote
  #4  
Old 08-26-2008, 08:37 AM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
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]

__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #5  
Old 08-26-2008, 07:45 PM
Understood Understood is offline
Registered User
Join Date: Jun 2006
Location: Orlando, FL
Posts: 120
Understood is on a distinguished road
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.
Reply With Quote
  #6  
Old 08-27-2008, 12:07 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by xXziroXx View Post
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)
__________________
Reply With Quote
  #7  
Old 08-27-2008, 01:08 AM
Understood Understood is offline
Registered User
Join Date: Jun 2006
Location: Orlando, FL
Posts: 120
Understood is on a distinguished road
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.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 11:40 AM.


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