@ PCS
I think you should also control the last position, to avoid repeating positions in the next map test.
If someone wants to try this script, they must create a text file with the notepad, write the number "0" (without quotes) and save as "
random_pos.txt" in the
Files folder.
I suggest that the buildings be similar in size, otherwise you will have to make adjustments to the script and the thing gets complicated.
Although in this case it helps a lot that the script is for your game, since you know your houses, you know their sizes, properties and so on, so you can adjust the script to fit your needs.
local h1_x, h1_y, h1_z = 0,0,0
local h2_x, h2_y, h2_z = 0,0,0
local h3_x, h3_y, h3_z = 0,0,0
local pos = 0
local old_pos = 0
function randompos_init(e)
--h1_x, h1_y, h1_z,_,_,_ = GetEntityPosAng( 1 )
--h2_x, h2_y, h2_z,_,_,_ = GetEntityPosAng( 2 )
--h3_x, h3_y, h3_z,_,_,_ = GetEntityPosAng( 3 )
h1_x = GetEntityPositionX( 1 )
h1_y = GetEntityPositionY( 1 )
h1_z = GetEntityPositionZ( 1 )
h2_x = GetEntityPositionX( 2 )
h2_y = GetEntityPositionY( 2 )
h2_z = GetEntityPositionZ( 2 )
h3_x = GetEntityPositionX( 3 )
h3_y = GetEntityPositionY( 3 )
h3_z = GetEntityPositionZ( 3 )
local h = assert( io.open( "random_pos.txt", "r") )
old_pos = tonumber( h:read() )
h:close()
end --init
function randompos_main(e)
CollisionOff(1) --house1
CollisionOff(2) --house2
CollisionOff(3) --house3
math.randomseed(os.clock())
if pos == 0 then
repeat
pos = math.random(1,3) -- increase last value to fit your needs
until pos ~= old_pos
end
Prompt(pos)
if pos ~= old_pos then
if pos == 1 then
SetPosition(1,h3_x,h1_y,h1_z) --house1
SetPosition(2,h1_x,h2_y,h2_z) --house2
SetPosition(3,h2_x,h3_y,h3_z) ---house3
elseif pos == 2 then
SetPosition(1,h2_x,h1_y,h1_z)
SetPosition(2,h3_x,h2_y,h2_z)
SetPosition(3,h1_x,h3_y,h3_z)
elseif pos == 3 then
SetPosition(1,h1_x,h1_y,h1_z)
SetPosition(2,h2_x,h2_y,h2_z)
SetPosition(3,h3_x,h3_y,h3_z)
end
local f = assert( io.open( "random_pos.txt", "w") )
f:write(pos)
f:close()
--Destroy(e)
end
end --main
hth
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz
OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4