Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   how would i make my gun go full auto not semi? (https://forums.graalonline.com/forums/showthread.php?t=134257113)

GULTHEX 11-29-2009 06:07 AM

how would i make my gun go full auto not semi?
 
how would i heres what i got so far

NPC Code:
//#CLIENTSIDE
function onWeaponFired()
{
// testing purpose only
freezeplayer(.01);
setani("millenium_scar-fire", "");

this.spread=.1;
this.speed=5;
this.reload=50;
this.load=50;

temp.angl = getangle(vecx(player.dir), vecy(player.dir))+random(this.spread*-1,this.spread);
shoot(player.x + 0.5 + vecx(player.dir), player.y + vecy(player.dir), player.z, temp.angl, 0, 0, "idle", player.dir);
}
if(actionprojectile){
hurt 1;
}



so how would i make it go rapidfire without holding tab and d :P

GULTHEX 11-29-2009 06:12 AM

ok i just noticed i posted in wrong section please move the thread

cbk1994 11-29-2009 06:14 AM

You'll want to use onKeyPressed() and GraalControl.onKeyUp()

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
this.spread 0.1;
  
this.freeze 0.1// player freeze time
  
this.speed 0.05// controls the timeout
  
this.reload 50;
  
this.load 50;
}
function 
onKeyPressed(codekeyscan) {
  if (
player.weapon != this) {
    return; 
// weapon not selected
  
}
  
  if (
this.keyD) {
    return;
  }
  
  if (
key == "d") {
    
this.keyD true;
    
this.onTimeOut();
  }
}

function 
GraalControl.onKeyUp(codekeyscan) {
  if (
key == "d") {
    
this.keyD false;
    
this.setTimer(0); // end the timeout, stop shooting
  
}
}

function 
onTimeOut() { // this is where the shooting goes
  
freezePlayer(this.freeze);
  
setAni("millenium_scar-fire"NULL);

  
temp.angl getangle(vecx(player.dir), vecy(player.dir))+random(this.spread*-1,this.spread);
  
  
shoot(player.0.5 vecx(player.dir), player.vecy(player.dir), player.ztemp.angl00"idle"player.dir);
  
setTimer(this.speed);


You'll also need to add checks for things like reloading, etc.


Also, remember not to mix GS1 and GS2 (and not to use GS1), such as you're doing here:

PHP Code:

if(actionprojectile){

hurt 1;



The proper way to do that is:

PHP Code:

function onActionProjectile() {
  
hurt(1);


...which should go in a system weapon, anyway.

fowlplay4 11-29-2009 06:19 AM

You could use onWeaponFired instead of onKeyPressed in cbk's example as well I believe, so if you have multiple guns it won't fire them at the same time.

Using key == keyname(4) instead of key == "d" would be better to use as well, so it's re-mappable by players.

cbk1994 11-29-2009 06:21 AM

Quote:

Originally Posted by fowlplay4 (Post 1541069)
Well the use of a timeout and keydown would suffice, here's the basic shell of it.

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
setTimer(0.05);
}

function 
onTimeout() {
  
// Check if weapon currently selected.
  
if (this.id == selectedweapon) {
    
// Check if "D" / Weapon key is pressed down
    
if (keydown(4)) onShoot();
    
// Loop
    
setTimer(0.1);
  }
  else 
setTimer(0.1);
}

function 
onShoot() {
  
// Gun shooting stuff here.
  /*
      would be your onWeaponFired code.
  */



Why would you always have a timeout running if not needed? And yeah, I forgot to add if the weapon was selected in mine, oops.

Also, "on" is for events, not for functions !pissed!

DustyPorViva 11-29-2009 06:26 AM

onKeypressed will keep firing over and over, because of the repeat function(which is dependent on the player's OS keyboard settings, which makes it unreliable for game settings like this, as some players may fire faster than others).

You could simply do something like this:

PHP Code:

function onCreated() {
  
this.firerate .1;
}

function 
onWeaponFired() {
  while (
keydown(4)) {
    
FireGun();
    
sleep(this.firerate);
  }
}

function 
FireGun() {
  
//shoot stuff


However, I have been told using sleep is bad before, so this may get some resistance.

fowlplay4 11-29-2009 06:30 AM

Quote:

Originally Posted by cbk1994 (Post 1541070)
Why would you always have a timeout running if not needed? And yeah, I forgot to add if the weapon was selected in mine, oops.

Also, "on" is for events, not for functions !pissed!

Was just providing a different way to do things, and I like to be able to trigger, and schedule the functions I make. ^^

cbk1994 11-29-2009 06:37 AM

Quote:

Originally Posted by fowlplay4 (Post 1541073)
Was just providing a different way to do things, and I like to be able to trigger, and schedule the functions I make. ^^

Fair enough, didn't mean to jump on you :p

EDIT: Updated my first post with something that should fix the onKeyPressed repeat

fowlplay4 11-29-2009 06:42 AM

Quote:

Originally Posted by DustyPorViva (Post 1541071)
However, I have been told using sleep is bad before, so this may get some resistance.

Could use waitfor instead, that function is pretty cool i.e:

PHP Code:

function onWeaponFired() {
  while (
keydown(4) && !this.jammed) {
    
FireGun();
    
waitfor(this"Jammed"this.firerate);
  }
}

function 
onJammed() {
  
this.jammed true;
  
player.chat "$#!&ing gun jammed.";


and have some sort of script behind the scenes throw out random jammed events to guns.


All times are GMT +2. The time now is 04:55 AM.

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