twirly 11 Posted July 6, 2011 (edited) Here's another SP Respawn that's also easy to use. Demo here or the scripts alone here. You can respawn into a playable random AI unit or as yourself (new unit) at a marker. You will also be shown by camera who your killer was (if any) and then the camera will move to your new unit. It's code I put in another thread that I thought some of you might might find usefull in your SP missions. It consists of two scripts:- onPlayerKilled.sqf and playerKilled.sqf. Create a file named onPlayerKilled.sqf in your mission folder. If you want to respawn as a random playable AI.... put this code in the file. private ["_plyr","_kilr"]; _plyr = _this select 0; _kilr = _this select 1; nul = [_plyr,_kilr] execVM "playerKilled.sqf"; If you want to respawn as yourself (same type of soldier) at a marker... then put this code in the file. Where "markername" is the name of your marker. private ["_plyr","_kilr"]; _plyr = _this select 0; _kilr = _this select 1; nul = [_plyr,_kilr,[b]"markername"[/b]] execVM "playerKilled.sqf"; Then create the second script playerKilled.sqf also in your mission folder. Add this code to the file. /* A script for SP Respawn. By Twirly - 6th July 2011 */ private ["_plyr","_kilr","_mrkr","_type","_group","_dist","_camera","_found","_unit"]; _plyr = _this select 0; _kilr = _this select 1; _mrkr = if (count _this >2) then {_this select 2}; //grab some stuff we need later _type = typeOf _plyr; _group = group _plyr; _dist = _plyr distance _kilr; //camera initialisation _camera = "camera" camCreate getpos _plyr; _camera cameraEffect ["internal","back"]; //camera look at player _camera camSetTarget vehicle _plyr; _camera camSetRelPos [0.2,0.4,2]; _camera camSetFOV 0.143; _camera camCommit 0; waituntil {(camCommitted _camera)}; //camera zooms out over 5 seconds _camera camSetRelPos [0,8,3.5]; _camera camSetFOV 0.7; _camera camCommit 5; waituntil {(camCommitted _camera)}; if (not (isNull _kilr)) then { titleText [format ["Player killed by %1 at %2m",name _kilr,round _dist],"plain down"]; } else { titleText ["Player killed by UNKNOWN","plain down"]; }; //hide and delete the body hideBody _plyr; sleep 3; deleteVehicle _plyr; //check if killer exists.... skip if killed by artillery, bomb, unknown etc... if (not (isNull _kilr)) then { //camera move to killer _camera camSetTarget vehicle _kilr; _camera camSetRelPos [2,5,2]; if (_dist > 500) then {_camera camCommit 10} else {_camera camCommit 5}; waituntil {(camCommitted _camera)}; }; _found = false; if (count _this > 2) then { //if (not (isNil _mrkr)) then { //create the new unit.... same group _unit = _group createUnit [_type, (getMarkerPos _mrkr), [], 0, "NONE"]; addSwitchableUnit _unit; selectPlayer _unit; waitUntil {_unit == player}; _found = true; } else { //try to find a random playable unit while {(not (_found)) and ((count switchableunits) >=1)} do { _unit = switchableunits select (floor (random (count switchableunits))); if (alive _unit) then { _found = true; selectplayer _unit; }; sleep 1; }; }; //if no available units for respawn then end game if (not (_found)) exitWith { titleText ["No units available for respawn!","plain down"]; sleep 2; enableEndDialog; }; sleep 3; //check if killer exists.... skip if killed by artillery, bomb, unknown etc... if (not (isNull _kilr)) then { //camera move to new dude _camera camSetTarget vehicle _unit; _camera camSetRelPos [2,5,2]; if (_kilr distance _unit > 500) then {_camera camCommit 10} else {_camera camCommit 5}; waituntil {(camCommitted _camera)}; }; sleep 2; //quick fade-in on internal point of view of the next unit _camera camSetTarget _unit; vehicle _unit switchCamera "INTERNAL"; _unit cameraEffect ["terminate","back"]; //fade from black 3 seconds titlecut [" ","black in",3]; camDestroy _camera; [b]//run any initialization scripts for the player here //custom loadout, healing etc...[/b] //nul = [] execVM "blahblahblah.sqf"; The scripts can be downloaded here and a demo mission here. EDIT: Scripts and Demo mission updated. 12th July. Two new variables added. Download the new Demo or scripts and read the commented portion at the top of the script for instructions. Edited July 12, 2011 by twirly Clarity and updated links Share this post Link to post Share on other sites
katipo66 94 Posted July 6, 2011 (edited) When it rains it pours? Not sure if I got that right! Cheers man sounds good! Try it out later.. Edit* Links broken - "Invalid or Deleted File." Edited July 6, 2011 by Katipo66 Share this post Link to post Share on other sites
twirly 11 Posted July 6, 2011 Links broken - "Invalid or Deleted File." I forgot I had links top and bottom of the post. Thanks for heads up. All links should work now. Hope so! :) Share this post Link to post Share on other sites
katipo66 94 Posted July 6, 2011 Hey bro, i played your demo... very cool, nice work :D Share this post Link to post Share on other sites
katipo66 94 Posted July 11, 2011 So i been using this a lot, what do you think about when the camera moves back to the respawned player that it kind off slows down swings around the back and then into the player if you get what i mean? kinda like a wide handbrake 360!? Share this post Link to post Share on other sites
twirly 11 Posted July 11, 2011 Glad you like it man. I'll fiddle as soon as I have time and see what I can do to improve the camera movement. Share this post Link to post Share on other sites
twirly 11 Posted July 12, 2011 @Katipo66.... I updated the scripts and demo in the original poste mate. Or just copy and paste the stuff in the spoiler into your "playerKilled.sqf" It probably does not do exactly what you want.... but you can fiddle with the camera positions and see what you can come up with. It also should be re-written at this stage.....but it works and where it is used (when the player is dead!) it is not critical that it be efficient streamlined code. /* A script for SP Respawn. By Twirly - 6th July 2011 Version 1.1 Last updated 12th July 2011. Execute this script from OnPlayerKilled.sqs or OnPlayerKilled.sqf which must exist in your mission folder. Here is the code for OnPlayerKilled.sqf private ["_plyr","_kilr"]; _plyr = _this select 0; _kilr = _this select 1; //Optional camera control. If true camera will pan...if false camera will move instantly and fade from black. //If these variables aren't set somewhere. They will be created with default values of TRUE TWIRL_DeathCamMoveToKiller = false; TWIRL_DeathCamMoveToNewUnit = false; //If you want to respawn at a marker...call the script like this... nul = [_plyr,_kilr,"wrespawn0"] execVM "playerKilled.sqf"; //If you want to respawn as a playable AI...call the script like this... //nul = [_plyr,_kilr] execVM "playerKilled.sqf"; Should be easy enough to follow. It's well commented. */ private ["_plyr","_kilr","_type","_group","_dist","_camera","_found","_rand","_unit"]; _plyr = _this select 0; _kilr = _this select 1; _mrkr = if (count _this >2) then {_this select 2}; if (isNil "_kilr") then {_kilr = objNull}; //if these variables are not set...set them if (isNil "TWIRL_DeathCamMoveToKiller") then {TWIRL_DeathCamMoveToKiller = true}; if (isNil "TWIRL_DeathCamMoveToNewUnit") then {TWIRL_DeathCamMoveToNewUnit = true}; //grab some stuff we need later _type = typeOf _plyr; _group = group _plyr; _dist = _plyr distance _kilr; //camera initialisation _camera = "camera" camCreate getpos _plyr; _camera cameraEffect ["internal","back"]; //camera look at player _camera camSetTarget vehicle _plyr; _camera camSetRelPos [0.2,0.4,2]; _camera camSetFOV 0.143; _camera camCommit 0; waituntil {(camCommitted _camera)}; //camera zooms out over 5 seconds _camera camSetRelPos [0,8,3.5]; _camera camSetFOV 0.7; _camera camCommit 5; waituntil {(camCommitted _camera)}; //hide and delete the body hideBody _plyr; sleep 3; deleteVehicle _plyr; if (not (isNull _kilr)) then { titleText [format ["Player killed by %1 at %2m",name _kilr,round _dist],"plain down"]; } else { titleText ["Player killed by UNKNOWN","plain down"]; }; sleep 2; //check if killer exists.... skip if killed by artillery, bomb, unknown etc... if (not (isNull _kilr)) then { //camera move to killer _camera camSetTarget vehicle _kilr; _camera camSetRelPos [2,5,2]; if (TWIRL_DeathCamMoveToKiller) then { if (_dist > 500) then {_camera camCommit 10} else {_camera camCommit 5}; } else { //titlecut [" ","black out",1]; _camera camCommit 0; //fade from black 5 seconds titlecut ["","black in",5]; }; waituntil {(camCommitted _camera)}; }; _found = false; if (count _this > 2) then { //if (not (isNil _mrkr)) then { //create the new unit.... same group _unit = _group createUnit [_type, (getMarkerPos _mrkr), [], 0, "NONE"]; addSwitchableUnit _unit; _unit setUnitPos "DOWN"; sleep 2; selectPlayer _unit; _found = true; //titleText [format ["Switching to new player - %1",name player],"plain down"]; } else { //try to find a random playable unit while {(not (_found)) and ((count switchableunits) >=1)} do { _unit = switchableunits select (floor (random (count switchableunits))); if (alive _unit) then { //if unit is not in a vehicle then make him go prone if (vehicle _unit == _unit) then {_unit setUnitPos "DOWN"}; sleep 2; //need time for unit get down selectplayer _unit; //make the unit the player _found = true; //stop looping }; sleep 0.01; }; }; //if no available units for respawn then end game if (not (_found)) exitWith { titleText ["No units available for respawn!","plain down"]; sleep 2; enableEndDialog; }; sleep 4; titleText [format ["Switching to new player - %1",name _unit],"plain down"]; //camera move to new dude _camera camSetTarget vehicle _unit; _camera camSetRelPos [2,5,2]; //if distance is greater then 500m then take longer to move the camera if (TWIRL_DeathCamMoveToNewUnit) then { if (_kilr distance _unit > 500) then {_camera camCommit 10} else {_camera camCommit 5}; } else { _camera camCommit 0; //fade from black 5 seconds titlecut [" ","black in",5]; }; waituntil {(camCommitted _camera)}; //camera move to directly above new dude _camera camSetRelPos [0,0,4]; _camera camCommit 2; waituntil {(camCommitted _camera)}; //camera move to a position that depends on if AI is in vehicle or not if (vehicle _unit != _unit) then {_camera camSetRelPos [0,0,2]} else {_camera camSetRelPos [0,0.5,0.65]}; //_camera camSetRelPos [0,0,1.7]; _camera camCommit 2; waituntil {(camCommitted _camera)}; //quick fade-in on internal point of view of the next unit _camera camSetTarget _unit; vehicle _unit switchCamera "INTERNAL"; _unit cameraEffect ["terminate","back"]; //fade from black 3 seconds titlecut [" ","black in",3]; camDestroy _camera; //run any initialization scripts for the player here //nul = [] execVM "blahblahblah.sqf"; Also added some true/false variables to control the camera movement... TWIRL_DeathCamMoveToKiller and TWIRL_DeathCamMoveToNewUnit If set to true...camera will do the normal pan between units. If set to false camera will be set instantly to the object and fade from black. I'm sure you'll figure it out. Share this post Link to post Share on other sites
katipo66 94 Posted July 13, 2011 Good stuff, I'll check it out tomorrow, cheers Share this post Link to post Share on other sites
kremator 1065 Posted July 13, 2011 This looks lovely. Just what I need ! Share this post Link to post Share on other sites
katipo66 94 Posted July 14, 2011 Just tried it, aha no quite a handbrake but much improved in my opinion, i like it! and yes messn with the camera settings look easy enough, cheers bro! Share this post Link to post Share on other sites
katipo66 94 Posted July 15, 2011 Hey Twirly, I was thinking again:p yes u can see the smoke! Anyway respawn is always a safe bet, and can make you take liberties whilst Rambo'n in the field. I always thought it would be more fun if respawn was not always garaunteed, 50/50 or 60/40? Share this post Link to post Share on other sites
twirly 11 Posted July 15, 2011 @Katipo66.... here's a quick addition for what you need. As it is here...there's a 40 percent chance you won't respawn. For a 90 percent chance you won't respawn change the 40 to 90. Place the block of code right above the line...._found = false; so it ends up looking like this.... [color="Red"]if ((random 100) < [b]40[/b]) exitWith { sleep 3; titleText ["Bad luck! Rambo has left the building.\nNo more respawns available.","plain down"]; sleep 5; enableEndDialog; };[/color] _found = false; Hope it's what you want Bro... Share this post Link to post Share on other sites
MadM0nkey 1 Posted September 28, 2012 (edited) Hi twirly, First off thanks for the efforts in making the script, it does work well in your exampled demo mission..flawless oddly enough however, I tested it for use in WarWelcome using your spawn to marker option & it keeps locking up after the killercam scene sequence for me with message error: no vehicle found I have to kill the process.. perhaps the cause is some conflict within war welcomes scripts? <edit> think I found the issue though I am not exactly sure.. in playerKilled.sqf //hide and delete the body hideBody _plyr; sleep 3; [color=#ff0000]deleteVehicle _plyr[/color]; what happened was while I was playing around in the editor testing it out I crashed an apache..a tree jumped out in front of me, anyway.. because I was in a vehicle the script couldn't locate the player to hide the body then sticks in the death cam scene because the script doesn't know what to do when there is no player vehicle to remove? </edit> Edited September 28, 2012 by MadM0nkey Share this post Link to post Share on other sites
twirly 11 Posted September 28, 2012 Hi mate. I don't know anything about "War Welcome"... but I think you have found the problem. If the player is being deleted and then another script needs the player.... then there will most certainly be a problem. Share this post Link to post Share on other sites
MadM0nkey 1 Posted September 29, 2012 Hi mate. I don't know anything about "War Welcome"... but I think you have found the problem. If the player is being deleted and then another script needs the player.... then there will most certainly be a problem. I am speaking of WarWelcome.utes which is a default SP/MP mission scenario that came originally with ArmA 2. basically I converted/ported the mission for use with Warfare OA & the Reshmaan Province map along with crB_UnitCaching_2-3 + your respawn script and the error only occurs after playing in it for some time.. 9/10 your script works as it should & I respawn as a new team leader at the west flag back@base. I was hoping to also include some side mission scripts from patrol ops 2 into it as well as an optional promotion rank earning bonus for required use access better weapons/vehicles/aircraft upgrades in the mission, however until I can pinpoint & fix the exact conflicted discrepancy in your script vs warfare module I am afraid I am at a standstill. there are no other bugs at its current state besides this one bug being the main issue I have run into besides that the game runs fine you just don't have a guarantee of respawning + locked into camera. If by chance you wouldn't mind going out of your way when you get some free time to have a look threw what I have so far PM me & I would be more then happy to pack it up & send it to you so you can have a look. if not no trouble I will find/fix it eventually.. I hope cheers. Share this post Link to post Share on other sites
twirly 11 Posted September 29, 2012 For a quick test.... just try commenting out the deleteVehicle _plyr line. Another thought is it might be some kind of timing problem. PM sent. Share this post Link to post Share on other sites
MadM0nkey 1 Posted October 2, 2012 problem resolved it had nothing to do with your script or how it was made.. turns out it was something I had overlooked then jumped the gun & ignorantly suspected your script was the issue. It's a good script &, thanks for creating it + taking the time to confirm/test my issue on your end. Regards. Share this post Link to post Share on other sites