Jump to content
Play3r

[Solved] turn the Submarine (vanilla)

Recommended Posts

Hi every one.

I am trying to make a HMS Proteus move by using the AttachTo command.

i can attach it to the Speedboat minigun.(BluFor)

 

But my problem is that the Proteus is turned 180 degrees  to the SpeedBoat so the Submarine is sailing backwards.

I have tried to read about the SetPos but i don't understand how to set the sub accordingly to the SpeedBoat's direction.

if anyone can tell my how to do it i will be glad.. 

 

// Play3r

  • Like 2

Share this post


Link to post
Share on other sites

Hi Play3r,

Pardon if you tried this already, but the wiki presents a solution with setDir: https://community.bistudio.com/wiki/attachTo

Also; why not just use one of the extensive workshop submarine mods?

https://steamcommunity.com/sharedfiles/filedetails/?id=1362114638
https://steamcommunity.com/sharedfiles/filedetails/?id=1611319861

  • Like 1

Share this post


Link to post
Share on other sites
On 11/3/2019 at 12:35 AM, Melody_Mike said:

Hi Play3r,

Pardon if you tried this already, but the wiki presents a solution with setDir: https://community.bistudio.com/wiki/attachTo

Also; why not just use one of the extensive workshop submarine mods?

https://steamcommunity.com/sharedfiles/filedetails/?id=1362114638
https://steamcommunity.com/sharedfiles/filedetails/?id=1611319861

Thanks for the links but I want to make the game with no mods, but I will have a look at them.

 

On 11/3/2019 at 10:55 AM, killzone_kid said:

After you attached, use

_ship setVectorDirAndUp [[0,-1,0],[0,0,1]];

Thanks for the answer killzone will try it.

Share this post


Link to post
Share on other sites
On 11/3/2019 at 10:55 AM, killzone_kid said:

After you attached, use

_ship setVectorDirAndUp [[0,-1,0],[0,0,1]];

Hi @killzone_kid

if i want to add a EH til the speedboat so if i fire a Titan missile at the submarine how can i do that.

i have found this one :

this addEventHandler ["Explosion", { params ["_vehicle", "_damage"]; }];

i have named the submarine "sub" and the Speedboat "speedboat" just to keep it simple.

i have tried to put the name of the speedboat in the _vehicle and i want the damage to be 1.

like this :

>>  this addEventHandler ["Explosion", { params ["speedboat", "1"]; }]; <<

but i get a error about a local variable in global space, can you help me to see what i do wrong

Share this post


Link to post
Share on other sites
On 11/6/2019 at 9:53 PM, killzone_kid said:

I'm sorry Killzone_kid

i have looked at the page you link to, but i don't understand it.

Do i have to set something up in my INIT or somewhere else, i have tried to put a <_> infront of the speedboat and the Damagenumber but that don't work for me,

Do i have to define the speedboat's variable somewhere , and what example of the 10 do i have to use.

 

 

Share this post


Link to post
Share on other sites

If you don’t understand what command does, why do you use it? Use what you can understand, like _this select n instead

Share this post


Link to post
Share on other sites

@killzone_kid

I just want to learn some small scripts so I start with some simple ones.

Normally I would just not do the thing I want to do with this script. 

But thanks for your time and guides , I will try to see if I can get I to work.

Share this post


Link to post
Share on other sites

To make it short and less moralist, you can't pass global variable in params. (And it's totally useless).

 

params is used for passing _local data from a scope (script level) to another one (other script, spawned script,  EH code, add action code...). Some of them are already sent by the engine (like for EHs, addAction).

params ["speedboat", "1"]; has no sense because speedboat and 1 are values working everywhere (as soon as speedboat is defined). speedboat (without underscore) is a global variable. For example, the name you gave in editor to the boat.

 

As you can read here, your "explosion" EH has 2 parameters: (_vehicle and _damage) but you can rename it if you want.

Try:

this addEventHandler ["Explosion", { params ["_veh"];  _veh setDamage 1}];

 

 

  • Like 1

Share this post


Link to post
Share on other sites
4 hours ago, pierremgi said:

