Jump to content
Sign in to follow this  
G4meM0ment

Vehicle respawn - scripted coop mission

Recommended Posts

Hi guys,

I need to say first that I do scripting often an skilled (a bit) with java. I just wanted to say that before you're gonna tell me to start with easy stuff and not the best stuff like domination similar things.

I just started to script in ArmA so I have no idea of tis API the docu is not a big help with this, and tutorials are bad and rare...

My first question is how you would create an timer which counts down (for example 5 minutes) until a vehicle respawns.

I know how to use scripts and spawn vehicles and so on but I have no idea how to "save" the current time negate it with the after 5 minutes and create an condition which checks if 5 minutes are over after the vehicle has been destroyed.

One more problem I have is, how do I name a vehicle if I spawn it via script, and always the same?

Is there any kind of startup listener which executes scripts on startup?

And at last is there anyway to save variables in a file?

Thank you very much for your help, sorry if my english is confusing :P

Julian

Share this post


Link to post
Share on other sites

Add this to the init line of the vehicle.

handle = this addEventHandler ["HandleDamage", {[_this] execVM "vehDmgEH.sqf";}];

Then in the "vehDmgEH.sqf" put.

private["_vcl","_type","_newVeh"];
_vcl = _this;
if (!alive _vcl) then
{
_type = typeOf _vcl;
deleteVehicle _vcl;
sleep 300; //5 mins
_newVeh = _type createVehicle (getMarkerPos "vehrespawn_marker");
};

For your second question, use a handler when you create the vehicle. Like.

vehicle1 = "classname" createVehicle (getPos somepos);

For your 3rd question, I think you're thinking of the init.sqf

For the 4th, if you mean save variables for after like a server restart or actually write text to a document, no. You can save variables after a server restart if you use MySQL, which is fairly complicated.

Share this post


Link to post
Share on other sites
Add this to the init line of the vehicle.

handle = this addEventHandler ["HandleDamage", {[_this] execVM "vehDmgEH.sqf";}];

Then in the "vehDmgEH.sqf" put.

private["_vcl","_type","_newVeh"];
_vcl = _this;
if (!alive _vcl) then
{
_type = typeOf _vcl;
deleteVehicle _vcl;
sleep 300; //5 mins
_newVeh = _type createVehicle (getMarkerPos "vehrespawn_marker");
};

For your second question, use a handler when you create the vehicle. Like.

vehicle1 = "classname" createVehicle (getPos somepos);

For your 3rd question, I think you're thinking of the init.sqf

For the 4th, if you mean save variables for after like a server restart or actually write text to a document, no. You can save variables after a server restart if you use MySQL, which is fairly complicated.

Thank you thats great :D

Does you mean the init.sqf for the 'init line of the vehicle'?

And how do I make the respawn Marker variable, for example name always the marker like the vehicle and do something like _vcl getName or is that an String?

EDIT: Or would thzat cause an duplicate variable? Maybe that could be fixed by adding an suffix but I dont know how to do that in arma scripts for example "getMarkerPos _vcl + "_pos"".

And how do I make markers invisible or can I use other stuff to to mark positions, I already read about making final positions.

Edited by G4meM0ment

Share this post


Link to post
Share on other sites

init.sqf is a text file you create in the mission folder. It's contents are run when you connect to the mission.

Share this post


Link to post
Share on other sites
init.sqf is a text file you create in the mission folder. It's contents are run when you connect to the mission.

Also in multiplayer if anyone join the game?

And whats the init line of the vehicle, where I spawn it? Or in the editor anywhere?

Edited by G4meM0ment

Share this post


Link to post
Share on other sites
Also in multiplayer if anyone join the game?

Yes

And whats the init line of the vehicle, where I spawn it? Or in the editor anywhere?

In the editor. Double click on the vehicle and look for the Initialization: text box.

Share this post


Link to post
Share on other sites
Yes

In the editor. Double click on the vehicle and look for the Initialization: text box.

Already foudn thank you!

I've another problem may you know that line here:

waitUntil{!(isNil "BIS_fnc_init")};

[str ("Das Entscheidet sich mit der Zeit") , str ("Armeestützpunkt "Zargabad" - 18:00 Uhr")] spawn BIS_fnc_infoText;

this is in my init.sqf normaly i think it should display an text on mission start/player join. But it simply not executes. In another mission i needed to execute the init.sqf (convoy defend script) I thought it would execute automaticially... ?

@Horner

Sorry but your script don't works :/ I put the handle = this addEventHandler ["HandleDamage", {[_this] execVM "vehDmgEH.sqf";}]; in the vehicle init line in the editor and created an vehDmgEH.sqf I first wanted to have it in another directory (Scripts/Vehicles) but I didn't do it I thought it could cause bugs. After that I created an marker and named it like the vehicle (which already created in the editor) and at the same place. I set the sleep time to 20 (I didn't wanted to wait 5 min everytime) and destroyed the vehicle while playing coop with a friend... but 1. it was really titanium ^^ so I couldn't destroy it well and if it exploded finally it did not respawn....

Share this post


Link to post
Share on other sites

Sorry, Change the script to this.

private["_vcl","_type","_newVeh","_handled"];
_vcl = _this;
if (!alive _vcl) then
{
_type = typeOf _vcl;
deleteVehicle _vcl;
       []spawn
       {
        sleep 300;
        _newVeh = _type createVehicle (getMarkerPos "vehrespawn_marker");
       };
       _handled = true;
} else {
       _handled = false;
};

_handled

Forgot EH's have to return something. Silly me.

Edited by Horner
damn semicolons ;)

Share this post


Link to post
Share on other sites
Sorry, Change the script to this.

private["_vcl","_type","_newVeh","_handled"];
_vcl = _this;
if (!alive _vcl) then
{
_type = typeOf _vcl;
deleteVehicle _vcl;
       []spawn
       {
        sleep 300;
        _newVeh = _type createVehicle (getMarkerPos "vehrespawn_marker");
       };
       _handled = true;
} else {
       _handled = false;
};

_handled

Forgot EH's have to return something. Silly me.

Thank you, ill tell if it worked, another question - variable markers - is that _vcl an String? So if I would name the marker the same as the vehicle I could use (getMarkerPos _vcl) and I only need one script all vehicles with the same spawn time.

EDIT: I just tested your script now... it didn't work :(

The wrack of the vehicle won't despawn and there is no vehicle respawning... is the init line right, I have no clue of the api so does the "handle" won't need an "_"?

EDIT 2: Aren't the sleep int's miliseconds?! So it would be 300000 .... but it also dont works :/ and the vehicles are nearly undestroyable. (Tank, SMAW shoot at an AH-6Z won't kill it ?!)

EDIT 3: The error is located at the "if(!alive _vcl)" it says alive needs an object, so i think the "_vcl = _this;" don't works...

Edited by G4meM0ment

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  

×