Graalians

Graalians (https://www.graalians.com/forums/index.php)
-   Creative Corner (https://www.graalians.com/forums/forumdisplay.php?f=17)
-   -   John's Scripts (https://www.graalians.com/forums/showthread.php?t=9528)

callimuc 09-08-2012 08:29 PM

Quote:

Posted by PerfectDark (Post 192680)
PHP Code:

function onActionServerside() {
  switch (
params[0]) {
  case 
"Var1":
    {
      
player.chat "Woot I triggered this case!";
      break;
    }
  case 
"Var2":
    {
      if (
clientr.banned != NULL
    {
      
player.chat "I have been banned from using this function :(";
    } else {
      
player.chat "Woot I triggered another case, I am on fire!";
    }
    break;
  }



that styling .____. meh

Johnaudi 09-08-2012 08:33 PM

Quote:

Posted by callimuc (Post 194993)
that styling .____. meh

Okay, so let's get back to questions...
I was looking forward for a way to script the TTS :sort thingy, I'm trying to make the players cut in half and randomly goes to different location.

Emera 09-08-2012 08:38 PM

Quote:

Posted by Johnaudi (Post 194995)
Okay, so let's get back to questions...
I was looking forward for a way to script the TTS :sort thingy, I'm trying to make the players cut in half and randomly goes to different location.

Sorting the players into 2 teams? This should work.
PHP Code:

temp.teams = {
  
"Team 1""Team "
};

for (
temp.plplayers) {
  
temp.team temp.teams[temp.count temp.teams.size()];
  
temp.count++;

  if (
temp.team == "Team 1") {
    
temp.pl.x10;
    
temp.pl.10;
  }
  elseif(
temp.team == "Team 2") {
    
temp.pl.20;
    
temp.pl.20;
  }



Tricxta 09-08-2012 09:47 PM

Quote:

Posted by callimuc (Post 194993)
that styling .____. meh

Indenting* I also like how that script uses multiple conventions as though the author can't pick which one to use. :0

Johnaudi 09-08-2012 09:56 PM

Quote:

Posted by Emera (Post 194998)
Sorting the players into 2 teams? This should work.
PHP Code:

temp.teams = {
  
"Team 1""Team "
};

for (
temp.plplayers) {
  
temp.team temp.teams[temp.count temp.teams.size()];
  
temp.count++;

  if (
temp.team == "Team 1") {
    
player.10;
    
player.10;
  }
  elseif(
temp.team == "Team 2") {
    
player.20;
    
player.20;
  }



Sorry but, 1) you didn't use temp.pl 2) I didn't quite understand the usage of
temp.team = temp.teams[temp.count % temp.teams.size()];
temp.count++;
Thanks!

Emera 09-08-2012 09:57 PM

Quote:

Posted by Johnaudi (Post 195015)
Sorry but, 1) you didn't use temp.pl 2) I didn't quite understand the usage of
temp.team = temp.teams[temp.count % temp.teams.size()];
temp.count++;
Thanks!

Oh god, my bad at #1, let me fix that for you. And that basically sorts them into 2 groups <3

Johnaudi 09-08-2012 10:00 PM

What's temp.count and what does % do xD

Tricxta 09-08-2012 10:42 PM

Quote:

Posted by Johnaudi (Post 195019)
What's temp.count and what does % do xD

% is the symbol for modular division.
It basically works but...urghh I suck at explaining it, have a wiki:http://en.wikipedia.org/wiki/Modulo_operation

But basically it's allowing the variable to pick between to the 2 teams swapping back and fourth.

temp.count=0:0%2 = element 0 = team 1
temp.count = 1:1%2 = element 1 = team 2
temp.count = 2:2%2=0 = element 0 = team 1
temp.count = 3:3%2 = 1 = element 1 = team 2
and so on. It's a really nice solution btw emera.

Emera 09-08-2012 10:59 PM

Quote:

Posted by Tricxta (Post 195039)
% is the symbol for modular division.
It basically works but...urghh I suck at explaining it, have a wiki:http://en.wikipedia.org/wiki/Modulo_operation

But basically it's allowing the variable to pick between to the 2 teams swapping back and fourth.

temp.count=0:0%2 = element 0 = team 1
temp.count = 1:1%2 = element 1 = team 2
temp.count = 2:2%2=0 = element 0 = team 1
temp.count = 3:3%2 = 1 = element 1 = team 2
and so on. It's a really nice solution btw emera.

Thanks :P And thanks for the nice explanation. Mine would've sucked.

callimuc 09-09-2012 01:50 AM

Quote:

Posted by Emera (Post 194998)
Sorting the players into 2 teams? This should work.
PHP Code:

temp.teams = {
  
"Team 1""Team "
};

for (
temp.plplayers) {
  
temp.team temp.teams[temp.count temp.teams.size()];
  
temp.count++;

  if (
temp.team == "Team 1") {
    
temp.pl.x10;
    
temp.pl.10;
  }
  elseif(
temp.team == "Team 2") {
    
temp.pl.20;
    
temp.pl.20;
  }




Quote:

Posted by Tricxta (Post 195039)
and so on. It's a really nice solution btw emera.

the only thing i dont like about it: whenever you want to randomnize it with the same players, wouldnt it keep them in the same team? at least i think so, since the players array is sorted by the account, right?

Tricxta 09-09-2012 02:20 AM

Quote:

Posted by callimuc (Post 195121)
the only thing i dont like about it: whenever you want to randomnize it with the same players, wouldnt it keep them in the same team? at least i think so, since the players array is sorted by the account, right?

I thought that as well, I was going to say something but i'm not super sure how the players are listed since everyone would have their own arrays I guess.

A way to ensure randomness would be to do something like:
PHP Code:

temp.pArr players;
temp.teams = {0,0};
temp.toggle 0;
while (
pArr.size() > 0){
  
toggle =(toggle+1)%2;
  
temp.rInd int(random(0,pArr.size());
  
temp.teams[toggle].add(pArr[rInd]);
  
pArr.remove(rInd);


But meh...

Mofujohn 09-09-2012 04:28 AM

Wish I knew what this stuff meant.

xXziroXx 09-09-2012 10:11 PM

PHP Code:

function onCreated()
{
  
// -- START EDIT
  
temp.objectList    allplayers// List of players to process
  
temp.numberOfTeams 2// Number of teams
  // -- END EDIT
  
  
temp.playerList = new[0];
  
// Generates a new list of objects we can work with
  
for (temp.objecttemp.objectList) {
    
// Let's avoid adding those silly RemoteControls
    
if (temp.object.level.name != "")
      continue;
    
    
temp.playerList.add(temp.object);
  }
  
  
// Amount of players
  
temp.amountOfPlayers temp.playerList.size();
  
// Array creation based on number of teams
  
temp.teams           = new[temp.numberOfTeams];
  
temp.team            0;
  
  
// Do we have enough players to make even teams?
  
if (temp.amountOfPlayers%temp.numberOfTeams)
    
temp.oddManOut true;
  
  
// Let's add players to the teams!
  
while (!temp.teamsGenerated) {
    
// Grab a random player from the list...
    
temp.object      randomString(temp.playerList);
    
temp.objectIndex temp.playerList.index(temp.object);
    
    
// Abort if an object wasn't found anymore
    
if (temp.objectIndex == -1)
      return echo(
"[" this.name "]: Index of object returned -1!");
    
    
// Add the player to the team array
    
temp.teams[temp.team].add(temp.object);
    
// Remove the player from the player list
    
temp.playerList.delete(temp.objectIndex);
    
    echo(
"[" this.name "]: Added '" temp.object "' to team '" temp.team "'!");
    
    
// Based on how many players are left, we may stop now.
    
temp.remainingPlayers temp.playerList.size();
    if (
temp.remainingPlayers == 0)
      break;
    else if (
temp.remainingPlayers == temp.numberOfTeams && temp.oddManOut)
      break;
    
    
// If we do have more players to work with, change the team for the next one.
    
temp.team ++;
    
temp.team %= temp.numberOfTeams;
  }
  
  echo(
"[" this.name "]: All" SPC temp.numberOfTeams SPC "teams sorted evenly!" SPC temp.remainingPlayers SPC "player(s) were left out" SPC (temp.remainingPlayers ":(" ":)"));


:p


Quote:

Posted by Tricxta (Post 195137)
I thought that as well, I was going to say something but i'm not super sure how the players are listed since everyone would have their own arrays I guess.

A way to ensure randomness would be to do something like:
PHP Code:

temp.pArr players;
temp.teams = {0,0};
temp.toggle 0;
while (
pArr.size() > 0){
  
toggle =(toggle+1)%2;
  
temp.rInd int(random(0,pArr.size());
  
temp.teams[toggle].add(pArr[rInd]);
  
pArr.remove(rInd);


But meh...

Please, oh -PLEASE-, start naming your variables more logically. Stuff like "pArr" and "rInd" might make sense at the time of making, but when looking back at code you'll quickly come to realize how stupid you were by naming it that. It also makes it hard for anyone else to figure out what your code actually does.

Tricxta 09-09-2012 10:36 PM

Quote:

Posted by xXziroXx (Post 195557)
Please, oh -PLEASE-, start naming your variables more logically. Stuff like "pArr" and "rInd" might make sense at the time of making, but when looking back at code you'll quickly come to realize how stupid you were by naming it that. It also makes it hard for anyone else to figure out what your code actually does.

My code's so good, I never have to look back at it anyway. Besides i'm use to gs1 coding where the variable name in a client string actually counts towards the character limit.Besides, if I hadn't been so half assed, I would usually leave comments.

You don't got **** me on me ;o

xXziroXx 09-09-2012 10:41 PM

Quote:

Posted by Tricxta (Post 195562)
My code's so good, I never have to look back at it anyway. Besides i'm use to gs1 coding where the variable name in a client string actually counts towards the character limit.Besides, if I hadn't been so half assed, I would usually leave comments.

You don't got **** me on me ;o

Being used to doing something in one way is a poor excuse for not needing to change. There's no need to be so defensive, I was trying to give you some pointers, that's all. John is trying to learn GScript, if you should ever lead by a good example, this is as good of a time as it gets.


All times are GMT. The time now is 10:31 AM.

Powered by vBulletin/Copyright ©2000 - 2025, vBulletin Solutions Inc.