Jump to content
Sign in to follow this  
anusmangler

Civ script for Opfor to attack.

Recommended Posts

Ok so I got this mission set up where the FIA (guerrillas) are fighting Opfor that controls the island (I should mention now that Im making this happen with the help of Alive). I have you spawn as a Civ (but can be changed) (to simulate being a new recruit so you have to go out into the war to raid bases and load up cars and what not so you and your friends have better equipment). I've tried to think of a way to do 2 things but have failed over the course of the last month trying to figure it out.

1. How to make Opfor shoot at a civ that's attacking them. yeah it can be done but you (as a civ) have to kill like 10 guys to finally be shot and that's not realistic or fun. Maybe a script or something that opfor will attack at a civ that's shooting them but over time if you stay low profile or get away they will not shoot at you (to sim the idea of no shooting innocents) (last part it not really necessary just would like to see opfor shoot at civs shooting at them)

2. How to make opfor shot a civs getting to close to their bases. (Not a whole lot of fun if you can just walk in there raid the place and walk out without shooting anyone and not very real.

Please someones help would be greatly appreciated. Dont forget any ideas or suggestions you have are dependent on Alives spawning units into the game. (idk if that matters.) Thanks for anyone for a helping hand

Share this post


Link to post
Share on other sites

You can make the civ a BLUFOR unit by grouping it to any BLUFOR unit, even if the unit it is grouped to has a 0% Probability of presence.

Once grouped to a BLUFOR unit, the OPFOR soliders will treat him like any other BLUFOR unit and attempt to kill him.

Share this post


Link to post
Share on other sites

I'd go with this usual setup:

1) Add "this setCaptive TRUE;" to the player unit's init

2) Create a new blufor unit

3) Set that unit's "probability of presence" slider to zero

4) Group the player under him

This way the player is actually a blufor unit that's just treated like a civilian by other sides. Then whenever you want to remove this status you can use "playername setCaptive FALSE;" The approach isn't without problems though, since enemies won't instantly react after setCaptive has been set to false. And the harder part is usually following the player's actions in such a way that the enemy's reactions seem logical.

In case of the military base you'll probably just want to create a trigger that takes setCaptive away if opfor notices the player - don't use "blufor noticed by opfor", though, since a captive isn't treated as his regular side. Rather group the trigger to the player unit.

For reacting to firing I'd use Killed and Hit event handlers applied to all units, but that's the part that isn't compatible with ALiVE. I don't know if there are features in it that allow for applying EH's to all spawned units.

Share this post


Link to post
Share on other sites

^ Will that method work with respawns? This mission is meant to be played with friends, or single player, but a better experience with co-op. At this point it seems to much trouble to go through just to get something that may not work 100%. just wish I knew how to re spawn players with no inventory.

Share this post


Link to post
Share on other sites

The grouping setup should work, since respawning doesn't change the group. As for setCaptive, you just apply it again after respawn. Create a file called onPlayerRespawn.sqf in your mission directory and add this in it:

_unit = _this select 0;

_unit setCaptive TRUE;

You can also modify the loadout at that point with stuff like "removeAllWeapons _unit;", just remember that remove/addUniform is very problematic and should be avoided, since the latter is a command with a local effect and onPlayerRespawn fires only locally.

List of possible Event Scripts like onPlayerRespawn if someone is interested.

Anyway, since it's a multiplayer mission, the "no civilians allowed" base's trigger needs to be different. Maybe rely on the locality of player command. Create a trigger, group it with the player group, and try these settings:

- Size: the size of the base

- Activator: any member of group

- Detected by opfor

- Condition: player in thisList

- On Act.: player setCaptive FALSE;

Share this post


Link to post
Share on other sites

Forget all about the setcaptive command, it will make most triggers/conditions unusable that check for a units side and is way too complicated to set up.

If you want a reliable method that's easy to setup simply use addRating.

put

this addrating -20000;

into a units init field and it will get shot, works for all sides

this will put a unit to the "ENEMY" side and set it hostile to everyone

Share this post


Link to post
Share on other sites

