Jump to content
Sign in to follow this  
wedge123

Reall basic scriipt help needed

Recommended Posts

Hi all

sorry for the simplicity of this post but im dying with frustration trying to work out what stupid little mistake im making!

I have spawned a unit in via a script and am trying to use the waituntil command so when the unit dies my script comtinues...

I know...how basic...and again apologise. I may have made plenty of terrain in my time but never attempted scripting :-)

at the moment it looks something like this...

_grptank = [getMarkerPos "tankspawn", 0, "O_MBT_02_cannon_F", EAST] call BIS_fnc_spawnVehicle; 
createVehicleCrew (_grptank select 0);
waituntil {!(alive _grptank)};

["task1", "Succeeded"] call BIS_fnc_taskSetState;

sleep 3;

Player sidechat "Well Done team, Mission Complete";
Player sidechat "Return To Base";
hint "Mission Complete - Return to the Captain to debrief";

It gives me an error {!#(alive _grptank)}.

Any help greatly appreciated

All the best

Wedge

ps. feel free to point out anythin else wrong i have done:-)

Share this post


Link to post
Share on other sites

the "_grpTank" variable is not a unit, but is an array. Therefore calling (!alive _grpTank) will produce syntax error.

[] call BIS_fnc_spawnVehicle returns the following:

Array:

0: new vehicle (Object).

1: all crew (Array of Objects).

2: vehicle's group (Group).

to check if the tank (and not the crew) are alive use: waitUntil{!(alive (_grpTank select 0))};

Regards,

Bull

Share this post


Link to post
Share on other sites

BIS_fnc_spawnVehicle returns an array, not just the new vehicle, so:

_grptank select 0

Returns the vehicle itself.

Share this post


Link to post
Share on other sites
Hi all

sorry for the simplicity of this post but im dying with frustration trying to work out what stupid little mistake im making!

I have spawned a unit in via a script and am trying to use the waituntil command so when the unit dies my script comtinues...

I know...how basic...and again apologise. I may have made plenty of terrain in my time but never attempted scripting :-)

at the moment it looks something like this...

_grptank = [getMarkerPos "tankspawn", 0, "O_MBT_02_cannon_F", EAST] call BIS_fnc_spawnVehicle; 
createVehicleCrew (_grptank select 0);
waituntil {!(alive _grptank)};

["task1", "Succeeded"] call BIS_fnc_taskSetState;

sleep 3;

Player sidechat "Well Done team, Mission Complete";
Player sidechat "Return To Base";
hint "Mission Complete - Return to the Captain to debrief";

It gives me an error {!#(alive _grptank)}.

Any help greatly appreciated

All the best

Wedge

ps. feel free to point out anythin else wrong i have done:-)

Hi Wedge,

I use a similar command on my missions, I will send you soon as i can.

Edited by M4RT14L

Share this post


Link to post
Share on other sites

w

Hi Wedge,

replace,

waituntil {!(alive _grptank)};

by,

waituntil { !alive _grptank };

Parenthesis are good practice and make no difference here.

Share this post


Link to post
Share on other sites
w

Parenthesis are good practice and make no difference here.

Totally, did not see the error confusing array variable with name of the unit,:) sorry.

Share this post


Link to post
Share on other sites

Thank you chaps, much appreciated. Will give it a shot in a bit

Although I do have another question .....

Is it the possible to include the crew within the original bis_fnc_spawnvehicle...... Instead of createVehicleCrew (_grptank select 0);?

Thanks again

Share this post


Link to post
Share on other sites

Vehicles spawned by call BIS_fnc_SpawnVehicle function have all their crew.

Share this post


Link to post
Share on other sites

I believe the BIS function spawns a crew as well and to access that info it's:

_grptank select 1

Share this post


Link to post
Share on other sites

Hmmmm that's interesting!

When I originally tried it with just the bis function the tank wasn't running idle and no one ever seemed to get out of the tank when I blew the crap out of it.

Hence why I added the extra line, the minute I did its engine was idling and crew got out when the tank was damaged.

Il have another look later. Thanks again for your quick responses.

On a side note I wish there were more useful examples in the wiki, don't get me wrong the knowledge there is indispensable and we are lucky to have it as a resource .... I just feel that if things were explained as you guys have above my learning curve would be tripled ..... Not a rant , just my 2p :-)

