Bnae 1431 Posted February 16, 2016 Hello, I'm wondering if it's possible to give function to all the object/ items of same kind. For example, i wan't to place items on the ground with my random spawn script and i wan't that one of the items have "addAction" on the init. And the addAction has two functions aswell. Init of item this addAction ["Pick up", "script.sqf"]; script.sqf _remove = _this select 0; removeAllAction _remove; my_code = my_code +1; Any ideas? Share this post Link to post Share on other sites
Nikander 123 Posted February 16, 2016 I'm wondering if it's possible to give function to all the object/ items of same kind See the commands typeOf and isKindOf For example, if your spawned objects are in array "_objects", you could add your action to every bloodbag like this: { if (typeOf _x isEqualTo "Land_BloodBag_F") then { _x addAction ["Pick up", "script.sqf"]; }; } forEach _objects; I Hope this helps, Nikander Share this post Link to post Share on other sites
donelsarjo 60 Posted February 16, 2016 then have a look at your random spawn script. there is propaby a line like this: _obj = "some_item" createVehicle _somePosition; you could add following to it: _obj = "some_item" createVehicle _somePosition; if (typeOf _obj isEqualTo "someThingUwant") then {[_obj,["Pick up", "script.sqf"]] remoteExecCall ["addaction", -2]} // or 0 instead of -2 Share this post Link to post Share on other sites
Bnae 1431 Posted February 17, 2016 See the commands typeOf and isKindOf For example, if your spawned objects are in array "_objects", you could add your action to every bloodbag like this: { if (typeOf _x isEqualTo "Land_BloodBag_F") then { _x addAction ["Pick up", "script.sqf"]; }; } forEach _objects; I Hope this helps, Nikander then have a look at your random spawn script. there is propaby a line like this: _obj = "some_item" createVehicle _somePosition; you could add following to it: _obj = "some_item" createVehicle _somePosition; if (typeOf _obj isEqualTo "someThingUwant") then {[_obj,["Pick up", "script.sqf"]] remoteExecCall ["addaction", -2]} // or 0 instead of -2 Excellent! These will save a lot of time. Thanks both of you! Share this post Link to post Share on other sites
Lala14 135 Posted February 17, 2016 why not instead change it so that the addAction is on the player and use cursorTarget to identify if the object they're currently looking at will work (isKindOf) e.g. player addAction ["Pick Up",{[(_this select 0), cursorTarget] execVM "script.sqf"},nil,1.5,true,true,'',"cursorTarget isKindOf 'Land_BloodBag_F'"];don't forget though to add the action every time the player respawns! Share this post Link to post Share on other sites
Bnae 1431 Posted February 17, 2016 why not instead change it so that the addAction is on the player and use cursorTarget to identify if the object they're currently looking at will work (isKindOf) e.g. player addAction ["Pick Up",{[(_this select 0), cursorTarget] execVM "script.sqf"},nil,1.5,true,true,'',"cursorTarget isKindOf 'Land_BloodBag_F'"];don't forget though to add the action every time the player respawns! This will come handy as well, thank you! Share this post Link to post Share on other sites
davidoss 552 Posted February 17, 2016 Why you add addaction to player instead to object? Share this post Link to post Share on other sites
dreadedentity 278 Posted February 17, 2016 Why you add addaction to player instead to object? There are times when you want to add an action to an object, but the hitbox is wacky. In these cases, it's better to add an action to the player and use a distance check in the action condition. Probably not the case here but I'm just giving you an example Share this post Link to post Share on other sites
davidoss 552 Posted February 17, 2016 I am not sure about that. First of all we need a global function for addaction in MP fnc_addactionMP = { params ["_object", "_screenMsg", "_scriptToCall", "_arguments", "_priority", "_showWindow", "_hideOnUse", "_shortcut", "_condition"]; if(isNull _object) exitWith {}; _object addaction [_screenMsg,_scriptToCall,_arguments,_priority,_showWindow,_hideOnUse,_shortcut,_condition]; }; And in this case or other random objects another global function : fnc_secureMP = { params ["_object", "_object_type"]; _object_type = typeOf _object; switch (_object_type) do { case "Land_BloodBag_F": { [[_object,"<t color='#ff9900'>Take Bloodbag</t>",{ private ["_grabber","_obj"]; _obj = _this select 0; _grabber = _this select 1; _grabber playMove "AinvPknlMstpSnonWnonDnon_medic_1"; sleep 5; deleteVehicle _obj; },nil,6,true,true,"","(_target distance _this) < 5"],"fnc_addactionMP",true,true] spawn BIS_fnc_MP; }; case "Land_SurvivalRadio_F": { [[_object,"<t color='#ff9900'>Take radio</t>",{ private ["_grabber","_obj"]; _obj = _this select 0; _grabber = _this select 1; _grabber playMove "AinvPknlMstpSnonWnonDnon_medic_1"; sleep 5; deleteVehicle _obj; },nil,6,true,true,"","(_target distance _this) < 5"],"fnc_addactionMP",true,true] spawn BIS_fnc_MP; }; case "Land_Suitcase_F": { [[_object,"<t color='#ff9900'>Take suitcase</t>",{ private ["_grabber","_obj"]; _obj = _this select 0; _grabber = _this select 1; _grabber playMove "AinvPknlMstpSnonWnonDnon_medic_1"; sleep 5; deleteVehicle _obj; },nil,6,true,true,"","(_target distance _this) < 5"],"fnc_addactionMP",true,true] spawn BIS_fnc_MP; }; case "Land_Laptop_device_F": { [[_object,"<t color='#ff9900'>Take notebook</t>",{ private ["_grabber","_obj"]; _obj = _this select 0; _grabber = _this select 1; _grabber playMove "AinvPknlMstpSnonWnonDnon_medic_1"; sleep 5; deleteVehicle _obj; },nil,6,true,true,"","(_target distance _this) < 5"],"fnc_addactionMP",true,true] spawn BIS_fnc_MP; }; }; }; next when you spawn an object: if (isServer) then { _obj = "some_item" createVehicle _somePosition; [_obj] call fnc_secureMP; }; And this is the easiest and beautiful way Share this post Link to post Share on other sites
Bnae 1431 Posted February 17, 2016 I am not sure about that. First of all we need a global function for addaction in MP fnc_addactionMP = { params ["_object", "_screenMsg", "_scriptToCall", "_arguments", "_priority", "_showWindow", "_hideOnUse", "_shortcut", "_condition"]; if(isNull _object) exitWith {}; _object addaction [_screenMsg,_scriptToCall,_arguments,_priority,_showWindow,_hideOnUse,_shortcut,_condition]; }; And in this case or other random objects another global function : fnc_secureMP = { params ["_object", "_object_type"]; _object_type = typeOf _object; switch (_object_type) do { case "Land_BloodBag_F": { [[_object,"<t color='#ff9900'>Take Bloodbag</t>",{ private ["_grabber","_obj"]; _obj = _this select 0; _grabber = _this select 1; _grabber playMove "AinvPknlMstpSnonWnonDnon_medic_1"; sleep 5; deleteVehicle _obj; },nil,6,true,true,"","(_target distance _this) < 5"],"fnc_addactionMP",true,true] spawn BIS_fnc_MP; }; case "Land_SurvivalRadio_F": { [[_object,"<t color='#ff9900'>Take radio</t>",{ private ["_grabber","_obj"]; _obj = _this select 0; _grabber = _this select 1; _grabber playMove "AinvPknlMstpSnonWnonDnon_medic_1"; sleep 5; deleteVehicle _obj; },nil,6,true,true,"","(_target distance _this) < 5"],"fnc_addactionMP",true,true] spawn BIS_fnc_MP; }; case "Land_Suitcase_F": { [[_object,"<t color='#ff9900'>Take suitcase</t>",{ private ["_grabber","_obj"]; _obj = _this select 0; _grabber = _this select 1; _grabber playMove "AinvPknlMstpSnonWnonDnon_medic_1"; sleep 5; deleteVehicle _obj; },nil,6,true,true,"","(_target distance _this) < 5"],"fnc_addactionMP",true,true] spawn BIS_fnc_MP; }; case "Land_Laptop_device_F": { [[_object,"<t color='#ff9900'>Take notebook</t>",{ private ["_grabber","_obj"]; _obj = _this select 0; _grabber = _this select 1; _grabber playMove "AinvPknlMstpSnonWnonDnon_medic_1"; sleep 5; deleteVehicle _obj; },nil,6,true,true,"","(_target distance _this) < 5"],"fnc_addactionMP",true,true] spawn BIS_fnc_MP; }; }; }; next when you spawn an object: if (isServer) then { _obj = "some_item" createVehicle _somePosition; [_obj] call fnc_secureMP; }; And this is the easiest and beautiful way I have to admit that's quite clever. How do you execute these scripts? And since you're good with these things i have to ask one question. I have counter on the picked object, how i make the counter personal on every player? I mean, if i make this with similiar style and add like "count_this = count_this + 1;" Of course i can figure it out by myself, but it's annoying to test when you need other person to check if it works on MP (well not if you're good enough) Share this post Link to post Share on other sites
davidoss 552 Posted February 17, 2016 You do not need to execute "these scripts". You need to put these functions in one file called for example "myfnc.sqf" and add a line in init.sqf to preprocess that file. [] call compile preprocessFileLineNumbers "myfnc.sqf"; Without any condition (need to be run on every machine). The function "fnc_secureMP" are called by: [_obj] call fnc_secureMP; with passing object [_obj] into it. The function "fnc_addactionMP" are called automatically by "fnc_secureMP". If you need a counter how many object are picked up you need to use a global variable updated by every player which has pickup the object. for example: define variable in init.sqf globally like this: if (isnil {missionNamespace getVariable "objectcount"}) then { missionNamespace setVariable ["objectcount",0,true]; }; Its need to be in if isnil condition because of JIP clients which will reset this to 0 on connect. then in function "fnc_secureMP" add the line like this: [[_object,"<t color='#ff9900'>Take Bloodbag</t>",{ private ["_grabber","_obj"]; _obj = _this select 0; _grabber = _this select 1; _grabber playMove "AinvPknlMstpSnonWnonDnon_medic_1"; sleep 5; deleteVehicle _obj; missionNamespace setVariable ["objectcount",(objectcount + 1),true]; //add this line, true is for global effect and JIP, same as publicVariable "" },nil,6,true,true,"","(_target distance _this) < 5"],"fnc_addactionMP",true,true] spawn BIS_fnc_MP; }; for each objects. Enjoy.. 1 Share this post Link to post Share on other sites
Bnae 1431 Posted February 17, 2016 You do not need to execute "these scripts". You need to put these functions in one file called for example "myfnc.sqf" and add a line in init.sqf to preprocess that file. [] call compile preprocessFileLineNumbers "myfnc.sqf"; Without any condition (need to be run on every machine). The function "fnc_secureMP" are called by: [_obj] call fnc_secureMP; with passing object into it. The function "fnc_addactionMP" are called automatically by "fnc_secureMP". If you need a counter how many object are picked up you need to use a global variable updated by every player which has pickup the object. for example: define variable in init.sqf globally like this: if (isnil {missionNamespace getVariable "objectcount"}) then { missionNamespace setVariable ["objectcount",0,true]; }; Its need to be in if isnil condition because of JIP clients which will reset this to 0 on connect. then in function "fnc_secureMP" add the line like this: [[_object,"<t color='#ff9900'>Take Bloodbag</t>",{ private ["_grabber","_obj"]; _obj = _this select 0; _grabber = _this select 1; _grabber playMove "AinvPknlMstpSnonWnonDnon_medic_1"; sleep 5; deleteVehicle _obj; missionNamespace setVariable ["objectcount",(objectcount + 1),true]; //add this line, true is for global effect and JIP, same as publicVariable "" },nil,6,true,true,"","(_target distance _this) < 5"],"fnc_addactionMP",true,true] spawn BIS_fnc_MP; }; for each objects. Enjoy.. This will help me a lot! I'm so grateful, because these are things that been holding me back for a while. Glad to see that you used your time to help me. Thank you! Share this post Link to post Share on other sites