Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   onWeaponFired() in a custome movement (https://forums.graalonline.com/forums/showthread.php?t=134264103)

callimuc 08-04-2011 10:57 PM

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?

Tricxta 08-04-2011 11:09 PM

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.

callimuc 08-04-2011 11:18 PM

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?

Tricxta 08-04-2011 11:21 PM

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 :)

Crow 08-04-2011 11:27 PM

If you use GraalControl.onKeyDown() and GraalControl.onKeyUp(), you don't have to rely on that while loop.

xXziroXx 08-04-2011 11:31 PM

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.

cbk1994 08-04-2011 11:36 PM

PHP Code:

player.weapon.trigger("weaponFired"param1param2param3); 

will fire the currently selected weapon. No need for findWeapon etc.

ffcmike 08-04-2011 11:59 PM

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.

callimuc 08-05-2011 01:16 AM

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?

fowlplay4 08-05-2011 01:31 AM

Use keydown(4) instead so it uses Graal's key-mappings.

onWeaponFired doesn't need to be public either.

Mark Sir Link 08-05-2011 01:34 AM

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.


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

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