Home   Help Search Login Register  

Author Topic: AddAction - Medic sets up a MASH  (Read 3416 times)

0 Members and 1 Guest are viewing this topic.

Offline Speeder

  • Members
  • *
    • OFP.nu
AddAction - Medic sets up a MASH
« on: 03 Apr 2007, 09:29:05 »
Okay - I'm having some trouble getting this to work.

I've made a addaction to the medics init linie calling a sqs file.

MakeMedicten.sqs:
tent = createVehicle MASH... bla bla..


My problem lies within deleting the MASH again.

Could anyone please write a working code which checks nearest building, checks if building is a MASH if it's a MASH or even the same MASH that the Medic has just setup, the Medic should get an action to delete/destroy it.  It needs to be MP compatible.

I tried to get it to work for 4 hours last night, and it sort of did, but not every time.

Please help me with it.

Thank you so much in advange
----------------------------------------------------------------------------------------
THE SCRIPT.
----------------------------------------------------------------------------------------
setupmash.sqf
Code: [Select]
_unit = _this select 0;
_id = _this select 2;
_unit removeAction _id;
_unit playMove "AinvPknlMstpSlayWrflDnon_medic";
sleep 1;
_mash = createVehicle ["MASH",[0,0,0], [], 0, "NONE"];
_mash setDir ((direction _unit) -180);
_mash  setdammage 0.8;
sleep 1;
_mash setPos (_unit modelToWorld [0,6,((position _unit) select 2)]);
_mash  setdammage 0.5;
_unit playMove "AinvPknlMstpSlayWrflDnon_medic";
sleep 2;
_mash  setdammage 0.2;
sleep 2;
_mash  setdammage 0;
sleep 2;
_unit addAction ["Dismantle MASH","takedownmash.sqf",_mash,1,false];

takedownmash.sqf
Code: [Select]
if (!local server) exitWith {true};

_unit = _this select 0;
_id = _this select 2;
_mash = _this select 3;
_unit removeAction _id;
_unit playMove "AinvPknlMstpSlayWrflDnon_medic";
sleep 1;
_mash  setdammage 0.2;
sleep 2;
_mash  setdammage 0.5;
_unit playMove "AinvPknlMstpSlayWrflDnon_medic";
sleep 2;
_mash  setdammage 0.8;
sleep 2;
_mash  setdammage 1;
sleep 2;
deleteVehicle _mash;
sleep 2;
_unit addAction ["Deploy MASH", "setupmash.sqf","",1,false];

INIT line og My medic:
Code: [Select]
this addAction ["Deploy MASH", "setupmash.sqf","",1,false]



« Last Edit: 05 Apr 2007, 17:01:03 by Speeder »
There are 10 kinds of people in this world. Those who get it, and those who don't.

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: AddAction - Medic sets up a MASH
« Reply #1 on: 03 Apr 2007, 10:29:44 »
I did this using sqf, but that's just because I'm now so used to it I can't even write sqs anymore...

First, add the action in the init field
Code: [Select]
this addAction ["Deploy MASH", "setupmash.sqf","",1,false]Those extra bits are the new things available in ArmA, the false for example prevents the action from showing up on the center of the screen all the time..

setupmash.sqf
Code: [Select]
_unit = _this select 0;
_id = _this select 2;

_unit removeAction _id;

_mash = "MASH" createVehicleLocal [0,0,0];
_mash setDir ((direction _unit) -180);
_mash setPos (_unit modelToWorld [0,6,((position _unit) select 2)]);
sleep 1;

_unit addAction ["Dismantle MASH","takedownmash.sqf",_mash,1,false];
In ArmA you can now pass custom arguments into the script executed by the action which makes this easier..
And don't be confused by the modelToWorld command there, it just easier to 'misuse' the command like that instead of using the sin/cos stuff to get the MASH deployed in front of the medic..

takedownmash.sqf
Code: [Select]
_unit = _this select 0;
_id = _this select 2;
_mash = _this select 3;

_unit removeAction _id;

