Jump to content
Sign in to follow this  
spookygnu

Changing the Side of a respawned unit

Recommended Posts

I've searched the forum and google and not come up with a solution yet to this query yet.

I have a mission planned where the players spawn in as OPFOR and assault a compound. Once they are dead they are then to respawn in the compound (which they do), but I want to change the side of the player once inside the compound so that they basically reinforce the compound in a way. Once all the OPFOR units are dead and the players have reinforced the BLUFOR side its mission over.

Sounds like a weird idea, but the concept I think is quite unique and worth trying out.

Now, I'm thinking of a number of ways of doing this, I saw Armaidiot did a tut on YouTube on switching sides using a trigger-zone, but BI decided to take out the module that does it. GREAT! Another way I thought was once the the player dies they respawn in a room in the compound they kill an OPFOR which would be spawned in at the same time as the player, (I don't know how to do this) then they kill that OPFOR unit, thus switching the side. Then using VAS the player would get their loadout from a pre-saved loadout for BluFOR.

I appreciate that this question has been asked a few times and that many have said that it is not possible to switch sides in game except by killing a member of your own side. But there must be a work around somewhere or somehow??

Anyone got any ideas?

Share this post


Link to post
Share on other sites

Killing members of your own side doesn't switch you to the opposing side, it sets you as hostile to all and everyone. But just changing the side is very simple, basically put

if isServer then { bluforgroup = createGroup blufor; publicVariable "bluforgroup" };

in init.sqf and

[player] joinSilent bluforgroup;

in onPlayerRespawn.sqf in your mission directory. Group determines the side of the unit, so that'll make respawning units blufor. If your respawn position for OPFOR is in the BLUFOR compound, and you setup the loadout after that, it should be all you need.

Unless onPlayerRespawn runs at the start of the game too for missions with respawn enabled? In that case it should be

// Player's old unit is the second parameter passed to the script.
_oldunit = _this select 1;

// If the old unit is null, then the player hasn't died yet. If it isn't null, switch to blufor.
if (!isNull _oldunit) then
{
[player] joinSilent bluforgroup;

// Loadout stuff here

};

Edit: More info on the respawn scripts at the wiki

Edit 2: Realised that the server probably has to publicVariable the created group so the players can access it; added.

Edited by Magirot

Share this post


Link to post
Share on other sites

Thats great thanks for tips. I'm using a simple respawn when a player dies through the description.ext, so at which point do i place the script command to fire the sqf etc?

Share this post


Link to post
Share on other sites

Simple respawn as in 3/BASE? Or, I suppose it'll work with any of those stock templates. Anyway, a simple thing you can do is essentially make your own template that runs in parallel to BASE, or whatever you chose. See the info on Respawn Templates. As well, here is an example of how I have it running, though a little differently:

Respawn = 3;
respawnDelay = 5;
RespawnDialog = false;

class CfgRespawnTemplates
{
class G_Revive
{
	onPlayerKilled = "G_Revive\G_Killed.sqf";
	onPlayerRespawn = "G_Revive\G_Respawn.sqf";
};
};

respawnTemplates[] = {"G_Revive"};

What you need to focus on is the onPlayerRespawn bit. Honestly, just put your script directory their, take out the onPlayerKilled (assuming you want it done on respawn and not killed), and just see what happens. Adjust from there.

Share this post


Link to post
Share on other sites

You don't actually need to execute the script anywhere, the default is (or at least was) that onPlayerRespawn.sqf is called when any respawn is run. From the wiki link: "When you create files called onPlayerKilled.sqf and onPlayerRespawn.sqf in your mission directory, they will be automatically executed on player's computer when he dies and respawns."

Share this post


Link to post
Share on other sites

I'm still having a few problems getting this to work. I'm either doing something wrong or the advice given is not working correctly. I appreciate your knowledge base on this and don't want you to think I'm dissing your advice but this doesn't seem to be working how I'd expect it. I'm still spawning in the base but the Blufor units still see me as OPFOR.

I was on the skype channel for scripting last night and terox suggested I use a game logic and group it to a higher ranked unit. Then when I spawn after death I join his group.

Here is some of the script he suggested I use to help me.

In the init.sqf I create an eventHandler

init.sqf

