Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   How do you equip a weapon without shooting? (https://forums.graalonline.com/forums/showthread.php?t=134260470)

khortez 09-07-2010 11:41 PM

How do you equip a weapon without shooting?
 
I've tried this quite a bit by myself but it seems like i only got it partially working. How do i make it so when a person equips a weapon, a projectile isn't shot automaticly? so far I've got it to where you can equip it once without shooting. But if you unequip a weapon then requip it again, it'll shoot. Any ideas?

DrakilorP2P 09-07-2010 11:52 PM

Do you mean default weapons and Q menu?

papajchris 09-07-2010 11:53 PM

No he means like how on Era when you press D to equpt a gun, it ONLY equipts it. It doesnt shoot. Not until you press D again. (Or i tihnk thats whats he meant

cbk1994 09-07-2010 11:58 PM

Set a variable like "this.gunOut" on the first press. If it's false, show the gun. If it's true, shoot. If the weapon changes or the player puts the gun away, set it to false.

khortez 09-08-2010 02:30 AM

Quote:

Originally Posted by cbk1994 (Post 1599529)
Set a variable like "this.gunOut" on the first press. If it's false, show the gun. If it's true, shoot. If the weapon changes or the player puts the gun away, set it to false.

Believe I tried that in multiple ways. still it shoots on the second equip, Here's what I have so far:

PHP Code:

//#CLIENTSIDE
function onKeyPressed(codekey)
switch(
key)

case 
"d":

this.equip = !this.equip;

if(!
this.equip || this.equip == false)
freezeplayer(0.1);

setani(this.gani.idlenull);

replaceani("walk"this.gani.walk);

replaceani("idle"this.gani.idle);

if(
this.equip || this.equip == true)

onFire();

break; 

Missing braces intentional on here. Other then that, something i missed?

Edit: Feel free to state anything you see wrong, but i believe i found my own mistake.

Quote:

Originally Posted by papajchris (Post 1599525)
No he means like how on Era when you press D to equpt a gun, it ONLY equipts it. It doesnt shoot. Not until you press D again. (Or i tihnk thats whats he meant

Yes it is what I meant.

salesman 09-08-2010 03:41 AM

Quote:

Originally Posted by khortez (Post 1599546)
[PHP]
this.equip = !this.equip;

You're toggling this.equip every time the fire button is pressed. You should only set this.equip to false whenever you want to unequip the weapon, and only set it to true when you want to equip the weapon.

if you want the fire button to also equip a gun the first time it's pressed, then do something like:
PHP Code:

// whenever the fire button is pressed
if (! this.equip) { // the gun isn't equipped yet, so equip it
  
this.equip true;
  
// equip ganis or whatever else you want to do
  
return; // don't do any of the shooting stuff yet
}

// do shooting stuff 

I should probably also add that you might want to use a timeout and keydown() functions instead of onKeyPressed() so that you can handle automatic weapons more efficiently.

cbk1994 09-08-2010 03:53 AM

Quote:

Originally Posted by salesman (Post 1599552)
I should probably also add that you might want to use a timeout and keydown() functions instead of onKeyPressed() so that you can handle automatic weapons more efficiently.

Better yet:

PHP Code:

function GraalControl.onKeyDown(codekey) {
  if (
key == "d" && player.weapon == this && ! this.d) {
    
this.onTimeOut();
    
this.true;
  }
}

function 
onTimeOut() {
  if (
player.weapon != this) {
    return;
  }
  
  
// shoot stuff goes here
  
  
if (this.isAutomatic) {
    
this.setTimer(this.sleepTime);
  }
}

function 
GraalControl.onKeyUp(codekey) {
  if (
key == "d" && player.weapon == this) {
    
this.setTimer(0);
    
this.false;
  }



Raeiphon 09-08-2010 01:02 PM

PHP Code:

function onWeaponFired() {
  if (
this.out) {
    
this.doAttack();
  } else {
    
this.drawGun();
  }


Handle this.out in drawGun(); and your projectile function in doAttack(); and you're right as rain. I normally handle gani replacement within such scripts and ensuring that the weapon variables are properly set/carried across uses in functions like this at the same time. This may seem a bit sparse, but I'm sure you're capable of toggling a boolean value within a function without being told how to do it.

You really don't need to use a timeout for this.

khortez 09-09-2010 03:20 AM

Thanks guys, I'll give it a shot.

Although chris, I'm not exactly familiar with GraalControl yet.

or Keyup and KeyDown even though, i have tried using them before. (keydown that is)


Quote:

Originally Posted by cbk1994 (Post 1599555)
Better yet:

PHP Code:

function GraalControl.onKeyDown(codekey) {
  if (
key == "d" && player.weapon == this && ! this.d) {
    
this.onTimeOut();
    
this.true;
  }
}

function 
onTimeOut() {
  if (
player.weapon != this) {
    return;
  }
  
  
// shoot stuff goes here
  
  
if (this.isAutomatic) {
    
this.setTimer(this.sleepTime);
  }
}

function 
GraalControl.onKeyUp(codekey) {
  if (
key == "d" && player.weapon == this) {
    
this.setTimer(0);
    
this.false;
  }





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

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