====== Comfort: Mauern ziehen ====== ===== Beschreibung ===== Diese Comfort Funktion ermöglicht ein Mauernziehen unangreifbarer Mauern (Spieler ID 0) per Skript.\\ Es ermöglicht ausserdem das saubere ziehen von Mauern in beliebigen Winkeln von Punkt A nach Punkt B.\\ Eigentlich setzt das Comfort andere Entities und gibt diesen nur den Anschein von Mauern. Das ist Spielbedingt so nötig weil Mauern nur an bestimmten Positionen und Ausrichtungen gesetzt werden können. ===== Anwendung ===== Es sind die Comforts "GetDistance" und "Winkel" nötig.\\ Die Funktion wird dann so aufgerufen: -- _pos Table mit X und Y nötig CreateWallsFromTo(_pos1,_pos2) Ein Aufruf könnte so aussehen: local _pos1 = {X=30500,Y=18950} local _pos2 = {X=20700,Y=1820} CreateWallsFromTo(_pos1,_pos2) ===== Code ===== CreateWallsFromTo = function(_pos1,_pos2) Logic.SetModelAndAnimSet(Logic.CreateEntity( Entities.XD_IronGrid4, _pos1.X, _pos1.Y, 0, 0 ),Models.XD_WallCorner) Logic.SetModelAndAnimSet(Logic.CreateEntity( Entities.XD_IronGrid4, _pos2.X, _pos2.Y, 0, 0 ),Models.XD_WallCorner) local _Winkel = Winkel(_pos1,_pos2) local _Rotation = _Winkel + 90 if _Rotation > 360 then _Rotation = _Rotation - 360 end local _XStep = math.cos(_Winkel/360*math.pi*2) * 200 local _YStep = math.sin(_Winkel/360*math.pi*2) * 200 _CurrentWallPos = {X = _pos1.X+_XStep,Y = _pos1.Y+_YStep} _visible = true while math.floor(Winkel(_CurrentWallPos,_pos2)) == math.floor(_Winkel) and GetDistance(_CurrentWallPos,_pos2) > 200 do if _visible then Logic.SetModelAndAnimSet(Logic.CreateEntity( Entities.XD_IronGrid4, _CurrentWallPos.X, _CurrentWallPos.Y, _Rotation, 0 ),Models.XD_WallStraight) else Logic.SetModelAndAnimSet(Logic.CreateEntity( Entities.XD_Rock7, _CurrentWallPos.X, _CurrentWallPos.Y, _Rotation, 0 ),Models.XD_Rock1) end _visible = not _visible _CurrentWallPos = {X = _CurrentWallPos.X+_XStep,Y = _CurrentWallPos.Y+_YStep} end _CurrentWallPos = {X = _pos2.X-_XStep,Y = _pos2.Y-_YStep} Logic.CreateEntity( Entities.XD_WallStraight, _CurrentWallPos.X, _CurrentWallPos.Y, _Rotation, 0 ) end ===== Abhängigkeiten / Zusätzlich nötige Funktionen ===== Winkel = function(_Pos1,_Pos2) local delta_X = 0; local delta_Y = 0; local alpha = 0 if type (_Pos1) == "string" or type (_Pos1) == "number" then _Pos1 = GetPosition(GetEntityId(_Pos1)); end if type (_Pos2) == "string" or type (_Pos2) == "number" then _Pos2 = GetPosition(GetEntityId(_Pos2)); end delta_X = _Pos1.X - _Pos2.X delta_Y = _Pos1.Y - _Pos2.Y if delta_X == 0 and delta_Y == 0 then -- Gleicher Punkt return 0 end alpha = math.deg(math.asin(math.abs(delta_X)/(math.sqrt(__pow(delta_X, 2)+__pow(delta_Y, 2))))) if delta_X >= 0 and delta_Y > 0 then alpha = 270 - alpha elseif delta_X < 0 and delta_Y > 0 then alpha = 270 + alpha elseif delta_X < 0 and delta_Y <= 0 then alpha = 90 - alpha elseif delta_X >= 0 and delta_Y <= 0 then alpha = 90 + alpha end return alpha end GetDistance = function(_a, _b) if type(_a) ~= "table" then _a = GetPosition(_a); end if type(_b) ~= "table" then _b = GetPosition(_b); end return math.sqrt((_a.X - _b.X)^2+(_a.Y - _b.Y)^2) end