bluspawn =compile preprocessfilelineumbers "bluspawn.sqf";
if (Hasinterface)then{ Player addeventhandler ["Killed",{_this spawn bluspawn}];};

Then because I created a custom function I fire that from an sqf.

bluspawn.sqf

waitUntil {sleep 1, alive player};
Player joinsilent (sideLogic);
Player joinsilent (grpNull);

My game logic is a blufor side logic called "sideLogic" and that is group to a unit ranked as colonel with probablity of presence zero.

So to summarise, either way I'm doing this is not working. I can spawn in the blufor compound and I'm still hostile to Blufor.

@Grimes: I am using the respawn = Base in the description.ext.

Share this post


Link to post
Share on other sites

Here's an example mission containing what I described, which worked when I tested it, at least. dl (3kb)

Share this post


Link to post
Share on other sites

thats brilliant Maigrot, thankyou very much and appreciate your assistance on this. I'll try this out this evening and get my notepad out! lol!:)

---------- Post added at 17:57 ---------- Previous post was at 17:36 ----------

ok I tried this out just now and it pretty much did the same thing as it was doing last night, the Blufor were still killing me when I spawned in? I haven't changed the script or anything, I just placed it in my mission directory and tested it out in MP so I could respawn.

Not only that but I followed what you explained to me the first time and I looked at how you did it which was the same, so I hadn't done anything thing wrong which I initially thought.

somethings missing I think???

Share this post


Link to post
Share on other sites

:Oo: When I tested it before it worked fine. Sorry, I'm not sure if I can re-check it today, but I'll take a look tomorrow if no-one else can help you in the meantime.

Share this post


Link to post
Share on other sites

ok thanks dude! I'll keep doing about of research on it and see what happens. It pretty much was a carbon copy of what was happening last night except all the other AI from OPFOR were spawning in at Blufor with me when they died. lol! and died, and died, and died, I died, they died, we all died. lmao!

Share this post


Link to post
Share on other sites

Thanks for your efforts guys! I managed to get it working.

I actually placed a trigger over the spawn point.

1.place your spawn marker and place a trigger over it.

2. set the trigger to OPFOR Is Present and Repeated

3. place this line in the onAct [player] joinSilent (createGroup west);

thats pretty much it. SOOOOO FRIGGIN SIMPLE TO DOH! anyway, after much asking and looking around I think I've finally solved the issue which is good. I do have other things working like a game logic group to a unit and the side set etc, but I think the trigger might have done it by itself, because the other methods didn't seem to work how I'd hoped.

Thanks for your help Maigrot, sorry to tell you that you workaround didn't provide the result for me like it did for you. But I have it working now.

Cheers

Spook

Share this post


Link to post
Share on other sites

After 144 spawns you'll run out of groups.

Share this post


Link to post
Share on other sites

its not a large scale operation dude! it's a small assault on a small compound for the GU I'm in. I see what you are saying for other people to take reference, but for my purpose, 144 spawns is pretty out there for what I need it for. lol!

Share this post


Link to post
Share on other sites

That's a relief. Just wanted to be sure you had all the relevant information.:)

Share this post


Link to post
Share on other sites

Hello Everyone , I have one question it's possibel to switch the side Of the unit in the game with one trigger or one module ?

Share this post


Link to post
Share on other sites

debug the side with something like

waitUntil {sleep 1, alive player};

player sidechat format ["Side Logic : %1", side sidelogic];

Player joinsilent (sideLogic);

waitUntil {sleep 1, Player in (group Sidelogic)};

player sidechat format ["Side Player : %1", side Player];

Player joinsilent (grpNull);

player sidechat format ["Side Player : %1", side Player];

Another thing i would probably do is have the player respawn away from anywhere, do the join sidelogic bit then setpos the player to the area you want him

Share this post


Link to post
Share on other sites
Hello Everyone , I have one question it's possibel to switch the side Of the unit in the game with one trigger or one module ?

yes look at post 11 by me. I figured it out this morning.

Share this post


Link to post
Share on other sites

I retested it now. My cardinal error earlier was to not use a dedicated server, thinking it won't matter in this case.

At least for me, the side does change if the player dies - however, the lag between the server and the player results in the BLUFOR AI taking a few seconds to realise this, enough to fire a volley or two.

