Msypon Posted September 6, 2013 Share Posted September 6, 2013 hi guys i need your help with my table locations: locations = { { -- beach ls { 529, -1884, 3 }, { 612, -1884, 3 } }, { -- sf beach { -2920, 68, 1 }, { -2913, 159, 3 } } } so i want to create 2 objects randomly in these places, wat i have to do? Link to comment
denny199 Posted September 6, 2013 Share Posted September 6, 2013 locations = { [1]= { startX=529, startY=-1884, startZ=3 , endX=612, endY=-1884, endZ=3 }, --ls [2]= { startX=-2920, startY=68, startZ=1,endX=-2913, endY=159, endZ=3 } --sf } function createRandomObject(tableNumber) local startX,startY,startZ = locations[tableNumber].startX,locations[tableNumber].startY,locations[tableNumber].startZ local endX,endY,endZ = locations[tableNumber].endX,locations[tableNumber].endY,locations[tableNumber].endZ local realX, realY, realZ = math.random(startX,endX),math.random(startY,endY),math.random(startZ,endZ) createObject ( 980, realX, realY, realZ ) end Something like that ;p Link to comment
Prat Posted September 6, 2013 Share Posted September 6, 2013 Hi there , i'v fixed it so now it gonna create 2 object randomly from #locations once the resource starts. replace ID in line 12 & 13 with the object model id , you can find it in map editor. i believe this code is easier than denny's. Good Luck locations = { { 529, -1884, 3 }, { 612, -1884, 3 }, { -2920, 68, 1 }, { -2913, 159, 3 }, } function startDaTable () random = math.random(#locations) x, y, z = locations[random][1], pickupT[random][2], pickupT[random][3] createObject ( ID, x, y, z) createObject ( ID, x, y, z) end addEventHandler ("onResourceStart", root, startDaTable) Link to comment
Moderators IIYAMA Posted September 6, 2013 Moderators Share Posted September 6, 2013 @Part, Easier, doesn't mean it is better. Btw you are creating objects randomly every time a resource starts, it doesn't even matter which one. "Oh let we start(restart) admin then we got event more random objects!" To be honest I don't know exactly how he wants it, Link to comment
denny199 Posted September 6, 2013 Share Posted September 6, 2013 Where's pickupT defined, prat? Link to comment
Msypon Posted September 6, 2013 Author Share Posted September 6, 2013 No guys, you didnt understand me, im creating a treasure script and lets say that i set the time (setTimer) to 60000, then two objects will appear in LS or SF beach, but i dont know how to do it randomly Link to comment
Moderators IIYAMA Posted September 6, 2013 Moderators Share Posted September 6, 2013 local locations = { { -- ls_beach { x=529, y=-1884, z=3 }, { x=612, y=-1884, z=3 } }, { -- sf_beach { x=-2920, y=68, z=1 }, { x=-2913, y=159, z=3 } } } addEventHandler("onResourceStart", resourceRoot, function () setTimer(function() local randomResult = locations[math.random(1,#locations)] for i=1,#randomResult do local locationInfo = randomResult[i] createObject ( 1337, locationInfo.x, locationInfo.y, locationInfo.z) end end,60000,1) end) Link to comment
Moderators IIYAMA Posted September 6, 2013 Moderators Share Posted September 6, 2013 np. 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