Jump to content
Sign in to follow this  
OmniMax

Naming a createdvehicle

Recommended Posts

Can you name a vehicle while in mission by script? I saw the name command but I think thats only to return a string (the name) of the vehicle and I don't think you can assign it a name in mid-mission. Would be very useful.

But then again, I'll probally be flamed because you probally can, thank god for a great built in object oriented language.

Share this post


Link to post
Share on other sites
Guest jacobaby

If you use a name that is already used, your new one simply replaces the older one.

Share this post


Link to post
Share on other sites

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (jacobaby @ April 10 2003,11:36)</td></tr><tr><td id="QUOTE">If you use a name that is already used, your new one simply replaces the older one.<span id='postcolor'>

Okay, and how do you assign them indiviual names? step up var? or is that even how you assign names?

like..

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">

b = b + 1

b = "m113" createVehicle getmarkerpos "Respawn_West"

b addaction ["20mm APC light mortar","apc_mortar.sqs"

goto "end"

#end

exit

<span id='postcolor'>

if the beginning of the createvehicle command (b in this case) serves as the vehicle's object name, then I am, sir, a retard.

A powerful function indeed. Though, how do you mix a string with a variable? Unless you can add a number to the end of a variable to stop colision...

(say if you had two createvehicle "spawners" b could equal 100 in this case, and lets say we also spawn uh60s in the same manner, using variable a, same script manner, and the first a is one, the first b being 100. a will eventually catch up with b thus overiding the first m113's name. how do you mix strings with variables, use a quotes comma variable letter or a percent sign?)

blargh. never sleep all day then wake up at 2 in the morning.

Share this post


Link to post
Share on other sites
Guest BratZ

something like this maybe?

?b == objnull: b = "m113" createVehicle getmarkerpos "Respawn_West"

Several other ways,but just check if its been used is what you asked

Share this post


Link to post
Share on other sites

I have read this thread, and I have one question: WHAT?

Can you rephrase what you are trying to do. b + 1 and then b = vehicle makes no sense.

Share this post


Link to post
Share on other sites

Okay maybe this will help

in a script

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_x = 0;

#loop

?(_x >= 10): exit;

newM113Name = format ["M113%1",_x];

call format ["%1 =""m113"" createVehicle getmarkerpos ""Respawn_West""",newM113Name];

_x = _x + 1;

goto "loop"<span id='postcolor'>

this should create 10 M113's and they can be accessed by: M1130, M1131, M1132, M1133, M1134, M1135, M1136, M1137, M1138, M1139

not tested

Share this post


Link to post
Share on other sites
Guest BratZ

Nice bn880 that is very usefull and helpfull : )

Share this post


Link to post
Share on other sites

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (bn880 @ April 10 2003,18:25)</td></tr><tr><td id="QUOTE">Okay maybe this will help

in a script

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_x = 0;

#loop

?(_x >= 10): exit;

newM113Name = format ["M113%1",_x];

call format ["%1 =""m113"" createVehicle getmarkerpos ""Respawn_West""",newM113Name];

_x = _x + 1;

goto "loop"<span id='postcolor'>

this should create 10 M113's and they can be accessed by: M1130, M1131, M1132, M1133, M1134, M1135, M1136, M1137, M1138, M1139

not tested<span id='postcolor'>

so...

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">

newM113Name = format ["M113%1",_x];

call format ["%1 =""m113"" createVehicle getmarkerpos ""Respawn_West""",newM113Name];

<span id='postcolor'>

Useful snipt of code there...

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">

call format ["%1 =""m113"" createVehicle getmarkerpos ""Respawn_West""",newM113Name];

<span id='postcolor'>

I was just really looking for a way to name vehicles while in game via script. "Step(ing) up" variables are fun though, eh?

So I assume the first part of the CreateVehicle command is which designates the obj_name of that vehicle. If void, then the name also being void. Not sure what that "",newM113name]; is at the end is for, though.

Good show. So then vehicles with advanced functions through the addaction method can be created without all these messy addons. I like it. A lot.

Share this post


Link to post
Share on other sites

I gotta ask you something: what is naming a vehicle? biggrin.gif exactly

Share this post


Link to post
Share on other sites

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (OmniMax @ April 10 2003,12:39)</td></tr><tr><td id="QUOTE"></span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">b = b + 1

