Jump to content
Sign in to follow this  
HumaineNZ

Switch sides on Trigger

Recommended Posts

Hi, I'm looking at creating a mission where the players start as civilians but if they cross into an area, bluefor forces will shoot them.

This is the first time I've tried scripting so forgive my lack of knowledge on this.

 

I found the simple way to do this is to change the player to Opfor on a trigger when that happens, with something that does this:

player joinAsSilent [createGroup east, 5];

 

but, once one player switches, then every other player switches as well, no matter where they are. ( which isn't ideal)

Also when the player dies, he can't respawn using the civi point, as he remains Opfor.

 

A messy way around this was to created an opfor respawn at the start point, and another trigger to switch them back to Civi

player joinAsSilent [createGroup civilian, 5];

 

This works, but again every player changes as well... and i'm sure I read somewhere that every time you do something like this, it creates a new group, and that there is a limit to how many new groups can be created.

 

Is there another way i could do this? how about on death the player switches back to civi?  Not sure how to script that.

 

Thanks for any help, if you can.

 

Share this post


Link to post
Share on other sites
3 hours ago, HumaineNZ said:

Hi, I'm looking at creating a mission where the players start as civilians but if they cross into an area, bluefor forces will shoot them.

This is the first time I've tried scripting so forgive my lack of knowledge on this.

 

I found the simple way to do this is to change the player to Opfor on a trigger when that happens, with something that does this:

player joinAsSilent [createGroup east, 5];

 

but, once one player switches, then every other player switches as well, no matter where they are. ( which isn't ideal)

Also when the player dies, he can't respawn using the civi point, as he remains Opfor.

 

A messy way around this was to created an opfor respawn at the start point, and another trigger to switch them back to Civi

player joinAsSilent [createGroup civilian, 5];

 

This works, but again every player changes as well... and i'm sure I read somewhere that every time you do something like this, it creates a new group, and that there is a limit to how many new groups can be created.

 

Is there another way i could do this? how about on death the player switches back to civi?  Not sure how to script that.

 

Thanks for any help, if you can.

 

What im assuming is happening (correct me if im wrong), you made a trigger, when a civ player is detected it runs a script thats in your activation. If thats the case then player joinAsSilent [createGroup east, 5]; is running on every players machine which is forcing all players to become opfor. What you can do in the triggers activation, you can go through all the players that are inside of the trigger and use thislist(a list of everything inside the triggers activation) to make only the players that are in the trigger opfor. Now as for switching back to Civi when you die (im not 100% sure if this will work since you will be dead) is add an event handler "killed" to the player so when the player dies he is (hopefully) set back as a civ.

so in the triggers activation put this. _x is the selected thing in thislist. think of thislist as an ice cube tray(an array) where each slot of the tray holds a unit or object ect. ForEach goes through that tray one slot at a time. Think of _x as the unit/object inside of the tray(like the ice cube). so if we have a tray(array) of players, then when we run ForEach on the array, the first time it runs _x is equal to the first ice cube(player) in that tray(array), then the second time it runs its on the second ice cube(player) in the tray(array). its like a loop for all filled slots in the tray.

{
	if (IsPlayer _x) then //if the unit is a player
	{
		if (Side _x != east) then //if their side is not already opfor/east
		{
			_x joinAsSilent [createGroup east, true]; //then create an opfor group and join it
			_x AddEventHandler ["Killed", //then add an event handler to run when the player is killed
			{
				params ["_unit", "_killer", "_instigator", "_useEffects"];
				_unit joinAsSilent [createGroup Civilian, true]; //that will create a civ group and join it
			}];
		}
	};
} ForEach thislist; //run for everything inside the trigger

if the respawning switch to Civilian doesnt work, post back and ill explain another method for you to try.

  • Like 2

Share this post


Link to post
Share on other sites

Hey gokitty1199,

 

Sorry mate, not sure how to add this to the activation of the trigger, as its coming up with an expression error.

 

Is this script added in to the activation section or somewhere else?

 

Thanks for any Help.

Share this post


Link to post
Share on other sites
13 hours ago, HumaineNZ said:

Hey gokitty1199,

 

Sorry mate, not sure how to add this to the activation of the trigger, as its coming up with an expression error.

 

Is this script added in to the activation section or somewhere else?

 

Thanks for any Help.

im sorry i never got a notification that you replied. this gets added to the activation of the trigger (wasnt tested before so ill try it on my end and fix it)

 

EDIT: the errors were because of the comments //comment being used inside of the trigger and apparently JoinAsSilent does not work on civilian units, so i changed up the script to use JoinSilent instead. this goes in the activation of the trigger

{
	_Grp = CreateGroup [east, true];
	_Arry = [_x];
	_Arry joinSilent _Grp;//because joinSilent takes in an array instead of individual units
	hint str (Side _x);//remove this, but this shows you the side of the unit(test it yourself) after changing sides, will be EAST
	_x AddEventHandler ["Killed",
	{
		params ["_unit", "_killer", "_instigator", "_useEffects"];
		_Grp = CreateGroup [civilian, true];
		_Arry = [_unit];
		_Arry joinSilent _Grp;
		hint str (Side _unit);//remove this, but this shows you the side of the unit(test it yourself) after dying, will be CIV
	}];
} ForEach (thislist Select {IsPlayer _x && Side _x != EAST});//for all units that are players and civilians

 

  • Like 2

Share this post


Link to post
Share on other sites

Thanks gokitty1199, this works really well. Thanks you soo much... you are a legend!

Share this post


Link to post
Share on other sites

Doh... spoke too soon... once i had more then one player, we started having problems.... the respawn point would become disabled after a few attempts for some players, and then all players.. hmmm.
I'll post you a video in a bit of whats happening, and you can see.

Share this post


Link to post
Share on other sites

(Quote after watching the video I made, of testing the script - Watch the video at your peril LOL)

 

Quote

That's kind of strange. I noticed the hint said CIV when he entered the zone, but the AI still engaged him so he should be part of an opfor group(unless you set the AI to fire on Civs in the zone) so is that portion working correctly? is it just the respawning that is having issues?

 

Yes, it is weird. and no the AI are just regular Bluefor. No changes made to them.

 

Yes the change over from Civ to Opfor is working well, and when we tried it again the other day it was working, but we noticed that a new value came up after I had respawned from being killed by the AI at the outpost. The other player had driven off to a different trigger further out at another outpost. The hint came up 'ENEMY' for me at the respawn.

 

We will be testing it again tonight and see if there is a condition when these issues come up. Anyone is welcome to join and figure this out... hehehe

Share this post


Link to post
Share on other sites
1 hour ago, HumaineNZ said:

(Quote after watching the video I made, of testing the script - Watch the video at your peril LOL)

 

 

Yes, it is weird. and no the AI are just regular Bluefor. No changes made to them.

 

Yes the change over from Civ to Opfor is working well, and when we tried it again the other day it was working, but we noticed that a new value came up after I had respawned from being killed by the AI at the outpost. The other player had driven off to a different trigger further out at another outpost. The hint came up 'ENEMY' for me at the respawn.

 

We will be testing it again tonight and see if there is a condition when these issues come up. Anyone is welcome to join and figure this out... hehehe

thats strange, i would like to step get an exact explanation on what you want from it as well as watch it/try stuff live to figure out where something wrong is happening if you dont mind. discord: [GH] Cody#9273

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  

×