Icaruk 14 Posted May 24, 2014 I'm trying to do a script that does the following: when you are near obj, you hold it, then it adds an action that allows you to push it away from you, then removing the action. myscript.sqf waituntil {player == player}; _unit = _this select 0; while {true} do { if ((obj distance _unit) < 4) then { obj attachTo [_unit, [0,1.2,0.4]]; _unit addAction ["<t color='#FF0000'>PUSH OBJ</t>", "detach obj, removeAllActions _unit, obj setvelocity [10,0,5]", {}]; waituntil {((obj distance _unit) >= 4)}; }; sleep 1; }; Now, there are 3 problems: - I need to push the obj in the direction I'm facing. - I don't know how to put all these things inside the addaction. - I need to run this just on the client that runs the script, not affecting others. Any help? Share this post Link to post Share on other sites
f2k sel 164 Posted May 24, 2014 There are more issues When walking while pushing using detach causes damage to player You can get in a vehicle while pushing and when you get out a second addaction is applied As for MP good luck I'm not even going to try and mess with that. I fixed the damage issue and it will work with quite a few objects that are class "thing" Call with null=[player] execvm "Push.sqf" I cobbled together this bit of code save as Push.sqf FNC_vel_push = { _unit = _this select 0; _obj = (_this select 0) getvariable "object"; _vel = velocity _unit; _dir = direction _unit; _speed = 8; _obj setVelocity [(_vel select 0)+(sin _dir*_speed),(_vel select 1)+ (cos _dir*_speed),(_vel select 2)]; _unit spawn {sleep 0.3;_this enableCollisionWith (_this getvariable "object");}; }; waituntil {player == player}; _unit = _this select 0; //_obj = _this select 1; _obj = cursortarget; _unit setvariable ["object",_obj,true]; while {alive _unit} do { _obj = cursortarget; _unit setvariable ["object",_obj,true]; if ((_obj distance _unit) < 4 and _obj iskindof "thing") then { _obj attachTo [_unit, [0,1.2,0.4]]; _unit addAction ["<t color='#FF0000'>PUSH OBJ</t>",{ _obj = (_this select 0) getvariable "object";(_this select 0) disableCollisionWith _obj ;detach _obj;removeAllActions (_this select 0);_this call FNC_vel_push}]; waituntil {((_obj distance _unit) >= 4 )}; }; sleep 1; }; Share this post Link to post Share on other sites
opec666 22 Posted May 24, 2014 (edited) I am doing a sports mission that does exactly that. Here, "quaffle" is the object I attached, detached, and sent off when the action is fired. This is executed from the addAction (uses the CBA function, I guess vanilla would use BIS_fnc_MP): [ "quaffle_shot", [ _firer ] ] call CBA_fnc_globalEvent; And here's the event handler that executes the same event for everyone: [ "quaffle_shot", { _firer = _this select 0; _vel = velocity quaffle; _dir = direction quaffle; detach quaffle; _speed = 275; //Added speed eyes = eyeDirection _firer; quaffle setVelocity [ ( _vel select 0 ) + ( ( eyes select 0 ) * _speed ), ( _vel select 1 ) + ( ( eyes select 1 ) * _speed ), ( _vel select 2 ) ]; } ] call CBA_fnc_addEventHandler; eyeDirection is bugged with the Z value, see the feedback tracker (ID 15580, sorry, can't post links as a new member). My code just uses the current Z velocity of the object being fired off, and not the up/down facing direction. edit: mis-read where OP wanted it local only. I'll leave it up just in case it's useful for someone else Edited May 24, 2014 by opec666 Share this post Link to post Share on other sites
TittErS 13 Posted May 24, 2014 Simply with SIN and COS waituntil {player == player}; _unit = _this select 0; while {true} do { if ((obj distance _unit) < 4) then { obj attachTo [_unit, [0,1.2,0.4]]; _unit addAction ["<t color='#FF0000'>PUSH OBJ</t>", "detach obj, removeAllActions _unit, obj setvelocity [sin (getDir _unit) * 10, cos (getDir _unit) * 10,5]", {}]; waituntil {((obj distance _unit) >= 4)}; }; sleep 1; }; Share this post Link to post Share on other sites
Icaruk 14 Posted May 24, 2014 There are more issuesWhen walking while pushing using detach causes damage to player You can get in a vehicle while pushing and when you get out a second addaction is applied As for MP good luck I'm not even going to try and mess with that. I fixed the damage issue and it will work with quite a few objects that are class "thing" Call with null=[player] execvm "Push.sqf" I cobbled together this bit of code save as Push.sqf FNC_vel_push = { _unit = _this select 0; _obj = (_this select 0) getvariable "object"; _vel = velocity _unit; _dir = direction _unit; _speed = 8; _obj setVelocity [(_vel select 0)+(sin _dir*_speed),(_vel select 1)+ (cos _dir*_speed),(_vel select 2)]; _unit spawn {sleep 0.3;_this enableCollisionWith (_this getvariable "object");}; }; waituntil {player == player}; _unit = _this select 0; //_obj = _this select 1; _obj = cursortarget; _unit setvariable ["object",_obj,true]; while {alive _unit} do { _obj = cursortarget; _unit setvariable ["object",_obj,true]; if ((_obj distance _unit) < 4 and _obj iskindof "thing") then { _obj attachTo [_unit, [0,1.2,0.4]]; _unit addAction ["<t color='#FF0000'>PUSH OBJ</t>",{ _obj = (_this select 0) getvariable "object";(_this select 0) disableCollisionWith _obj ;detach _obj;removeAllActions (_this select 0);_this call FNC_vel_push}]; waituntil {((_obj distance _unit) >= 4 )}; }; sleep 1; }; It works nice, thanks! I'll modify some things then I'll post the final script here ^^ Share this post Link to post Share on other sites
Icaruk 14 Posted May 24, 2014 Well, this is the script atm: FNC_chute = { _unit = _this select 0; _obj = (_this select 0) getvariable "object"; _vel = velocity _unit; _dir = direction _unit; if ((speed _unit) < 10) then { _speed = 8; _obj setVelocity [((_vel select 0) - 3) + (sin _dir*_speed),((_vel select 1) - 3) + (cos _dir*_speed),(_vel select 2) + 10]; _unit spawn {sleep 0.3;_this enableCollisionWith (_this getvariable "object");}; }; if (((speed _unit) > 10) and ((speed _unit)) < 20) then { _speed = 8; _obj setVelocity [((_vel select 0) - 1) + (sin _dir*_speed),((_vel select 1) - 1) + (cos _dir*_speed),(_vel select 2) + 2]; _unit spawn {sleep 0.3;_this enableCollisionWith (_this getvariable "object");}; }; if ((speed _unit) > 20) then { _speed = 13; _obj setVelocity [((_vel select 0) + 7) + (sin _dir*_speed),((_vel select 1) + 7) + (cos _dir*_speed),(_vel select 2) + 3]; _unit spawn {sleep 0.3;_this enableCollisionWith (_this getvariable "object");}; }; }; waituntil {player == player}; _unit = _this select 0; //_obj = _this select 1; _obj = cursortarget; _unit setvariable ["object",_obj,true]; while {alive _unit} do { _obj = cursortarget; _unit setvariable ["object",_obj,true]; if ((_obj distance _unit) < 4 and _obj iskindof "thing") then { detach _obj; _obj attachTo [_unit, [0,1.2,0.4]]; _unit addAction ["<t color='#FF0000'>Chutar</t>",{ _obj = (_this select 0) getvariable "object";(_this select 0) disableCollisionWith _obj ;detach _obj;removeAllActions (_this select 0);_this call FNC_chute}]; waituntil {((_obj distance _unit) >= 4 )}; }; hint format ["%1",(speed _unit)]; sleep 1; }; The main problem now is MP related. If I create a game, I run the script and it works nice, but when a second player runs it, he can hold the object, but when he uses the action to push it away, it just does detach. Any ideas? Share this post Link to post Share on other sites
f2k sel 164 Posted May 24, 2014 Maybe you could check if the object is attached already if (isNull attachedTo _obj1) then { hint "_obj1 is not attached to anything."; }; and add a version of it to the filter line if ((_obj distance _unit) < 4 and _obj iskindof "thing" and (isNull attachedTo _obj)) then { Can't test right now. Share this post Link to post Share on other sites
Icaruk 14 Posted May 25, 2014 Maybe you could check if the object is attached alreadyif (isNull attachedTo _obj1) then { hint "_obj1 is not attached to anything."; }; and add a version of it to the filter line if ((_obj distance _unit) < 4 and _obj iskindof "thing" and (isNull attachedTo _obj)) then { Can't test right now. With the script I posted did that if someone else is near you, the obj will detach and it will attach to the new owner. Any more ideas please? Share this post Link to post Share on other sites
f2k sel 164 Posted May 25, 2014 See if this is working, seems to be in single player using switched unit private ["_unit","_obj"]; FNC_chute = { _unit = _this select 0; _obj = (_this select 0) getvariable "object"; _vel = velocity _unit; _dir = direction _unit; if ((speed _unit) < 10) then { _speed = 8; _obj setVelocity [((_vel select 0) - 3) + (sin _dir*_speed),((_vel select 1) - 3) + (cos _dir*_speed),(_vel select 2) + 10]; _unit spawn {sleep 0.3;_this enableCollisionWith (_this getvariable "object");}; }; if (((speed _unit) > 10) and ((speed _unit)) < 20) then { _speed = 8; _obj setVelocity [((_vel select 0) - 1) + (sin _dir*_speed),((_vel select 1) - 1) + (cos _dir*_speed),(_vel select 2) + 2]; _unit spawn {sleep 0.3;_this enableCollisionWith (_this getvariable "object");}; }; if ((speed _unit) > 20) then { _speed = 13; _obj setVelocity [((_vel select 0) + 7) + (sin _dir*_speed),((_vel select 1) + 7) + (cos _dir*_speed),(_vel select 2) + 3]; _unit spawn {sleep 0.3;_this enableCollisionWith (_this getvariable "object");}; }; _obj setvariable ["free",true,true]; }; waituntil {player == player}; _unit = _this select 0; //_obj = _this select 1; //_obj = cursortarget; while {alive _unit} do { _obj = cursorTarget; //_unit setvariable ["object",_obj,true]; if ((_obj distance _unit) < 4 and _obj iskindof "thing" and (_obj getvariable ["free",true])) then { detach _obj; hint str _obj; _obj attachTo [_unit, [0,1.2,0.4]]; _unit setvariable ["object",_obj,true]; _obj setvariable ["free",false,true]; _unit addAction ["<t color='#FF0000'>Chutar</t>",{ _obj = (_this select 0) getvariable "object";(_this select 0) disableCollisionWith _obj ;detach _obj;removeAllActions (_this select 0);_this call FNC_chute},[],0,true,true,"","_target == _this"]; waituntil {((_obj distance _unit) >= 4 )}; }; hint format ["%1",(speed _unit)]; sleep 1; }; Share this post Link to post Share on other sites
Icaruk 14 Posted May 26, 2014 With my last script I found that I can hold and throw the OBJ, but someone else can just hold it. But he can hold and throw ground weapons LOL. Any ideas? Share this post Link to post Share on other sites