Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   "hooking" functions? (https://forums.graalonline.com/forums/showthread.php?t=64726)

projectigi 03-13-2006 03:29 PM

"hooking" functions?
 
Hi,

is there a way to "hook" functions?
like to modify them or put own code on them?
or to fully rewrite them?

Projectshifter 03-13-2006 07:42 PM

What exactly are you trying to do?

projectigi 03-13-2006 08:42 PM

Basically changing functions
or Events
like onPlayerTouchsMe
or like changing the gui controls to use other template setup or stretch/dont stretch images etc xD or to make own syntaxhighlightning at the guitext ctrls

napo_p2p 03-13-2006 10:09 PM

The way you format your posts makes it hard for me to understand what you are talking about.

I am under the impression that you want to override built-in functions/events? I am pretty sure that you can't. What you can do, though, is script your own.

Ajira 03-13-2006 10:26 PM

He wants to rescript default events/functions. :D

projectigi 03-13-2006 11:02 PM

Ajira got it xD
or simply add something to them

Projectshifter 03-14-2006 01:14 AM

As far as I know you can't override the default functions, but you can always make your own. If you mold your server properly then you can have certain NPCs handle certain events instead of having 45973497534 NPCs that could be combined for efficiency and editability (and yes, it is a word, I just made it up so get over it).

projectigi 03-14-2006 04:15 PM

Yeah you can make your own but that means fully redoing the function instead of changing it X_x

Projectshifter 03-14-2006 04:18 PM

Quote:

Originally Posted by projectigi
Yeah you can make your own but that means fully redoing the function instead of changing it X_x

I fail to see the problem ;) Sure Graal has some built in functions, but you have a lot more control and understanding of the systems if you rewrite majority of it from scratch (plus it's more fun lol).

Rick 03-14-2006 04:22 PM

Projectshifter, have you ever used the GUI controls in Graal?

Projectshifter 03-14-2006 04:36 PM

Quote:

Originally Posted by Rick
Projectshifter, have you ever used the GUI controls in Graal?

Many a time. Personally I don't like them, but it's mostly because I was using them when the new engine was in its infancy and it wasn't supported by any client other than the one that basically the GST and Stefan had, so it wasn't worth writing a lot of stuff in it. I wrote a nice RC equivalent program with it. But yes, I have used the GUI controls in Graal and until graalv4 becomes mandatory, I don't think they should be used.

projectigi 03-14-2006 04:47 PM

Well look at GuiControls
they are nice but u cant change the template(well you cant change positioning/use/size of it XD

Projectshifter 03-14-2006 04:52 PM

Quote:

Originally Posted by projectigi
Well look at GuiControls
they are nice but u cant change the template(well you cant change positioning/use/size of it XD

? I remember back when we were testing it when Stefan first designed it you could change the template and the scheme and positioning?

ApothiX 03-14-2006 05:06 PM

Hmm, using catchevent() would probably be the closest thing you could do to 'hooking functions'

projectigi 03-14-2006 05:09 PM

AFAIK you can change the image it uses and by that changing its style but i dont know of changing the template it uses o_o like having an other order of the elements on the image etc or adding new things

jake13jake 03-15-2006 08:50 PM

playertouchsme is the strangest event handler in the sense that you can't modify it. There are several instances in which you might want to, but you just can't.

You can most easily control certain clientside events if you can disable them (consider disableweapons). However, you can't control all serverside events quite as efficiently. I'm pretty sure you could tell an NPC not to recognize an event and use the trigger function to call it whenever you needed it, but it would be hard to mimick serverside with the lack of a timeout (especially for playertouchsme).

I'm hoping Stefan will release at least one more event handler, being similar to playertouchsme, for the player overlapping or bordering the NPC. Playertouchsme doesn't do that specifically, but there are a lot of places it could be used if you simply wanted a script to be based on a field and use the npc's x,y,width,height to define that field. Perhaps damage fields, or even any coordinate dependent zones that activate some other script functionality. Damage fields would be what I would immediately use this for, but the concept can certainly cover other aspects of things as well. I would probably think the best implementation would be something like:
onPlayerEntersMyShape() and onPlayerLeavesMyShape(). It would be comparable to having onPlayerEnters() and onPlayerLeaves(), but the player only enters a part of the level that's defined by an NPC's x,y,w,h... or leaves a part of the level that's defined by an NPC's x,y,w,h. It would make sense to call the onPlayerLeavesMyShape() for the NPC the player has not left the shape of before the player leaves the level. I ought to post this in my other thread about playertouchsme.

It would certainly help a bit to have such functionality.

Rick 03-15-2006 10:27 PM

Quote:

Originally Posted by projectigi
AFAIK you can change the image it uses and by that changing its style but i dont know of changing the template it uses o_o like having an other order of the elements on the image etc or adding new things

What do you mean by template? Profiles are 100% customizable.

projectigi 03-15-2006 11:38 PM

with template i mean the order of the elements on the bitmap it uses

Projectshifter 03-17-2006 12:46 AM

Quote:

Originally Posted by jake13jake
I would probably think the best implementation would be something like:
onPlayerEntersMyShape() and onPlayerLeavesMyShape(). It would be comparable to having onPlayerEnters() and onPlayerLeaves(), but the player only enters a part of the level that's defined by an NPC's x,y,w,h... or leaves a part of the level that's defined by an NPC's x,y,w,h. It would make sense to call the onPlayerLeavesMyShape() for the NPC the player has not left the shape of before the player leaves the level. I ought to post this in my other thread about playertouchsme.

It would certainly help a bit to have such functionality.

I don't see the use of it being added in all seriousness. If you really want that functionality you could do it with a while() loop or so if you were so compelled using a combination of npc.x/y/width/height and player coords. Sadly the few times that I've used while() loops in conjunction with coord and keydown checks (with simple commands) seemed to make Graal unstable and often times crash. Sad day.

jake13jake 03-17-2006 02:45 AM

Quote:

Originally Posted by Projectshifter
I don't see the use of it being added in all seriousness. If you really want that functionality you could do it with a while() loop or so if you were so compelled using a combination of npc.x/y/width/height and player coords. Sadly the few times that I've used while() loops in conjunction with coord and keydown checks (with simple commands) seemed to make Graal unstable and often times crash. Sad day.

AS SERVERSIDE EVENTS.....

There would be no way to create that functionality serverside without crashing the NPC server.

If you don't see the use of it being added, it's your sad day.

Here's one scenario: say we have a sparring area within a level. You want to lock the sparring area when two players are in the arena and warp anyone else out.

What you would never be able to script as effectively without this event handler:
PHP Code:

function onCreated() {
  
setshape(1,widthofspar*16,heightofspar*16);
}

function 
onPlayerEntersMyShape() {
  
this.myPlayers.add(player); //keep of track of all players in area

  //two players per spar
  
if (this.myPlayers.size() == 2) {
    
//to keep the spar civil
    
lockArena();
    
healPlayers();
    
initializeSpar();
  } else if (
this.myPlayers.size() > 2) {
    
//keep extra people from getting into the sparring area
    
kickFromSpar(player);
  }
}

function 
onPlayerLeavesMyShape() {
  
this.myPlayers.remove(player); //keep track of players in area
  
if (this.myPlayers.size() < 2)
    
unlockArena();


They can be used in any similar script. The "playertouchsme" event handler would be similar to "PlayerEntersMyShape", but it wouldn't be the same functionality because the player doesn't have to be touching the NPC to touch it. In addition, a "PlayerLeavesMyShape" would help to more easily keep track of who's in the area. That would bring a lot of functionality upon itself. Sparring, guild wars, special areas on a gmap, nopk zones, pk-specific zones... It would be like having "playerenters" and "playerleaves" but on a sub-level scale that offers a huge amount of flexibility. It could also be used in damage systems (which I'm all ready to do).

excaliber7388 03-18-2006 04:18 AM

In the past, we've used x's and y's or setshape, but yeah, I would like this. It would also have to be modify...able. You would have to be able to control the area around it. Maybe even an option of using radius, so you can have a circle. (in my oppinion, this would be an exelent addition, i'm tired of sine, cosine, a^2 and so on).

Projectshifter 03-18-2006 09:47 AM

Generally this is done with a trigger and/or a timeout. I'm comprehending what you're saying you want, and why you seem to think you need it, I just really don't see it being that big of a deal and something that cannot be accomplished in other ways just fine.

jake13jake 03-18-2006 10:37 PM

Quote:

Originally Posted by excaliber7388
In the past, we've used x's and y's or setshape, but yeah, I would like this. It would also have to be modify...able. You would have to be able to control the area around it. Maybe even an option of using radius, so you can have a circle. (in my oppinion, this would be an exelent addition, i'm tired of sine, cosine, a^2 and so on).

Well, this is why it would be awesome to have a setshape mode for circles/ellipses. (I suggested that a while ago too when I was building my damage system).

Quote:

Originally Posted by Projectshifter
Generally this is done with a trigger and/or a timeout. I'm comprehending what you're saying you want, and why you seem to think you need it, I just really don't see it being that big of a deal and something that cannot be accomplished in other ways just fine.

It would certainly be much more secure for the server to detect it than the client (because the clientside scripts are run by the client and not the server, therefore, the player could potentially modify the client... blahblahblah... In essence, what would be the purpose of a serverside hit detection system if the detection was being done clientside). In regards to scripts that interact with many players, the scripting should be serverside. If a script is a show script or a script that you want to interact solely with the client player rather than all server players, it should be scripted clientside.


All times are GMT +2. The time now is 09:47 AM.

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