| Name | Typ | Von |
|---|---|---|
| isInRadius(obj, rad) | Definition | AFRLme |
Mit dieser gar nicht so kleinen Funktion kannst du schnell abfragen, ob sich der Mauszeiger aktuell innerhalb eines bestimmten Radius befindet, basierend auf der aktuellen Position eines Charakters, der Mittelpunktkoordinate einer abgespielten Animation oder dem Sprite/der Animation, die zu einem Szenenobjekt gehört.
Anweisungen
1. Füge das Hauptskript im Skripteditor von Visionaire Studio hinzu und lege es als Definitionsskript fest.
2a. Beispiel Nr. 1: Prüfen, ob sich der Cursor innerhalb eines 50-Pixel-Radius von der aktuellen Position des Charakters befindet Aktionsteil Wenn Lua-Ergebnis.
return isInRadius(game.CurrentCharacter, 50)
2b. Beispiel Nr. 2: Prüfen, ob sich der Cursor innerhalb eines 50-Pixel-Radius von der Mitte des Bildes/Animations-Sprites befindet, das zum angegebenen Szenenobjekt gehört Aktionsteil Wenn Lua-Ergebnis.
return isInRadius(game.CurrentScene.Objects["object_name"], 50)
2c. Beispiel Nr. 3: Prüfen, ob sich der Cursor innerhalb eines 50-Pixel-Radius von der Mitte der angegebenen Animation befindet Aktionsteil Wenn Lua-Ergebnis.
return isInRadius(ActiveAnimations["animation_name"], 50)
2d. Beispiel Nr. 4: Prüfen, ob sich der Cursor innerhalb eines 50-Pixel-Radius von der Position des angegebenen Charakters innerhalb einer regulären IF-Abfrage befindet.
if isInRadius(game.CurrentCharacter, 50) then
-- true, add some actions here
else
-- false, add some actions here
end
Hauptskript
local x, y -- empty variables which will be used to store data in later on
local radius = 20 -- specify the radius in pixels (from characters position in scene)
local pos = {} -- empty table which we will store the mouse cursor positions in
function isInRadius(obj, rad)
pos.x = game.ScrollPosition.x + getCursorPos().x; pos.y = game.ScrollPosition.y + getCursorPos().y -- store current cursor position in the scene
if obj:getId().tableId == eObjects then if not obj.Animation:isEmpty() then obj = ActiveAnimations[obj.Animation:getName()] end end -- check if object & contains animation
-- + character position & radius + --
if obj:getId().tableId == eCharacters then -- check if character
x = obj.Position.x; y = obj.Position.y -- store characters position
rad = math.floor(obj.Size * radius) / 100 -- dynamically adjust radius size based on current scale value of character
-- + object sprite position & radius + --
elseif obj:getId().tableId == eObjects then
x = obj.Sprite.Sprite:getPosition().x + (obj.Sprite.Sprite:getSize().x / 2) -- calculate center coordinate belonging to object sprite (x)
y = obj.Sprite.Sprite:getPosition().y + (obj.Sprite.Sprite:getSize().y / 2) -- calculate center coordinate belonging to object sprite (y)
rad = math.floor(obj.Scale * radius) -- dynamically adjust radius size based on current scale value of object
-- + animation sprite position & radius + --
elseif obj:getId().tableId == eActiveAnimations then
x = obj.CurrentPosition.x + (getAnimationSize(obj).x / 2) -- calculate center coordinate belonging to the currently displayed sprite of the animation (x)
y = obj.CurrentPosition.y + (getAnimationSize(obj).y / 2) -- calculate center coordinate belonging to the currently displayed sprite of the animation (y)
rad = rad = math.floor(obj.Scale * radius) -- dynamically adjust radius size based on current scale value of animation
end
-- + calculate distance from circle center + --
if x > pos.x then x = math.floor(x - pos.x) else x = math.floor(pos.x - x) end -- fallback to invert position calculation in case x is greater than pos.x
if y > pos.y then y = math.floor(y - pos.y) else y = math.floor(pos.y - y) end -- fallback to invert position calculation in case y is greater than pos.y
if math.floor( (x ^ 2) + (y ^ 2) ) <= (rad ^ 2) then return true else return false end -- check if in radius & return true or false
end
Syntaxaufschlüsselung
| Name | Typ | Beschreibung |
|---|---|---|
| obj | Link | Dies sollte ein Link zu einem Szenenobjekt, einer aktiven Animation oder einer Figur sein. |
| rad | Ganzzahl | Dies sollte ein Zahlenwert sein, der den Radiuswert des Kreises enthält. Radius = Kreisdurchmesser ÷ 2. |