deleteVehicle _mash;
sleep 1;

_unit addAction ["Deploy MASH", "setupmash.sqf","",1,false];

Now, I'm not at all sure this would work in MP 'out fo the box' but that's a start I think :dunno:
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Speeder

  • Members
  • *
    • OFP.nu
Re: AddAction - Medic sets up a MASH
« Reply #2 on: 03 Apr 2007, 10:52:22 »
I'm gonna test this the minut I get home. It looks great, and just might work. But could it be made so it only ran on the server.

I'm sending a lot of good karma your way if this works.
There are 10 kinds of people in this world. Those who get it, and those who don't.

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: AddAction - Medic sets up a MASH
« Reply #3 on: 03 Apr 2007, 11:12:22 »
Quote
But could it be made so it only ran on the server.
I'm not at all familiar with MP scripting, but I guess if you have a gamelogic called 'server' in the mission and add something like
Code: [Select]
if (!local server) exitWith {true};in the beginning of each script that might work..

You can also try adding scopes in the scripts and use the breakOut command for exiting sqf script


Code: [Select]
if (!local server) exitWith {true};

_unit = _this select 0;
_id = _this select 2;

_unit removeAction _id;

_mash = "MASH" createVehicleLocal [0,0,0];
_mash setDir ((direction _unit) -180);
_mash setPos (_unit modelToWorld [0,6,((position _unit) select 2)]);
sleep 1;

_unit addAction ["Dismantle MASH","takedownmash.sqf",_mash,1,false];

or

Code: [Select]
scopeName "setupmash";
if (!local server)
 then {breakOut "setupmash"};

_unit = _this select 0;
_id = _this select 2;

_unit removeAction _id;

_mash = "MASH" createVehicleLocal [0,0,0];
_mash setDir ((direction _unit) -180);
_mash setPos (_unit modelToWorld [0,6,((position _unit) select 2)]);
sleep 1;

_unit addAction ["Dismantle MASH","takedownmash.sqf",_mash,1,false];

Dunno how the createVehicleLocal works in situation like this though, but that remains to be seen I guess..
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Speeder

  • Members
  • *
    • OFP.nu
Re: AddAction - Medic sets up a MASH
« Reply #4 on: 03 Apr 2007, 12:41:57 »
If I was not to use createvehiclelocal what should I then use? Because the MASH isn't being made atm
There are 10 kinds of people in this world. Those who get it, and those who don't.

Offline Speeder

  • Members
  • *
    • OFP.nu
Re: AddAction - Medic sets up a MASH
« Reply #5 on: 03 Apr 2007, 18:09:15 »
so I got it working - The createvehiclelocal did not work, so I just found away around that.

However - is it possible to make sure that no other players gets the medics actions when they are close to him??

That's my setupmash.sqf

Code: [Select]
_unit = _this select 0;
_id = _this select 2;
_unit removeAction _id;
_unit playMove "AinvPknlMstpSlayWrflDnon_medic";
sleep 1;
_mash = createVehicle ["MASH",[0,0,0], [], 0, "NONE"];
_mash setDir ((direction _unit) -180);
_mash  setdammage 0.8;
sleep 1;
_mash setPos (_unit modelToWorld [0,6,((position _unit) select 2)]);
_mash  setdammage 0.5;
_unit playMove "AinvPknlMstpSlayWrflDnon_medic";
sleep 1;
_mash  setdammage 0.2;
sleep 1;
_mash  setdammage 0;
sleep 1;
_unit addAction ["Dismantle MASH","takedownmash.sqf",_mash,1,false];

Medics INIT
Code: [Select]
this addAction ["Deploy MASH", "setupmash.sqf","",1,false]

Would it be possible to make a check in the script to see if the unit using the script is of the medic class?
There are 10 kinds of people in this world. Those who get it, and those who don't.

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: AddAction - Medic sets up a MASH
« Reply #6 on: 03 Apr 2007, 22:03:29 »
First: Please, do not double post. Edit your previous post if you have someting to add.