Share this post


Link to post
Share on other sites

I can agree that there is a lack of examples, however, it does tell you it's return, and in this case it's an array, so you had to have basic array knowledge to be able to access the returned information.

Share this post


Link to post
Share on other sites

Hi Wedge as I promised,

_grptank = createGroup EAST;
[getMarkerPos "tankspawn", 0, "O_MBT_02_cannon_F", _grptank] call BIS_fnc_spawnvehicle;

This creates the vehicle and and assigns it to a group called "_grptank",

to check the target

waitUntil {{ alive _x } count units _grptank == 0};

however, the script keeps running only when all tank crew is dead, regardless of whether is tank destroyed or not.

second choice,

_tank = createVehicle ["O_MBT_02_cannon_F",  getMarkerPos "tankspawn", [], 0, "NONE"];

This creates EMPTY vehicle,

_armor = createGroup EAST;
_crew1 = _armor createUnit ["O_crew_F", [0,0,1], [], 0, "CAN_COLLIDE"];
_crew1 moveInCommander _tank;
_crew2 = _armor createUnit ["O_crew_F", [0,0,1], [], 0, "CAN_COLLIDE"];
_crew2 moveInGunner _tank;
_crew3 = _armor createUnit ["O_crew_F", [0,0,1], [], 0, "CAN_COLLIDE"];
_crew3 moveInDriver _tank;

With this the crew for this tank,

waitUntil { !alive _tank };

And the condition, in this way the script continues when the vehicle is destroyed regardless of crew.

Hope this helps.

Share this post


Link to post
Share on other sites

Again...

BIS_fnc_spawnVehicle returns an array:

0- Is the vehicle itself

1- The crew in the vehicle

2- The group of the vehicle

So...

_tank = [(getMarkerPos "tankspawn"), 0, "O_MBT_02_cannon_F", EAST] call BIS_fnc_spawnVehicle;

waitUntil {!alive (_tank select 0)};
//Will check for the vehicle to be dead

waitUntil {{alive _x} count (_tank select 1) isEqualTo 0};
//Will check for the crew to be dead, and only the crew

waitUntil {(!alive (_tank select 0)) && ({alive _x} count (_tank select 1) isEqualTo 0)};
//Will check for both the vehicle and the crew to be dead

waitUntil {(!alive (_tank select 0)) || ({alive _x} count (_tank select 1) isEqualTo 0)};
//Will check for either the vehicle to be dead or the crew

EDIT: Sorry, forgot you edited your first post in this thread saying you were going to share your code that you use, it was not my intention to undermine you in any way, but I have now provided some other examples of how the returned array can be accessed and used :p.

Edited by JShock

Share this post


Link to post
Share on other sites

Chaps, Thank you very much for this info and great examples.

I am guessing that they all produce pretty much the same results and that no one way is technically better than another?

or does one function quicker/better than the other? i am asking this purely for my future knowledge .....

ok i have another request for assistance.

To change it up every time we play the mission i wanted to spawn the tank in one of , maybe, 4 random locations.

Im not asking anyone to write this for me just maybe give me some pointers? i will have a go at this myself now and post up what i come up with (which im sure will be laughable) :-)

Again your help is always appreciated

Wedge

---------- Post added at 10:53 ---------- Previous post was at 10:07 ----------

Ok so i have done this so far

_tankspawnrnd = floor(random 4);
_tankspawnarray = ["tankspawn1","tankspawn2","tankspawn3","tankspawn4"];Hint format ["%1 ",_tankspawnarray select _tankspawnrnd];
_tank = [(getMarkerPos "??_tankspawnarray??"), 0, "O_MBT_02_cannon_F", EAST] call BIS_fnc_spawnVehicle;

so this returns a random hint for my array and works fine

I cannot seem to work out the correct way to implement it into the spawn vehicle fnc

Edited by wedge123

Share this post


Link to post
Share on other sites

This should work,

First place four markers called "tankspawn" from 1 to 4,

_markerArray = ["tankspawn1","tankspawn2","tankspawn3","tankspawn4"];
_rnd 	= floor (random (count(_markerArray)));
_mrkSpawnTank = getMarkerPos (_markerArray select _rnd);

Now the code for spawn the vehicle,

