AeroXbird Posted July 31, 2010 Share Posted July 31, 2010 I made an attachment script based on deject3d's map editor. But whenever i make 2 items, i am supposed to get a message that i am not able to create a third, but i can just make a third object PS: See attachment for script Link to comment
Namorek Posted August 1, 2010 Share Posted August 1, 2010 function attach1(startedresource) if startedresource == getThisResource() then A1 = createVehicle ( ID, X, Y, Z, rotX, rotY, rotZ ) B2 = createObject ( ID, X, Y, Z, rotX, rotY, rotZ ) C3 = attachElements ( B2, A1, 0, 0, 0 ) D4 = createObject ( ID, X, Y, Z, rotX, rotY, rotZ ) attachElements ( D4, C3, 0, 0, 0 ) end end Link to comment
AeroXbird Posted August 3, 2010 Author Share Posted August 3, 2010 You really dont get it, i want people to be able to create and attach 2 objects seperately (so not in one time) and the script i use is way more advanced than that. Link to comment
50p Posted August 3, 2010 Share Posted August 3, 2010 Why did you zipped it and uploaded here? Just pastebin it. Link to comment
dzek (varez) Posted August 3, 2010 Share Posted August 3, 2010 Namorek's "script" is pretty random.. Attaching Element to boolean value Link to comment
AeroXbird Posted August 3, 2010 Author Share Posted August 3, 2010 On request of 50p: http://mta.pastebin.com/P1pDZHVG Link to comment
50p Posted August 4, 2010 Share Posted August 4, 2010 I would suggest you have a table with objects. Then check if the table size is greater then 2, if it is, then print a message. You have complicated your script way too much. local objects = { } local selectedObjIndex = { }; if not objects[ playerSource ] then objects[ playerSource ] = { }; end -- when you create new object, check its size: if #objects[ playerSource ] < 2 then -- we can create 1 more object local obj = createObject( ...... ); -- you don't have to assign it to a variable but it'll make the code cleaner local objTab = { obj, { 0,0,0, 0,0,0 } }; -- make a table with the object and a table for its offset coords, NOTE that coords table is at index 2! object element at 1! table.insert( objects[ playerSource ], objTab ); selectedObjIndex[ playerSource ] = #objects[ playerSource ]; -- make the new object as a selected else return outputChatBox( "You can only create 2 objects!!!", playerSource ); end -- in your movement functions use the selectedObjIndex instead of argument passed from pressed key (bindKey) -- this will shorten the script by all not necessary bindKey with different objects -- something like this: local selectedIndex = selectedObjIndex[ playerSource ]; if key ..... then objects[ playerSource ][ selectedIndex ][ 2 ][ 1 ] = objects[ playerSource ][ selectedIndex ][ 2 ][ 1 ] - precision; -- [ 2 ] <-- will be the table of the offset coords... [ 2 ][ 1 ] would be offsetX, [ 2 ][ 2 ] offsetY, [ 2 ][ 3 ] offsetZ, etc. -- as noted on line 8 setElementAttachedOffset( objects[ playerSource ][ selectedIndex ][ 1 ], ........ ); -- [ 1 ] will return the object element end It may look a bit complicated at first but if you'll read the comments and try to understand the code then you'll be fine. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now