sideEnemy has its own issues you should keep in mind, though. One is that the noticed player gets thrown out of the group, which can be annoying in MP, other is that all units of all sides start attacking the player, including any blufor that the player should be working for. But if there are no armed units that are supposed to stay friendly to the players, that can indeed be the best method.

Edit: Then again, in case all you need is armed friendly units for flavour's sake, you could just init them with { this disableAI _x } forEach ["TARGET", "AUTOTARGET"]; this allowFleeing 0; this setBehaviour "CARELESS"; and they shouldn't fire or react to anyone, including an enemy player.

Edited by Magirot

Share this post


Link to post
Share on other sites

Can I send both of you guys my mission? I think maybe something is getting lost in translation. I don't want Blufor to attack the civ units...but like i said they dont NEED to be civ if being another unit type would fix the problem. I mean the mission works as of right now but It would be great to have that scouting and ambush thing going on so you can destroy convoys or blow up structures and surprise the enemy.

Share this post


Link to post
Share on other sites

I'll try to clarify, please correct any mistakes:

  1. There's no easy, elegant solution
  2. The unit type isn't really relevant in this case, but if it's a civilian, it's better to change the side of the unit to blufor with the aforementioned invisible group leader or some other trick.
  3. This is done because sides other than civilian get an easy command for switching them to civilians temporarily (setCaptive).
  4. With it, you can set them to be treated as civilians initially, and switch them back to their original side (that is, their group's side) when opfor is alerted.
  5. But it's not simple or straightforward, since you need to keep track of player actions with scripting to figure when they shouldn't be civilians anymore.
  6. (The unit also doesn't register as a member of its side while setCaptive is on, which is why I earlier talked about grouping triggers to the group instead)

The point of the last few messages was:

  1. The system with setCaptive is complicated to set up and manage.
  2. You can use "this addRating -20000"* instead, to make everyone hostile to the unit without affecting its side.
  3. However, that makes everyone hostile, including any allies that the mission setup would have the players have.
  4. In this case it will also still warrant following player actions to determine when to run it.
  5. Given that you want friendly blufor units in the mission, setCaptive is probably more to the purpose.

* Rating is a system that's used by the game for, among other things, following friendly fire. If the rating gets too low, the unit gets tagged as a renegade that everyone is hostile towards.

As for the rest, I already explained the solutions and problems I know of in posts 3 and 5. I don't know a thing about ALiVE, but it might work if you modify the spawning to add the required event handlers to newly spawned units as well. You can test it with units that already exist in the mission by adding something like this to init.sqf:

// Only set the EH's if it's the server
if (isServer) then
{
// Declare functions

OpforAnnoy_KilledEH =
{
	// declare private variable
	private "_killer"; 

	// causedBy is the 2nd variable passed by the EH
	_killer = _this select 1;

	// if still captive, remove setCaptive
	if (captive _killer) then {
		_killer setCaptive FALSE;
	};
};

OpforAnnoy_HitEH = 
{
	// declare the private variable
	private "_damager";

	// causedBy is the 2nd variable passed by the EH
	_damager = _this select 1;

	// if still captive, remove setCaptive
	if (captive _damager) then {
		_damager setCaptive FALSE;
	};				
};

// 'forEach allUnits' block start
{ 	
	// Only add if the unit is OPFOR
	if (side _x == opfor) then
	{
		// add EH's
		_x addEventHandler ["Killed", OpforAnnoy_KilledEH];						
		_x addEventHandler ["Hit",    OpforAnnoy_HitEH];
	};	
} forEach allUnits; // cycle through all existing units
};

So to reiterate this whole mess, in case you want to try the setCaptive path:

  1. Group the civilian player units under a blufor commander that has probability of presence slider set to zero.
  2. Add this setCaptive TRUE; to the init of all player units.
  3. Add that block of code above to init.sqf; it will make all opfor units that have been placed in the editor react to players shooting them. (Or rather, react to players hitting and killing them; in case of players firing madly near them or missing their shots, they'll at most go prone. This is why it always feels a bit lacking, and you'd need to add even more EH's to simulate it better.)
  4. To reset captivity on respawn, create onPlayerRespawn.sqf in the mission directory with the snippet in post 5 in it.
  5. Add the trigger from post 5 to the military base(s) to make them react to intruders.

Edited by Magirot

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  

×