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-10-2011, 09:39 PM
furry_mougle furry_mougle is offline
big heart
furry_mougle's Avatar
Join Date: Aug 2011
Posts: 42
furry_mougle is an unknown quantity at this point
weapon equip/dequip

I've been trying to figure this out for ages, and I simply cannot figure it out.

Essentially I've been having a problem with onWeaponFired and the detection of an equipped weapon.

What I want to do is when the player presses D, it 'equips' the weapon (sets ganis) and when they dequip it (pressing S) it'll reset the ganis. However, when I want to use onWeaponFired it'll immediately fire the weapon even though the weapon isn't equipped by pressing D. I've tried many different ways including with booleans, but it doesn't go over very well because pressing D is the same thing as executing onWeaponFired at the same time. Not really sure how I would go about this.

Also, one thing to note is that this isn't a clone of Era or something I just made the weapon for fun and uhh I know Era uses the same equip/dequip system for guns. First you press D, it equips then you press D again and it fires the weapon.

PHP Code:
//#CLIENTSIDE
/*
  0 dequipped
  1 equipped
*/
function onCreated(){
  
this.on false;
  
this.dPress 0;
}

function 
onKeyPressed(code,key){
  if (
key == "d" && player.weapons[selectedweapon] == this.name && this.dPress == 0){ 
     
this.on true;
     
player.chat this.dPress;
     
gravAni();
     
this.dPress 1;
    
// this.increment += 1; 
  
}
  if (
key == "s" && player.weapons[selectedweapon] == this.name && this.dPress == 1){ 
     
this.on false;
     
gravAni();
     
this.dPress 0;
     
player.chat this.dPress;
  }


function 
gravAni(){
  if (
this.on){
    
replaceani("idle""gravgun_idle");
    
replaceani("walk""gravgun_walk");
    
setani("gravgun_idle"NULL);
  }else if(!
this.on){
    
replaceani("idle""idle");
    
replaceani("walk""walk");
  }
}

function 
onWeaponFired(){
 if( 
this.on ){ // if equipped, fire
      
setani("gravgun_fire"NULL);
    
player.chat "Fired";
    
//  player.chat = this.dPress;
      //sleep(this.increment - );
      //  player.chat = "Fired for " @ this.increment;
      //  setani("gravgun_idle", NULL);
 
}

Is there a way to prevent onWeaponFired from being executed this way?
__________________
Quote:
Originally Posted by ffcmike View Post
But make sure to change beer.png to Orange Juice.
pay bills to play graal
Reply With Quote
  #2  
Old 09-10-2011, 09:49 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
PHP Code:
function onWeaponFired() {
  if (! 
this.isEquipped()) {
    return 
this.equip(); // it's not already equipped, so equip it
  
}
  
  
// it's already equipped
  
this.fire();
}

function 
GraalControl.onKeyCode(temp.codetemp.key) {
  if (
temp.key == "s" && this.isEquipped()) {
    
// pressed "s" while equipped, unequip it
    
this.unequip();
  }

Just do something like this.


Also, note that this is incorrect:

PHP Code:
player.weapons[selectedweapon] == this.name 
weapons is an array of weapon objects, not weapon names. The only reason it works is because the weapon object is coerced into a string, which is then compared to the current weapon's name.

The correct way would be to do
PHP Code:
player.weapons[selectedweapon] == this 
However, the best way would just be to do

PHP Code:
player.weapon == this 
(player.weapon always refers to the currently selected weapon)
__________________
Reply With Quote
  #3  
Old 09-10-2011, 09:59 PM
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
Make a system npc to manage the equipping and un-equipping. I.e:

-System/Equipment

PHP Code:
//#CLIENTSIDE
public function equip(wep) {
  if (
isEquipped(wep)) {
    
unequip();
  } else {
    
this.equipped wep;
  }
}

public function 
unequip() {
  
this.equipped "";
}

public function 
isEquipped(wep) {
  return (
this.equipped == wep);

then in your weapon you can do:

PHP Code:
//#CLIENTSIDE
function onWeaponFired() {
  
// Equip/Unequip Weapon
  
("-System/Equipment").equip(this);
  
// Check if Weapons is Equipped
  
if (("-System/Equipment").isEquipped(this)) {
    
// set appropriate anis
  
} else {
    
// return anis to normal
  
}
}

function 
onKeyPressed() {
  if ((
"-System/Equipment").isEquipped(this)) {
    if (
keydown(5)) fireWeapon();
  }
}

function 
fireWeapon() {
  
// pew pew pew
  // RED DRAGONS

This is just a basic implementation, you can expand upon it and do more in -System/Equipment to the point where all you're doing is setting different configuration variables in your weapons.

Also use keydown(5) instead of key == "s" that way players can re-assign the attack key via F3 Options.
__________________
Quote:
Reply With Quote
  #4  
Old 09-10-2011, 10:00 PM
furry_mougle furry_mougle is offline
big heart
furry_mougle's Avatar
Join Date: Aug 2011
Posts: 42
furry_mougle is an unknown quantity at this point
The only thing I don't understand is why you wrote ! this.isEquipped() instead of !this.Equipped? How can you check empty parameters like that? (cbk) FP4: by 'system' NPC do you mean a class or an actual system NPC? Also why would I want to fire with the S key? wat
__________________
Quote:
Originally Posted by ffcmike View Post
But make sure to change beer.png to Orange Juice.
pay bills to play graal
Reply With Quote
  #5  
Old 09-10-2011, 10:12 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by furry_mougle View Post
The only thing I don't understand is why you wrote ! this.isEquipped() instead of !this.Equipped?
Preference.
__________________
Reply With Quote
  #6  
Old 09-10-2011, 10:13 PM
furry_mougle furry_mougle is offline
big heart
furry_mougle's Avatar
Join Date: Aug 2011
Posts: 42
furry_mougle is an unknown quantity at this point
Quote:
Originally Posted by Crow View Post
Preference.
Don't the parameters reference a function?
__________________
Quote:
Originally Posted by ffcmike View Post
But make sure to change beer.png to Orange Juice.
pay bills to play graal
Reply With Quote
  #7  
Old 09-10-2011, 10:13 PM
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
An actual weapon NPC.

I misread your post but I feel if you're going to use D/keydown(4) to equip/unequip weapons you should use a different key to actually fire the weapon otherwise why even bother equipping them.
__________________
Quote:
Reply With Quote
  #8  
Old 09-10-2011, 10:16 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by furry_mougle View Post
Don't the parameters reference a function?
Missed the parenthesis. Thought you were talking about the space after the exclamation mark. I guess he put the parenthesis by accident.
__________________
Reply With Quote
  #9  
Old 09-10-2011, 10:18 PM
furry_mougle furry_mougle is offline
big heart
furry_mougle's Avatar
Join Date: Aug 2011
Posts: 42
furry_mougle is an unknown quantity at this point
Quote:
Originally Posted by fowlplay4 View Post
An actual weapon NPC.

I misread your post but I feel if you're going to use D/keydown(4) to equip/unequip weapons you should use a different key to actually fire the weapon otherwise why even both equipping them.
That's the whole reason I made this forum post, lol. How would I equip and then fire?
__________________
Quote:
Originally Posted by ffcmike View Post
But make sure to change beer.png to Orange Juice.
pay bills to play graal
Reply With Quote
  #10  
Old 09-10-2011, 10:21 PM
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 furry_mougle View Post
That's the whole reason I made this forum post, lol. How would I equip and then fire?
I already displayed my method of doing so.
__________________
Quote:
Reply With Quote
  #11  
Old 09-10-2011, 10:27 PM
furry_mougle furry_mougle is offline
big heart
furry_mougle's Avatar
Join Date: Aug 2011
Posts: 42
furry_mougle is an unknown quantity at this point
Quote:
Originally Posted by fowlplay4 View Post
I already displayed my method of doing so.
I don't want to like spam the thread by asking meaningless questions, but essentially what you mean by System NPC is to create an NPC called -System/Equipment (does the -System even mean anything? wat) (on testbed mind you) and manage the equipping and dequipping of weapons? Huh? Why would you create a SYSTEM Npc for that? Why not a class?
__________________
Quote:
Originally Posted by ffcmike View Post
But make sure to change beer.png to Orange Juice.
pay bills to play graal
Reply With Quote
  #12  
Old 09-10-2011, 10:47 PM
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 furry_mougle View Post
I don't want to like spam the thread by asking meaningless questions, but essentially what you mean by System NPC is to create an NPC called -System/Equipment (does the -System even mean anything? wat) (on testbed mind you) and manage the equipping and dequipping of weapons? Huh? Why would you create a SYSTEM Npc for that? Why not a class?
A class is basically just for pasting functions into your script/weapon/level-npc. It doesn't actually exist as anything until it's joined to an DB-NPC Weapon-NPC, Level-NPC, or an object.

By System NPC I just mean a weapon that is added to the player that's primarily used for background tasks and as a database. In this case it's used to keep track of what weapon you currently have equipped and provides a standard way of equipping a weapon.

If you have two weapons: A and B, and you equip A how will B know that you have equipped A if you only tell A that it's equipped?

To deal with that you use a system npc and route your equip requests through it like my example does.

You don't have to use -System/Equipment as the weapon name either, you can use any name just make sure you update the scripts to make calls to it instead of -System/Equipment.
__________________
Quote:
Reply With Quote
  #13  
Old 09-10-2011, 10:50 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
Weapons in Graal are not necessarily (and usually aren't) actual usable weapons. Classes are kind of like includes; they can't be on their own, they have to be joined to a weapon or NPC.

Quote:
Originally Posted by furry_mougle View Post
The only thing I don't understand is why you wrote ! this.isEquipped() instead of !this.Equipped? How can you check empty parameters like that? (cbk) FP4: by 'system' NPC do you mean a class or an actual system NPC? Also why would I want to fire with the S key? wat
isEquipped() is just a function, you can either define it or use a variable directly.

Quote:
Originally Posted by Crow View Post
Missed the parenthesis. Thought you were talking about the space after the exclamation mark. I guess he put the parenthesis by accident.
No, I did it on purpose. I like to use functions for this kind of thing as it gives far more flexibility and makes it easier to make changes in the future.
__________________
Reply With Quote
  #14  
Old 09-10-2011, 11:06 PM
furry_mougle furry_mougle is offline
big heart
furry_mougle's Avatar
Join Date: Aug 2011
Posts: 42
furry_mougle is an unknown quantity at this point
Quote:
Originally Posted by fowlplay4 View Post
A class is basically just for pasting functions into your script/weapon/level-npc. It doesn't actually exist as anything until it's joined to an DB-NPC Weapon-NPC, Level-NPC, or an object.

By System NPC I just mean a weapon that is added to the player that's primarily used for background tasks and as a database. In this case it's used to keep track of what weapon you currently have equipped and provides a standard way of equipping a weapon.

If you have two weapons: A and B, and you equip A how will B know that you have equipped A if you only tell A that it's equipped?

To deal with that you use a system npc and route your equip requests through it like my example does.

You don't have to use -System/Equipment as the weapon name either, you can use any name just make sure you update the scripts to make calls to it instead of -System/Equipment.
Ah OK. I thought you meant an actual NPC, but you just meant a weapon used as a System.

edit: nothing works and I pretty much managed to messed up my weapons to the point that I can't even execute a basic player.chat, will probably have to make a completely different thread attempting to fix this (it's probably a server bug not sure)

Anyway thanks for attempting to help me I guess
__________________
Quote:
Originally Posted by ffcmike View Post
But make sure to change beer.png to Orange Juice.
pay bills to play graal

Last edited by furry_mougle; 09-11-2011 at 05:40 AM..
Reply With Quote
  #15  
Old 10-15-2012, 03:55 AM
sorgen sorgen is offline
Registered User
Join Date: May 2012
Posts: 3
sorgen is on a distinguished road
this is clientside is there one for serverside?
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 12:13 AM.


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