Home   Help Search Login Register  

Author Topic: How do I get the name of an Object?  (Read 557 times)

0 Members and 1 Guest are viewing this topic.

EXS

  • Guest
How do I get the name of an Object?
« 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

Code: [Select]
"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")

Offline Messiah

  • Honourary OFPEC Patron & Drinking Buddy of Wolfsbane
  • Honoured Contributor
  • ***
  • OFPEC Veteran
    • Project UK Forces
Re:How do I get the name of an Object?
« Reply #1 on: 18 Jul 2004, 18:21:18 »
name = "object" creatvehicle [0,0,0]

name is now your knew name for the vehicle
Proud Member of the Volunteer Commando Battalion

EXS

  • Guest
Re:How do I get the name of an Object?
« Reply #2 on: 19 Jul 2004, 07:33:22 »
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.

Code: [Select]
...
_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

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:How do I get the name of an Object?
« Reply #3 on: 19 Jul 2004, 09:20:26 »
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... ;)

Offline Messiah

  • Honourary OFPEC Patron & Drinking Buddy of Wolfsbane
  • Honoured Contributor
  • ***
  • OFPEC Veteran
    • Project UK Forces
Re:How do I get the name of an Object?
« Reply #4 on: 19 Jul 2004, 10:46:21 »
sorry for the misunderstanding by the way - Sui gets there before me  :)
Proud Member of the Volunteer Commando Battalion

EXS

  • Guest
Re:How do I get the name of an Object?
« Reply #5 on: 19 Jul 2004, 14:29:04 »
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

Code: [Select]
;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]

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:How do I get the name of an Object?
« Reply #6 on: 19 Jul 2004, 18:02:36 »
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
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:How do I get the name of an Object?
« Reply #7 on: 21 Jul 2004, 08:08:57 »
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.

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:How do I get the name of an Object?
« Reply #8 on: 21 Jul 2004, 11:41:01 »
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...
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:How do I get the name of an Object?
« Reply #9 on: 22 Jul 2004, 12:07:00 »
I don't think eventhandlers like 'em though... at least none that I've ever talked to ;)

I could be wrong of course...