Hello Modding Collegues,
I've got a small Problem. For one of my new WIP-Mods i need a way to "block" an area. As all the positioning is totaly random i need to block the Area of an object, so the next object can't be build there. I tried to figure a way out to do this, but it seem to do not work. I've created some functions:
The Table for Blocked Areas looks like this.
Every single Area is added with this.
1. check if the blocked Area is free
function RPGFabi_Gardencalculation.checkiffree(Blockierte_Flaeche, Pos_X, Pos_Y)
local blocked = false
for i = 0,#Blockierte_Flaeche do
if
((Pos_Y > Blockierte_Flaeche[i][1]) and (Pos_Y < Blockierte_Flaeche[i][2]))
or
((Pos_X > Blockierte_Flaeche[i][4]) and (Pos_X < Blockierte_Flaeche[i][3]))
then
blocked = true
break
else
end
end
return blocked
end
Alles anzeigen
2. create an block from Center
function RPGFabi_Gardencalculation.createblock(X_Pos, Y_Pos, Width_X, Width_Y, safety_width)
local Table = {
Y_Pos - Width_Y/2 - safety_width,
Y_Pos + Width_Y/2 + safety_width,
X_Pos - Width_X/2 - safety_width,
X_Pos + Width_X/2 + safety_width
}
end
Width is the Distance from the first end of the object to the last end of the object
safety width is the extra distance where nothing can be placed.
3. show blocked Areas
Place an Object at the side of every Block
function RPGFabi_Gardencalculation.showblocked(Blocked_Areas, Y_Housepos)
local Table = {}
local skalierung = {
x = 0.1,
y = 0.1,
z = 0.1
}
local rotation = {
x = math.rad(0),
y = math.rad(0),
z = math.rad(0)
}
for i = 1,#Blocked_Areas do
local X_Mid = Blocked_Areas[i][4] - Blocked_Areas[i][3]
local Y_Mid = Blocked_Areas[i][2] - Blocked_Areas[i][1]
local Modelpfad = "asset/track_multi_gleisfeldleuchte_db_doppelt"
local translation_A = {
x = X_Mid,
y = Blocked_Areas[i][2],
z = 0
}
local translation_B = {
x = X_Mid,
y = Blocked_Areas[i][1],
z = 0
}
local translation_C = {
x = Blocked_Areas[i][4],
y = Y_Mid,
z = 0
}
local translation_D = {
x = Blocked_Areas[i][3],
y = Y_Mid,
z = 0
}
local translation_E = {
x = X_Mid,
y = Y_Mid,
z = 0
}
-- [[
Table[#Table +1] = {
id = Modelpfad..".mdl",
transf = transf.scaleRotZYXTransl(skalierung, rotation, translation_A)
}
Table[#Table +1] = {
id = Modelpfad..".mdl",
transf = transf.scaleRotZYXTransl(skalierung, rotation, translation_B)
}
Table[#Table +1] = {
id = Modelpfad..".mdl",
transf = transf.scaleRotZYXTransl(skalierung, rotation, translation_C)
}
Table[#Table +1] = {
id = Modelpfad..".mdl",
transf = transf.scaleRotZYXTransl(skalierung, rotation, translation_D)
}
-- ]]
--[[
Table[#Table +1] = {
id = Modelpfad..".mdl",
transf = transf.scaleRotZYXTransl(skalierung, rotation, translation_E)
}
]]
end
return Table
end
Alles anzeigen
4. Create the m and b variable of an straight line out of 4 coordinates
function RPGFabi_Gardencalculation.getLine(Einfahrt_Y, Einfahrt_X, Haus_Y, Haus_X)
local m = (Einfahrt_Y - Haus_Y) / (Einfahrt_X - Haus_X) -- Steigung
local b = Einfahrt_X - (m * Einfahrt_Y) -- Offset
local Table_Line = { m, b }
return Table_Line
end
5. Use the Lines (2 create an groundface) to create an blocked Area. This should use small slices of the Area to create better blocked Areas
function RPGFabi_Gardencalculation.blockArea(Line_A, Line_B, EX, Haus_X, Y_Houseposition)
local Distance = 0.5 -- Scheibengröße
local Amount = (EX - Haus_X) / Distance -- Anzahl der Scheiben
local Left_Y = 0
local Right_Y = 0
local Table_Block = { }
-- erstelle Koordinaten für Scheibenweise Blockaden
for i = 0,Amount do
-- get low x
local low_X = EX - (i * Distance)
-- get high x
local high_X = low_X - Distance
-- get left Y
local L_YA = (low_X - Line_A[2]) / Line_A[1]
local L_YB = (high_X - Line_A[2]) / Line_A[1]
if L_YA > L_YB then
Left_Y = L_YB
else
Left_Y = L_YA
end
-- get right Y
local R_YA = (low_X - Line_B[2]) / Line_B[1]
local R_YB = (high_X - Line_B[2]) / Line_B[1]
if R_YA > L_YB then
Right_Y = R_YB
else
Right_Y = R_YA
end
-- Create Blocked Table
Table_Block[#Table_Block +1] = { Left_Y, Right_Y, high_X, low_X }
end
return Table_Block
end
Alles anzeigen
Problem:
It doesn't show me the blocks correct. As I don't know if they are created correct or not, which I need to check soon, I thought Hey maybe someone else got an easier way.
Can someone help with the creation and use of an blocked Area Table?
The Beginning would be the Table groundfaces use: