Jump to content
Sign in to follow this  
rawrbear

Positioning based on another object

Recommended Posts

Hi there, first post woo :yay:

Ok so I've just started playing around with scripting(190hours clocked in game so far and it's time for a change). I've done a bit of coding before and I know to start small ha so I've played about with a few things and I'm tinkering with explosions atm and I've hit a problem(I spent 30 mins working through an issue I was having before realising I needed the functions module on the map so it's probably an easy solution).

Basically the explosion I'm spawning seems to do very little damage so I thought I'd try spawning it just above it's current location to see how it effected it, However I can't seem to find out how to do it.

Here's what I'm working with just now, the getPos at the end is where I'm having trouble:

//Creating an explosion based on a randomly selected explosion type

_bomb = _this select 0;
//Debug text
//hint "IED script triggered";

//Defines the type of explosions that can be selected in an array
_shellArray =
[
	"ARTY_Sh_81_HE",
	"ARTY_Sh_81_HE"
];

//Selects a random shell type from the array
//NOTE: You need to have the function module on the map
_shell = _shellArray call BIS_fnc_selectRandom;

//Spawn the explosion that's been selected on the object
_explosion = _shell createVehicle getpos [_bomb select 0, _bomb select 1, 0.2];

---------- Post added at 01:02 PM ---------- Previous post was at 11:38 AM ----------

Ok I've altered it a bit after reading another thread on here doing something similar with objects and the last line reads as

_explosion = _shell createVehicle getpos [(getpos _bomb select 0),(getpos _bomb select 1),0.2];

Which still doesn't work but

_explosion = _shell createVehicle getpos _bomb;

does. I can't see where it's going wrong. :(

Share this post


Link to post
Share on other sites

You have two getPos'es in the first. Not tested, but try:

_explosion = _shell createVehicle [(getpos _bomb select 0),(getpos _bomb select 1),0.2];

Also, start Arma using the -showScriptErrors parameter, and the error would have showed up. It would have said something like "error getPos, object expected, array provided" or something like that.

Share this post


Link to post
Share on other sites

That worked perfectly thanks. I can't believe I didn't think of that >.>

Also thanks for the tip I'll use that in future :D

Share this post


Link to post
Share on other sites

Question in regards to this script(It seems pointless opening a new thread)

How would I remove the object "_bomb" from the world?

I've tried "deleteVehicle _bomb;" but that doesn't seem to work. Any help would be appreciated. Also if anyone can point me to a guide to creating conversation that would be lovely.

Share this post


Link to post
Share on other sites

When you see a _ infront of a word it means that that variable is local to that script so you would have to make the _bomb a global variable

The real questions is what are you attempting to do by deleting _bomb

Share this post


Link to post
Share on other sites

I want to remove it from the world.

Basically I have a trigger with the on activation doing "_nil = [iED0_1] execVM "IED.sqf";"

IED.sqf is more or less what I posted in the OP with changes made as suggested earlier.

IED0_1 in this case is the name of an object I have near the trigger so that when the trigger is "tripped" it spawns an explosion just above the object. I want the object to be removed after the explosion is triggered as right now it still remains after the blast and looks rather silly.

I was under the impression(based on how other stuff works) if I refer to _bomb it refers back to the object I passed to the script so in the case of the code mentioned earlier

deleteVehicle _bomb;

Would delete the object named IED0_1 from the world.

After redoing it, it seems to work now without a hitch I've no idea why it wasn't working last night. Happy times :yay:

Edited by rawrbear

Share this post


Link to post
Share on other sites

you cannot delete world items, mostly.

as they are part of the map.

what is _bomb(IED0_1) and how is it placed wherever it is?

Share this post


Link to post
Share on other sites

I didn't mean a world item such as a building or a tree I meant one I'd placed with the editor. Sorry about the confusion :S

Well in once instance it's an empty vehicle in others it's one of the IED items that were added with BAF and in others it's just a box but I seem to have it sorted now anyway :D

Don't suppose anyone has a link to a good guide on creating conversations for between the PC and NPC's?

Share this post


Link to post
Share on other sites

alright, if you have placed a object in editor and that is correctly called to the script, (i asume the explosion goes as planned on the objects position) then deleteVehicle _bomb should delete the object, in some cases if its a vehicle with crew inside, you need to delete the crew first like this, even though you dont see the crew:

{deleteVehicle _x} foreach crew _bomb;
deleteVehicle _bomb;

Share this post


Link to post
Share on other sites

I've got it all working now, though I think I'll put in a new variable with an if statement so I can leave vehicles wrecks but still remove other objects, that should be simple enough.

2 questions though:

In the code you just posted what does "_x" refer to, or mean?

Also is there a way to detect which unit cause a trigger to activate? So that I can have an NPC driven convoy come along and when the explosion is triggered it detects the vehicle that triggered it and removes the crew from that one only?

Share this post


Link to post
Share on other sites

That really handy. One final question(that I can think of just now)

What happens if I don't bother passing data into a script that the script requires but have already gave it a default value? Does this cause issues(yes I know it's bad coding ha)

For instance if I have

_remove = 0

_bomb = _this select 0;
_remove = _this select 1;

At the start but I only do [iED0_1] execVM "IED.sqf"; in my trigger. Would _remove still remain as 0? Or would this cause issues?

Share this post


Link to post
Share on other sites

there is issues with replacing types with other types:

_var = "string";

_var = "newString";

works fine,

_var = "string";

_var = 956;

will probably cause errror.

_var = "string";

_var = [something];

error as well.

but using the names placed in name window in editor will work just fine.

deleteVehicle IED0_1;

edit:

_remove = nameofObject1;
_remove = _this select 0;// now _remove is nameofNewObject.

Share this post


Link to post
Share on other sites

You can do something like this. If you don't supply the second paramater to the script it will default to 0.

_bomb = _this select 0;
_remove = if (count _this >1) then {_this select 1} else {0};

Edited by twirly
Clarity

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
Sign in to follow this  

×