_tank = [_mrkSpawnTank, 0, "O_MBT_02_cannon_F", EAST] call BIS_fnc_spawnVehicle;

Try it,

Share this post


Link to post
Share on other sites

ok thanks

I actually just got it working using this....

_tankspawnarray = ["tankspawn1","tankspawn2","tankspawn3","tankspawn4"];
_tankspawnpos = getmarkerpos (_tankspawnarray select floor (random (count _tankspawnarray)));
_tank = [_tankspawnpos, 0, "O_MBT_02_cannon_F", EAST] call BIS_fnc_spawnVehicle;

Similar but seems to work okay.Would there be a preferance using yours?

Wedge

Share this post


Link to post
Share on other sites

Use your code, the main preferance is you did work:).

besides is practically the same.

Share this post


Link to post
Share on other sites

You could also use BIS_fnc_selectRandom:

_randomMarker = ["mrk1","mrk2","mrk3","mrk4"] call BIS_fnc_selectRandom;
_tank = [getMarkerPos _randomMarker....] call BIS_fnc_spawnVehicle;

Share this post


Link to post
Share on other sites
You could also use BIS_fnc_selectRandom:

_randomMarker = ["mrk1","mrk2","mrk3","mrk4"] call BIS_fnc_selectRandom;
_tank = [getMarkerPos _randomMarker....] call BIS_fnc_spawnVehicle;

Yeah that's a good shout I may do that for consistency.

Il try it when I get home.

Thanks again for everyone's help

Share this post


Link to post
Share on other sites

And to quickly answer your initial question in post #15, the fewer lines of code the faster the code is.

Share this post


Link to post
Share on other sites

Slightly different question.....

Does anyone have any up to date info regarding the BIS_fnc_MP function and using it with the BIS_fnc_TaskCreate function?

What i mean by this is does it work?

The mission i have been working on as the subject of this thread all came to a crashing halt when hosted with other players. I have found info on here but just wondered if someone can clarify that it works before i waste untold hours trying to get t work :-) .

Thanks

Share this post


Link to post
Share on other sites

I currently have it setup like this

sleep 1;

[ 
player, // Units
       "task1", // Unique task id 
  [ 
      "An enemy tank has been spotted moving into <marker name = marker1> This Town </marker>.Find and eliminate this Armoured threat", // Description 
      "Eliminate Enemy Armour", // Actual title 
      "Eliminate Armour" // GUI title (waypoint marker text) 
  ],  

  (getmarkerpos _selakano), // Task position 
  true // Set as current task?? 

] call BIS_fnc_taskCreate; 
["task1", "Assigned"] call BIS_fnc_taskSetState;
sleep 3;


waitUntil {!alive (_tank select 0)};

["task1", "Succeeded"] call BIS_fnc_taskSetState;

sleep 3;

So this worked perfectly for whoever was running the server but would not start the tasks for any other player so tried this....

sleep 1;

[ 
player, // Units
       "task1", // Unique task id 
  [ 
      "An enemy tank has been spotted moving into <marker name = marker1> This Town </marker>.Find and eliminate this Armoured threat", // Description 
      "Eliminate Enemy Armour", // Actual title 
      "Eliminate Armour" // GUI title (waypoint marker text) 
  ],  

  (getmarkerpos _selakano), // Task position 
  true // Set as current task

] call BIS_fnc_taskCreate; 
[["task1", "created"],"BIS_fnc_taskSetState", true, true] call BIS_fnc_MP; 
sleep 2;
["task1", "Assigned"] call BIS_fnc_taskSetState;
[["task1", "Assigned"],"BIS_fnc_taskSetState", true, true] call BIS_fnc_MP; 

But still no joy....

Can you shed any light?

Edit....

Is it anything to do with the fact ive used Player as the unit???

Edited by wedge123

Share this post


Link to post
Share on other sites

You would need to use BIS_fnc_MP on the BIS_fnc_taskCreate as well, because the created task isn't broadcasted so broadcasting just the change of the task state doesn't do anything because the task itself hasn't been broadcasted, leaving "task1" in a way, undefined when the state of the task is broadcasted. (Confusing I'm sure, could probably be worded better :p)

EDIT: Saw your edit, it could be that as well, if this script is being executed on every client "player" will only work for the local machine it was executed on.

Edited by JShock

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  

×