Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 08-04-2011, 10:57 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
onWeaponFired() in a custome movement

Hey there,

I found this movement in the Code Gallery and I was messing around with it.
While that I realized, that you can´t use onWeaponFired(). Is it generally when using disabledefaultmovement() or is there something in this script (couldn´t find anything)?
And what can I do to fix this so I can fire weapons?
__________________
MEEP!
Reply With Quote
  #2  
Old 08-04-2011, 11:09 PM
Tricxta Tricxta is offline
The Muffin Man
Tricxta's Avatar
Join Date: Oct 2010
Location: Australia
Posts: 563
Tricxta is just really niceTricxta is just really nice
When you disable default movement you also disable the ability to use the weaponfired call. To fix this you could make your own trigger script:
PHP Code:
function onKeypressed(){
  if (
keydown2(keycode(d),true) && this.key==0){
    
this.key=1;
    
callweapon selectedweapon,"weaponfired";
    while (
keydown2(keycode(d),true))sleep .05;
    
this.key=0;
  }

I know this method is a bit crude but your going to have excuse me since I dont actually code in GS2, however it does show the main idea I'm trying to convey. Hope this helps.
__________________
Quote:
Originally Posted by Crono View Post
No look at it, Stefan is totally trolling Thor. Calling Classic a "playerworld" (something it's not supposed to be) is the ultimate subtle insult to a true fan.

It's genius.
Reply With Quote
  #3  
Old 08-04-2011, 11:18 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
After using your method it didn´t work:

PHP Code:
//#CLIENTSIDE
function onKeypressed(){
  if (
keydown2(keycode(d),true) && this.key==0){
    
this.key=1;
    
callweapon selectedweapon,"weaponfired";
    while (
keydown2(keycode(d),true))sleep .05;
    
this.key=0;
  }
}
function 
onWeaponFired() {
  
player.chat "test";

Also a lot parts where in GS1 ;I
But the script got me into some ideas so I came up to this:

PHP Code:
//#CLIENTSIDE
function onKeypressed(){
  if (
keydown2(keycode(d),true) && this.key==0){
    
this.key=1;
    
findweapon(name).onWeaponFired();
    while (
keydown2(keycode(d),true)) sleep(.05);
    
this.key=0;
  }
}

public function 
onWeaponFired() {
  
player.chat "test";

This also works. But is it a good way of using it like this?
__________________
MEEP!
Reply With Quote
  #4  
Old 08-04-2011, 11:21 PM
Tricxta Tricxta is offline
The Muffin Man
Tricxta's Avatar
Join Date: Oct 2010
Location: Australia
Posts: 563
Tricxta is just really niceTricxta is just really nice
I believe its an adequate way of using it. However you would be better off getting clarification from Chris or someone else who knows what there talking about
__________________
Quote:
Originally Posted by Crono View Post
No look at it, Stefan is totally trolling Thor. Calling Classic a "playerworld" (something it's not supposed to be) is the ultimate subtle insult to a true fan.

It's genius.
Reply With Quote
  #5  
Old 08-04-2011, 11:27 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
If you use GraalControl.onKeyDown() and GraalControl.onKeyUp(), you don't have to rely on that while loop.
Reply With Quote
  #6  
Old 08-04-2011, 11:31 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
In addition to what Crow said, you'd also ideally want to replace

PHP Code:
findweapon(name).onWeaponFired(); 
with

PHP Code:
findweapon(name).trigger("WeaponFired""param1""param2""etc."); 
since it'll avoid causing scripterrors in weapons where the onWeaponFired() function isn't defined.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #7  
Old 08-04-2011, 11:36 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:
player.weapon.trigger("weaponFired"param1param2param3); 
will fire the currently selected weapon. No need for findWeapon etc.
__________________
Reply With Quote
  #8  
Old 08-04-2011, 11:59 PM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
One thing I rarely see brought with this type of thing, which may not be entirely necessary but can be convenient down the line, is that it would be much better to create a single system for detecting your various key presses so that you can both more easily prevent them from interfering with eachother and process them in an intended order.

If you have different instances of "function onKeyPressed" within a lot of weapons it becomes harder to keep track of everything going on.
Reply With Quote
  #9  
Old 08-05-2011, 01:16 AM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
ok thx guys

just to make sure I understood correctly:
PHP Code:
//#CLIENTSIDE
function onKeypressed(){
  if (
keydown2(keycode(d),true)){
    
player.weapon.trigger("weaponFired");  
  }
}

public function 
onWeaponFired() {
  
player.chat "test";

Is this the way it should be?
__________________
MEEP!
Reply With Quote
  #10  
Old 08-05-2011, 01:31 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
Use keydown(4) instead so it uses Graal's key-mappings.

onWeaponFired doesn't need to be public either.
__________________
Quote:
Reply With Quote
  #11  
Old 08-05-2011, 01:34 AM
Mark Sir Link Mark Sir Link is offline
Kevin Azite
Mark Sir Link's Avatar
Join Date: Sep 2005
Posts: 1,489
Mark Sir Link is just really niceMark Sir Link is just really nice
Send a message via AIM to Mark Sir Link
You should probably be using the keydown value instead of keydown2 to not force players with different control schemes to have to use the D key.


Also, that would only change player's chat to test if that were the selected weapon, player.weapon.trigger will execute on whatever weapon you have selected. You only need the GraalControl.onKeyDown in one place.
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 05:00 AM.


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