Jump to content
Charles Barkley

Deleting object after action added to it has run

Recommended Posts

I want to have a backpack initialized with an action to build up a campsite. For now I have the working script to add the action to the backpack and run the script as the action is triggered/used.

Now I want the backpack to disappear after the campsite has been built up.

 

I tried to call deleteVehicle but failed. I think it is because the script is bound to the object that I want to remove and therefore does not work.


What I am looking for is like a custom event I might create? Like publishing an event called campFinished and registering and event handler to my object which will kill it in the callback function.

Is something like this possible? If not - what is the common approach to achieve a similar result?

 

Complete code is open here: https://github.com/xetra11/ReconMod 

If anybody wants to reproduce it on it's own.

 

fn_backpackInit.sqf

params ["_backpackItem"];

format['init backpack: %1', typeOf _backpackItem] call ReconMod_fnc_log;
_backpackItem addAction ["Build Recon Camp", ReconMod_fnc_buildCampsite];

 

fn_buildCampsite.sqf (last line is my try to delete the backpack - does not work)

params ["_target", "_caller"];
private ["_message", "_campComposition"];

_message = format['%1 is building up a campsite', name _caller];
hint _message;

'playing build up animation' call ReconMod_fnc_log;
_caller playMove "AinvPknlMstpSnonWnonDnon_medicUp3";

_campComposition = [
	["Land_FirePlace_F",[0.407715,-0.0605469,0.00431442],0,1,0,[],"","",true,false],
	["Land_WoodenLog_F",[1.30078,-1.04712,4.19617e-005],0,1,0,[],"","",true,false],
	["Land_Ground_sheet_folded_khaki_F",[-0.0664063,1.74048,8.01086e-005],260.778,1,0,[],"","",true,false],
	["Land_Laptop_02_unfolded_F",[1.31445,-1.0542,0.5],136.964,1,0,[],"","",true,false],
	["Land_Sleeping_bag_F",[-1.36768,-0.928467,-0.00595856],37.9681,1,0,[],"","",true,false],
	["Land_Sleeping_bag_brown_folded_F",[2.34326,-0.0712891,-3.8147e-006],245.926,1,0,[],"","",true,false],
	["Land_Sleeping_bag_F",[-0.641113,1.8584,-0.0278778],174.749,1,0,[],"","",true,false],
	["Land_Sleeping_bag_F",[2.49707,0.719482,0.0018959],266.758,1,0,[],"","",true,false],
	["Land_Ground_sheet_khaki_F",[3.14111,-0.101318,3.8147e-006],96.0028,1,0,[],"","",true,false],
	["Land_CanisterFuel_F",[-2.85938,1.72168,0.000972748],191.718,1,0,[],"","",true,false],
	["Land_Ammobox_rounds_F",[3.03857,1.61816,0.00495911],218.802,1,0,[],"","",true,false],
	["Land_TentDome_F",[-4.22217,-0.0065918,0.00314331],181.884,1,0,[],"","",true,false],
	["Land_Ammobox_rounds_F",[3.88281,1.70947,9.53674e-005],143.886,1,0,[],"","",true,false],
	["Land_TentDome_F",[-2.9668,3.74658,0.0138435],215.286,1,0,[],"","",true,false],
	["Land_TentDome_F",[3.51807,3.35718,0.00638962],320.122,1,0,[],"","",true,false]
];

'constructing camp...' call ReconMod_fnc_log;
[position _caller, 0, _campComposition] call BIS_fnc_ObjectsMapper;
'camp build!' call ReconMod_fnc_log;

hint 'recon camp has been built up';

_message = format['deleting campsite building item: %1', _target];
_message call ReconMod_fnc_log;
deleteVehicle _target;

 

Share this post


Link to post
Share on other sites

What is class name of _backpackItem/_target?

If it is something like "WeaponHolder" then use this code:

clearBackpackCargoGlobal _target;

deleteVehicle _target;

If it is backback then use this code:

_holder = objectParent _target;

clearBackpackCargoGlobal _holder;

deleteVehicle _holder;

 

Share this post


Link to post
Share on other sites

Can you explain why I first have to add it to a container before I remove it? Because placing it in the first place - isn't the backpack added to a global (world) container therefore and should be "deletable" as well?

Share this post


Link to post
Share on other sites

@Charles Barkley, when you create backpack (using createVehicle) or place it in editor holder creates automatically and backpack is placed to holder. So, to delete backpack you need clear holder (using clearBackpackCargo[Global]), then delete holder.

  • Like 1

Share this post


Link to post
Share on other sites

This is my code now

 

_holder objectParent _target;
clearBackpackCargoGlobal _holder;
deleteVehicle _holder;

and this my error message when I run the action on the backpack


 

_holder objectParent _target;
clearBackp>
20:53:10   Error position: <_holder objectParent _target;
clearBackp>
20:53:10   Error Undefined variable in expression: _holder
20:53:10 File camp\fn_buildCampsite.sqf [ReconMod_fnc_buildCampsite], line 40

 

Share this post


Link to post
Share on other sites

ohhhh... 

 

It is so weird with these differences in the syntax to figure such mistakes out :3

 

Thanks!

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

×