Forum Jump :

Author Message


Posts: 7
Rank:


Level: Member

Country: us
Location:
Occupation:
Age: 42
In-game name:

 
#1 Posted at 2015-12-10 04:10        
     
I have a script so that when the player's cursor is on some objects the player can "Search" for loot. The script works great as it creates the LootBox and removes it 15 mins later. The issue I'm having is that this is a MP server and if the player that does the Search logs off before the 15 mins is up the LootBox will not be removed. I know this is because I have the uisleep 900, but I was wondering if there is a way to make the script finish when the time is up even if the user has logged off. Any help with this will be greatly appreciated.



private ["_playerPos","_nearobjects","_Object"];

call gear_ui_init;

_playerPos = getPosATL player;
_nearobjects = count nearestObjects [_playerPos, ["LootBox"], 10] > 0;

if (vehicle player == player) then {
if (!_nearobjects ) then {
disableUserInput true;
player playActionNow "PutDown";
taskhint ["Now searching the area for loot.", [0, 1, 0, 1], "taskDone"];
uisleep 1;
_Object = createVehicle ["LootBox", (player modelToWorld [0,1,0]),[], 0, "CAN_COLLIDE"];
_Object setVehiclePosition [(player modelToWorld [0,0.5,0.1]), [], 0, "CAN_COLLIDE"];
[_Object,"XMMSAmmoL3"] call LootBox_Fill;
uisleep 1;
disableUserInput false;
disableUserInput true;
disableUserInput false;
uisleep 900;
deleteVehicle _Object;
}else{
taskhint ["A search has already been executed in this area.", [1, 0, 0, 1], "taskFailed"];
};
}else{
taskhint ["You are unable to search while you are in a vehicle.", [1, 0, 0, 1], "taskFailed"];
};


Author Message


Posts: 1589
Rank:


Level: Member

Country: pf
Location: Tahiti
Occupation: too many Arma
Age: 60
In-game name: Kobayashi Maru

 
#2 Posted at 2015-12-10 05:42        
     
I didn't test thiat but what I'll try:

First, identify specific lootboxes for each player :

a variable at each player's initialization ( initPlayerLocal.sqf is fine):
 plyr_loot = 0;

then in your script:
_Object = createVehicle ["LootBox", (player modelToWorld [0,1,0]),[], 0, "CAN_COLLIDE"];
player setVariable ["loot_"+ name player + str(plyr_loot), _object];
plyr_loot = plyr_loot + 1;
...

then further:
["someId", "onPlayerDisconnected", {
       for "_i" from 0 to plyr_loot do {
	 deleteVehicle  (player getvariable "loot_" + name player + str(_i) );
      };
}] call BIS_fnc_addStackedEventHandler;

Something like that. I'm not sure it's the best code ever written about your aim.

PLEASE CONTACT ME ON BI FORUMS FOR ANY SCRIPT / MOD QUESTION. TKS

Advertisement


Author Message


Posts: 7
Rank:


Level: Member

Country: us
Location:
Occupation:
Age: 42
In-game name:

 
#3 Posted at 2015-12-10 09:13        
     
I think call BIS_fnc_addStackedEventHandler; may be only ArmA 3 It's not working for me and this is on a ArmA II OA Server.
Is it possible to make the script finishing running for the remainder of the time even if the user is not connected? If not how would I go about making the server delete the LootBox 15 mins after a player creates them. Like each LootBox has a 15 min clock that counts down then deletes itself. Again thank you for the help I've been on this for 4 days now and I'm about out of coffee lol

Also so you can better understand I've attached a video of how the Search allows the player to look for a LootBox

Video...


Author Message


Posts: 1589
Rank:


Level: Member

Country: pf
Location: Tahiti
Occupation: too many Arma
Age: 60
In-game name: Kobayashi Maru

 
#4 Posted at 2015-12-10 14:49        
     
Sorry, i didn't remark you're in Arma2 OA. Did you try "onplayerDisconnected" comand? https://community.bistudio.com/wiki/onPlayerDisconnected

I personally use a distance condition for loot presence, instead of a timing.

PLEASE CONTACT ME ON BI FORUMS FOR ANY SCRIPT / MOD QUESTION. TKS

Author Message


Posts: 7
Rank:


Level: Member

Country: us
Location:
Occupation:
Age: 42
In-game name:

 
#5 Posted at 2015-12-15 06:29        
     
Okay so I removed this code below from my LootBox search script.

uisleep 900;
deleteVehicle _Object;

This has made the LootBox spawn and stay even if the client disconnects. Then I made the script below on the server to cleanup the spawned LootBox.
	if (isServer) then {
		[] spawn {
			while {true} do {
				diag_log format ["[Purge Check]: at %1", time];
				_Objects1 = (allMissionObjects "LootBox");
				_Objects2 = (allMissionObjects "Camp_Fire");
				_ObjectsTotal = _Objects1 + _Objects2;

				{
					_nearby = {isPlayer _x} count (_x nearEntities [["CAManBase"], 300]);
					if (_nearby == 0) then {
						diag_log format ["[Purge]: Deleting %1", _x];
						deleteVehicle _x;
					};
				} forEach _ObjectsTotal;
			uiSleep 900;
			};
		};
	};
All of this is working but it removes all LootBoxes every 15 mins even if a LootBox is less than 5 mins old. Now I need to learn how to make it only remove Lootboxes that are > 15 mins from the time they are spawned. *YAHOO*


Author Message


Posts: 1589
Rank:


Level: Member

Country: pf
Location: Tahiti
Occupation: too many Arma
Age: 60
In-game name: Kobayashi Maru

 
#6 Posted at 2015-12-15 08:02        
     
you need to add a variable on each box. Try diag_ticktime for dating:
list_of_crates = [];
create _objet....
_object setVariable ["time_start", diag_Ticktime]; 
list_of_crates pushback _object;

then check this variable in a loop:
0 = [] spawn {
while {true} do {
{ if (diag_Ticktime > (_x geVariable "time_start") + 300) then {deleteVehicle _x} } foreach list_of_crates;
sleep 5;
};
};

PLEASE CONTACT ME ON BI FORUMS FOR ANY SCRIPT / MOD QUESTION. TKS