Jump to content
Sign in to follow this  
Nephris1

MP: addaction

Recommended Posts

Hi guys,

I tried to create an addaction script for MP.

My scripting knowledge is not the best, but this is what i ve done so far.

(the basic idea: a case must be found by 2 opposite teams, and be transported to an extract point.Therefore the case gets an addaction entry "take case".As soon the a player took the case it will ported to a dummy location.If the player dies the case gets ported back to the position of the died player who took it.

As addition (and there begins my prob) the player shall be able to detach the case awhile carrying it and take it again, e.g. to set up a trap.

The case gets a marker (gps signal), that pops over to the player who carries it.

init.sqf

/////////////////////////////////////////////
/////   Koffer AddAction   /////
/////////////////////////////////////////////


 _actionID = 0;

 if ! (IsDedicated)then
 			{

			_actionID = Koffer addAction ["take case", "take.sqf"];    // Koffer = case

 			};

take. sqf

  _caller 	= _this select 1;
 _id 		= _this select 2;

ID = _caller addAction ["detach case", "detach.sqf"];
if !(player == _caller)exitwith{};

if ( (!isServer) && (detach) ) then
{

while {alive _caller} do {
//if (detach) then {exit} else {
Koffer setpos getpos place;                       // place = dummy position
"mkr" setmarkerpos getpos _caller;


sleep 1;		

 // Koffer removeaction _id;
 //Deletevehicle Koffer;
//hint"Debug: Koffer klar ";



 if (!(alive _caller)) then {
  Koffer setpos getpos _caller;
  "mkr" setmarkerpos getpos Koffer;



   };
};


};

detach.sqf

 _caller2 	= _this select 1;
 _id 		= _this select 2;

//if !(player == _caller2)exitwith{};

  detach = true;
publicVariable "detach";

 _caller2 removeaction _id;

 Koffer setpos getpos _caller2;
  "mkr" setmarkerpos getpos Koffer;

   if (true)exitwith{};

The player can take the case (the case gets ported to dummy place), but when he wants to detach it, the case simply jumps for 1 sec (sleep 1) to players position , and then back to its dummy place and the player gets more and more "detach" action entryies.

I am sure the proiblem is anywhere inside a "while loop" in the take.sqf, but i guess my logical knowledge is not bif enough to get the point.

Does anyone see the problem?

What optimisation should i do to get it working properly in MP (dedicated?)

Share this post


Link to post
Share on other sites

Hi Nephris1!

Let's try this ;)

init.sqf

//variable initialization
_actionID = 0;
detach = true;
detached = true;

if !(IsDedicated) then{

   _actionID = Koffer addAction ["take case", "take.sqf"];    // Koffer = case

};

take.sqf

_caller 	= _this select 1;
_id 		= _this select 2;

ID = _caller addAction ["detach case", "detach.sqf"];

if !(player == _caller)exitwith{};

if ( (!isServer) && (detach) ) then
{
Koffer setpos getpos place;                       // place = dummy position
detached = false;
while {alive _caller && !(detached)} do {

	"mkr" setmarkerpos getpos _caller;
	sleep 1;		

	if (!(alive _caller)) then {
		Koffer setpos getpos _caller;
		"mkr" setmarkerpos getpos Koffer;
               };
};
};

detach.sqf

_caller2 	= _this select 1;
_id 		= _this select 2;

detach = true;
publicVariable "detach";

_caller2 removeaction _id;

Koffer setpos getpos _caller2;
"mkr" setmarkerpos getpos Koffer;
detached = true;

if (true) exitwith{};

There was a problem in the while loop. The code works very well in MP! I've tested it ;)

Edited by goliath86

Share this post


Link to post
Share on other sites

Init of an briefcase object in editor:

this addAction ["Take case","case.sqf","take"]; caseholder = objNull

case.sqf:

_o = _this select 0;
_p = _this select 1;

switch (_this select 3) do {
 case "take": {
   caseholder = _p;
   publicvariable "caseholder";
   deletevehicle _o;
   _id = _p addaction ["Drop case","case.sqf","drop"];

   if (isnil "markerCase") then {
     _m = createmarker ["markerCase",getpos _p];
     _m setmarkershape "icon";
     _m setmarkertype "dot";
     _m setmarkercolor "colororange";
   };

   while {sleep 3; alive _p && caseholder == _p} do {
     "markerCase" setmarkerpos getpos _p;
   };
   _p removeaction _id;

   _o = "Suitcase" createvehicle [1,1,1];
   _o setposasl getposasl _p;
   _o setvehicleinit "this addaction [""Take case"",""case.sqf"",""take""]";
   _o setvehicleinit "player reveal this";
   processInitCommands;
 };
 case "drop": {
   _p removeaction (_this select 2);
   caseholder = objnull;
   publicvariable "caseholder";
 };
};

To check if the case carrier is in the extract area use trigger like:

activation: anybody or side of the carrier
condition: caseholder in thislist

Share this post


Link to post
Share on other sites

Sample mission maybe?

How would I make a mission that AI guards for example 10 briefcases and 2 teams battle them (AI) and each other to bring them back to their base?

And if carrier dies/vehicle explodes it returns to the starting pos?

Share this post


Link to post
Share on other sites
Sample mission maybe?

http://derfel.org/arma2/scripts/briefcase.rar

How would I make a mission that AI guards for example 10 briefcases and 2 teams battle them (AI) and each other to bring them back to their base?

And if carrier dies/vehicle explodes it returns to the starting pos?

Isn't all the fun in figuring it out. ;) There should be most of the stuff in the code above, just change the alive check to create the case at the starting pos instead of the corpse etc.

Share this post


Link to post
Share on other sites

Thx a lot for your effort guys

:thumbs up:

Gonna check it when off duty and Mr. Heimbergers`smoker leg got finally sawed off :yay:

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  

×