Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > New Scripting Engine (GS2)
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 11-29-2009, 06:07 AM
GULTHEX GULTHEX is offline
Registered User
Join Date: Jul 2008
Posts: 148
GULTHEX can only hope to improve
Red face 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
Reply With Quote
  #2  
Old 11-29-2009, 06:12 AM
GULTHEX GULTHEX is offline
Registered User
Join Date: Jul 2008
Posts: 148
GULTHEX can only hope to improve
ok i just noticed i posted in wrong section please move the thread
Reply With Quote
  #3  
Old 11-29-2009, 06:14 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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.
__________________

Last edited by cbk1994; 11-29-2009 at 06:37 AM..
Reply With Quote
  #4  
Old 11-29-2009, 06:19 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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.
__________________
Quote:
Reply With Quote
  #5  
Old 11-29-2009, 06:21 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by fowlplay4 View Post
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
__________________
Reply With Quote
  #6  
Old 11-29-2009, 06:26 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
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.
Reply With Quote
  #7  
Old 11-29-2009, 06:30 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by cbk1994 View Post
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
Was just providing a different way to do things, and I like to be able to trigger, and schedule the functions I make.
__________________
Quote:
Reply With Quote
  #8  
Old 11-29-2009, 06:37 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by fowlplay4 View Post
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

EDIT: Updated my first post with something that should fix the onKeyPressed repeat
__________________
Reply With Quote
  #9  
Old 11-29-2009, 06:42 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by DustyPorViva View Post
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.
__________________
Quote:
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 03:06 AM.


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