Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 09-07-2010, 11:41 PM
khortez khortez is offline
PrototypeX
khortez's Avatar
Join Date: Dec 2008
Posts: 91
khortez will become famous soon enough
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?
Reply With Quote
  #2  
Old 09-07-2010, 11:52 PM
DrakilorP2P DrakilorP2P is offline
Registered User
DrakilorP2P's Avatar
Join Date: Apr 2006
Posts: 755
DrakilorP2P is just really niceDrakilorP2P is just really nice
Do you mean default weapons and Q menu?
Reply With Quote
  #3  
Old 09-07-2010, 11:53 PM
papajchris papajchris is offline
Zeus Condero
papajchris's Avatar
Join Date: Jan 2006
Location: Michigan
Posts: 1,600
papajchris is a splendid one to beholdpapajchris is a splendid one to beholdpapajchris is a splendid one to beholdpapajchris is a splendid one to behold
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
__________________
Reply With Quote
  #4  
Old 09-07-2010, 11:58 PM
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
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.
__________________
Reply With Quote
  #5  
Old 09-08-2010, 02:30 AM
khortez khortez is offline
PrototypeX
khortez's Avatar
Join Date: Dec 2008
Posts: 91
khortez will become famous soon enough
Quote:
Originally Posted by cbk1994 View Post
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 View Post
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.

Last edited by khortez; 09-08-2010 at 02:36 AM.. Reason: Mistake possibly found
Reply With Quote
  #6  
Old 09-08-2010, 03:41 AM
salesman salesman is offline
Finger lickin' good.
salesman's Avatar
Join Date: Nov 2008
Location: Colorado
Posts: 1,865
salesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud of
Quote:
Originally Posted by khortez View Post
[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.
__________________
Reply With Quote
  #7  
Old 09-08-2010, 03:53 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 salesman View Post
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;
  }

__________________
Reply With Quote
  #8  
Old 09-08-2010, 01:02 PM
Raeiphon Raeiphon is offline
I never asked for this.
Join Date: Jun 2005
Posts: 855
Raeiphon is on a distinguished road
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.
__________________

I hope for nothing. I fear nothing. I am free.
Reply With Quote
  #9  
Old 09-09-2010, 03:20 AM
khortez khortez is offline
PrototypeX
khortez's Avatar
Join Date: Dec 2008
Posts: 91
khortez will become famous soon enough
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 View Post
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;
  }

Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 10:00 AM.


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