Jump to content
*zeewolf*

Demo: Dynamically change unit class

Recommended Posts

I mentioned in this thread that I'd come up with a bodge to allow players to change their class while in a mission, which apparently has never been done. I've gotten around to making a little demo mission. It can be used to give the player the impression that they are simply changing clothes (except for the globalchat "killed" message).

Just open the dialog from the action menu (note the reused MWC assets). You can pick any unit from the class database declared in init.sqs, notice that you can even use unit classes from another side (although you will still remain on the same side).

This needs to be run as a multiplayer mission due to it relying upon engine respawn mechanics to shift the player into another class, but I don't see that as being a real problem as there are already ways to load and save game data in multiplayer. If you want other AI units in a player's group then you'll need to modify the mission to shift players into temporary groups when they class switch using "join" before moving them back to their original group once the class switch is complete. If you need to transfer a player's identity to their new unit then I suggest you use saveIdentity in the init script to save their initial identity then use loadidentity to transfer it to the new unit whenever they switch.

The demo mission is permadeath. If you want to respawn as well as class switch you'll need to spawn a second unit into the player's group for them to respawn into before they die!

Edited by *Zeewolf*

Share this post


Link to post
Share on other sites

Amazing creation *Zeewolf*!!! :ok:

Correct me if I am wrong, but does this script make creating weapon dependent animations possible? :butbut:

Icarus

Share this post


Link to post
Share on other sites
Amazing creation *Zeewolf*!!! :ok:

Correct me if I am wrong, but does this script make creating weapon dependent animations possible? :butbut:

Icarus

I guess so, you could define an individual animation set for each "man" class, then use scripts to detect changes in loadout which trigger a class change.

My recent tribulations with trying to override states for a Juggernaut unit have left me loathing the sight of CfgMovesMC. Based on my experience you're definitely better off using StatesExt to override the standard state classes rather than trying to override the actions that call them, even if it looks messy.

So the Juggernaut addon's config.cpp is basically:

class CfgMovesMC
{
class Default {};
class DefaultDie: Default {};
class StandBase: Default {};
};
class CfgMovesMCJugg:CfgMovesMC
{
class StatesExt
{
	class Combat:Default
	{
		// member variable overrides for Combat
	};
	class CombatWalkF:Default
	{
		// member variable overrides for CombatWalkF
	};
	... etc
};
};

class CfgVehicles
{
class All{};
class Land:All{};
class Man:Land{};
class Soldier:Man{};
class SoldierWB:Soldier{};
class JuggernautW:SoldierWB
{
	moves="CfgMovesMCJugg";
	displayName="Juggernaut";
	model="\ww4_trp\bosold.p3d";
	armor=50;
	armorStructural=6;
	armorHead=2;
	armorBody=12;
	armorHands=12;
	armorLegs=12;
	weapons[]={"PK","Revolver","Throw","Put"};
	magazines[]={"PK","PK","PK","PK","handgrenade","smokeshell","RevolverMag","RevolverMag","RevolverMag","RevolverMag"};
};
class JuggernautE:JuggernautW
{
	side=0;
};

class JuggernautR:JuggernautW
{
	side=2;
};
};

So, if I wanted I could make SoldierWMG use CfgMovesMCJugg then use a script to detect when the player (using a SoldierWB class for example) picks up a PK or M60 then switch them into SoldierWMG while preserving their loadout, the player would look the same but their animations would be changed to that of the new class. When they drop the MG, the script switches them back to a SoldierWB etc.

In the demo mission there is 2 second delay when switching classes, this could probably be reduced, I kept them in there to spread out the extra bandwidth demand of the createunit and loadout manipulations, if you remove the "black in" cuttexts in the demo's dialog script you'll see the transfer to another unit takes just one frame, the camera in the game's standard "onPlayerKilledRespawnAsOtherUnit" script just gives you the impression it takes a long time. I guess the amount of "black in" you use is dependent upon whether you want the player to see what your script is actually doing, dropping dead every time you pick up a weapon might get annoying.

Edited by *Zeewolf*

Share this post


Link to post
Share on other sites
In the demo mission there is 2 second delay when switching classes, this could probably be reduced, I kept them in there to spread out the extra bandwidth demand of the createunit and loadout manipulations, if you remove the "black in" cuttexts in the demo's dialog script you'll see the transfer to another unit takes just one frame, the camera in the game's standard "onPlayerKilledRespawnAsOtherUnit" script just gives you the impression it takes a long time. I guess the amount of "black in" you use is dependent upon whether you want the player to see what your script is actually doing, dropping dead every time you pick up a weapon might get annoying.

True. You don't want the end user to see technical details that kill immersion... :butbut:

However making the script work take as little time as possible (without sacrificing performance) is really desirable :)

Icarus

Share this post


Link to post
Share on other sites

Another issue is that this feature needs to be rolled out as a combined mission template/addon framework which as you know I am a fan of but they don't appear to be very fashionable around here. So I'm not expecting to see it used in any releases just for that reason.

Share this post


Link to post
Share on other sites

Very great :) can I use this for my Mod ? I will mention you of course :)

Share this post


Link to post
Share on other sites
Very great :) can I use this for my Mod ? I will mention you of course :)

Sure, just put a comment in the relevant script section saying where you got it from. That way anyone reading the script to figure out how it works can find out more about it.

Share this post


Link to post
Share on other sites

Öhm your link says that the file was deleted because of copyright issues O.o? Maybe a reupload on a other mirror?

Edit: Oh nevermind ^^

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

×