b = "m113" createVehicle getmarkerpos "Respawn_West"

b addaction ["20mm APC light mortar","apc_mortar.sqs"

goto "end"

#end

exit

<span id='postcolor'>if the beginning of the createvehicle command (b in this case) serves as the vehicle's object name, then I am, sir, a retard.<span id='postcolor'>

Here comes a late reply...

I'm pretty sure the 'b' part is the name of the created vehicle, at least it works like it. I use an _ infront though. Later in the script you can for exampel set its direction using the 'b' part.

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">_b = "M113" createVehicle getmarkerpos "Respawn_West"

_b setdir 180<span id='postcolor'>

Tested!

Share this post


Link to post
Share on other sites
Guest jacobaby

ineo, if you use an underscore in the name, you confine the name to the script, ie, you will not ba able to affect it in other scripts or triggers.

Naming things sequentially is just one part of the powerful FORMAT command, it is one WELL worht practising with.

TJ

Share this post


Link to post
Share on other sites

How do I translate;

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_vcl = _class createVehicle getpos _Location

into the above post mentioned form;

Quote[/b] ]call format ["%1 =""m113"" createVehicle getmarkerpos ""Respawn_West""",newM113Name];

Tried;

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_vcl = call format ["%1 = _class createVehicle getpos _Location","XX"]

the right type of vehicle is created at the location, has the "XX" name, but _vcl seems to be unassigned ........ sad_o.gif

eg I cant then use _vcl to change the vehicles location anymore.

Being used in a vehicle repawn script where I need to maintain the vehicles name ......

Share this post


Link to post
Share on other sites

If you need the local variable _vcl to refer to the last vehicle created, assuming the vehicles are created like bn880 shows above, you'd have to do a

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

....

call format ["%1 =""m113"" createVehicle getmarkerpos ""Respawn_West""",newM113Name];

call format ["_vcl = %1", newM113Name];

...

Now wether this combination of tricks is useful or even a good solution for your exact problem is another matter...

Share this post


Link to post
Share on other sites

Thanks Killswitch ... that didnt work but it pointed me in the right direction smile_o.gif

What worked was ....

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_vcl = call format["%1","XX"]

or to your example ...

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_vcl = call format ["%1", newM113Name]

THANKS !

Share this post


Link to post
Share on other sites

ARH Bugger ! sad_o.gif

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">.........

deleteVehicle _vcl

call format ["%1 = _class createVehicle getpos _Location", _vname]

Error: Reserved variable in expression sad_o.gifsad_o.gif

_vname was the NAME assigned to the original vehicle (like "West1")

Deleting the vehicle doesnt seem to "release" the variable .... hence ..... looks like I can't re-create (respawn) a vehicle with the same name.

Any ideas ? ........ how to release the "Reserved Variable" ?

Share this post


Link to post
Share on other sites
Gnat @ Feb. 03 2004,13:47)]ARH Bugger ! sad_o.gif

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">.........

deleteVehicle _vcl

call format ["%1 = _class createVehicle getpos _Location", _vname]

Error: Reserved variable in expression  sad_o.gifsad_o.gif

_vname was the NAME assigned to the original vehicle (like "West1")

Deleting the vehicle doesnt seem to "release" the variable .... hence ..... looks like I can't re-create (respawn) a vehicle with the same name.

Any ideas ? ........ how to release the "Reserved Variable" ?

Do not name vehicles on the map. The simplest way how to do it can be to create them in the start of misson.

If you name vehicle on map (in the editor) then vehicle name will be reserved variable. But if you name vehicle via format command then it will be standard variable that can change its content.

Share this post


Link to post
Share on other sites

ok ... now I'm a little confused .....

I'm naming vehicles because I need an set array of all vehicle names in the game so I can check if they are within a trigger zone.

This would not be an issue except these vehicles are respawning and thus loose their name.

How do I check if a player is within a respawned vehicle and within a zone ?

I also have to be able to identify the vehicle because I have to do a height above sea level check.

Respawn .... VR.sqs

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">?!(local Server): Goto "end"

_vcl = _this select 0

_Location = _this select 1

_azimut = _this select 2

_class = _this select 3

_vname = _this select 4

_respawndelay = 10

#start

~1

?(Alive _vcl):Goto "start"

~_respawndelay

