Graal Forums

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

boolean 09-16-2012 02:54 AM

Invisibility
 
weapon_control:
PHP Code:

function onCreated()
{
   
this.helper "weapon2"// weapon2, changes alpha on clientside
   
this.db "boolean"// define npc to store exceptions
}
 
function 
onActionServerSide(temp.cmdtemp.alphatemp.user)
{
   if(
temp.cmd == "set")
   {
      for(
temp.pl players)
      {
         if(
temp.pl == player)
            continue;
 
         
temp.pl.addWeapon(this.helper);
         
temp.exists = !(temp.pl.account in ( @ this.db ).exceptions);
         
temp.pl.triggerClient("gui"this.helperplayer.accounttemp.exists temp.alpha temp.alpha == 0.5 1);
      }
   }
 
   if(
temp.cmd == "add" || temp.cmd == "remove")
   {
      
temp.exists temp.user in ( @ this.db ).exceptions;
 
      if(
temp.user == NULL || !temp.exists && temp.cmd == "remove" || temp.exists && temp.cmd == "add" || temp.user == player.account)
      {
         
player.chat "Error!";
         return;
      }
 
      if(
temp.cmd == "add")
         ( @ 
this.db ).exceptions.add(temp.user);
      else
         ( @ 
this.db ).exceptions.remove(temp.user);
 
      
player.chat temp.user " was " @ ( temp.cmd == "add" "added" "removed" ) @ "!";
   }
 
   if(
temp.cmd == "view")
   {
      for(
temp.pla : ( @ this.db ).exceptions)
      {
         
temp.total = @ temp.total @ ( temp.total != NULL ", " "" ) @ temp.pla;
      }
 
      if(
temp.total != NULL)
         
player.chat temp.total;
   }
}
 
//#CLIENTSIDE
 
function onPlayerChats()
{    
   if(
player.chat.starts("/add"))
      
triggerServer("gui"this.name"add"NULLplayer.chat.tokenize()[1]);
 
   if(
player.chat.starts("/remove"))
      
triggerServer("gui"this.name"remove"NULLplayer.chat.tokenize()[1]);
 
   if(
player.chat == "/exceptions")
   {
      
triggerServer("gui"this.name"view");
      
player.chat "";
   }  
 
   if(
player.chat.starts("/add") || player.chat.starts("/remove"))
      
player.chat "";
}
 
function 
onWeaponFired()
{
   
this.invis = !this.invis;
   
player.alpha this.invis 0.5 1;
 
   
setTimer(0.05);
}
 
