Jump to content
Sign in to follow this  
Cards525

Repeat & Randomize?

Recommended Posts

Allo all. Here to bother you with another useless script I need fixed.

The goal of the script is to create a marker within 150M of the object. The object is set to respawn and re-execute this script every time it is destroyed.

if (playerSide == West) then {
_plMarker = createMarkerLocal ["Cache1", position Cache_1];
_plMarker setMarkerColorLocal "ColorBlack";
_plMarker setMarkerTypeLocal "ELLIPSE";
_plMarker setMarkerTextLocal format["Ammo cache?"];
_plMarker setMarkerSizeLocal [30, 30];
_plMarker setMarkerDirLocal getdir Cache_1;
};
Hint "Complete";

I need help with :

-Setting the createmarker command to work off a 150M radius of the object.

-When the object respawns, it is created at least 300M away from its previous position.

Thank you in advance

Share this post


Link to post
Share on other sites

Local only creates things for the player. It's unnecessary to use createMarkerLocal if you're making a SP mission.

_pos = [(getpos Cache1 select 0) + 15, (getpos Cache1 select 1) + 15, 0];
_plMarker = createMarker ["Cache1",_pos];

For the marker to properly respawn use EHandler Killed

player addEventHandler ["Killed","[player] execVM ""mkr.sqf"""];

mkr.sqf

deleteMarker _plMarker;
if (playerSide == West) then { 
_pos = [(getpos Cache1 select 0) + 15, (getpos Cache1 select 1) + 15, 0];
_plMarker = createMarker ["Cache1", _pos]; 
_plMarker setMarkerColor "ColorBlack";
_plMarker setMarkerType "ELLIPSE"; 
_plMarker setMarkerText format["Ammo cache?"]; 
_plMarker setMarkerSize [30, 30]; 
_plMarker setMarkerDir (getdir Cache_1);
}; 
Hint "Complete";

Hope this helps.

Share this post


Link to post
Share on other sites

Its for multiplayer :), if that makes any difference.

And thank you.

---------- Post added at 02:44 PM ---------- Previous post was at 01:51 PM ----------

Uh, ran into an issue. The marker won't delete and re-create.

deleteMarker _plMarker;
if (playerSide == West) then { 
_pos = [(getpos Cache_1 select 0) + 15, (getpos Cache_1 select 1) + 15, 0];
_plMarker = createMarker ["Cache1", _pos]; 
_plMarker setMarkerColor "ColorRed";
_plMarker setmarkerShape "Ellipse";
_plMarker setMarkerText format["Ammo cache?"]; 
_plMarker setMarkerSize [150, 150]; 
_plMarker setMarkerDir (getdir Cache_1);
}; 
Hint "Complete";  

The init of the box is

0 = [this, 300] execVM "Scripts\crB_scripts\crB_HousePos.sqf";
0 = [this] execvm "Scripts\marker.sqf";
veh = [this, 10, 9999999, 0, False, FALSE, "0 = [this, 250] execVM 'Scripts\crB_scripts\crB_HousePos.sqf';0 = [this] execvm 'Scripts\marker.sqf'"] execVM "Scripts\vehicle.sqf";

Share this post


Link to post
Share on other sites

You need to add a Killed EventHandler for it to work, as the init will only run if the player re-jips, it doesn't re-run if he dies.

Share this post


Link to post
Share on other sites

Just to verify. This is for an MP mission. Multiple people and it needs to run for a long ass time. Just to clarify that.

player addEventHandler ["Killed","[player] execVM "mkr.sqf""] how will I re'do that then for multiple people

Share this post


Link to post
Share on other sites

Yes everytime it gets destroyed, it will rerun your script. But here you're trying to delete a marker out of it's scope. Even though if you already created the marker, it's a local variable, so when the new script runs, that script doesn't know anything about _plMarker. Use the markers name or global handle. unless you pass the _local variable to the script.

