Jump to content
Sign in to follow this  
cfsfirefighter

attachTo building problem

Recommended Posts

Hey guys im having problems with the attach to command im trying to spawn a unit and get him to stand in the middle of the room this it what i have tried and all return errors

_shopkeeper = "B_RangeMaster_F" createUnit [_position,group SPY_GAMELOGIC];
_shopkeeper attachTo [341b7900# 1442061: i_shop_01_v1_f.p3d,[0,0,0]];

"B_RangeMaster_F" createUnit [_position,group SPY_GAMELOGIC, this attachTo [341b7900# 1442061: i_shop_01_v1_f.p3d,[0,0,0]]];

This last one returns the error

Error in expression <teUnit [_position,group SPY_GAMELOGIC,""this attachTo [341b7900# 1442061: i_shop>
 Error position: <this attachTo [341b7900# 1442061: i_shop>
 Error Missing ]

Also 341b7900# 1442061: i_shop_01_v1_f.p3d is the name of the object which i found through

_shop = nearestBuilding _position;
diag_log format ["Shop %1",_shop];

Thanks for any help

Share this post


Link to post
Share on other sites

hi cfsfirefighter,

Creating the unit works?

why are you trying to bind a unit on a house, it's unlikely that it will move, you know?

Maybe i need more coffee to understand the intention here??

greetings Na_Palm

Share this post


Link to post
Share on other sites

nah u dont need more coffee :-) i need to to go to a certain position in the building, as a user purchase the building an AI spawns and attaches to a certain spot on the building and he cannot then be run over or pushed out of position. i am going to have an array of buildings with positions cheers

Share this post


Link to post
Share on other sites

You can't reference an object like that.

This should work:

_shop = nearestBuilding _position;
_shopkeeper = "B_RangeMaster_F" createUnit [_position,group SPY_GAMELOGIC];
_shopkeeper attachTo [_shop,[0,0,0]];

Share this post


Link to post
Share on other sites

nah tried it that way and i get this error

Error in expression <teUnit [_position,group SPY_GAMELOGIC];
_shopkeeper attachTo [_shop,[0,0,0]];  
>
 Error position: <_shopkeeper attachTo [_shop,[0,0,0]];  
>
 Error Undefined variable in expression: _shopkeeper

Share this post


Link to post
Share on other sites

that error suggests that your createunit command is'nt working as _shopkeeper is empty...

so does creating the unit work. does you see it in game?

Share this post


Link to post
Share on other sites

createUnit doesn't actually return anything, not even the unit created. To capture the unit you should use createUnit array.

_shop = nearestBuilding _position;
_shopkeeper = group SPY_GAMELOGIC createUnit ["B_RangeMaster_F", _position, [], 0, "NONE"];
_shopkeeper attachTo [_shop,[0,0,0]];

Share this post


Link to post
Share on other sites

Ok no errors but the people are spawning in the ocean at ref 999999 so its like it cannot find the location. and yes the soldier did appear with the last script but didnt attach

Share this post


Link to post
Share on other sites

Im still banging my head on my bench anyone else have any ideas why the AI is being teleported to the edge of the map in the water, however without the attachto the AI placed in the building.

Share this post


Link to post
Share on other sites

You could try a test to see it the unit name is correct.

Replace the attach line with this line

_shopkeeper setdamage 1;

if the unit dies then it's a problem with the attacto command not working with the building.

Share this post


Link to post
Share on other sites

nearestBuilding awaits an object and no position on the right side from it.

have you tried to change it to:

_shop = nearestBuilding _shopkeeper;

and change the order therefor too, to:

_shopkeeper = group SPY_GAMELOGIC createUnit ["B_RangeMaster_F", _position, [], 0, "NONE"];
_shop = nearestBuilding _shopkeeper;
_shopkeeper attachTo [_shop,[0,0,0]]; 

Share this post


Link to post
Share on other sites

to check it, i used now:

this setpos [3871.25,17520.5,0.00143433]; this attachTo [nearestBuilding this,[0,0,0]]; 

on a newly created mission on Altis. Only created the player char and put the above in the init.

It's working as intended.

Could it be that you have somewhere in your mission code something that changes the shopkeepers position?

In the Wasteland missions as an ex. the player chars get new positions as of JIP...

Share this post


Link to post
Share on other sites
to check it, i used now:

this setpos [3871.25,17520.5,0.00143433]; this attachTo [nearestBuilding this,[0,0,0]]; 

on a newly created mission on Altis. Only created the player char and put the above in the init.

It's working as intended.

Could it be that you have somewhere in your mission code something that changes the shopkeepers position?

In the Wasteland missions as an ex. the player chars get new positions as of JIP...

Hey Na_palm,

The problem is this is run on the server as it starts up.

Do the same thing with a dedicated server. Put that in the init line, then join. Unit isn't attached.

Share this post


Link to post
Share on other sites

Ok, somehow i was under the impression you are working on an SP mission.... Nevermind, an init.sqf conform way would be this:

if (!isServer) exitWith {};

shop_list = ["Shopkeeper_1"];
_group = createGroup civilian;
{
_pos = getMarkerPos _x;
_shop = nearestBuilding _pos;
_shopkeeper = _group createUnit ["B_RangeMaster_F", _pos, [], 0, "CAN_COLLIDE"];
_shopkeeper attachTo [_shop,[0,0,0]]; 
sleep 0.001;
}forEach shop_list;

This code assumes that you place an map marker on the house you want as a shop and then put the markers name in the "shop_list" ARRAY.

Nothing else must be placed on the map.

greetings Na_Palm

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  

×