Jump to content
Sign in to follow this  
guyfawkestom

A setpos script for which I need help

Recommended Posts

Good morning Paraiso,

I'm currently trying to set up a script to trigger the setpos of a unit (a sniper for instance) in a particular building position.

The original script was found here : http://forums.bistudio.com/showpost.php?p=1328174&postcount=4

"My" setbpos.sqf script looks like this :

_obj = _this select 0; // Object to teleport
_index = _this select 1; // Building position #
_pos = _this select 2; // My addition : coordinates/name object near build.
_building = nearestObject position _pos;
_obj setPos (_building buildingPos _index);

The cunning plan is to trigger the setpos at the position decided in the line used to execute the script, instead of placig the unit next to the building :

nul=[unit,x,pos1] execVM "setbpos.sqf";

(x= number of the position in the building, pos1 = the name of the object/game logic that stands next to the building of interest or the coordinates)

I've tried with :

nul=[unit,x,position pos1] execVM "setbpos.sqf"; and

nul=[unit,x, pos1] execVM "setbpos.sqf";

But it does not work...

Does someone have any Ideas ?

I'd be glad to make it work !

Thanks and regards,

GFt

Edited by guyfawkestom

Share this post


Link to post
Share on other sites

i asume you just used this here in the post not in the actual script?

 --> Object to teleport

proper way to comment in a sqf is to use

// comment behind here.

try using getPos instead of position, try using a object like a helipad or small barrel or something instead of a gamelogic.

PS: unsure what you have done:

nul=[unit,x, _pos] execVM "setbpos.sqf";

x should be a number, you know that right?

and _pos canot work unless called from inside aonther script.

it should be name of the object, for example called pos1 or helipad1 etc.. no underscores in front.

Edited by Demonized

Share this post


Link to post
Share on other sites

Hello Demonized,

You assumed well. I'm really sorry not to have used correct conventions. I have rewritten my code with correct comments.

I'll try your tips and let you know the results.

EDIT : No, it does not work with getPos

I have no error report with this code :

_obj = _this select 0;//Unit to move
_index = _this select 1;//Building position number (x)
_pos = _this select 2; //pos1 object
_building = nearestBuilding _pos;
_obj setPos (_building buildingPos _index);

And

nul = [unit,x,pos1] execVM "setbpos.sqf"

Any Idea ?

Edited by guyfawkestom

Share this post


Link to post
Share on other sites

Sounds (to me) like you dont need all that script stuff...

Just put that into the unit's init:

this setPos ((nearestBuilding this) buildingPos [color="RoyalBlue"]1[/color]);

Replace the 1 with your number (building pos) of choice.

Share this post


Link to post
Share on other sites

A couple things I found while playing with this.

This should work but it doesn't seem to...

_building = nearestBuilding _pos;

This does work....

_building = nearestObject [_pos, "Building"];

Also... it seems _pos (pos1 object) can only be certain objects. It works with a fuel can... but not with a garbage can or flagpole!

For instance... when you use a garbage can the nearest building returned is the garbage can itself.... so no positions to be found there!

Share this post


Link to post
Share on other sites

@ Twirly : Thanks I'll try your code and I'll choose another object. I'll edit and I'll post the result.

EDIT : BRAVO ! It works perfectly like that. I'll post the code as soon as I have time

Here is the working setbpos.sqf :

_obj = _this select 0; //unit to move
_index = _this select 1; // building position number
_position = _this select 2; // Name of the object standing near the building, works with a [b]fuel can[/b]...
_building = nearestObject [ _position, "Building"];
_obj setPos (_building buildingPos _index);

You can call the script with :

nul = [unit,x,unitpos] execVM "setbpos.sqf"

where x = number, or you can use round(random x) if you want

unitpos can be the name of the trigger that calls the script then you just change the place of the trigger to another building and the unit is setpos automatically to this building.

@ sxp2high : Thanks for your help, this works perfeclty, but, eventually I'd like to make it more dynamic (with some random and other features...), and not at the init of the mission, that's why I may need a script. And it does not hurt to learn scripting for me, since I'd like to solve it for the beauty of the code !

Edited by guyfawkestom

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  

×