Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Bush Destroying System (https://forums.graalonline.com/forums/showthread.php?t=73784)

cbk1994 05-01-2007 11:38 PM

Bush Destroying System
 
Hi people, someone needed a bush destroying system, and I needed one for my server anyway, so here it is. Basicly how it works:

When called, checks if there are bushes near player (player facing). If there is, triggers an event on serverside to change the tiles to the dead bush tiles, then puts an NPC joining the class "effect_bush" which shows the effect typically shown. (This can be edited to drop a rupee, or something). The server automaticly changes this tile back after x amount of seconds (determined in serveroptions as respawntime I think).

Here is the code.

Code for Weapon/GUI-Script -Player/Bush:
PHP Code:

// Made by Chris Zakuto
function onActionServerSide( cmd, dpos, tiles )
{
  switch ( 
cmd )
  {
    case 
"changeBush":
    {
      
level.tiles[ dpos[0], dpos[1] ] = tiles[0];
      
level.tiles[ dpos[0] + 1, dpos[1] ] = tiles[1];
      
level.tiles[ dpos[0], dpos[1] + 1 ] = tiles[2];
      
level.tiles[ dpos[0] + 1, dpos[1] + 1 ] = tiles[3];
      
updateboard( dpos[0], dpos[1], 2, 2 );
      
      
temp.n = "effect_bush";
      
putnpc2( dpos[0], dpos[1], "
      join( \"" 
@ temp.n @ "\" );
      " 
);
      break;
    }
  }
}
//#CLIENTSIDE
function onCreated()
{
  
/*
      1 2
      3 4
  */
  
  // Default tiles, should work fine. (Change if you need to)
  
this.tileOne = 2;
  
this.tileTwo = 3;
  
this.tileThree = 18;
  
this.tileFour = 19;
  
  
this.deadTileOne = 677;
  
this.deadTileTwo = 678;
  
this.deadTileThree = 693;
  
this.deadTileFour = 694;
  
doInit();
}
function 
doInit()
{
  
temp.vars = {
                
"tileOne",
                
"tileTwo",
                
"tileThree",
                
"tileFour"
              
};
  
  if ( 
this.bushTiles != NULL )
  {
    
this.bushTiles.clear();
  }
  
  for ( 
temp.a: temp.vars )
  {
    
temp.value = this.( @ temp.a );
    
this.bushTiles.add( temp.value );
  }
}
public function 
destroyBushes()
{
  
temp.dirx_0 = { -2, -1, 0, 1, 2 };
  
temp.diry_0 = { -1, 0 };
  
temp.dirx_1 = { -2, -1, 0 };
  
temp.diry_1 = { -2, -1, 0, 1, 2 };
  
temp.dirx_2 = { -2, -1, 0, 1, 2 };
  
temp.diry_2 = { 0, 1, 2, 3, 4 };
  
temp.dirx_3 = { -1, 0, 1, 2, 3, 4 };
  
temp.diry_3 = { -3, -2, -1, 0, 1, 2, 3 };
  
  if ( 
this.tempTiles != NULL )
  {
    
this.tempTiles.clear();
  }
  for ( 
temp.i: temp.( @ "dirx_" @ player.dir ) )
  {
    for ( 
temp.a: temp.( @ "diry_" @ player.dir ) )
    {
      
temp.tile = tiles[ int( player.x ) + temp.i, int( player.y ) + temp.a ];
      if ( 
temp.tile in this.bushTiles )
      {
        
temp.obj = { temp.tile, { int( player.x ) + temp.i, int( player.y ) + temp.a } };
        
this.tempTiles.add( temp.obj );
      }
    }
  }
  if ( 
checkBush( this.tempTiles ) == true )
  {
    if ( 
temp.tileOne != NULL )
    {
      
temp.tileOne.clear();
    }
    for ( 
temp.n: this.tempTiles )
    {
      if ( 
temp.n[0] == 2 )
      {
        
temp.tileOne.add( temp.n[1] );
      }
    }
    for ( 
temp.z: temp.tileOne )
    {
      
triggerServer( "gui", name, "changeBush", temp.z, { this.deadTileOne, this.deadTileTwo, this.deadTileThree, this.deadTileFour } );
    }
  }
}
function 
checkBush( tiles )
{
  for ( 
temp.i: this.bushTiles )
  {
    
temp.foo = false;
    for ( 
temp.a: tiles )
    {
      if ( 
temp.a[0] == temp.i )
      {
        
temp.foo = true;
      }
    }
    if ( 
temp.foo == false )
    {
      return 
false;
    }
    
    
temp.foo = false;
  }
  return 
true;
} 

Here is the class for the bush killing effect, which can be modified easily.

Code for Class effect_bush:
PHP Code:

function onCreated()
{
  
sleep( .5 );
  
destroy();
}
//#CLIENTSIDE
function onCreated()
{
  
putleaps( 0, this.x, this.y );
} 

To call the bush killing, just trigger the weapon like so.

PHP Code:

( @ "-Player/Bush" ).destroyBushes(); 

If you need any help installing this system/modifying it, I'm happy to help.

Rapidwolve 05-01-2007 11:56 PM

Cool, could be a little laggy though

cbk1994 05-02-2007 12:16 AM

Quote:

Originally Posted by Rapidwolve (Post 1304946)
Cool, could be a little laggy though

I know, but this is the best way I could think of doing it. When I tested it, there wasn't much lag, just slightly slower than default. It's really not much slower.

Novo 05-02-2007 12:26 AM

I think you're taking him too literally when he said he wanted a Bush destroying system. The other Bush is what he meant!

Rapidwolve 05-02-2007 12:44 AM

Alert
Novo, cbkbud, and Stan are missing, the goverment has nothing to say on this issue.

Rapidwolve 05-02-2007 03:59 AM

temp.idiot = new TStaticVar();
I thought you couldn't destroy non-TStaticVars

Gambet 05-02-2007 04:15 AM

Quote:

Originally Posted by Rapidwolve (Post 1305025)
temp.idiot = new TStaticVar();
I thought you couldn't destroy non-TStaticVars


temp vars are temporary, so what would there be to destroy? >_<

Chandler 05-02-2007 08:05 AM

lol

I made my own, hehe.
Thanks! :p


All times are GMT +2. The time now is 12:02 AM.

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