_vcl setdammage 0.2

deleteVehicle _vcl

call format ["%1 = _class createVehicle getpos _Location", _vname]

_vcl = call format["%1", format ["%1",_vname]]

_vcl setdir _azimut

Goto "start"

Called in the INIT like;

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[this, r_1, 0, "A10","West1"] exec "VR.sqs"

Share this post


Link to post
Share on other sites

Name all vehicles by another way:

-do NOT give them names in editor

-make trigger that covers area with all vehicles you want to name (or place them inside trigger area)

-trigger: activated by anybody once present; name namer

-on activation field: [thislist] exec "namethem.sqs"

-namethem.sqs:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">~1

_array=+_this select 0

deletevehicle namer

_n=0

_i=count _array

#next

_i=_i-1

_x=_array select _i

?"man" counttype [_x] == 1 :goto "notvehicle"

_n=_n+1

call format["West%1=_x",_n]

#notvehicle

?_i>0:goto "next"

hintc format["%1 vehicles named",_n]

(tested in SP)

Then if you have 10 vehicles they will have names from West1 to West10. But keep in mind that vehicles will be named after 1 second - not at the beginnig of the mission. You do not know which name belongs to specific vehicle but you can use that names in arrays etc.

The simpliest way: name vehicles in their init line smile_o.gif

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">West1=this

---

You can use typeOf command in your VR.sqs:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[this, r_1, 0,"West1"] exec "VR.sqs"

VR.sqs:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_vcl = _this select 0

_Location = _this select 1

_azimut = _this select 2

_class = typeOf _vcl

...

Share this post


Link to post
Share on other sites

Thanks Bart.Jan ! smile_o.gif

That helped a lot ...... now have vehicles that keep there names.

I did notice that if you have a script looping and looking at named vehicle ..... if the vehicle dies, you have to terminate the script and recall it for the new spawned vehicle again, because even though it is the same name ..... the first script call "looses" the link to that name after the vehicle dies.

Muchly appreciated !

Share this post


Link to post
Share on other sites

I think you need to change the script slightly, from:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_array=+_this select 0

To:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_array=+(_this select 0)

Or change the trigger to:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[+thislist] exec "namethem.sqs"

But if you just want to add vehicles from the start you could add this to your init.sqs:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">VehiclesArray=[]

And in the init field of each vehicle put this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">VehiclesArray=VehiclesArray+[This]

Share this post


Link to post
Share on other sites
I think you need to change the script slightly, from:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_array=+_this select 0

To:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_array=+(_this select 0)

Or change the trigger to:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[+thislist] exec "namethem.sqs"

It's not necessary.

Gnat @ Feb. 04 2004,16:42)]I did notice that if you have a script looping and looking at named vehicle ..... if the vehicle dies, you have to terminate the script and recall it for the new spawned vehicle again, because even though it is the same name ..... the first script call "looses" the link to that name after the vehicle dies.

You can try to change end of VR.sqs to:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">...

_vcl setdir _azimut

[_vcl, _Location, _azimut, _class, _vname ] exec "VR.sqs"

exit

And then you don't need another script.

Share this post


Link to post
Share on other sites

Hmmm

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_array=+_this select 0

Just creates a copy of the array _this which is not the cause of Gnat loosing the link to dead vehicles. Remeber _this is just a local array of parameters passed to the script.

Any arrays contained within the _this (the actual info Gnat is interested in) do not get copied.

In other words it still points to ThisList in the trigger. So it gets updated every time the trigger does, hence loosing the dead vehicles, because triggers will filter out dead units.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_array=+(_this select 0)

Makes a copy of the content of ThisList so, when a vehicle gets destroyed he can just respawn the vehicle back into its original position in the array.

I would say, dont use a trigger just to get a list of vehicles at the start of a mission, its overkill no matter how you look at it.

Share this post


Link to post
Share on other sites
Hmmm

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_array=+_this select 0

Just creates a copy of the array _this which is not the cause of Gnat loosing the link to dead vehicles. Remeber _this is just a local array of parameters passed to the script.

Any arrays contained within the _this (the actual info Gnat is interested in) do not get copied.

In other words it still points to ThisList in the trigger. So it gets updated every time the trigger does, hence loosing the dead vehicles, because triggers will filter out dead units.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_array=+(_this select 0)

