Jump to content

[Release] Ring of Protection - Warning then death if a player gets too close to a named object type.


RimBlock

Recommended Posts

Have just rewritten a script for MatthewK to try and help out (thread ) and though I would release for all to enjoy.

 

Set the _classnameProtected to a class name of an object you want to protect.  Classnames are types of objects.  In the code below it is all wooden DZ sheds. 

 

Save the following as something (i.e. mpmissions\[MAP NAME]\Custom\RingOfProtection\RingOfProtection.sqf)

// Ring of Protection by RimBlock (http://epochmod.com/forum/index.php?/user/12612-rimblock/)
//
// This script will allow you to set two rings around an object (vehicle, building, player).  The first ring will create a warning, the second will kill the player.
// 
// Completely rewritten from initial code by [MIC] Murcielago.

Private ["_n","_classnameProtected","_nearbyProtected","_vehiclePlayer","_nearestProtected","_warningRange","_deathRange","_nearbyProtected","_aliveNearbyProtected"];

_n = 0;
_warningRange = 20;
_deathRange = 7;
_classnameProtected = "Wooden_shed_DZ";

While {True} Do 
{
	_nearbyProtected = [];	
	_aliveNearbyProtected = [];	
	_nearestProtected = "";	
	_vehiclePlayer = (Vehicle Player);	
	_nearbyProtected = nearestObjects [_vehiclePlayer, [_classnameProtected], _warningRange];
	if ((count _nearbyProtected) >= 1) then {
		{
			if (alive _x) then { 
				_aliveNearbyProtected set [(count _aliveNearbyProtected),_x]; 
			}; 
		}count _nearbyProtected;
		if ((count _aliveNearbyProtected) >= 1) then{
			_nearestProtected = _aliveNearbyProtected select 0;
			If ((_vehiclePlayer Distance _nearestProtected) < _deathRange) Then {Player Setdamage 1;};
			If ((_n == 0) && {_vehiclePlayer Distance _nearestProtected  >= _deathRange}) Then {
				TitleText ["[WARNING]: Entering restricted area.  Continuing will result in death.","PLAIN"];
			};
			_n = _n + 0.05;
		};
	};
	Sleep 0.05;
	If ( _n > 1 ) Then {
		_n = 0;
	};
};

Put the following in your custom compiles.sqf (just after "progressLoadingScreen 0.8;" should work).

ringOfProtection = compile preprocessFileLineNumbers "Custom\RingOfProtection\RingOfProtection.sqf";    

Call it (probably from the init.sqf)  after the line "_playerMonitor = ..." with

[] spawn ringOfProtection;

Note this is likely to have at least a small impact on each player.

 

Possible future upgrade:

 It could probably be addapted to a single item (i.e. admin base) but the item would need to be tagged (i.e. with a setvariable item "Protected" true type but of code) and then after the item classname is detected in range, the variable can be checked to see if that one in particular is protected.

 
Link to comment
Share on other sites

you could.

 

You could also assign a special skin to admins and then set this to act as a safe zone around that skin so if anyone went close to admins they would die  ;) .

 

How about making zombies infectious so if you went within 2mtrs of them then you would get infected.

 

You could set up a radiation zone and then require anyone entering to have a special skin (ie. a rad suit) or they would die.  Would not take much to amend the code.

 

Lots of options, good and bad that this can be used for.  QWhat is here is a base setup but with a bit of tweaking it can be expanded in many ways.

 

The thing to remember is that this script is attached to the player character and polls for objects in range 20x / second.  The larger the range, the more work the client has to do finding objects, querying them and then acting on the results.

 

If you wanted to section off an island I would be more inclined to put markers around its border XXXmtrs apart and set the range to that distance so the players are stopped at the barrier around the island rather than having to poll for the item central to the island for a distance equal to the furthest point from the item to the island border.

Link to comment
Share on other sites

Hey Rim, what do you think about changing setdamage to setvelocity? Think that would work? I wrote my own mod that would have an AI do setdamage if he locked onto a player and chased him down and it worked no problem, but the moment I tried to do setvelocity it for whatever reason would never work. Don't know if there is some special rule about setvelocity vs setdamage, although all scripts that I have seen where setvelocity is used seems to always spawn something in conjunction with it, as if they spawn an item, attach it to the player and them use the setvelocity command on the object, maybe I don't understand the Arma engine will enough but that just seems weird. I wrote a setvelocity script for my action menu that works no problem when the player executes it and I never had to spawn anything, But I digress, I'll give this a go and see if it works with setvelocity.

Link to comment
Share on other sites

  • 3 weeks later...

Great script. I've used it to play morse code messages when within range of a receiver. It is working brilliantly except I cannot get it to work with more than one object type. How would I add multiple object types?

 

I have tried:

_classnameProtected = "Object1", "Object2";

_classnameProtected = ["Object1", "Object2"];

_classnameProtected = ("Object1", "Object2");

_classnameProtected = ("Object1" or "Object2");

 

None of these variations have worked so far. Any advice?

Link to comment
Share on other sites

You would need to change

_classnameProtected = "Wooden_shed_DZ"; 

into

