OFPEC Forum
Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting Multiplayer => Topic started by: Knight Trane on 30 Mar 2009, 19:10:29
-
Ok,
Trying to write a script that uses "call compile format". This is how I setup my array:
flagcarrier = rng
array = [];
array = array + ["objName",xdist1,ydist1,tnDir,"laneNumber",xdist2,ydist2,lnDir,];
{
call compile format [%1 = "Land_strelecky_post_new" createVehicle [(rng select 0)+ %2,(rng select 1)+%3,0],_x select 0,_x select 1,_x select 2];];
)foreach array;
I'm trying to construct a range by use of an "addaction" on flagcarrier. The reason I'm scripting it is , one to learn how, and two, allow different types of ranges at the same location without overlap.
My question is about using the
[(rng select 0)+ %2,(rng select 1)+%3,0]
to calculate the x and y position off of rng to place my targets.
This is all for multiplayer so I left off the _in the variable names.
I'm sure I'm not using the "" properly, but I'll figure that out. It's the structure I'm having trouble with.
Any help would be appriciated.
KT,
-
%1 = "Land_strelecky_post_new" createVehicle [(rng select 0)+ %2,(rng select 1)+%3,0]
Has to be one string, so it should be:
'%1 = "Land_strelecky_post_new" createVehicle [(rng select 0)+ %2,(rng select 1)+%3,0]'
And the underscore doesn't depend on mp or not!
Btw: What is your question?
-
I'll rephrase it.
obj1 = getPos flagcarrier;
If I want to place an object 5m to the East right and 100m North of obj1, do I write
object2 = "Land_strelecky_post_new" createVehicle [(obj1 select 0)+ 5,(object1 select 1)+100,0]
I'm a little confused on how to write the expression. ie how and when to use [] and ().
-
When to use () with arrays.
array = [player, man2]
data = damage array select 0;
<should be>
array = [player, man2]
data = damage (array select 0);
Otherwise the interpreter would try and retrieve the damage of: [player, man2], and then failing that, it would try to select 0 of the return value... very messy. :D
-
Ok,
--Edited 05:07 31 Mar 09
start=getPos _flagcarrier
array=[]
array=array+[player,man2,5,100];
{
call compile format ['%1 = "What_ever" createVehicle [(start select 0) + %2,(start select 1)+%3,0]', _x select 1, _x select 2, _x select 3];
}foreach array;
So this should create an object ("What_ever"), named "man2", 5m to the East, and 100m North of my object _flagcarrier.
What if element 3 of array was -5? Would it be read as (start select 0)+(-5)? Putting my object 5m to the West, or would I have to adjust it something else. I read somewhere that the engine didn't see the "-" sign, but I see it all over in scripts. Confusing.
KT
-
You got the createVehicle syntax wrong.
It's supposed to be:
name = type createVehicle position.
Also format for the compile is wrong.
_x select 1 would return man2
_x select 2 would return 5
_x select 3 would return 100
-
Oops! Thanks,
I should have some coffee before I post. "man2" is the name(variable) I'm creating. "player" has nothing to do with this example, except as an element I could use in another call later in the script.
What if element 3 of array was -5? Would it be read as (start select 0)+(-5)? Putting my object 5m to the West, or would I have to adjust it something else?
--Edit
Well I'm getting errors on it as is. I'll do some testing and post the actual script when I get home.
--Edit: Today at 06:54:53 PM
Ok, this is what I got:
rngpos = getpos sb1;
/* Create range array krr_array
krr_array = [];
krr_array = krr_array + ["TargetName",xm left/right,ym out from shooting blok,"Lane",Lnpos xm left/right of sb1,Lnpos ym from sb1,Dir lane];*/
krr_array = [];
krr_array = krr_array + ["krt111",-10,100,180,"krln1",0,10,0];
krr_array = krr_array + ["krt112",10,100,180,"krrln1",0,10,0];
krr_array = krr_array + ["krt121",-15,150,180,"krrln1",0,10,0];
krr_array = krr_array + ["krt122",0,150,180,"krrln1",0,10,0];
krr_array = krr_array + ["krt123",15,150,180,"krrln1",0,10,0];
krr_array = krr_array + ["krt131",-15,200,180,"krrln1",0,10,0];
krr_array = krr_array + ["krt132",0,200,180,"krrln1",0,10,0];
krr_array = krr_array + ["krt133",15,200,180,"krrln1",0,10,0];
krr_array = krr_array + ["krt141",-15,250,180,"krrln1",0,10,0];
krr_array = krr_array + ["krt142",-7,250,180,"krrln1",0,10,0];
krr_array = krr_array + ["krt143",7,250,180,"krrln1",0,10,0];
krr_array = krr_array + ["krt144",15,250,180,"krrln1",0,10,0];
krr_array = krr_array + ["krt151",-15,300,180,"krrln1",0,10,0];
krr_array = krr_array + ["krt152",-7,300,180,"krrln1",0,10,0];
krr_array = krr_array + ["krt153",7,300,180,"krrln1",0,10,0];
krr_array = krr_array + ["krt154",15,300,180,"krrln1",0,10,0];
krr_array = krr_array + ["krt161",-15,350,180,"krrln1",0,10,0];
krr_array = krr_array + ["krt162",-7,350,180,"krrln1",0,10,0];
krr_array = krr_array + ["krt163",7,350,180,"krrln1",0,10,0];
krr_array = krr_array + ["krt164",15,350,180,"krrln1",0,10,0];
{
call compile format['%1 = "Land_strelecky_post_new" createVehicle [(rngPos select 0) + %2,(rngPos select 1) + %3,0];',_x select 4,_x select 5,_x select 6];
} foreach krr_array;
krr_array
The error I get is:
...%2,(rngPos select 1) + %3,0];',_x# select 4,_x select 5,_x select 6];
error typed string, expected array config entry
-
Well, the problem is your array.
What you currently get is this:
["krt111",-10,100,180,"krln1",0,10,0,krt112",10,100,180,"krrln1",0,10,0, ...];
I believe you want to achieve this:
[["krt111",-10,100,180,"krln1",0,10,0], ["krt112",10,100,180,"krrln1",0,10,0], ...];
If so just add an extra set of squared brackets to the values added into the array:
krr_array = [];
krr_array = krr_array + [["krt111",-10,100,180,"krln1",0,10,0]];
That should do the trick.
Oh, one more thing: createVehicle doesn't create the object precisely on the given coordinates.
To get the object on the exact spot simply setPos it after creating it.