Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Just going to mess around with some stuff (https://forums.graalonline.com/forums/showthread.php?t=78415)

Knightmare1 01-21-2008 03:27 AM

Just going to mess around with some stuff
 
hey, im Nightmare, and yes, im new to scripting, so now im going to try to learn to script.

im trying to make a weapon that will overheat, this is what i have so far:
PHP Code:

//#CLIENTSIDE
function onCreated()
{
  
this.overheat_max 100;
  
this.overheat 0;
}

function 
onWeaponFired()
{
  
this.active = !this.active;
  if (
this.active)
  {
     
setTimer);
  }
  if (!
this.active)
  {
     
onCreated()
  }
}
function 
onKeyPressed()
{
  if (
this.key "s")
  {
    if (
this.active)
    {
      if (
this.overheat = !100)
      {
        
//shoot functions.. havent gotten that far..
        
this.overheat +=1;
      }
    }
  }
}

function 
onTimeOut()
{
  if (
this.overheat this.overheat_max)
  {
    
//makes it so it cant shoot anymore..
  
}



cbk1994 01-21-2008 05:57 AM

Needs some work ;)

One thing I noticed right away was you were doing

if ( var = ! var2 )

use

if ( var != var2 )

Knightmare1 01-21-2008 02:15 PM

Quote:

Originally Posted by cbkbud (Post 1370889)
Needs some work ;)

One thing I noticed right away was you were doing

if ( var = ! var2 )

use

if ( var != var2 )

ok ty.

Toxen 01-21-2008 04:17 PM

Well try to change the key pressed part to this,

function onKeyPressed()
{
if (keydown2(getkeycode("s"),true))
{
if (this.active)
{
if (this.overheat = !100)
{
//shoot functions.. havent gotten that far..
this.overheat +=1;
}
}
}
}

Angel_Light 01-21-2008 04:36 PM

PHP Code:

//#CLIENTSIDE
function onCreated()
{
  
this.overheat_max 100;
  
this.overheat 0;
}

function 
onWeaponFired()
{
  
this.active = !this.active;
  if (
this.active)
  {
     
setTimer);
  }
  if (!
this.active)
  {
     
onCreated()
  }
}
function 
onKeyPressedcodekeyind)
{
  if (
temp.key == "s")
  {
    if (
this.active)
    {
      if (
this.overheat != 100)
      {
        
this.angle getanglevecxplayer.dir), vecyplayer.dir));
        
shootthis.xthis.ythis.zthis.angle00"arrow"NULL);
        
this.overheat +=1;
        
sleep0.1);
      }
    }
  }
}

function 
onTimeOut()
{
  if (
this.overheat >= this.overheat_max)
  {
     
this.active 2;

      
sleep5);

      
this.active 1;
  }

  
setTimer0.05);



cbk1994 01-21-2008 05:45 PM

Quote:

Originally Posted by Toxen (Post 1370958)
Well try to change the key pressed part to this,

function onKeyPressed()
{
if (keydown2(getkeycode("s"),true))
{
if (this.active)
{
if (this.overheat = !100)
{
//shoot functions.. havent gotten that far..
this.overheat +=1;
}
}
}
}

Why would you do this? Simply

PHP Code:

function onKeyPressedcodekey )
{
  if ( 
key == "s" )
  {
    if ( 
this.active )
    {
       
// etc
    
}
  }


No need for keydown2 except to tell if something is held down; the onKeyPressed event tells you the key.

Toxen 01-23-2008 04:31 AM

Well hes saying it over heats, so im guessing you needed to charge it ;O?

cbk1994 01-23-2008 05:03 AM

For guns you would want something like this:

PHP Code:

function onTimeOut()
{
  
temp.keydown2getKeyCode"s" ), true );
  if ( 
temp.)
  {
    if ( ! 
this.isKeyPressed )
    {
       
// the key is not being held down; has been pressed once.
    
}
    else
    {
      
// the key is being held down; not just pressed once.
    
}
  }
  
this.isKeyPressed temp.k;
  
setTimer0.05 );


Just an example.

PrinceOfKenshin 01-23-2008 05:06 AM

Quote:

Originally Posted by cbkbud (Post 1371394)
For guns you would want something like this:

PHP Code:

function onTimeOut()
{
  
temp.keydown2getKeyCode"s" ), true );
  if ( 
temp.)
  {
    if ( ! 
this.isKeyPressed )
    {
       
// the key is not being held down; has been pressed once.
    
}
    else
    {
      
// the key is being held down; not just pressed once.
    
}
  }
  
this.isKeyPressed temp.k;
  
setTimer0.05 );


Just an example.

I'm kinda new to gs2, why would you use a temp variable for that?

cbk1994 01-23-2008 05:26 AM

Quote:

Originally Posted by PrinceOfKenshin (Post 1371399)
I'm kinda new to gs2, why would you use a temp variable for that?

Because there's no point in taking up memory when this doesn't need to be stored past this function.

If you knew GS1, it's basically equivelant to a variable with no prefix, which is lost after the function is over.

temp.k just told me true/false the key is pressed. I could have eliminated this and made it into an if statement; this was just easier and simpler.

this.isKeyPressed tells me if LAST time around it was pressed, so I can tell if it is being held down, or touched once. This is so you can have modes such as single, automatic, etc.

Angel_Light 01-23-2008 05:38 AM

in essence, it causes a fraction of a fraction of less lag, (Which adds up quick) It basically saves Memory, (RAM Memory Space).

this.var is saved until it is updated again.

temp.var is saved until the function, that it was called in, ends.

=]

bscharff 01-24-2008 03:04 AM

*knocks on wood*

Chompy 01-24-2008 04:05 PM

Quote:

Originally Posted by bscharff (Post 1371620)
*knocks on wood*

err, what?

Tolnaftate2004 01-24-2008 07:50 PM

Quote:

Originally Posted by cbkbud (Post 1371411)
Because there's no point in taking up memory when this doesn't need to be stored past this function.

If you knew GS1, it's basically equivelant to a variable with no prefix, which is lost after the function is over

temp variables still take up memory, it's just stored on the stack versus the heap. Variables defined with no prefix are global, they act now as they did in GS1 for backwards compatibility.

Inverness 01-25-2008 01:07 AM

Function parameters are also automatically temp. variables and can be referenced as such.

Once you declare a temp. variable you can reference it without the prefix and it will not be a global. Because of this for most functions I prefer to declare all my temp.variable = 0; at the beginning of the function.

Ex:
PHP Code:

public function save(filename) {
  
temp.output 0;
  
temp.0;
  
temp.0;
  
temp.keys this.getdynamicvarnames();
  
temp.vars 0;
  
  for (
0keys.size(); ++) {
    if (
this.(@ keys[i]).type() != -1) {
      continue;
    }
    
output.add("[" keys[i] @ "]");
    
vars this.(@ keys[i]).getdynamicvarnames();
    for (
0vars.size(); ++) {
      if (
this.(@ keys[i]).(@ vars[e]) != null) {
        
output.add(vars[e] @ "=" this.(@ keys[i]).(@ vars[e]));
      }
    }
  }
  
output.savelines(filename0);




All times are GMT +2. The time now is 09:02 PM.

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