Makes a copy of the content of ThisList so, when a vehicle gets destroyed he can just respawn the vehicle back into its original position in the array.

I tested that script (with ..=+_this ...) and it works on my comuter. I'm playing v.1.96beta and it was working with 1.91 for sure in similar scripts I made before. (edit:It's working with v.1.91)

Try it too.

Or try this line in any radio trigger on activation field:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">a=[[1,2],["3","4"]];hint format["%1 %2\n%3 %4",+a select 0,+a select 1,a select 0,a select 1]

Quote[/b] ]I would say, dont use a trigger just to get a list of vehicles at the start of a mission, its overkill no matter how you look at it.

Advantage of that triiger is that there is no need for manual listing - you simply change (remove, add) vehicle and script does the rest. You can use various probabilities of vehicle presence easily with that.

Share this post


Link to post
Share on other sites

I tried it both ways, the way I originaly tested it. With this in the trigger:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">Temp1=+(ThisList)

Temp1 being a global variable, but it works the same passed to a script. This worked as expected with the dead units staying in the array indefinetly.

I then tried using parameters passed to a script as you suggested. So in the trigger I had:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[ThisList] Exec "Script.sqs"

And in Script.sqs I have this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Temp1=+_This Select 0

#Loop

Hint Format["List %1",_Temp1]

~1

goto "Loop"

After about 60 deconds the dead units start to disapear from the list, perhaps this delay is why your test appears to work?

I tested this with AI men and vehicles, I can send you the test mission if you want to try it for yourself.

Edit:

Another thing about triggers is, even though you set it to activate once the condition is checked every ~0.5 seconds.

Try adding this in the Condition field, to a trigger thats set to activate once:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">Call {Hint Format ["%1",Time]; This}

The probability of presence works the same for a units init field as it does with a trigger. If it does not showup in the game it will not be added to the array.

Share this post


Link to post
Share on other sites

Thanks guys ..... I wasnt using that bit of the posted examples biggrin_o.gif

FYI

"Air Score" script.

Stay in the air between a certain height above sea level and inside a trigger area to score points (ie CTF or C&H type)

In the Airborne vehicle INIT line.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">EV6=this; [this, s_5, 135, "EV6"] exec "VR.sqs"; ["EV6"] exec "Airscore.sqs"

Airscore.sqs

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">?!(local Server): Goto "Dend1"

_name = _this select 0

_unit = call format["%1",_name]

_sea_level = "emptyDetector" camCreate [0,0,0]

#loop

~1

?!(alive _unit):goto "Dend2"

?!(_unit in list HotZone): goto "loop"

~20

_sea_level setPos [(getPos _unit)select 0, (getPos _unit)select 1, 0]

unit_height_asl = (getpos _unit select 2) -(getpos _sea_level select 2)

?!((_unit in list HotZone) AND (unit_height_asl > 48) AND (unit_height_asl < 200)): goto "loop"

?!((side Driver _unit == west) OR (side Driver _unit == east)) : goto "loop"

?(side Driver _unit == west): WScore = WScore + 1

?(side Driver _unit == east): EScore = EScore + 1

titletext[format ["%1 Air Scored for the %2\n\nScore : NATO %3 - Soviet %4", name Driver _unit, side Driver _unit, WScore, EScore], "Plain down"]

goto "loop"

#Dend2

camDestroy _sea_level

#Dend1

exit

Vehicle Respawn script

In example "s_5" is a GameLogic located as your respawn point for that vehicle.

No my script, mod of someones elses.

VR.sqs

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">?!(local Server): Goto "end"

_vcl = _this select 0

_Location = _this select 1

_azimut = _this select 2

_class = typeOf _vcl

_vname = _this select 3

_respawndelay = 30

#start

~1

?(Alive _vcl):Goto "start"

~_respawndelay

_vcl setdammage 0.2

deleteVehicle _vcl

call format ["%1 = _class createVehicle getpos _Location", _vname]

_vcl = call format["%1", format ["%1",_vname]]

_vcl setpos[(getpos _Location select 0),(getpos _Location select 1),(getpos _Location select 2)+20]

_vcl setdir _azimut

[_vname] exec "Airscore.sqs"

Goto "start"

#end

Exit

Again .... Im no perfect coder .... but though others may be interested.

Cheers.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×