Anubhav Posted May 17, 2015 Posted May 17, 2015 Hey everyone! I was wondering, if it's possible to spawn random on ground or buildings, without giving X,Y,Z it will keep spawning objects on grounds. I hope so a solution is there. See my some resources: Skin shop: https://community.multitheftauto.com/in ... ls&id=8008 Note script: https://community.multitheftauto.com/in ... ls&id=8009 Rules Panel: https://community.multitheftauto.com/in ... ls&id=8246 Random Money: https://community.multitheftauto.com/in ... ls&id=8718
xXMADEXx Posted May 17, 2015 Posted May 17, 2015 You can use math.random to calculate the X and Y, then use getGroundPosition. The Ultimate Lua Tutorial! | MTA PHP SDK
Mr.unpredictable. Posted May 17, 2015 Posted May 17, 2015 I remember i created something similar to this but it had weird bugs. Like sometimes it was creating object on objects.
Anubhav Posted May 17, 2015 Author Posted May 17, 2015 The method din't work. It has bugs, it's just making objects too high in the air items = { "Water Bottle", "Tea", "Fence", 'Morphine', "Pizza", "Chicken Burger", "Pepsi", "Fanta", "Engine", "Wheel" } function getXY( ) return math.random(9999), math.random(9999), math.random(9999) end function spawnObjects( ) local x, y, z = getXY( ) z = getGroundPosition( x, y, z ) -- local x, y, z = local object = createObject( 1271, x, y, z + 0.3 ) setElementData( object, "item", items[ math.random( #items ) ] ) createBlip( 1, x, y, z ) setTimer( spawnObjects, 3000, 1 ) end spawnObjects( ) See my some resources: Skin shop: https://community.multitheftauto.com/in ... ls&id=8008 Note script: https://community.multitheftauto.com/in ... ls&id=8009 Rules Panel: https://community.multitheftauto.com/in ... ls&id=8246 Random Money: https://community.multitheftauto.com/in ... ls&id=8718
WhoAmI Posted May 17, 2015 Posted May 17, 2015 Because minimal x and y is -1500 and maximum 1500. Try this items = { "Water Bottle", "Tea", "Fence", 'Morphine', "Pizza", "Chicken Burger", "Pepsi", "Fanta", "Engine", "Wheel" } function getXY( ) return math.random(-1500, 1500), math.random(-1500, 1500), 0 end function spawnObjects( ) local x, y, z = getXY( ) z = getGroundPosition( x, y, z ) local object = createObject( 1271, x, y, z + 0.3 ) setElementData( object, "item", items[ math.random( #items ) ] ) createBlip( 1, x, y, z ) setTimer( spawnObjects, 3000, 1 ) end spawnObjects( )
Anubhav Posted May 17, 2015 Author Posted May 17, 2015 Now it spawns too low ( under the objects ) or too high in the sky. Z is always going wrong.. See my some resources: Skin shop: https://community.multitheftauto.com/in ... ls&id=8008 Note script: https://community.multitheftauto.com/in ... ls&id=8009 Rules Panel: https://community.multitheftauto.com/in ... ls&id=8246 Random Money: https://community.multitheftauto.com/in ... ls&id=8718
ALw7sH Posted May 17, 2015 Posted May 17, 2015 Because minimal x and y is -1500 and maximum 1500. Try this items = { "Water Bottle", "Tea", "Fence", 'Morphine', "Pizza", "Chicken Burger", "Pepsi", "Fanta", "Engine", "Wheel" } function getXY( ) return math.random(-1500, 1500), math.random(-1500, 1500), 0 end function spawnObjects( ) local x, y, z = getXY( ) z = getGroundPosition( x, y, z ) local object = createObject( 1271, x, y, z + 0.3 ) setElementData( object, "item", items[ math.random( #items ) ] ) createBlip( 1, x, y, z ) setTimer( spawnObjects, 3000, 1 ) end spawnObjects( ) it's -3000,3000 not -1500,1500
Anubhav Posted May 17, 2015 Author Posted May 17, 2015 It doesn't matter for now, the problem is Z. It's not getting ground position properly. Any other function that I can use? See my some resources: Skin shop: https://community.multitheftauto.com/in ... ls&id=8008 Note script: https://community.multitheftauto.com/in ... ls&id=8009 Rules Panel: https://community.multitheftauto.com/in ... ls&id=8246 Random Money: https://community.multitheftauto.com/in ... ls&id=8718
Walid Posted May 17, 2015 Posted May 17, 2015 It doesn't matter for now, the problem is Z. It's not getting ground position properly. Any other function that I can use? according to this and this z is always 0 it mean 0+0.3 = 0.3 Do not yield your back to your enemy, might feel something strange in your ass. Two things are infinite the universe and human stupidity and i'm not sure about the universe. UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators
ALw7sH Posted May 17, 2015 Posted May 17, 2015 (edited) local Timers = {} items = { "Water Bottle", "Tea", "Fence", 'Morphine', "Pizza", "Chicken Burger", "Pepsi", "Fanta", "Engine", "Wheel" } function getXY( ) return math.random(-1500, 1500), math.random(-1500, 1500) end function spawnObjects( ) local x, y = getXY( ) local object = createObject( 1271, x, y, 0 ) setElementData( object, "item", items[ math.random( #items ) ] ) setElementOnGround(object) createBlip( 1, x, y, 100 ) setTimer( spawnObjects, 3000, 1 ) end spawnObjects( ) function setElementOnGround(element) local eX,eY,eZ = getElementPosition(element) Timers[element] = setTimer( function(x,y,z) local succeed, _, _, groundZ = processLineOfSight(x, y, 3000, x, y, -3000) if succeed then local wZ = getWaterLevel(x, y, 100) z = (wZ and math.max(groundZ, wZ) or groundZ) + getElementDistanceFromCentreOfMassToBaseOfModel(element) setElementPosition(x,y,z) killTimer(Timers[element]) Timers[element] = nil end end,100,0,eX,eY,eZ) end setElementOnGround function codes&idea rights back to who created the freeroam, i have just make it as a function Edit: I haven't test, so im not sure if it's gonna works Edited May 17, 2015 by Guest
Walid Posted May 17, 2015 Posted May 17, 2015 You need to add the element here Do not yield your back to your enemy, might feel something strange in your ass. Two things are infinite the universe and human stupidity and i'm not sure about the universe. UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators
Anubhav Posted May 17, 2015 Author Posted May 17, 2015 ALw7sh @ Thanks for helping me. There were bugs in setElementPosition argument 1 element, and element wasn't defined in timer. I fixed it and it worked like charm! FIXED VERSION IF SOMEONE NEEDS: local Timers = {} items = { "Water Bottle", "Tea", "Fence", 'Morphine', "Pizza", "Chicken Burger", "Pepsi", "Fanta", "Engine", "Wheel" } function getXY( ) return math.random(-1500, 1500), math.random(-1500, 1500) end function setElementOnGround(element) local eX,eY,eZ = getElementPosition(element) Timers[element] = setTimer( function(x,y,z, element) local succeed, _, _, groundZ = processLineOfSight(x, y, 3000, x, y, -3000) if succeed then local wZ = getWaterLevel(x, y, 100) z = (wZ and math.max(groundZ, wZ) or groundZ) + getElementDistanceFromCentreOfMassToBaseOfModel(element) setElementPosition(element, x,y,z) killTimer(Timers[element]) Timers[element] = nil end end,100,0,eX,eY,eZ, element) end function spawnObjects( ) local x, y = getXY( ) local object = createObject( 1271, x, y, 0 ) setTimer( function() setElementData( object, "item", items[ math.random( #items ) ] ) setElementOnGround(object) createBlip( x, y, 1, 0 ) end, 200, 1 ) setTimer( spawnObjects, 3000, 1 ) end spawnObjects( ) See my some resources: Skin shop: https://community.multitheftauto.com/in ... ls&id=8008 Note script: https://community.multitheftauto.com/in ... ls&id=8009 Rules Panel: https://community.multitheftauto.com/in ... ls&id=8246 Random Money: https://community.multitheftauto.com/in ... ls&id=8718
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