Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Glow effect (https://forums.graalonline.com/forums/showthread.php?t=134263801)

pez307 07-09-2011 05:05 AM

Glow effect
 
Okay so, i took this script from chris posted on forums, and i've added it, yet when players log off the light remains on the ground, how would i prevent that?

Script:
PHP Code:

//#CLIENTSIDE
function onCreated() {
  
onTimeOut();
}

function 
onTimeOut() {

  for (
temp.pl players) {
    
showimg(200 pl.id"light2.png"pl.2.5pl.2.0);
    
changeimgvis(200 pl.id0);
    
changeimgcolors(200 pl.id188.8);
  }

  
setTimer(0.05);



fowlplay4 07-09-2011 05:34 AM

Quote:

Originally Posted by pez307 (Post 1658021)
Okay so, i took this script from chris posted on forums, and i've added it, yet when players log off the light remains on the ground, how would i prevent that?

1. Count the number of players. I.e: this.player_count = players.size();
2. Check if the number has changed from the last time you checked. I.e: if (players.size() != this.player_count)
3. If the number changed hide the images. I.e: hideimgs(200,1000);

It looks something like this:

PHP Code:

function checkPlayerCount() {
  
// Get current playercount
  
temp.current_count players.size();
  
// Compare to the last playercount
  
if (this.player_count != temp.current_count) {
    
// Playercount has changed.
    
doSomething();
    
// Update last playercount
    
this.player_count temp.current_count;
  }


Hint: You'll have to do this in your timeout loop.

cbk1994 07-09-2011 05:37 AM

It would probably be better to use a GANI with light2.png and set it as a player attribute (player.attr[10] = "myglow.gani"). Use COLOREFFECT in the GANI file to change the colors. Probably much less CPU-intensive this way.

xXziroXx 07-09-2011 12:41 PM

Quote:

Originally Posted by cbk1994 (Post 1658029)
Probably much less CPU-intensive this way.

Stefan stated somewhere many years ago (5+) that running a loop through all players to show chat/nick etc. is less CPU extensive than having gani's attached to achieve the same effect.

Crow 07-09-2011 12:53 PM

Quote:

Originally Posted by xXziroXx (Post 1658041)
Stefan stated somewhere many years ago (5+) that running a loop through all players to show chat/nick etc. is less CPU extensive than having gani's attached to achieve the same effect.

Since this is about a simple glow effect though, which can be achieved without using GS2 in a gani, I believe it'd be better.

cbk1994 07-09-2011 12:59 PM

Quote:

Originally Posted by xXziroXx (Post 1658041)
Stefan stated somewhere many years ago (5+) that running a loop through all players to show chat/nick etc. is less CPU extensive than having gani's attached to achieve the same effect.

That was for timeouts in GANIs for each player, not for an image in a GANI without any GANI script.

pez307 07-09-2011 01:19 PM

Fixed it, thanks for the comments, i used the player.attr[10] thanks Chris

ffcmike 07-09-2011 01:28 PM

What I tend to do with this type of thing (Classic nicks/ratings/hp/map display etc) is store each display object as a dynamically named variable according to the players account, store each account to an array on the display being created, add each player to a hash each frame while updating the coordinates of the already existing display objects, then simply loop through the array of stored accounts and remove the display objects for where the hash of the account isn't true.

Basic example:

PHP Code:

//#CLIENTSIDE
function onCreated(){
  
this.display = new TStaticVar();
  
this.onTimeout();
}

function 
onTimeout(){

  if(
this.disabled){
    if(
this.storedaccounts != NULL){
      
this.hideimgs(200200 this.displayindex);
      
this.displayindex 0;
      
this.display.clearVars();
      
this.storedaccounts NULL;
    }
    
this.setTimer(0.05);
    return;
  }

  
temp.hash = new TStaticVar();

  for(
temp.pl players){
    
temp.hash.(@ temp.pl.account) = true;
    if(
this.display.(@ temp.pl.account) == NULL){
      
this.displayedaccounts.add(temp.pl.account);
      
this.display.(@ temp.pl.account) = this.showimg(200 this.displayindex"light2.png"temp.pl.2.5temp.pl.2);
      
this.changeimgvis(200 this.displayindex0); 
      
this.changeimgcolors(200 this.displayindex188.8);
      
this.displayindex ++;
    }
    else{
      
this.display.(@ temp.pl.account).temp.pl.2.5;
      
this.display.(@ temp.pl.account).temp.pl.2;
    }
  }

  
//could also use this.display.getdynamicvarnames to accomplish the same thing, but while easier it's slower
  
for(temp.this.displayedaccounts){
    if(!
temp.hash.(@ temp.a)){
      
this.hideimg(this.display.(@ temp.a).imageindex);
      
this.displayedaccounts.delete(temp.i);
    }
    else{
      
temp.++;
    }
  }

  
this.setTimer(0.05);


When it comes to things like nicknames instead of storing the singular display object I store an array such as {player.nick, player.ap, player.ispaused, displayobject} then use this to check for a change in order to update text or colour.

I suppose in the instance of a light effect this method would be more consuming than a gani attr, but it does provide you with a few advantages.
This prevents the problem of the light being affected by something such as player zoom/red/green/blue/alpha/rotation, it also allows you to easily disable it on your own client.


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

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