Terox's solution above would fix it (put the respawn far away, and setPos in the compound only after a while), or simply put the respawn in a building where they're out of sight of the AI at first. Making the player join the AI group might also work.

The trigger is nicely thought, but its behaviour right now would be pretty annoying when you play it with more than one player:

  1. An OPFOR walks in the trigger, triggering it for all players.
  2. All players get switched to BLUFOR, regardless of where they are, because player always refers to the local player and the trigger was triggered to everybody.

This should be fixed if you just change the trigger's Condition from "this" to "player in thisList". thisList is a special variable for triggers referring to all units which are in the trigger and fulfill the conditions (in this case being OPFOR). However, that won't change the fact that if someone wanders in the trigger when simply assaulting the compound as OPFOR, it'll change their side - I'd still try my hand with the onPlayerRespawn setup.

Share this post


Link to post
Share on other sites

thanks for taking another look at your file to see the error.

on the Trigger placement, I did place it in a building and it is unlikely that the OPFOR will get inside as there are already for Live players in the compound, the rest of the Live players are the OPFOR.

I did a test today and I was told that my uniform was removed. This was puzzling as I could see myself wearing my uniform. I had a backpack that was visual to both sides aswell, So that got me thinking maybe firing my switchSide command from an Sqf file once I spawn using:

if (isServer) [player] joinSilent (createGroup west);

Would this possibly solve this issue?

We are playing this tomorrow night on our dedi server with our GU, so if a hasty solution arises before then bonus. If not we can fight in our underpants. I'm sure many soldiers have done it before. LOL!

OPFOR changing sides aswell:

when I joined the group, the other live player who was already in the bluforGroup, spawned in other AI to see if they would react to me. I was teleported out of the compound and he spawned in some opfor right next to me. Within seconds I was slotted, so that proved I was hostile to any OPFOR around.

Share this post


Link to post
Share on other sites
I did a test today and I was told that my uniform was removed.

This is wholly related to addUniform not being global, unlike all of the other commands for adding / removing container items, and even removeUniform:

Added uniform disappears in multiplayer

addUniform is NOT Global (feedback tracker)

Since onPlayerRespawn (Edit: and the trigger as well, when the condition is player in thisList) is only executed for the player who is respawning, you have to replace the addUniform line with BIS_fnc_MP. It normally requires you to declare a new function for this, but using BIS_fnc_spawn (to pass code directly, instead of needing a new function) should work:

[[player, "U_B_CombatUniform_mcam"], { (_this select 0) addUniform (_this select 1) } ], "BIS_fnc_spawn", TRUE] call BIS_fnc_MP;

(replace the uniform name with something else if needed)

Share this post


Link to post
Share on other sites

Ok I took out the onPlayerRespawn.sqf and terox's suggestions on the game logic. I just used the command in the triggerzone.

I'd like to use this as my new start point for getting this correct.

I spawn in fine, I'm on Blufor side.

where do I put the line of code to have the units keep their uniforms on? Can it go in the trigger or does it HAVE to fire from an sqf??

Edited by SpookyGnu

Share this post


Link to post
Share on other sites
where do I put the line of code to have the units keep their uniforms on? Can it go in the trigger or does it HAVE to fire from an sqf??

You can put it wherever you setup the respawn loadout in, just replace your original addUniform with it.

Share this post


Link to post
Share on other sites

Wait, so the uniform disappeared even though you didn't modify the loadout? Now I again have no idea what's going on. The side change alone shouldn't affect it since the default uniform is from the unit config itself.

Edit: Or do you mean that you use the respawn menu inventory thing? Kind of weird if Bohemia hasn't taken the locality of addUniform into account there... You can just add something like this in the side switch trigger (linebreaks here for clarity's sake)

copieditems = uniformItems player; 
removeUniform player; 
[[player, "U_B_CombatUniform_mcam"], { (_this select 0) addUniform (_this select 1) } ], "BIS_fnc_spawn", TRUE] call BIS_fnc_MP; 
{ player addItemToUniform _x } [url="https://community.bistudio.com/wiki/forEach"]forEach[/url] copieditems;

Also copies the items from the old uniform so that part doesn't get wiped out.

Edited by Magirot

Share this post


Link to post
Share on other sites

no mate I don't use any respawn inventory, just the BASE in description.ext and the side swtich command in the trigger

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  

×