OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: EXS on 18 Jul 2004, 15:15:39
-
Hi there,
I'm working on my vehicle-respawn-script. I managed to create Vehicles and delete them.
My Problem is how do I get some Info of the vehicle/object?
For example I create a "Bradley", so the command to do this would be
"Bradley" createVehicle _pos
where _pos is an array of type Pos. What I get is an Object which would probably be a - suprise! Who did this expect? ;-) - Bradley.
How do I name that object? How do I get the type (= here I mean "Bradley") ?
What I wanna do is, create an object per script, add an EventHandler which would call another function that delete the object and than create a new object of the same typ (e. g. "Bradley")
-
name = "object" creatvehicle [0,0,0]
name is now your knew name for the vehicle
-
Well, that doesn't help me.
I try to explain my problem again:
I pass an object to a script called respawn_help.sqs. This script is called from an eventHandler.
...
_vehicle addEventHandler ["killed", {_this exec "respawn_help.sqs";}];
...
The script itself would call a function del_vehicle which removes an object after 15 seconds. After that the script waits another 15 seconds and then call a function add_vehicle.
The function add_vehicle needs the "typ" and the "pos" of an object.
So I think there a two possiblities:
1. find out what kind of object is passed to respawn_help.sqs. "Bradley", "Su25" ...
or
2. Pass the "typ" and "pos" with the eventHandler...
Unfortnatly none of the two ways are working for now, because I don't know how to do.
How do I find out the kind of an object OR how can I pass more variables to an eventHandler?
The second way would be the thing I'm looking for...
thanks for help
EXS
-
For the first option, there is the typeof command (after OFP v1.91 [size=0.25]??[/size] only).
So if you have a Bradley called vehicle,
Typeof vehicle
will return: "Bradley"
For the second bit, you can throw as many arguements to an event handler as you wish... try this:
_vehicle addEventHandler ["killed", {[ name, type, eyecolour, starsign ] exec "respawn_help.sqs";}]
Then in your script use:
name = _this select 0
type = _this select 1
eyecolour = _this select 2
etc... ;)
-
sorry for the misunderstanding by the way - Sui gets there before me :)
-
Thanks for help!
@sui: I hav tryed to pass as many arguments I need to the Eventhandler but the problem is that there already some arguments passed by.
For example
;Script 1:
...
_something_else = "hello there!";
player addEventHandler["killed", {[_this, _somthing_else] exec "script.sqs"];
...
exit
;Script2:
_who = _this select 0;
_what = _this select 1;
hint format["Who: %1\nWhat: %2", _who, _what];
...
exit
The effect I expected would be:
Who: "playername"
What: hello there!
unfortunatly thats not working, what really happens is:
Who: "playername"
What: "killed by anotherplayername"
because the eventHandler handles the "killed" and passes some arguments to the script.
So the Only thing you can pass iss the object itself and "killed" tell you what was killed and by whom it was killed...
I tryed that typeof-thing and it works great so thanks alot you ended some sleepless nights...
mfg EXS
[solved]
-
The killed EH returns two arguments, and they are used in the script like this:
_this select 0 : who's dead
_this select 1 : who did it
If you want to pass more variables:
this addEventhandler ["killed",{[_this select 0,_this select 1,yourVariable1,yourVariable2] exec "yourscript.sqs"
Should work...
Here's a couple of examples:
1)
this addeventHandler ["fired",{if (_this select 2 != "throw") then {[(nearestObject [_this select 0, _this select 4]),_this select 0,_this select 1,_this select 3] call htr_dispFire}}]
2)
this addEventHandler ["hit",{[_this select 0,_this select 2,"imHit_1"] exec "planeHit.sqs"}]
Then you call those elements in the script like you would when using a 'regular' array:
1)
_projectile = _this select 0;
_shooter = _this select 1;
_mode = _this select 2;
_vof = _this select 3;
2)
_plane = _this select 0
_damage = _this select 1
_message = _this select 2
-
Ahh ok. Yes, My apologies.
You can't pass it local variables. They have to be global ;)
If they have an underscore in front of them, the script will pick up the variables the event handler uses instead.
-
In eventHandler _this is an array that is returned by the eventHandler...
for example, in the fired eh _this referes to an array [who fired,weapon,muzzle,firemode,type of ammo]
Of course you can execute a script that does not use any of those... Then you just simply don't use any _this select x arguments...
this addEventHandler ["fired",{[2,attack=true] exec "script.sqs"}]
But I'm sure you all knew this already...
And, actually you can use local variables in calling functions (haven't tested on sqs or eventhandlers yet)... :P
If you dig up a mission called Bastige Battlefields (by bn880) at the BI Forums, in that you can find a CoC stuff in developement and it uses local variables when calling functions...
-
I don't think eventhandlers like 'em though... at least none that I've ever talked to ;)
I could be wrong of course...