Jump to content
Sign in to follow this  
schadler17

Safezone loop

Recommended Posts

Basically I'm trying to create a loop for my safezone script. I want it to simply check the distance between the player and a marker on the map, and if its more/less than 250, perform the scripts needed.

 

I had it looping through a trigger before, but I wanted it strictly through a script using a marker instead, just so you can see the area of the safezone.

_safezone = "westSafezone";

waitUntil {(player distance (getMarkerPos _safezone)) < 250} do {

     systemChat "You are in a safezone";

}:

waitUntil {(player distance (getMarkerPos _safezone)) > 250} do {

     systemChat "You are not in a safezone";

}:

Theres more too it of course, already got the system scripted, just need it to be called/looped in a manner thats not gonna consume too much processing power.

Share this post


Link to post
Share on other sites

Fixed.

 

Pretty easily fixed, here's the end result. Can be called for in each players init or through initPlayerLocal.sqf.

[player] execVM "scripts\safezone.sqf";
// Safezone Script
// Written by Schadler.C

private ["_safeZoneDamageEH", "_safeZoneFiredEH", "_safeZoneVehicleFiredEH", "_safeZoneVehicleDamageEH", "_type", "_projectile", "_projectileName"];

_safeZone = getMarkerPos "westSafeZone";
	
while {true} do {

	waitUntil {_safeZone distance player < 250};
		
		sleep 2;
		hint parseText format ["<t size = '1.5' color = '#FF0000'>SAFEZONE!</t><br/><br/>You have entered the safezone!<br/>Firing your weapon or throwing grenades is prohibited!"];
		player allowDamage false;
		_safeZoneDamageEH = player addEventhandler["HandleDamage",{false}];
		_safeZoneFiredEH = player addEventHandler ["Fired", {
			
			_unit = _this select 0;
			_type = _this select 5;
			_projectile = _this select 6;
			_projectileName = getText(configFile >> "CfgMagazines" >>_type >> "displayName");
			
			switch (_type) do {

					deleteVehicle _projectile;
					
				case "rhs_mag_30Rnd_556x45_M855A1_Stanag": {
					
					hint parseText format ["<t size = '1.5' color = '#FF0000'>SAFEZONE!</t><br/><br/>Do Not Discharge Weapons In Safezone!"];
					_unit setAmmo [currentWeapon player, 0];
					
				};
				
				case "rhs_mag_30Rnd_556x45_M855A1_Stanag_Tracer_Red": {
				
					hint parseText format ["<t size = '1.5' color = '#FF0000'>SAFEZONE!</t><br/><br/>Do Not Discharge Weapons In Safezone!"];
					_unit setAmmo [currentWeapon player, 0];
				
				};
				
				case "rhsusf_100Rnd_556x45_soft_pouch": {
				
					hint parseText format ["<t size = '1.5' color = '#FF0000'>SAFEZONE!</t><br/><br/>Do Not Discharge Weapons In Safezone!"];
					_unit setAmmo [currentWeapon player, 0];
				
				};
				
				case "rhs_mag_M441_HE": {
				
					hint parseText format ["<t size = '1.5' color = '#FF0000'>SAFEZONE!</t><br/><br/>Do Not Discharge Weapons In Safezone!<br/><br/>All %1s Removed From Inventory!", _projectileName];
					_unit removeMagazines "rhs_mag_M441_HE";
				
				};
					
				case "rhs_mag_M433_HE": {
				
					hint parseText format ["<t size = '1.5' color = '#FF0000'>SAFEZONE!</t><br/><br/>Do Not Discharge Weapons In Safezone!<br/><br/>All %1s Removed From Inventory!", _projectileName];
					_unit removeMagazines "rhs_mag_M433_HE";
				
				};
				
				case "rhs_m136_mag": {
				
					hint parseText format ["<t size = '1.5' color = '#FF0000'>SAFEZONE!</t><br/><br/>Do Not Discharge Weapons In Safezone!"];
					_unit setAmmo [currentWeapon player, 0];
				
				};
				
				case "rhs_fgm148_Magazines_AT": {
				
					hint parseText format ["<t size = '1.5' color = '#FF0000'>SAFEZONE!</t><br/><br/>Do Not Discharge Weapons In Safezone!<br/><br/>All %1s Removed From Inventory!", _projectileName];
					_unit removeMagazines "rhs_fgm148_Magazines_AT";
				
				};

				case "rhsusf_20Rnd_762x51_m118_special_Mag": {
				
					hint parseText format ["<t size = '1.5' color = '#FF0000'>SAFEZONE!</t><br/><br/>Do Not Discharge Weapons In Safezone!"];
					_unit setAmmo [currentWeapon player, 0];
				
				};
				
				case "rhsusf_5Rnd_300winmag_xm2010": {
				
					hint parseText format ["<t size = '1.5' color = '#FF0000'>SAFEZONE!</t><br/><br/>Do Not Discharge Weapons In Safezone!"];
					_unit setAmmo [currentWeapon player, 0];
				
				};

				case "rhs_mag_m67": {
					
					hint parseText format ["<t size = '1.5' color = '#FF0000'>SAFEZONE!</t><br/><br/>Do Not Throw Grenades In Safezone!<br/><br/>All Grenades Removed From Inventory!"];
					_unit removeMagazines "rhs_mag_m67";
					_unit removeMagazines "SmokeShell";
					_unit removeMagazines "SmokeShellBlue";
					_unit removeMagazines "SmokeShellRed";
					_unit removeMagazines "SmokeShellOrange";
				
				};
				
				case "SmokeShell": {
					
					hint parseText format ["<t size = '1.5' color = '#FF0000'>SAFEZONE!</t><br/><br/>Do Not Throw Grenades In Safezone!<br/><br/>All Grenades Removed From Inventory!"];
					_unit removeMagazines "rhs_mag_m67";
					_unit removeMagazines "SmokeShell";
					_unit removeMagazines "SmokeShellBlue";
					_unit removeMagazines "SmokeShellRed";
					_unit removeMagazines "SmokeShellOrange";
				
				};
				
				case "SmokeShellBlue": {
					
					hint parseText format ["<t size = '1.5' color = '#FF0000'>SAFEZONE!</t><br/><br/>Do Not Throw Grenades In Safezone!<br/><br/>All Grenades Removed From Inventory!"];
					_unit removeMagazines "rhs_mag_m67";
					_unit removeMagazines "SmokeShell";
					_unit removeMagazines "SmokeShellBlue";
					_unit removeMagazines "SmokeShellRed";
					_unit removeMagazines "SmokeShellOrange";	
				
				};
				
				case "SmokeShellRed": {
					
					hint parseText format ["<t size = '1.5' color = '#FF0000'>SAFEZONE!</t><br/><br/>Do Not Throw Grenades In Safezone!<br/><br/>All Grenades Removed From Inventory!"];
					_unit removeMagazines "rhs_mag_m67";
					_unit removeMagazines "SmokeShell";
					_unit removeMagazines "SmokeShellBlue";
					_unit removeMagazines "SmokeShellRed";
					_unit removeMagazines "SmokeShellOrange";
				
				};
				
				case "SmokeShellOrange": {
					
					hint parseText format ["<t size = '1.5' color = '#FF0000'>SAFEZONE!</t><br/><br/>Do Not Throw Grenades In Safezone!<br/><br/>All Grenades Removed From Inventory!"];
					_unit removeMagazines "rhs_mag_m67";
					_unit removeMagazines "SmokeShell";
					_unit removeMagazines "SmokeShellBlue";
					_unit removeMagazines "SmokeShellRed";
					_unit removeMagazines "SmokeShellOrange";
					
				};
				
				case "DemoCharge_Remote_Mag": {
					
					hint parseText format ["<t size = '1.5' color = '#FF0000'>SAFEZONE!</t><br/><br/>Do Not Discharge Weapons In Safezone!<br/><br/>All %1s Removed From Inventory!", _projectileName];
					_unit removeMagazines "DemoCharge_Remote_Mag";
					
				};

				case default {
					
					systemChat format ["%1", _this select 0];
					systemChat format ["%1", _this select 1];
					systemChat format ["%1", _this select 2];
					systemChat format ["%1", _this select 3];
					systemChat format ["%1", _this select 4];
					systemChat format ["%1", _this select 5];
					
					hint parseText format ["<t size = '1.5' color = '#FF0000'>BUG FOUND!</t><br/><br/>Please Report Ammotype (Located In Chat) To Admin/Developer!"];
					
				};
			};
				
		}];
		
	waitUntil {_safeZone distance player > 250};
		
		hint parseText format ["<t size = '1.5' color = '#FF0000'>SAFEZONE!</t><br/><br/>You are leaving the safezone!<br/>You are now vulnerable to enemies!"];
		player allowDamage true;
		player removeEventhandler["HandleDamage", _safeZoneDamageEH];
		player removeEventHandler["Fired", _safeZoneFiredEH];
		
};

Customize the magazine types to the ones you need, Im using RHSUSAF mags.

Script will remove current magazine ammo, grenades, or explosives that the player wants to use after deleting the projectiles to prevent firing/throwing/etc multiple times in safezone.

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  

×