To make it short and less moralist, you can't pass global variable in params. (And it's totally useless).

 

params is used for passing _local data from a scope (script level) to another one (other script, spawned script,  EH code, add action code...). Some of them are already sent by the engine (like for EHs, addAction).

params ["speedboat", "1"]; has no sense because speedboat and 1 are values working everywhere (as soon as speedboat is defined). speedboat (without underscore) is a global variable. For example, the name you gave in editor to the boat.

 

As you can read here, your "explosion" EH has 2 parameters: (_vehicle and _damage) but you can rename it if you want.

Try:

this addEventHandler ["Explosion", { params ["_veh"];  _veh setDamage 1}];

 

 

Thanks @pierremgi

 

So i did understand it right, i just didn't know that i had to type SetDamage 1 and not just the % i wanted it to damaged.

Am i right that i can type  >params["speedboat"] < instead of _veh if i want to?

 

Share this post


Link to post
Share on other sites
4 hours ago, Play3r said:

So i did understand it right, i just didn't know that i had to type SetDamage 1 and not just the % i wanted it to damaged.

Am i right that i can type  >params["speedboat"] < instead of _veh if i want to?

 

No you're wrong. As said, params doesn't accept a global variable. See BIKI for variables.

You can use _speedboat instead, no matter the name of your ship. With params, you start the inside code with "let's call here the object (on which you apply the EH "explosion" and passed as 1st param by engine):  _speedboat. This local variable has no "existence" in an outter scope (spawned or else).

 

If you want to apply a simple value like: 1, let's try the EH "handleDamage", far more difficult to understand, and not specific for explosion.

Share this post


Link to post
Share on other sites

@pierre MGI and @killzone_kid

 

Thank you for your help with this problem, but is look like the blast won't go true the submarine so it hits the speedboat.

I have tried with just the boat and there i can hit approx 3 mtr from the speedboat and it sinks fine, when i add the submarine nothing happens the submarine just keeps rocking in the water.

So i guess there has so be added another parameter like a distance to the blast from the boat, but that is way over my knowhow.

But thanks for your help, it was a success for me i did learn something.

Share this post


Link to post
Share on other sites
On 11/9/2019 at 9:25 AM, killzone_kid said:

How more obvious could this be? https://prnt.sc/pujsvq

Sure! But perhaps, you should take one more time for clear explanation rather than :

If you don’t understand what command does, why do you use it? Use what you can understand, like _this select n instead

Except if you want a forum for skilled persons only, without any basic question, just referencing the holy BIKI. Not my concept.

 

On 11/9/2019 at 12:00 PM, Play3r said:

@pierre MGI and @killzone_kid

 

Thank you for your help with this problem, but is look like the blast won't go true the submarine so it hits the speedboat.

I have tried with just the boat and there i can hit approx 3 mtr from the speedboat and it sinks fine, when i add the submarine nothing happens the submarine just keeps rocking in the water.

So i guess there has so be added another parameter like a distance to the blast from the boat, but that is way over my knowhow.

But thanks for your help, it was a success for me i did learn something.

Your submarine can't take hit. It's a structure, not a ship, without any effect with damage. The only thing you can do is a new cinematic (sinking) when your speeboat is destroyed: Re-attach to the wrecked boat, not tested, not sure it's feasible or applying a velocity like proteus (or name you gave to it)

after speedboat setdamage 1; write:

proteus spawn { _sub = _this; _timer = diag_tickTime; while {uiSleep 0.5; diag_tickTime < _timer + 30} do {_sub setVelocityModelSpace [0,2,-10]}; deleteVehicle proteus};

  • Like 3

Share this post


Link to post
Share on other sites
1 hour ago, pierremgi said:

But perhaps, you should take one more time for clear explanation

So in your opinion if I just repeat one more time what I have already written on BIKI somehow it is magically going to make someone to understand? Well it won’t, as this thread clearly showed.

Share this post


Link to post
Share on other sites
13 minutes ago, killzone_kid said:

