Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Old Scripting Engine (GS1) (https://forums.graalonline.com/forums/forumdisplay.php?f=154)
-   -   Online player search (https://forums.graalonline.com/forums/showthread.php?t=63951)

Idrox0 02-06-2006 05:16 PM

Online player search
 
Hey there, I'm a good scripter, but I've done next to nothing of online stuff. My question is, how do I go through the players in a level in a for loop? I do for (i=0;i<playerscount;i++) serverside and nothing happens, clientside and only I am affected. How do I access everyone in a level?

Skyld 02-06-2006 05:58 PM

Quote:

Originally Posted by Idrox0
Hey there, I'm a good scripter, but I've done next to nothing of online stuff. My question is, how do I go through the players in a level in a for loop? I do for (i=0;i<playerscount;i++) serverside and nothing happens, clientside and only I am affected. How do I access everyone in a level?

This'll need to be done serverside.

In old gscript, it'll be something like this:
PHP Code:

for (0playerscount++)
{
  
with (players[i])
  {
    
// Now in the focus of the player
    
setplayerprop #c,Hello!;
  
}


Just for reference, in gscript2, the improved for () allows you to cycle straight through the players array, like so:
PHP Code:

for (plplayers)
{
  
// Now, pl will be the player's object, i.e.
  
pl.chat "Hello!";



Idrox0 02-07-2006 12:34 AM

Hmm... so say I wanted to make a weapon that searched through the room and killed everyone in it, it would be done like so?
PHP Code:

if ( weaponfired ) {
  for ( 
0playerscounti++ ) {
    
players[i].hearts 0;
  }


Pardon the odd (I'm sure) spacing methods; it seems UnrealScript has rubbed off a bit on me.

ZeLpH_MyStiK 02-07-2006 01:08 AM

No it needs to be done serverside.

PHP Code:

if (actionserverside) { // receives the triggeraction
  
if (strequals(#p(0),params)) { // #p(x) are the params
// the above line was not needed but i just added it in for demo
    
for(i=0i<playerscounti++) {  // loops through everyone in the room
      
with(players[i]) {  // tells the npc which player to perform the actions on
        
playerhearts 0;
      }
    }
  }
}
//#CLIENTSIDE
if (weaponfired) {
  
triggeraction 0,0,serverside,WEAPONNAME,params;



Idrox0 02-07-2006 01:12 AM

Aha! I was wondering how a server would recieve a weaponfired flag. Thanks!

ApothiX 02-07-2006 06:25 AM

For future reference, players[i].hearts should work also (meaning you don't need the with() statement)

ZeLpH_MyStiK 02-07-2006 07:51 AM

Quote:

Originally Posted by ApothiX
For future reference, players[i].hearts should work also (meaning you don't need the with() statement)

True.

Idrox0 02-09-2006 01:47 AM

Hmm... if a script that works suddenly doesn't work, and GS2 was recently installed onto the server, does that mean GS2 screwed it up?

Skyld 02-09-2006 02:10 AM

Quote:

Originally Posted by Idrox0
Hmm... if a script that works suddenly doesn't work, and GS2 was recently installed onto the server, does that mean GS2 screwed it up?

Means it was probably badly scripted or has an error in it.

The new engine's compiler is a lot more picky.


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

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