Home   Help Search Login Register  

Author Topic: Tute on Eventhandlers?  (Read 852 times)

0 Members and 1 Guest are viewing this topic.

Offline Arctic

  • Members
  • *
  • In Utero
Tute on Eventhandlers?
« on: 12 Feb 2003, 00:36:21 »
I know what event handlers are, but I do not understand how to specify how they are to be used. Like I understand this:

Code: [Select]
player addEventhandler ["fire",{this exec somescript.sqs}]

I know that it means that when the player fires something, it will execute the script: somescript.sqs
But how do I specify the specifics of the Event handler? i.e,

Code: [Select]
   
"Fired" string:weapon,string:muzzle,string:mode,string:ammo
?

I've tried putting in the weapon string right after the "fired" thing, but it returned an error.

I've tried it but the official scripting commands doesnt really explain in enough detail for me to understand how to fully use this tool.
« Last Edit: 12 Feb 2003, 00:39:39 by Arctic »

Offline Blanco

  • Former Staff
  • ****
Re:Tute on Eventhandlers?
« Reply #1 on: 12 Feb 2003, 21:29:56 »
same prob ,here... i'm waitin' for so long for a tuto about this...plzzzzz :-\



 


Search or search or search before you ask.

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:Tute on Eventhandlers?
« Reply #2 on: 13 Feb 2003, 00:23:23 »
You can specify the arguements between the braces there... so you could do something like this:

player addEventhandler ["fire",{hint format ["Player fired: %1",_this select 1]}]

Would make a hint message pop up every time the player fires, displaying the name of the weapon they fired.
If you want to pass arguements to a script, you can do it thusly:

player addEventhandler ["fire",{[_this select 1, _this select 2] exec "somescript.sqs"}]

Just note that  _this select 0 always returns the object the event handler is attached to...

wi77ard

  • Guest
Re:Tute on Eventhandlers?
« Reply #3 on: 26 Mar 2003, 00:57:20 »
how do i make it so that it only works when my guy fires a ak47 ?

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re:Tute on Eventhandlers?
« Reply #4 on: 26 Mar 2003, 15:14:40 »
Quote
how do i make it so that it only works when my guy fires a ak47 ?

You need to add an eventhandler type: fired to the unit by
using it's init field.

this addEventHandler ["FIRED", {_this exec "script.sqs"}]


Now create the script and put following into:

?(_this select 1 == "AK47"): whatever you want to do then here
exit

@Sui

Just noticed you're passing _this select 0,_this select 1 with
the exec command.
That's not necessary, as you can pass _this and then you can
have access to the elements of _this inside the script aswell.

If you want to check the contents of _this, then you can display
the whole array aswell by:

hint format ["%1", _this]

~S~ CD
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:Tute on Eventhandlers?
« Reply #5 on: 27 Mar 2003, 00:52:32 »
That's an awfully good point... ;D

So instead of:

player addEventhandler ["fire",{[_this select 1, _this select 2] exec "somescript.sqs"}]

this would be better:

player addEventhandler ["fire",{_this exec "somescript.sqs"}]