So in your opinion if I just repeat one more time what I have already written on BIKI somehow it is magically going to make someone to understand? Well it won’t, as this thread clearly showed.

I wrote my opinion. Nothing to add, and especially nothing to remove. What I'm sure, there is nothing "magic" in your post.

Share this post


Link to post
Share on other sites

Thanks guys for the help but i'm dropping the idea since i can't get it to work.

 

after speedboat setdamage 1; write:

proteus spawn { _sub = _this; _timer = diag_tickTime; while {uiSleep 0.5; diag_tickTime < _timer + 30} do {_sub setVelocityModelSpace [0,2,-10]}; deleteVehicle proteus};

That linie would not do the trick or a least i don't know how to.

 

My problem is that the submarines is attached to the speedboat  and i hoped that the detonation on the hull of the submarine was enough to damage the speedboat so i could use the EH Explosion but that can't be done with my knowhow 

Share this post


Link to post
Share on other sites

Are you using naval mines? What is made your explosion of?

 

Anyway, here is an alternate solution:

- place your speedboat, name it speedboat, add waypoints;

- place your HMS Proteus, in its init field, write this code:


 

this attachTo [speedBoat,[0,0,-3]];
this setVectorDirAndUp [[0,-1,0],[0,0,1]];
0 = this spawn {
  _sub = _this;
  waitUntil {uiSleep 0.3; {_x distanceSqr _this < 2600} count allMissionObjects "#explosion" > 0};
  detach _this;
  {speedboat deleteVehicleCrew _x} count crew speedboat;
  deleteVehicle speedboat;
  _timer = diag_tickTime;
  while {uiSleep 0.1; diag_tickTime < _timer + 30} do {_sub setVelocityModelSpace [0,-5,-3]};
  deleteVehicle _sub
};

 

Optional : Smooth the waves (to zero) in environment menu.

Probably not the best solution, but the first one so far 😉

Enjoy.

  • Like 1

Share this post


Link to post
Share on other sites
9 hours ago, pierremgi said:

Are you using naval mines? What is made your explosion of?

 

Anyway, here is an alternate solution:

- place your speedboat, name it speedboat, add waypoints;

- place your HMS Proteus, in its init field, write this code:


 


this attachTo [speedBoat,[0,0,-3]];
this setVectorDirAndUp [[0,-1,0],[0,0,1]];
0 = this spawn {
  _sub = _this;
  waitUntil {uiSleep 0.3; {_x distanceSqr _this < 2600} count allMissionObjects "#explosion" > 0};
  detach _this;
  {speedboat deleteVehicleCrew _x} count crew speedboat;
  deleteVehicle speedboat;
  _timer = diag_tickTime;
  while {uiSleep 0.1; diag_tickTime < _timer + 30} do {_sub setVelocityModelSpace [0,-5,-3]};
  deleteVehicle _sub
};

 

Optional : Smooth the waves (to zero) in environment menu.

Probably not the best solution, but the first one so far 😉

Enjoy.

Thanks for this @pierremgi

 

It works, and for sinking the Sub i use a titan launcher or any other missiles the player can find,

Thanks Pierremgi for your help and patience.

 

 @killzone_kid I understand want you wanted to do by sending me to the Wiki pages you wanted me to read about it and let me try on my own, but the reading and the trying did not make it work for me since i didn't understand the code, i think you had it the same way when you started with arma, i'm just a 49 year old noob in arma that like to play in the editor and try to make some missions for myself, and if i like them i put them away in a safe place so i can have some fun with them later, a lot of the things i do in the editor is done by trigger or anything like it, but i like to read on the wiki and learn things but i am not that god at understanding all the paramters and the commands.  I don't have anything against your way of answering in this forum i guess you had to find out all by yourself when you was starting to script.

 

 

Share this post


Link to post
Share on other sites

When I started learning scripting I spent a lot of time on wiki which was not as good as it is now btw, and when it was lacking information I did my own experiments testing stuff and then adding it to wiki. What put me off spending more time answering your questions is what it seems to me like lack of effort from your side. Even a simple google search brings a lot of results from these forums about params. One of the top results on google: 

