Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Events: Teams? (https://forums.graalonline.com/forums/showthread.php?t=134261702)

MattKan 01-16-2011 07:40 AM

Events: Teams?
 
I've taken up event development, and have managed to make a few things. Currently, I'm at a loss at making teams for team events.

I need to split up the players in the room into 2 equal (random) groups, each group with a different guild name.

I figure I'll need to use a randomizer, but I've never really done that before. And I'll need to apply it to all players in the room, which I have trouble doing (:p)

So if you guys could help me, that'd be great. :fro:

And if you could help me with the script pointing out what the more complicated parts mean, that'd be great. My goal is to learn, not to copy.

Switch 01-16-2011 08:26 AM

Something simple is looping through all the players in the level and in each loop assign a team, then switch a flag, and go to the next.

PHP Code:

function AssignTeams() {
  
team 1;
  for (
player object players in the level) {
    
player guild team;
    
team = (team==1); //(arg ? true : false)
  
}



cbk1994 01-16-2011 08:35 AM

The easiest way is to use modulus (the % sign, think of it as "remainder" of division)

PHP Code:

temp.teams = {"Red Team""Blue Team"}; // array of teams
temp.0;

for (
temp.pl players) { // loop through the players
  
if (pl.guild == "Events Team") {
    continue; 
// if they have an ET tag, skip them
  
}
  
  
pl.guild teams[teams.size()];
  
++;


To add/remove teams just add them to the list at the top.

edit:


Quote:

Originally Posted by Switch (Post 1623121)
PHP Code:

  team 1


You should always prefix your variables unless you intend for them to be global.
Quote:

PHP Code:

  for (player players in the level) { 


Uhm...what?
Quote:

PHP Code:

    player.guild team


Never use player as a variable name except to refer to the active player; it's reserved.
Quote:

PHP Code:

team = (team=1); //(arg ? true : false) 


Use == for comparison, like so:
PHP Code:

team = (team == 1); 


Switch 01-16-2011 09:05 AM

Quote:

Originally Posted by cbk1994 (Post 1623123)
missing the point

I was outlining it for him, not actually making it.

Quote:

Originally Posted by MattKan (Post 1623117)
My goal is to learn, not to copy.


cbk1994 01-16-2011 09:06 AM

Quote:

Originally Posted by Switch (Post 1623135)
I was outlining it for him, not actually making it.

So you mixed instructions with GScript inside a PHP tag, and you're wondering why I "missed the point"?

This line, for example:
PHP Code:

team = (team=1); //(arg ? true : false) 

The code part of the line (before the comment) looks like actual code, and the comment looks like you're explaining that code. I don't believe it would be unreasonable to assume a person new to GScript could reach the conclusion I did and become confused when it doesn't work.

I hope you don't take this as me picking on you for helping others, of course :). I'm just trying to help you give assistance in a way that's less confusing.

Switch 01-16-2011 09:24 AM

Quote:

Originally Posted by cbk1994 (Post 1623136)
So you mixed instructions with GScript inside a PHP tag, and you're wondering why I "missed the point"?

This line, for example:
PHP Code:

team = (team=1); //(arg ? true : false) 

The code part of the line (before the comment) looks like actual code, and the comment looks like you're explaining that code. I don't believe it would be unreasonable to assume a person new to GScript could reach the conclusion I did and become confused when it doesn't work.

I hope you don't take this as me picking on you for helping others, of course :). I'm just trying to help you give assistance in a way that's less confusing.

True, didn't even notice that. It's so late.

fowlplay4 01-16-2011 05:22 PM

Modulus is so not fun enough.

Randomizing with Sortvalue

PHP Code:

// Loop through each player in the level
for (temp.plplayers) {
  
// Make sure they aren't part of the ET
  
if (temp.pl.guild != "Events Team") {
    
// Add Player to Temp Players Array
    
temp.plyrs.add(temp.pl);
    
// Assign the Player a Random Sortvalue
    
temp.plyrs[temp.plyrs.size()-1].sortvalue random(0100);
  }
}
// Sort the Array by Value
temp.plyrs.sortbyvalue("sortvalue""float"false);
// Split the Array Appropriately and Assign Guild Tags
for (temp.pltemp.plyrs) {
  
// Your other code here


It's not really necessary to use a randomizer since the order of the players array isn't exactly public knowledge but for a queuing system it might be something to prevent players from stacking teams.

MattKan 01-16-2011 06:56 PM

I wanted to do something where when player join the event and enter the level, they would be put on a team like this:

First person would go to Team 1, Second person would go to Team 2, Third Person would go to Team 1, and so on.

I tried using server flags to make it so that if a player logged in when
PHP Code:

server.eventname=

it would add the player to Team 1 and make
PHP Code:

server.eventname=

And then if they entered while
PHP Code:

server.eventname=

It would set the player to team 1 and reset:
PHP Code:

server.eventname=

That didn't work, and there probably is a better way. Thanks for all your advice on the first post, I will need those sometime soon, but for now I'm making an event where I want the players to be assigned teams alternatively as they enter. So, yeah, if you could help me again, lol


All times are GMT +2. The time now is 05:08 PM.

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