Quote
Would it be possible to make a check in the script to see if the unit using the script is of the medic class?
Yes.
However that would not prevent the action being available to other players, which is a shame really..

Anyways, you can do it in the same vein as the server check, by using exitWith or naming the scope and using breakOut..

Code: [Select]
if (!_unit in ["SoldierWMedic","SoldierEMedic","SoldierGMedic]) exitWith {true}

Btw, I would add a longer sleep before adding the dismantle action because currently the medic is still building the mash when he/she gets the dismantle action  :scratch:
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Speeder

  • Members
  • *
    • OFP.nu
Re: AddAction - Medic sets up a MASH
« Reply #7 on: 04 Apr 2007, 12:15:56 »
So now it builds the mash, and I tried addind the scope af descrieped, but that just crashed the server. I tried running it witout, but the createvehicle is not carried over the network, so no other players can see the mash..
There are 10 kinds of people in this world. Those who get it, and those who don't.

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: AddAction - Medic sets up a MASH
« Reply #8 on: 04 Apr 2007, 19:09:33 »
The action added to the medic will not be visible to other players if the addAction is executed only on the medic's machine. If this is done your setup script itself will not need a locality check.

In the medic unit's init you could put this:
Code: [Select]
If (local this) Then {this addAction ["Deploy MASH", "setupmash.sqf","",1,false]}
Make sure you remove the locality check from "setupmash.sqf". The createVehicle command should propagate the tent across all nodes. Put longer pauses in between the mash setDamage lines.
urp!

Offline Trash Can Man

  • Members
  • *
  • We are no longer the knights who say "Ni!"
Re: AddAction - Medic sets up a MASH
« Reply #9 on: 05 Apr 2007, 00:49:57 »
Speeder, when you get it worked out, could you post a sample mission? I would like to see this in action.  :)


TCM

Offline Speeder

  • Members
  • *
    • OFP.nu
Re: AddAction - Medic sets up a MASH
« Reply #10 on: 05 Apr 2007, 09:32:13 »
Do you mean like this?  (see top post.)
There are 10 kinds of people in this world. Those who get it, and those who don't.

Offline Speeder

  • Members
  • *
    • OFP.nu
Re: AddAction - Medic sets up a MASH
« Reply #11 on: 05 Apr 2007, 16:33:59 »
okay -. now my script won't run at all. Any chance one of you great guys could make one for me that works, and works in MP too please
There are 10 kinds of people in this world. Those who get it, and those who don't.

Offline Speeder

  • Members
  • *
    • OFP.nu
Re: AddAction - Medic sets up a MASH
« Reply #12 on: 05 Apr 2007, 17:02:27 »
okay - I got it running again, but with the code in post 1 the other players on the server still can't see the mash created.

Would someone be so kind to give my script the finishing touch.

thank you so very much
There are 10 kinds of people in this world. Those who get it, and those who don't.

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: AddAction - Medic sets up a MASH
« Reply #13 on: 05 Apr 2007, 18:22:05 »
I hate to repeat myself
Quote
Please, do not double post. Edit your previous post if you have someting to add.


Did you try what Peanut suggested?
Remove the server check from the script and change
Code: [Select]
this addAction ["Deploy MASH", "setupmash.sqf","",1,false]to
Code: [Select]
If (local this) Then {this addAction ["Deploy MASH", "setupmash.sqf","",1,false]}
:dunno:
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Speeder

  • Members
  • *
    • OFP.nu
Re: AddAction - Medic sets up a MASH
« Reply #14 on: 05 Apr 2007, 18:37:51 »
but by editing the topic will not be shown as new to the readers right? - Well - nevermind.
There are 10 kinds of people in this world. Those who get it, and those who don't.

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: AddAction - Medic sets up a MASH
« Reply #15 on: 05 Apr 2007, 19:33:07 »
Yes it will, it just won't be 'bumped'  :scratch:

But look, this our site policy, there is no reason to start getting into trouble for something as minor as this..
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.