Params page has many examples as well, if you find hard to understand the writing or notes which are put in frames to stress their importance, the examples show you the correct way of using params command, which surely should be enough to figure out what it does if one takes time to contemplate the code. I guess you are lucky there are people on these forums that have a lot of patience and are willing to tell you the same thing over and over. I admit, I lack patience for these sort of things, so shoot me.

  • Like 1

Share this post


Link to post
Share on other sites

The issue here was not variable naming, it was a complete missunderstanding about what params does.
I think with params ["speedboat"] the user was trying to do something like "if the first param is "speedboat" then do some magic stuff that I'm not even telling you, just read my mind please"
But sadly that's not how programming works. In programming you have to clearly express exactly what your program is supposed to do for you.

In your case I assume you wanted some script to happen IF the SPEEDBOAT was damaged by an explosion THEN do something.

So.. To do that you'd need to write an IF statement.
IF (_vehicle == speedboat) THEN { insert your code here };

 

what params does is it gives the PARAMeterS a name, such that you can access them.

As the wiki says https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#Explosion

Explosion should use

params ["_vehicle", "_damage"];

with vehicle being the vehicle that received the damage, which you want to check whether its your speedboat.

Also the eventhandler will only fire for the object its assigned to, which will be the speedboat, meaning you don't even need params, as you already know it will be "speedboat" and you also don't need a if check, as it only fires for "speedboat".

 

On 11/9/2019 at 10:26 PM, pierremgi said:

waitUntil {uiSleep 0.3; {_x distanceSqr _this < 2600} count allMissionObjects "#explosion" > 0};

This makes no sense.

for one, uiSleep continues running while game is paused, which is absolute nonsense here as when the game is paused, no explosions can happen.

also allMissionObjects is a terribly slow command and a really bad idea to use if you have a better alternative. cough Explosion EH cough

also count is a really bad idea to use, as it always iterates over all objects, while you only want to check whether there is one. findIf should be used instead here.

also waitUntil and scheduled scripts are way to imprecise, with the scheduler and other scripts running, your waitUntil might only check every few seconds. But a #explosion only exists for a very short time when the explosion is happening, making it likely that your waitUntil will just miss the explosion entirely.

 

On 11/8/2019 at 4:48 PM, pierremgi said:

you can't pass global variable in params

params doesn't "pass" any variables anyway.

 

On 11/8/2019 at 4:48 PM, pierremgi said:

params is used for passing _local data from a scope (script level) to another one

No its not. params grabs values out of the _this array (unless specified otherwise) and assigns them to a local variable with a name that you specify.

It doesn't pass anything anywhere.

 

 

 

  • Like 1

Share this post


Link to post
Share on other sites

Hi dedmen nice to read you!

Did you succeed in applying the EH "explosion" on the HMS Proteus, which is a structure without damage, or on the speedboat on which the submarine is attachedTo? After several trials on my side, I didn't find any EH triggering for such case (neither hit/damage nor epecontact). The reason why  I searched for another mean.

 

waitUntil {uiSleep 0.3; {_x distanceSqr _this < 2600} count allMissionObjects "#explosion" > 0};

You write that makes no sense ... but that work. The uiSleep is an habit (perhaps bad, but I didn't find any literature about any problem of using it instead of sleep). I did that from the moment I scripted for MP scenario (the game continues to run on pause). I found plenty of qualities with uiSleep but I'm fond of more detailed discussion about that.

 

The allMissionObject "#explosion" is probably not the best solution, I admitted, I tested FPS and found the uiSleep (or sleep if you want) 0.3 is a good deal between FPS saving and explosion catching. I tested and re-tested, and you?

 

For params, you're correcting me "passing _local data from a scope to another one", for "grabbing out of the _this". Thanks for such precision. Not sure to understand the difference at my level... but it's important to underline such point, because this confusion is too often made (search for: arma variable passing) by even skilled authors.

 

I hope such skilled people as you will take time to write a little working script as answer of this topic, far better than mine of course, with the same determination as you did for your explanations.

Thanks again.

 

 

  • Like 1

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

×