Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   setting teams in events. (https://forums.graalonline.com/forums/showthread.php?t=134260173)

xMane 08-12-2010 07:14 PM

setting teams in events.
 
PHP Code:

function onPlayerChats(){
if(
player.guild.starts("Events")){
if(
player.chat="/setteams"){
players.remove(player.account);
playerscount-1;
player.chat=int((playerscount-1)/4)@"/"@playerscount-1;
for (
i=0;i<playerscount-1;i++){
if(!(
players[int(i)].guild.starts("Events"))){
players[int(i/12)].setlevel2("event_ttw-lobby.nw",23.5,30);
players[int(i/12)].guild "TTW Team 1";
players[int(i/8)].setlevel2("event_ttw-lobby.nw",44,30);
players[int(i/8)].guild "TTW Team 2";
players[int(i/4)].setlevel2("event_ttw-lobby.nw",23.5,44.5);
players[int(i/4)].guild "TTW Team 3";
players[int(i)].setlevel2("event_ttw-lobby.nw",44,44.5);
players[int(i)].guild "TTW Team 4";
}
}
}
}


it keeps making the event's team as a player... how do i remove that.?
also is there any ways to make this script better?

Deas_Voice 08-12-2010 08:21 PM

ever heard of code styling? (if you haven't, google it!)

i doubt anyone would help you without you putting some effort in learning how to style your code.

PHP Code:

function exampleOfStyling() {
  if (
value == foo) {
    
doFoo();
  }
  else if (
value == bar) {
    if (
bar == 5) {
      
doBar();
    } else 
doBarTwo();
  }


it will also make your code much easier to read for others.

fowlplay4 08-12-2010 08:35 PM

For Loop Explanation: http://forums.graalonline.com/forums...11&postcount=4

You also can't modify the 'players' array.

Here's a common method for placing each person a different team, by just using an alternating boolean/flag.

PHP Code:

function setupTeams() {
  
// Initialize flag so first player is added to the Red team
  
temp.red true;
  
// Loop through players in level
  
for (temp.plyrplayers) {
    
// Ignore Events Team / Admin
    
if (!temp.plyr.guild.starts("Events")) {
      
// Check if setting to Red team.
      
if (temp.red) {
        
// Set guild to Red
        
temp.plyr.guild "Red";
        
// Reset flag so next player is blue
        
temp.red false;
      } else {
        
// Set guild to Blue
        
temp.plyr.guild "Blue";
        
// Set flag so next player is red
        
temp.red true;
      }
    }
  }



xMane 08-12-2010 08:36 PM

Quote:

Originally Posted by Deas_Voice (Post 1593199)
ever heard of code styling? (if you haven't, google it!)

i doubt anyone would help you without you putting some effort in learning how to style your code.

PHP Code:

function exampleOfStyling() {
  if (
value == foo) {
    
doFoo();
  }
  else if (
value == bar) {
    if (
bar == 5) {
      
doBar();
    } else 
doBarTwo();
  }


it will also make your code much easier to read for others.

ahh! fine...
PHP Code:

function onPlayerChats(){
  if(
player.guild.starts("Events")){
    if(
player.chat="/setteams"){
      
players.remove(player.account);
      
playerscount-1;
      
player.chat=int((playerscount-1)/4)@"/"@playerscount-1;
      for (
i=0;i<playerscount-1;i++){
        if(!(
players[int(i)].guild.starts("Events"))){
          
players[int(i/12)].setlevel2("event_ttw-lobby.nw",23.5,30);
          
players[int(i/12)].guild "TTW Team 1";
          
players[int(i/8)].setlevel2("event_ttw-lobby.nw",44,30);
          
players[int(i/8)].guild "TTW Team 2";
          
players[int(i/4)].setlevel2("event_ttw-lobby.nw",23.5,44.5);
          
players[int(i/4)].guild "TTW Team 3";
          
players[int(i)].setlevel2("event_ttw-lobby.nw",44,44.5);
          
players[int(i)].guild "TTW Team 4";
        }
      }
    }
  }



Dnegel 08-12-2010 09:21 PM

Quote:

Originally Posted by xMane (Post 1593187)
PHP Code:

function onPlayerChats(){
if(
player.guild.starts("Events")){
if(
player.chat="/setteams"){
players.remove(player.account);
playerscount-1;
player.chat=int((playerscount-1)/4)@"/"@playerscount-1;
for (
i=0;i<playerscount-1;i++){
if(!(
players[int(i)].guild.starts("Events"))){
players[int(i/12)].setlevel2("event_ttw-lobby.nw",23.5,30);
players[int(i/12)].guild "TTW Team 1";
players[int(i/8)].setlevel2("event_ttw-lobby.nw",44,30);
players[int(i/8)].guild "TTW Team 2";
players[int(i/4)].setlevel2("event_ttw-lobby.nw",23.5,44.5);
players[int(i/4)].guild "TTW Team 3";
players[int(i)].setlevel2("event_ttw-lobby.nw",44,44.5);
players[int(i)].guild "TTW Team 4";
}
}
}
}



Oh what a mess. x_x

xMane 08-12-2010 09:38 PM

also why doesnt
PHP Code:

if(hasweapon("weaponname")) 

works?

Deas_Voice 08-12-2010 09:41 PM

Quote:

Originally Posted by xMane (Post 1593214)
also why doesnt
PHP Code:

if(hasweapon("weaponname")) 

works?

because hasWeapon() is GS1 and un-supported in GS2

fowlplay4 08-12-2010 10:03 PM

The GS2 version of that function:

PHP Code:

public function hasWeapon(wepname) {
  return (
findweapon(wepnamein player.weapons);



cbk1994 08-12-2010 10:15 PM

PHP Code:

if(player.chat="/setteams"){ 

needs to be

PHP Code:

if(player.chat=="/setteams"){ 

This isn't just personal preference, it's necessary because otherwise the engine tries to assign a value to player.chat.

You can simplify your script very easily:

PHP Code:

function onPlayerChats() {
  if (
player.guild == "Events Team") {
    if (
player.chat == "/setteams") {
      
temp.teams = { // team name, level, x, y
                     
{"TTW Team 1""event_ttw-lobby.nw"23.530},
                     {
"TTW Team 2""event_ttw-lobby.nw"4430},
                     {
"TTW Team 3""event_ttw-lobby.nw"23.544.5},
                     {
"TTW Team 4""event_ttw-lobby.nw"4444.5}
                   };
      
      
temp.0;
      for (
temp.pl players) {
        if (
pl.guild == "Events Team") {
          continue;
        }
        
        
temp.team teams[teams.size()];
        
pl.guild team[0];
        
pl.setLevel2(team[1], team[2], team[3]);
        
++;
      }
    }
  }




All times are GMT +2. The time now is 06:24 PM.

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