[color=#ff0000]deleteMarker _plMarker; [/color]
if (playerSide == West) then {  
_pos = [(getpos Cache_1 select 0) + 15, (getpos Cache_1 select 1) + 15, 0];
_plMarker = createMarker ["Cache1", _pos];  
_plMarker setMarkerColor "ColorRed"; 
_plMarker setmarkerShape "Ellipse"; 
_plMarker setMarkerText format["Ammo cache?"];  
_plMarker setMarkerSize [150, 150]; 
_plMarker setMarkerDir (getdir Cache_1);  
}; 

Edited by Iceman77

Share this post


Link to post
Share on other sites

Question. Would it be easier to replace the _PLMarker variable with a pre-placed marker and move it each time?

IE :

if (playerSide == West) then {  
_pos = [(getpos Cache_1 select 0) + 15, (getpos Cache_1 select 1) + 15, 0];
Markurhurhur  setmarkerpos _Pos; 
Markurhurhur setMarkerDir (getdir Cache_1);  
};

Something along those lines?

Edited by Cards525

Share this post


Link to post
Share on other sites

Sure. Try this, it's untested. I just felt like writing some pseudo code, and I'm probably out of my mind :p

Init.sqf

[] call compile preProcessFile "Movemarker.sqf";
cache_1 addEventHandler ["Killed","[cache_1, "Markerururur"] Spawn MoveMrk_FNC"];
[cache_1, "Markerururur"] Spawn MoveMrk_FNC;


MoveMarker.sqf

MoveMrk_FNC =
{

              sleep 0.005;
              _This Select 1 (SetMarkerAlpha 0);
              WaitUntil {Alive _this Select 0};
              WaitUntil {GetDammage _This Select 0 < 0.5};

              Private ["_Marker","_MarkerPos"];
               If (IsServer) Then 
              {
                  _Obj = _This Select 0;
                  _Marker = _This Select 1;
                  _Distance = 50; // Adjust this value
                  _Marker SetMarkerAlpha 1;
                  _Coord = Random _Distance - Random _Distance;
                  _OffSet = [_Coord, _Coord, 0];
                  _MarkerPos = _Obj modelToWorld _OffSet;
                   Publicvariable "_MarkerPos";
              };

                              If (Side Player == West) then 
                              {
                                  _Marker setmarkerpos _MarkerPos;
                                  Publicvariable _Marker;
                              };


};

Edited by Iceman77

Share this post


Link to post
Share on other sites

nothin. :(

Does the script have to let the cache be destroyed before it can run or will it run with a fresh cache?

Share this post


Link to post
Share on other sites

The code didn't work.

Could you try attaching it in an example mission? Maybe Im just putting it in wrong

Share this post


Link to post
Share on other sites

Sorry bud, as I said, it was an idea out of left field! There was never any working example, but, if you don't get your question answered soon, I'll write something that works (tested).

Share this post


Link to post
Share on other sites

this will work... jut need to amend the distances - also not sure how or where you are spawning your cache - but this is a mock example that works to get you started :)

//create ammobox/cache object named cache_1 - place this code in its init.... cachestart = [] execvm "createmarker.sqf";

init.sqf

waitUntil { isServer ||!isNull player }; 
waitUntil { !isNil "BIS_MPF_InitDone" }; 
waitUntil { BIS_MPF_InitDone };

if (isServer) then 
{
"objmkr" addPublicVariableEventHandler 
{
	_marker = createMarker [((_this select 1) select 0), position ((_this select 1) select 1)];
	"Cache1" setMarkerShape "ELLIPSE";
//			"Cache1" setMarkerText "Ammo cache?";
		"Cache1" setMarkerSize [30, 30];
		"Cache1" setMarkerColor "ColorBlack";
};
};
[] call compile preProcessFile "MoveMarker.sqf";
[] call compile preProcessFile "Cache.sqf";
onplayerConnected {execVM "JipMarkers.sqf"};

Cache.sqf

CacheMarker = {
		//move the Cache_1 first or destroy it and then recreate it
		deletevehicle Cache_1;
		[] call MoveMarker;

	}; 

//createmarker.sqf

Private ["_loc"];
Cache_1 addEventHandler["killed", { (_this select 0) spawn CacheMarker; }]; 
		_distances = 50;
		_ang = random 360;  	
		_dis = _distances; 
		_dx = sin(_ang)*_dis; 
		_dy = cos(_ang)*_dis; 
		_loc = [((getpos Cache_1) select 0) + _dx, ((getpos Cache_1) select 1) + _dy, 0];

if (isServer) then 
   {
		if (playerSide == West) then 
		{				
		[nil,nil,rHINT,"Cache Marker Initialised- Check Map!"] call RE;
		_marker = createMarker ["Cache1", _loc];
		"Cache1" setMarkerShape "ELLIPSE";
//			"Cache1" setMarkerText "Ammo cache?";
		"Cache1" setMarkerSize [30, 30];
		"Cache1" setMarkerColor "ColorBlack";
		};			
	} 		
	else 
		{
			if (playerSide == West) then 
			{					
			HINT "Cache Marker Initialised- Check Map!";

			objmkr = ["Cache1", _loc]; publicVariable "objmkr";
			};			
		};

//JipMarkers.sqf


"Cache1" setMarkerPos (getMarkerPos "Cache1");

MoveMarker .sqf

MoveMarker = {

	Private ["_loc","_loc2"];


	_distances1 = 50;  //move marker
	_ang1 = random 360;  	
	_dis1 = _distances1; 
	_dx1 = sin(_ang1)*_dis1; 
	_dy1 = cos(_ang1)*_dis1; 
	_loc1 = [((getmarkerpos "Cache1") select 0) + _dx1, ((getmarkerpos "Cache1") select 1) + _dy1, 0];


	if (isserver) then {
				[nil,nil,rHINT,"Cache Marker Destroyed and recreated - Check Map!"] call RE;
				"cache1" setmarkerpos _loc1;

		 		}


		 else {

			 "cache1" setmarkerpos _loc1;

			 };


	_distances = 50;  //move marker
	_ang = random 360;  	
	_dis = _distances1; 
	_dx = sin(_ang)*_dis; 
	_dy = cos(_ang)*_dis; 
	_loc = [((getmarkerpos "Cache1") select 0) + _dx, ((getmarkerpos "Cache1") select 1) + _dy, 0];

	Cache_1 = "USBasicWeapons_EP1" createvehicle (_loc); PublicVariable "Cache_1";
	Cache_1 addEventHandler["killed", { (_this select 0) spawn CacheMarker; }]; 

};

Share this post


Link to post
Share on other sites

mikie your a genius!

Iceman, yours was good as well :), got me some framework to use :D

Thanks e'reyone.

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  

×