_classnameProtected = ""; 
_ProtectedClasses = []; // put in all the classes you want to protect.

You would then need to put all after

_vehiclePlayer = (Vehicle Player);

In a count loop (ie. { ....... }count _ProtectedClasses ;) and add after it

_classnameProtected = _x;

The

}count _ProtectedClasses;

needs to go before the last

};

That would probably work for multiple classes.

Link to comment
Share on other sites

  • 4 months later...

Sure but you would have to rework it a bit.

 

The code above is more of a framework but you can do a lot of other things with it.  It is quite simple to understand with a bit of checking back at the BIS Wiki for what the commands do.

 

Update: You could take a look at my Ring of Death on my Git and by mixing and matching both you could come out with something you want.  Yust make the monster a player instead (search for a player with a specific stream id for example).

Link to comment
Share on other sites

  • 1 year later...

Hey Rim,

with your _warningRange = 20;

and your _dethRange = 7;

these are in meters correct?

 

also how would you go about allowing curtain UIDs into to the rings but no one else?

Edited by TAGau
forgot a couple of other questions
Link to comment
Share on other sites

3 hours ago, TAGau said:

Hey Rim,

with your _warningRange = 20;

and your _dethRange = 7;

these are in meters correct?

 

also how would you go about allowing curtain UIDs into to the rings but no one else?

Last visited = 5 Oct 2015

I don't think you're getting an answer from OP.

 

Yes range is in meters.

 

For adding PUID you will need to add the functionality yourself, search the forums, there are examples on saving and comparing PUIDs

Link to comment
Share on other sites

1 hour ago, mgm said:

Last visited = 5 Oct 2015

I don't think you're getting an answer from OP.

 

Yes range is in meters.

 

For adding PUID you will need to add the functionality yourself, search the forums, there are examples on saving and comparing PUIDs

 

1 hour ago, mgm said:

Last visited = 5 Oct 2015

I don't think you're getting an answer from OP.

 

Yes range is in meters.

 

For adding PUID you will need to add the functionality yourself, search the forums, there are examples on saving and comparing PUIDs

Thanks for the reply mgm. I'll have a hunt around the forums, if i can't find one I'll go with a protection dome script I found earlier that uses world locations

Link to comment
Share on other sites

2 hours ago, TAGau said:

 

Thanks for the reply mgm. I'll have a hunt around the forums, if i can't find one I'll go with a protection dome script I found earlier that uses world locations

below is a quick try.
do this two modifications and give it a try. if it works, great.
if it doesn't work, create a new thread and I will follow up in your own thread - don't want to hijack @RimBlock's thread here.

edit: my (wrong!) code removed.

edit - what I copied here earlier definitely won't work. (it was too quick a try!).  I am happy to give a hand, please create a new thread and I will post the proposed code there.

Link to comment
Share on other sites

7 minutes ago, mgm said:

below is a quick try.
do this two modifications and give it a try. if it works, great.
if it doesn't work, create a new thread and I will follow up in your own thread - don't want to hijack @RimBlock's thread here.

---
STEP #1:

find this line (the one copied below):
    _nearbyProtected = [];
and replace it with the following:
    private    ["_uid", "_quickEscapeNow", "_imAllowed"]; _uid = (getPlayerUID player); _quickEscapeNow = false; _imAllowed = false; _nearbyProtected = [];
---

 

 

---
STEP #2:
find the original line (the one copied below):
            If ((_vehiclePlayer Distance _nearestProtected) < _deathRange) Then {Player Setdamage 1;};

replace it with the following:
            If ((_vehiclePlayer Distance _nearestProtected) < _deathRange) then { { scopeName "allowedPUIDsGroupTraverseScope"; if (_uid == _x) then { diag_log format ["[TOMNJERRY] [client-side_compare_PUID.sqf] allowedPUIDs match found!"]; _imAllowed = true; breakOut "allowedPUIDsGroupTraverseScope"; } else {    }; } forEach TOMNJERRY_pvdb_allowedPUIDsTextStringArray; if(!_imAllowed) then { player setDamage 1; }; };
---

 

Thanks mate. I can't test it right now cause I'm at work until sunday morning  (Brisbane, Aus time). But I'll have a go on Sunday and get back to you if it worked or if it failed.

Thanks in advance for your time and effort to help me out buddy ;) its much appreciated :)

Link to comment
Share on other sites

1 minute ago, TAGau said:

Thanks mate. I can't test it right now cause I'm at work until sunday morning  (Brisbane, Aus time). But I'll have a go on Sunday and get back to you if it worked or if it failed.

Thanks in advance for your time and effort to help me out buddy ;) its much appreciated :)

argh! delete that quoted code. I tried to quick copy & paste adapt my working code from another script,  in the office between phone calls but it ended up brainfart. you go create a new thread, I will post something for you tonight.

Link to comment
Share on other sites

15 minutes ago, mgm said:

argh! delete that quoted code. I tried to quick copy & paste adapt my working code from another script,  in the office between phone calls but it ended up brainfart. you go create a new thread, I will post something for you tonight.

Thread created mate.

I've given both you and RimBlock credit for the help. 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Discord

×
×
  • Create New...