OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: Crowey on 10 Jan 2009, 21:55:57

Title: Attatch a marker to a unit?
Post by: Crowey on 10 Jan 2009, 21:55:57
Hi fellas how do I attatch a marker to a unit whitch can then be trces via the map screen?
Title: Re: Attatch a marker to a unit?
Post by: Tyger on 11 Jan 2009, 06:04:10
Execute the following script as
Code: [Select]
[unitName, "markerName"] spawn compile preprocessfile "setPosMarker.sqf";
where unitName is the name of your unit and markerName is the name of the marker you wish to  have follow the unit (make sure it is surrounded in quotes).


Code: [Select]
private["_unit","_marker"];
_unit = _this select 0;
_marker = _this select 1;

while {alive _unit} do {
_marker setMarkerPos (getPos _unit);
sleep 0.1;
};
Title: Re: Attatch a marker to a unit?
Post by: Crowey on 13 Jan 2009, 20:25:43
Cheers pal, but im a script noob just correct me where im slipping up mate.....
1) I copied and pasted this into a wodpad doc and saved as  "setPosMarker.sqf"
private["_unit","_marker"];
_unit = _this select 0;
_marker = _this select 1;

while {alive _unit} do {
_marker setMarkerPos (getPos _unit);
sleep 0.1;
};

2) Then I gave the script command in the "script" line of the units 1st waypoint ""[unitName, "markerName"] spawn compile preprocessfile "setPosMarker.sqf";

3) in stage two i changed the unit name accordingly and called the marker "TARGET"


I didnt alter any of the text in stage 1? should i have?
I cant get it to work this way please tell me what im doing wrong.... sorry to be a gimp, lol
Title: Re: Attatch a marker to a unit?
Post by: hoz on 13 Jan 2009, 21:23:05
Code: [Select]
""[unitName", "markerName"] spawn compile preprocessfile "setPosMarker.sqf";
unitName, markerName have to be a unit and a marker which you've named ahead of time.
Title: Re: Attatch a marker to a unit?
Post by: Gray on 14 Jan 2009, 23:49:23
Hi, would this work to attach a trigger to a unit in the same way? i mean so that the trigger would be like stuck to the unit as it moved around? :blink:

Basically iv got a squad on a zombie infested island with random civs spawned over the island. They are on their own and set to allowfleeing so they run away. At the moment i have triggers at set points that when i get there the civs join my team so i can arm them and beef up my team.

What i need is just a way to get them to join just by me running up to them and i can't seem to find anything on the subject  :(

Any help greatly appreciated thanks!
Title: Re: Attatch a marker to a unit?
Post by: bedges on 15 Jan 2009, 00:01:20
Welcome to OFPEC  :good:

Indeed yes, it would work in exactly the same way, although obviously the syntax would change slightly (setpos (http://www.ofpec.com/COMREF/index.php?action=details&id=313) rather than setmarkerpos). Remember to give the trigger a name in the editor too, so you can pass it to the script.

Once again welcome.
Title: Re: Attatch a marker to a unit?
Post by: Gray on 15 Jan 2009, 12:41:34
Hi Bedges, thanks for the superfast reply!. I did have a mess with trying to get this working last night but as i was dead tired (oh and i should have prolly mentioned i don't know what i'm doing cos i'm a nub :confused:) i failed bigtime.

Sorry to be a pain but could *anyone may insert their name here :D* kindly give instruction on what exactly i need to do to to be able to get a civilian to join my group just by me getting within a few feet of them (without me having to go to a set trigger on the map)

Thanks in advance...again  :D
Title: Re: Attatch a marker to a unit?
Post by: Tyger on 15 Jan 2009, 13:43:55
Create a script in your mission folder called triggerLink.sqf.
Code: (triggerLink.sqf) [Select]
private["_unit","_trigger"];
_unit = _this select 0;
_trigger = _this select 1;

while {alive _unit} do {
_trigger setPos (getPos _unit);
sleep 0.1;
};

If you have a trigger called TRIG_AREA_1, and unit called my_civ_1, then execute the script as such:
Code: [Select]
nil = [my_civ_1, TRIG_AREA_1] spawn compile preprocessFile "triggerLink.sqf"
Put the above code (with the appropriate unit names replaced) in your init.sqf or the like.

Hope that helps  ;)
Title: Re: Attatch a marker to a unit?
Post by: Spooner on 15 Jan 2009, 21:02:06
Oops, don't use nil = (yes, I've been guilty of using that in the past), since that actually overwrites the "constant" value of nil for the entire mission (yes, I can't believe it does, but there you have it!). Use nul = instead. Also, I can't tell people enough that preprocessFile has been replaced in ArmA by the much better preprocessFileLineNumbers
Code: [Select]
nul = [my_civ_1, TRIG_AREA_1] spawn compile preprocessFileLineNumbers "triggerLink.sqf"
Title: Re: Attatch a marker to a unit?
Post by: Tyger on 16 Jan 2009, 04:38:42
That's good to know! But don't you only use preprocessFileLineNumbers when you're debugging?
Title: Re: Attatch a marker to a unit?
Post by: Spooner on 16 Jan 2009, 07:35:11
Well, I've yet to see any code released that isn't considered to be "beta", so I'd say "debugging" is relevant at all times. When users give you vague reports of getting errors without being able to tell you where that error occurred, you'll wish you'd left it as lineNumbers.

The question, however, is what is the cost of that line-numbers information? Well, I imagine it would cost a trivial amount of extra CPU cycles to generate it, and anyway, you usually compile functions once at the start of a mission, so that extra time is pretty irrelevant (in-game FPS is what matters, not FPS at startup). The relevant side, however, is that the game will store a complete copy of all function code (well, comments will all be trimmed by the preprocessor) . However, even the most complex script suites would barely waste any memory (e.g. all the scripts I've written would not amount to more than a couple of megabytes) and would probably just get swapped out to disk anyway, since the stored copy of the script isn't actually used, except when errors occur.

Perhaps I overstated my original comment though. If you don't want to use preprocessFileLineNumbers because you think it might impact on the performance of the game (I personally don't think this will be significant), then that is fine, but most people seem to use preprocessFile because they want to avoid typing such a long command (and virtually noone knows what the lineNumbers feature actually does!).
Title: Re: Attatch a marker to a unit?
Post by: Tyger on 16 Jan 2009, 16:47:32
Hmm. Good point. I was just kind of thinking about it along the lines of how in the old days, a hint was inserted in order to output a variable or something of the sort in order to bug test. I suppose this isn't quite that verbose :D.
Title: Re: Attatch a marker to a unit?
Post by: Spooner on 17 Jan 2009, 19:06:53
Yeah, you are right, you'd not want debugging hints appearing in production code, but this just means that if you do get a serious arma error, you at least get the maximum info about it.