Jump to content
Sign in to follow this  
SilentSpike

Creating an object stacking function

Recommended Posts

[color=#FF8040][color=#191970][b]private[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#7A7A7A]"_vehicle"[/color][color=#8B3E2F][b],[/b][/color][color=#7A7A7A]"_oldVehicle"[/color][color=#8B3E2F][b],[/b][/color][color=#7A7A7A]"_freeSpots"[/color][color=#8B3E2F][b],[/b][/color][color=#7A7A7A]"_returnValue"[/color][color=#8B3E2F][b],[/b][/color][color=#7A7A7A]"_extension"[/color][color=#8B3E2F][b],[/b][/color][color=#7A7A7A]"_dimensions"[/color][color=#8B3E2F][b],[/b][/color][color=#7A7A7A]"_offset"[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color]
[color=#1874CD]_vehicle[/color] [color=#8B3E2F][b]=[/b][/color] [color=#000000]_this[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]0[/color][color=#8B3E2F][b];[/b][/color]
[color=#1874CD]_oldVehicle[/color] [color=#8B3E2F][b]=[/b][/color] [color=#000000]_this[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]1[/color][color=#8B3E2F][b];[/b][/color]
[color=#1874CD]_freeSpots[/color] [color=#8B3E2F][b]=[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#1874CD]_vehicle[/color] [color=#191970][b]emptyPositions[/b][/color] [color=#7A7A7A]"Driver"[/color][color=#8B3E2F][b])[/b][/color] [color=#8B3E2F][b]+[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#1874CD]_vehicle[/color] [color=#191970][b]emptyPositions[/b][/color] [color=#7A7A7A]"Cargo"[/color][color=#8B3E2F][b])[/b][/color][color=#8B3E2F][b];[/b][/color]
[color=#191970][b]if[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#1874CD]_freeSpots[/color] [color=#8B3E2F][b]![/b][/color][color=#8B3E2F][b]=[/b][/color] [color=#FF0000]0[/color][color=#8B3E2F][b])[/b][/color] [color=#191970][b]then[/b][/color] [color=#8B3E2F][b]{[/b][/color]
   [color=#1874CD]_returnValue[/color] [color=#8B3E2F][b]=[/b][/color] [color=#1874CD]_vehicle[/color][color=#8B3E2F][b];[/b][/color]
[color=#8B3E2F][b]}[/b][/color] [color=#191970][b]else[/b][/color] [color=#8B3E2F][b]{[/b][/color]
   [color=#1874CD]_extension[/color] [color=#8B3E2F][b]=[/b][/color] [color=#191970][b]attachedObjects[/b][/color] [color=#1874CD]_vehicle[/color][color=#8B3E2F][b];[/b][/color]
   [color=#191970][b]if[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#8B3E2F][b]([/b][/color][color=#1874CD]_extension[/color] [color=#191970][b]isEqualTo[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b])[/b][/color] [color=#191970][b]or[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#1874CD]_extension[/color] [color=#191970][b]isEqualTo[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#1874CD]_oldVehicle[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b])[/b][/color][color=#8B3E2F][b])[/b][/color] [color=#191970][b]then[/b][/color] [color=#8B3E2F][b]{[/b][/color]
       [color=#1874CD]_extension[/color] [color=#8B3E2F][b]=[/b][/color] [color=#191970][b]createVehicle[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#7A7A7A]"Land_Pod_Heli_Transport_04_bench_F"[/color][color=#8B3E2F][b],[/b][/color][color=#8B3E2F][b][[/b][/color][color=#FF0000]0[/color][color=#8B3E2F][b],[/b][/color][color=#FF0000]0[/color][color=#8B3E2F][b],[/b][/color][color=#FF0000]50[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b],[/b][/color][color=#8B3E2F][b][[/b][/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b],[/b][/color][color=#FF0000]0[/color][color=#8B3E2F][b],[/b][/color][color=#7A7A7A]"NONE"[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color]
       [color=#1874CD]_extension[/color] [color=#191970][b]allowDamage[/b][/color] [color=#000000]false[/color][color=#8B3E2F][b];[/b][/color]
       [color=#1874CD]_extension[/color] [color=#191970][b]setVehicleLock[/b][/color] [color=#7A7A7A]"LOCKED"[/color][color=#8B3E2F][b];[/b][/color]


       [color=#1874CD]_dimensions[/color] [color=#8B3E2F][b]=[/b][/color] [color=#191970][b]boundingBoxReal[/b][/color] [color=#1874CD]_vehicle[/color][color=#8B3E2F][b];[/b][/color]
       [color=#1874CD]_offset[/color] [color=#8B3E2F][b]=[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#FF0000]0[/color][color=#8B3E2F][b],[/b][/color][color=#FF0000]0[/color][color=#8B3E2F][b],[/b][/color][color=#8B3E2F][b]([/b][/color][color=#8B3E2F][b]([/b][/color][color=#1874CD]_dimensions[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]1[/color][color=#8B3E2F][b])[/b][/color] [color=#191970][b]select[/b][/color] [color=#FF0000]2[/color][color=#8B3E2F][b])[/b][/color] [color=#8B3E2F][b]+[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#8B3E2F][b]([/b][/color][color=#191970][b]boundingCenter[/b][/color] [color=#1874CD]_extension[/color][color=#8B3E2F][b])[/b][/color] [color=#191970][b]select[/b][/color] [color=#FF0000]2[/color][color=#8B3E2F][b])[/b][/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color]
       [color=#1874CD]_extension[/color] [color=#191970][b]attachTo[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#1874CD]_vehicle[/color][color=#8B3E2F][b],[/b][/color][color=#1874CD]_offset[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color]
   [color=#8B3E2F][b]}[/b][/color] [color=#191970][b]else[/b][/color] [color=#8B3E2F][b]{[/b][/color]
       [color=#1874CD]_extension[/color] [color=#8B3E2F][b]=[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#1874CD]_extension[/color] [color=#8B3E2F][b]-[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#1874CD]_oldVehicle[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b])[/b][/color] [color=#191970][b]select[/b][/color] [color=#FF0000]0[/color][color=#8B3E2F][b];[/b][/color]
   [color=#8B3E2F][b]}[/b][/color][color=#8B3E2F][b];[/b][/color]
   [color=#1874CD]_returnValue[/color] [color=#8B3E2F][b]=[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#1874CD]_extension[/color][color=#8B3E2F][b],[/b][/color][color=#1874CD]_vehicle[/color][color=#8B3E2F][b]][/b][/color] [color=#191970][b]call[/b][/color] SPIKE_fnc_findWagonSpot[color=#8B3E2F][b];[/b][/color]
[color=#8B3E2F][b]}[/b][/color][color=#8B3E2F][b];[/b][/color]


[color=#1874CD]_returnValue[/color][/color]

Made with KK's SQF to BBCode Converter

I'm trying to make a function that will create a bench on top of the current stack if there are no vehicles in the stack with free driver/cargo seats. Here's is what happens when I run it: http://i.imgur.com/aLWzKjY.jpg

It works the first time, but when I force it to run in a loop all future benches are all added on top of the vehicle at the bottom of the stack. I suspect this is a scope issue but can't quite figure it out myself. All help is greatly appreciated!

---------- Post added at 23:12 ---------- Previous post was at 22:53 ----------

Ah, I just figured out what's happening, I need to exclude the previous object in the stack from the check for attached objects.

---------- Post added at 00:06 ---------- Previous post was at 23:41 ----------

My last examples works fine, I was having issues due to the way I was testing it. It did however contain a mistake in the stacking maths. OP has been updated with the final result, in case anybody out there in future is interested in creating something like this.

Edited by SilentSpike
Updated code

Share this post


Link to post
Share on other sites

Hehe, first thing that came to mind when i viewed your picture was one of those robot trasporters from IRobot. :D

Share this post


Link to post
Share on other sites

I'm confused. Instead of attaching the objects, why not just enableSimulation false on all of them? Then you can simply use _object setPos [x,y,0] and it should put it on top of your stack

Share this post


Link to post
Share on other sites
I'm confused. Instead of attaching the objects, why not just enableSimulation false on all of them? Then you can simply use _object setPos [x,y,0] and it should put it on top of your stack

Because I don't want their simulation to be disabled since they need to move with the vehicle at the bottom of the stack (for my purposes). Thread title was a little ambiguous, because I couldn't really capture that whole concept in the title :p

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  

×