function 
onTimeout()
{
   
triggerServer("gui"this.name"set"this.invis 1);
   
setTimer(this.invis 0.05 0);


weapon2 (clientside):
PHP Code:

//#CLIENTSIDE
 
function onActionClientside(temp.acctemp.alpha)
{
   
temp.pl findPlayer(temp.acc);
   
temp.pl.alpha temp.alpha;
 
   if(
temp.alpha == 0)
   {
      
enablefeatures(allfeatures & ~8);
      
temp.pl.chat "";
   }
   else
   {
      
enablefeatures(allfeatures);
   }


"exceptions" are just something I included so that certain players can see the player invisible, whereas others cannot

sorry if this is redundant, just haven't seen any real "invisibility/stealth" scripts out there (empty ganis suck)

criticisms accepted :pluffy:

BlueMelon 09-16-2012 03:07 AM

Just a tip, your code lacks of comments.

cbk1994 09-16-2012 03:09 AM

Generally the best way to do this is to either have a GANI script in one of the player's attrs that sets the player's alpha, or (generally preferred, especially if you'll have lots of different types of effects) to use an attr for storing the desired alpha (and other effects data, like zoom) and use a weapon that loops through all players in the level 20 times a second applying these.

The main problem with your script is that to keep it working you need to trigger serverside 20 times a second, then have the server trigger every player in the level that same number of times per second. With 50 players in a level, that's 50*20+20=1020 triggers per second which is going to be a really bad thing to do.

I haven't reviewed the entire script, but this is the general idea. Typically I'd rather loop through each player in the level n times per second instead, though; it's faster than having the same work done in GANI scripts (per Stefan). There's an example by Dusty here that uses a loop, but it's a bit old and messy. The loops are backwards to what I'd generally do.

edit: note that if your only goal is to hide you're better off just using hidePlayer as long as it's enabled on the server.

boolean 09-16-2012 03:19 AM

Quote:

Originally Posted by cbk1994 (Post 1703890)
The main problem with your script is that to keep it working you need to trigger serverside 20 times a second, then have the server trigger every player in the level that same number of times per second. With 50 players in a level, that's 50*20+20=1020 triggers per second which is going to be a really bad thing to do.

I don't plan on ever triggering that much. If I were being creative I'd probably just end up sending one trigger for every player that enters the level, otherwise just sending triggers whenever the weapon fires (to enable/disable alpha). At this stage though, I'd say performance isn't really an issue since I haven't had 50 players in a level at any given time (will have to try that out later). The timeout does is most definitely a hazard though, agree'd.

salesman 09-16-2012 03:45 AM

Quote:

Originally Posted by BlueMelon (Post 1703889)
Just a tip, your code lacks of comments.

I'd rather see clear code and functions/variables with appropriate names. Comments should only really be used when it might be unclear to another coder what you're trying to do.

I hate seeing stuff like this:
PHP Code:

// set hp to 100
this.hp 100

Unless you're trying to explain an algorithm to someone who isn't familiar with the language, having too many comments is just annoying.

callimuc 09-16-2012 03:00 PM

You should use something like this:
Quote:

Originally Posted by Twinny (Post 1620752)
This is what I did for Classic iPhone stealth (removed some other parts to provide this),

Weapon: -Staff/Stealth
PHP Code:

//#CLIENTSIDE
function onCreated() {
  
player.attr[22] = "unstealth.gani";
}

function 
ChatBar.onAction() {
  if (
ChatBar.text == "/stealth") {
    
toggleStealth();
    
ChatBar.text "";
  }
}

function 
toggleStealth() {
  
this.stealth = !this.stealth;
  if (
this.stealth)
    
player.attr[22] = "stealth.gani";
  else
    
player.attr[22] = "unstealth.gani";


in the gani,
PHP Code:

function onPlayerEnters() {
  if (
clientr.isStaff)
    
player.alpha 0.4;
  else
    
player.alpha 0;


So, all staff can see the stealthed person at half alpha while no-one else can see them.




also, something like this
Quote:

Originally Posted by boolean (Post 1703888)
PHP Code:

function onPlayerChats()
{    
   if(
player.chat.starts("/add"))
      
triggerServer("gui"this.name"add"NULLplayer.chat.tokenize()[1]);
 
   if(
player.chat.starts("/remove"))
      
triggerServer("gui"this.name"remove"NULLplayer.chat.tokenize()[1]);
 
   if(
player.chat == "/exceptions")
   {
      
triggerServer("gui"this.name"view");
      
player.chat "";
   }
 
   if(
player.chat.starts("/add") || player.chat.starts("/remove"))
      
player.chat "";



should be changed to something like this
PHP Code:

function onPlayerChats() {
  
temp.toks player.chat.tokenize();  
  if (
player.chat.starts("/add")) {
    
triggerServer("gui"this.name"add"NULLtemp.toks[1]);
    
player.chat " ";
  }
 
  else if (
player.chat.starts("/remove")) {
    
triggerServer("gui"this.name"remove"NULLtemp.toks[1]);
    
player.chat " ";
  }
  else if (
player.chat == "/exceptions") {
    
triggerServer("gui"this.name"view");
    
player.chat " ";
  }



styling your codes would also be something you should try out

boolean 09-16-2012 03:10 PM

Quote:

Originally Posted by callimuc (Post 1703906)
styling your codes would also be something you should try out

lol

and yes it is changing the opacity for the players within the list of "exceptions"

PHP Code:

temp.pl.triggerClient("gui"this.helperplayer.accounttemp.exists temp.alpha temp.alpha == 0.5 1); 

Honestly, I think the onPlayerChats() event becomes so boilerplate at this point I could care less as to how I interact with it

callimuc 09-16-2012 05:14 PM

Quote:

Originally Posted by boolean (Post 1703908)
lol

sorry, just realized it was the styling (with the brackets in a new line, etc.) which has been irritating me


All times are GMT +2. The time now is 11:42 PM.

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