Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Best way for this.... (https://forums.graalonline.com/forums/showthread.php?t=134267274)

Vatec 10-19-2012 12:55 PM

Best way for this....
 
I am making a Chance event and everything is good except how to check if the chosen number of the box has any players inside it, right now I have this

PHP Code:

  for (temp.plallplayers) {
    if (
temp.pl.level.name == this.level.name && playersInLevel >= 2) {
      {
        if (
temp.pl.x in coords[box 1][0], coords[box 1][1] | && temp.pl.y in coords[box 1][2], coords[box 1][3] | ) {
          
playerInBox true

Now this works but it is very buggy (wont cycle through different boxes, it chooses a player and no matter how many times you grab the block it still chooses the same box), can someone help me with the best way to do this event?

fowlplay4 10-19-2012 04:01 PM

Use players (local to the levels) instead of allplayers (entire server).

PHP Code:

temp.boxes = {
  {
001010}, // x, y, width, height
  
{10101010},
};
temp.box temp.boxes[int(random(0,temp.boxes.size()))];
for (
temp.plplayers) {
  if (
temp.pl.x in |temp.box[0], temp.box[0] + temp.box[2]| && temp.pl.y in |temp.box[1],temp.box[1]+temp.box[3]|) {
    
temp.pl.setlevel2("warpout.nw"3030);
  }



Vatec 10-19-2012 09:09 PM

Thanks for that but I am still having a problem, what if the random box chosen has no players in it? I don't see a way to avoid an overflow when theres nobody in the boxes...

Starfire2001 10-19-2012 09:40 PM

The way I did Chance on UN was to go through each box before selecting the losing box and check if it has player in it's boundaries. If it did, I added it's number to an array. Then picked randomly from this array, so you always get a box with at least one player in it.

Crow 10-19-2012 09:43 PM

Quote:

Originally Posted by Vatec (Post 1706087)
Thanks for that but I am still having a problem, what if the random box chosen has no players in it? I don't see a way to avoid an overflow when theres nobody in the boxes...

What do you even mean? If there's nobody in the selected box, it will just end up looping through all the players in the level once and do nothing to any of them.

Vatec 10-19-2012 10:12 PM

Quote:

Originally Posted by Starfire2001 (Post 1706092)
The way I did Chance on UN was to go through each box before selecting the losing box and check if it has player in it's boundaries. If it did, I added it's number to an array. Then picked randomly from this array, so you always get a box with at least one player in it.

Great idea, did it and its working, thanks for the help

Fulg0reSama 10-19-2012 10:42 PM

Mind showing how the chance area looks?

Vatec 10-19-2012 10:44 PM

Quote:

Originally Posted by Fulg0reSama (Post 1706102)
Mind showing how the chance area looks?

I don't think I am allowed to post screenshots of the server, and the level is ugly right now

Fulg0reSama 10-19-2012 10:46 PM

Quote:

Originally Posted by Vatec (Post 1706103)
I don't think I am allowed to post screenshots of the server, and the level is ugly right now

Should I just assume a tic-tact-toe square then?

Vatec 10-19-2012 10:57 PM

Quote:

Originally Posted by Fulg0reSama (Post 1706104)
Should I just assume a tic-tact-toe square then?

Yes, why do you want to know that?

Tim_Rocks 10-20-2012 12:54 AM

You can draw a cute little picture?


All times are GMT +2. The time now is 10:06 AM.

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