Epoch/Sources/epoch_server_settings/EpochEvents/PlantSpawner.sqf

141 lines
4.9 KiB
Plaintext
Raw Normal View History

2015-07-24 14:16:25 +00:00
/*
Author/s:
Redbeard Actual
Aaron Clark - EpochMod.com
Description:
Improved Plant Spawner - Plant Patch Spawner
Event spawns a random number of plants based on plant type.
Prefers "Hill" locations and restricts Jammers and Protected Trader Zones.
Plants now decay after 20 minutes and marker will change to brown at 50%.
Plant patch marker will turn red after one plant is picked
Plants and marker will cleanup after all plants in a patch are picked or die due to decay.
2015-07-24 14:16:25 +00:00
Improvements and or bugfixes and other contributions are welcome via the github:
2016-06-13 16:54:19 +00:00
https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_server_settings/EpochEvents/PlantSpawner.sqf
2015-07-24 14:16:25 +00:00
*/
2017-05-02 12:35:38 +00:00
//[[[cog import generate_private_arrays ]]]
private ["_debug","_decayTime","_jammers","_marker","_nearbyLocations","_plant","_plantCount","_plants","_playersNearby","_position","_restricted","_scatter","_selectedLocation","_showPlantMarkers","_timeStamp"];
//[[[end]]]
// SET THIS TO TRUE TO GET MESSAGES IN LOG.
_debug = true;
_showPlantMarkers = true;
// select a plant type to spawn
_plant = selectRandom ["Goldenseal_EPOCH", "Goldenseal_EPOCH", "Goldenseal_EPOCH", "Poppy_EPOCH", "Pumpkin_EPOCH"];
// START PLANT PATCH SPAWN LIMIT CODE IF EPOCH_plantCounter HAS NOT BEEN INITIATED.
// THIS MAKES SURE IT ONLY DOES THIS BIT THE FIRST TIME THE EVENT RUNS.
Release 0.3.8 (#502) * first build for 0.3.8 * 0.3.8.0190 * 0.3.8.0202 * 0.3.8.0213 * 0.3.7.0214 * 0.3.8.0222 * 0.3.8.0246 * 0.3.8.0247 fixed typo * 0.3.8.0249 more fixes for server compiler * 0.3.8.0256 * add build number and simple batch file for packing * match build number with internal * add build numbers to server pbo's and mission files also reworked build script for more options * 0.3.8.0261 * 0.3.8.0261 * 0.3.8.0283 * 0.3.8.0284 * changelog * 0.3.8.0307 * 0.3.8.0311 * remove old BEC plugin * update redis-server.exe to latest build and full config * 0.3.8.0314 * 0.3.8.0315 * inverse logic This should correctly prevent spawning these units nearby jammer or protection zones * use pushbackUnique here * optimized loot function by using selectRandom instead of slower sqf logic * 0.3.8.0316 * make use of new getDir functionality instead of BIS fnc * add lower disconnect value to server.cfg * use new getpos functionality * 0.3.8.0317 * 0.3.8.0319 * 0.3.8.0327 * 0.3.8.0338 changelog update tba * changelog * 0.3.8.0341 * BE update * 0.3.8.0353 * changelog * removed duplicates * 0.3.8.0355 fixed error in getIDC * 0.3.8.0356 revert to BIS_fnc_param as params threw errors * 0.3.8.0357 fixes for #496 #497 * 0.3.8.0359 fixed #497 fixed #496 * 0.3.8.0365 * 0.3.8.0371 * 0.3.8.0373 * 0.3.8.0379 * 0.3.8.0381 * 0.3.8.0386 * 0.3.8.0393 * 0.3.8.0395 * 0.3.8.0396 * 0.3.8.0397 * 0.3.8.0406 * 0.3.8.0409 * 0.3.8.0410 loot balance suppress error in spawnloot make near object check based on building size * 0.3.8.0412 * 0.3.8.0414 removed classes with scope 0 test remove loot trash on gear for #498 fixed #501 * 0.3.8.0415 * same
2016-04-08 20:21:46 +00:00
if (isNil "EPOCH_plantCounter") then {
//SET COUNTER TO ZERO.
Release 0.3.8 (#502) * first build for 0.3.8 * 0.3.8.0190 * 0.3.8.0202 * 0.3.8.0213 * 0.3.7.0214 * 0.3.8.0222 * 0.3.8.0246 * 0.3.8.0247 fixed typo * 0.3.8.0249 more fixes for server compiler * 0.3.8.0256 * add build number and simple batch file for packing * match build number with internal * add build numbers to server pbo's and mission files also reworked build script for more options * 0.3.8.0261 * 0.3.8.0261 * 0.3.8.0283 * 0.3.8.0284 * changelog * 0.3.8.0307 * 0.3.8.0311 * remove old BEC plugin * update redis-server.exe to latest build and full config * 0.3.8.0314 * 0.3.8.0315 * inverse logic This should correctly prevent spawning these units nearby jammer or protection zones * use pushbackUnique here * optimized loot function by using selectRandom instead of slower sqf logic * 0.3.8.0316 * make use of new getDir functionality instead of BIS fnc * add lower disconnect value to server.cfg * use new getpos functionality * 0.3.8.0317 * 0.3.8.0319 * 0.3.8.0327 * 0.3.8.0338 changelog update tba * changelog * 0.3.8.0341 * BE update * 0.3.8.0353 * changelog * removed duplicates * 0.3.8.0355 fixed error in getIDC * 0.3.8.0356 revert to BIS_fnc_param as params threw errors * 0.3.8.0357 fixes for #496 #497 * 0.3.8.0359 fixed #497 fixed #496 * 0.3.8.0365 * 0.3.8.0371 * 0.3.8.0373 * 0.3.8.0379 * 0.3.8.0381 * 0.3.8.0386 * 0.3.8.0393 * 0.3.8.0395 * 0.3.8.0396 * 0.3.8.0397 * 0.3.8.0406 * 0.3.8.0409 * 0.3.8.0410 loot balance suppress error in spawnloot make near object check based on building size * 0.3.8.0412 * 0.3.8.0414 removed classes with scope 0 test remove loot trash on gear for #498 fixed #501 * 0.3.8.0415 * same
2016-04-08 20:21:46 +00:00
EPOCH_plantCounter = 0;
//SET LIMIT TO FIVE.
EPOCH_plantLimit = 5;
};
//STOP THE SCRIPT AND EXIT IF THE COUNTER IS TOO HIGH.
if (EPOCH_plantCounter >= EPOCH_plantLimit) exitWith {
if (_debug) then {diag_log "DEBUG: suppressed plant spawn over limit"};
};
2017-02-28 18:33:58 +00:00
// FIND A POSITION FOR PLANT PATCH prefer Hills and Vineyards
_nearbyLocations = nearestLocations [epoch_centerMarkerPosition,["VegetationVineyard","Hill"],EPOCH_dynamicVehicleArea];
if (_nearbyLocations isEqualTo []) then {
_position = [epoch_centerMarkerPosition, 0, EPOCH_dynamicVehicleArea, 10, 0, 4000, 0] call BIS_fnc_findSafePos;
Release 0.3.8 (#502) * first build for 0.3.8 * 0.3.8.0190 * 0.3.8.0202 * 0.3.8.0213 * 0.3.7.0214 * 0.3.8.0222 * 0.3.8.0246 * 0.3.8.0247 fixed typo * 0.3.8.0249 more fixes for server compiler * 0.3.8.0256 * add build number and simple batch file for packing * match build number with internal * add build numbers to server pbo's and mission files also reworked build script for more options * 0.3.8.0261 * 0.3.8.0261 * 0.3.8.0283 * 0.3.8.0284 * changelog * 0.3.8.0307 * 0.3.8.0311 * remove old BEC plugin * update redis-server.exe to latest build and full config * 0.3.8.0314 * 0.3.8.0315 * inverse logic This should correctly prevent spawning these units nearby jammer or protection zones * use pushbackUnique here * optimized loot function by using selectRandom instead of slower sqf logic * 0.3.8.0316 * make use of new getDir functionality instead of BIS fnc * add lower disconnect value to server.cfg * use new getpos functionality * 0.3.8.0317 * 0.3.8.0319 * 0.3.8.0327 * 0.3.8.0338 changelog update tba * changelog * 0.3.8.0341 * BE update * 0.3.8.0353 * changelog * removed duplicates * 0.3.8.0355 fixed error in getIDC * 0.3.8.0356 revert to BIS_fnc_param as params threw errors * 0.3.8.0357 fixes for #496 #497 * 0.3.8.0359 fixed #497 fixed #496 * 0.3.8.0365 * 0.3.8.0371 * 0.3.8.0373 * 0.3.8.0379 * 0.3.8.0381 * 0.3.8.0386 * 0.3.8.0393 * 0.3.8.0395 * 0.3.8.0396 * 0.3.8.0397 * 0.3.8.0406 * 0.3.8.0409 * 0.3.8.0410 loot balance suppress error in spawnloot make near object check based on building size * 0.3.8.0412 * 0.3.8.0414 removed classes with scope 0 test remove loot trash on gear for #498 fixed #501 * 0.3.8.0415 * same
2016-04-08 20:21:46 +00:00
} else {
_selectedLocation = locationPosition (selectRandom _nearbyLocations);
_position = [_selectedLocation, 0, 1000, 10, 0, 4000, 0] call BIS_fnc_findSafePos;
};
//CHECK FOR PROTECTED AREA WITIN 2000 METERS.
_restricted = nearestObjects [_position, ["ProtectionZone_Invisible_F"], 2000];
if(count _restricted > 0) exitWith {
if (_debug) then {diag_log "DEBUG: suppressed PLANT PATCH spawn TRADER too close"};
};
//CHECK FOR JAMMERS IN THE AREA WITHIN 1000 METERS.
_jammers = nearestObjects[_position, ["PlotPole_EPOCH"], 1000];
if(count _jammers > 0) exitWith {
if (_debug) then {diag_log "DEBUG: suppressed PLANT PATCH spawn jammer too close"};
Release 0.3.8 (#502) * first build for 0.3.8 * 0.3.8.0190 * 0.3.8.0202 * 0.3.8.0213 * 0.3.7.0214 * 0.3.8.0222 * 0.3.8.0246 * 0.3.8.0247 fixed typo * 0.3.8.0249 more fixes for server compiler * 0.3.8.0256 * add build number and simple batch file for packing * match build number with internal * add build numbers to server pbo's and mission files also reworked build script for more options * 0.3.8.0261 * 0.3.8.0261 * 0.3.8.0283 * 0.3.8.0284 * changelog * 0.3.8.0307 * 0.3.8.0311 * remove old BEC plugin * update redis-server.exe to latest build and full config * 0.3.8.0314 * 0.3.8.0315 * inverse logic This should correctly prevent spawning these units nearby jammer or protection zones * use pushbackUnique here * optimized loot function by using selectRandom instead of slower sqf logic * 0.3.8.0316 * make use of new getDir functionality instead of BIS fnc * add lower disconnect value to server.cfg * use new getpos functionality * 0.3.8.0317 * 0.3.8.0319 * 0.3.8.0327 * 0.3.8.0338 changelog update tba * changelog * 0.3.8.0341 * BE update * 0.3.8.0353 * changelog * removed duplicates * 0.3.8.0355 fixed error in getIDC * 0.3.8.0356 revert to BIS_fnc_param as params threw errors * 0.3.8.0357 fixes for #496 #497 * 0.3.8.0359 fixed #497 fixed #496 * 0.3.8.0365 * 0.3.8.0371 * 0.3.8.0373 * 0.3.8.0379 * 0.3.8.0381 * 0.3.8.0386 * 0.3.8.0393 * 0.3.8.0395 * 0.3.8.0396 * 0.3.8.0397 * 0.3.8.0406 * 0.3.8.0409 * 0.3.8.0410 loot balance suppress error in spawnloot make near object check based on building size * 0.3.8.0412 * 0.3.8.0414 removed classes with scope 0 test remove loot trash on gear for #498 fixed #501 * 0.3.8.0415 * same
2016-04-08 20:21:46 +00:00
};
//CHECK TO SEE IF PLAYERS WITHIN 900 METERS.
_playersNearby = _position nearEntities[["Epoch_Male_F", "Epoch_Female_F"], 900];
if(count _playersNearby > 0) exitWith {
if (_debug) then {diag_log "DEBUG: suppressed PLANT PATCH spawn PLAYER too close"};
};
// IF WE MADE IT THIS FAR, WE CAN SPAWN SOME SHIT.
if ((count _position) == 2) then{
// vary plant count and scatter by plant type
_plantCount = 1;
_scatter = 10;
_decayTime = 1200;
switch _plant do {
case "Goldenseal_EPOCH": {
_plantCount = (floor(random(4)))+3;
_scatter = 10;
};
case "Poppy_EPOCH": {
_plantCount = (floor(random(2)))+3;
_scatter = 15;
};
case "Pumpkin_EPOCH": {
_plantCount = (floor(random(3)))+5;
_scatter = 20;
};
};
Release 0.3.8 (#502) * first build for 0.3.8 * 0.3.8.0190 * 0.3.8.0202 * 0.3.8.0213 * 0.3.7.0214 * 0.3.8.0222 * 0.3.8.0246 * 0.3.8.0247 fixed typo * 0.3.8.0249 more fixes for server compiler * 0.3.8.0256 * add build number and simple batch file for packing * match build number with internal * add build numbers to server pbo's and mission files also reworked build script for more options * 0.3.8.0261 * 0.3.8.0261 * 0.3.8.0283 * 0.3.8.0284 * changelog * 0.3.8.0307 * 0.3.8.0311 * remove old BEC plugin * update redis-server.exe to latest build and full config * 0.3.8.0314 * 0.3.8.0315 * inverse logic This should correctly prevent spawning these units nearby jammer or protection zones * use pushbackUnique here * optimized loot function by using selectRandom instead of slower sqf logic * 0.3.8.0316 * make use of new getDir functionality instead of BIS fnc * add lower disconnect value to server.cfg * use new getpos functionality * 0.3.8.0317 * 0.3.8.0319 * 0.3.8.0327 * 0.3.8.0338 changelog update tba * changelog * 0.3.8.0341 * BE update * 0.3.8.0353 * changelog * removed duplicates * 0.3.8.0355 fixed error in getIDC * 0.3.8.0356 revert to BIS_fnc_param as params threw errors * 0.3.8.0357 fixes for #496 #497 * 0.3.8.0359 fixed #497 fixed #496 * 0.3.8.0365 * 0.3.8.0371 * 0.3.8.0373 * 0.3.8.0379 * 0.3.8.0381 * 0.3.8.0386 * 0.3.8.0393 * 0.3.8.0395 * 0.3.8.0396 * 0.3.8.0397 * 0.3.8.0406 * 0.3.8.0409 * 0.3.8.0410 loot balance suppress error in spawnloot make near object check based on building size * 0.3.8.0412 * 0.3.8.0414 removed classes with scope 0 test remove loot trash on gear for #498 fixed #501 * 0.3.8.0415 * same
2016-04-08 20:21:46 +00:00
_plants = [];
// CREATE THE PATCH OF PLANTS.
for "_i" from 1 to _plantCount step 1 do {
_plants pushBack createVehicle[_plant, _position, [], _scatter, "NONE"];
};
_timeStamp = diag_tickTime;
2015-06-04 14:11:41 +00:00
// SET UP THE MARKER.
if (_showPlantMarkers) then{
_marker = createMarker[str(_position), _position];
2015-06-04 14:11:41 +00:00
_marker setMarkerShape "ICON";
_marker setMarkerType "waypoint";
2015-06-04 14:11:41 +00:00
_marker setMarkerColor "ColorGreen";
};
// TICK COUNTER + 1 SPAWNED PLANT PATCH.
EPOCH_plantCounter = EPOCH_plantCounter + 1;
// wait loop to handle plant patch
while {true} do {
private _plantsLeft = _plants select {!isNull _x};
// Wait for all plants to be picked or to decay
if (_plantsLeft isEqualTo [] || (diag_tickTime - _timeStamp) > _decayTime) exitWith {
// TICK THE COUNTER DOWN SO A NEW PLANT PATCH WILL SPAWN TO TAKE ITS PLACE.
EPOCH_plantCounter = EPOCH_plantCounter - 1;
// DELETE THAT MARKER.
if (_showPlantMarkers) then{
deleteMarker _marker;
};
// remove any left over "dead" plants (only if decayTime is reached)
{deleteVehicle _x} forEach _plantsLeft;
};
// set marker to brown to show 50% decay but not if already marked as picked (red).
if !(getMarkerColor _marker in ["ColorRed","ColorBrown"]) then {
if ((diag_tickTime - _timeStamp) > (_decayTime/2)) then {
_marker setMarkerColor "ColorBrown";
};
};
// WAIT FOR A PLAYER TO Pick one plant then set marker to red
if (count _plantsLeft != _plantCount) then {
if (_showPlantMarkers) then{
if (getMarkerColor _marker != "ColorRed") then {
_marker setMarkerColor "ColorRed";
};
};
};
sleep 30;
};
2015-07-24 14:16:25 +00:00
};
// END SCRIPT.