-
-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Relative Vector3 type #68
Comments
Could the relative Vector3s contain some absolute coordinates or do they all have to be relative? |
No, if a command accepted only relative coordinates it'd probably just use a regular It's TBD how commands will distinguish relative and absolute coordinates, though. |
@LoganDark Yeah, I was thinking the same thing. So I think the best approach here would be to make a new class that allows mixing relative and absolute coordinates. Then the class could contain a method, |
Not gonna make a pr for this but if anyone is interested, here is a botched type implementation of a relative vector3 using the executor's position. Simply prepend a tilde example usage: type def: local Util = require(script.Parent.Parent.Shared.Util)
local function validateVector(value, i)
return pcall(assert, value ~= nil, `Invalid or missing number at position {i} in RelativeVector type.`)
end
local relativeVector3Type = {
Transform = function (text, executor)
local currentPos = executor.Character:GetPivot().Position
return Util.Map(Util.SplitPrioritizedDelimeter(text, {",", "%s"}), function(value, index)
if value:sub(1,1) ~= "~" then
return tonumber(value)
end
local currentCoord = 0
if index == 1 then currentCoord = currentPos.X
elseif index == 2 then currentCoord = currentPos.Y
elseif index == 3 then currentCoord = currentPos.Z
end
if value == "~" then
return currentCoord
end
return tonumber(value:sub(2)) + currentCoord
end)
end;
Validate = function (components)
if #components > 3 then
return false, "Maximum of 3 values allowed in sequence"
end
for i = 1, 3 or #components do
local valid, reason = validateVector(components[i], i)
if not valid then
return false, reason
end
end
return true
end;
Parse = function(components)
return Vector3.new(unpack(components))
end
}
return function (cmdr)
cmdr:RegisterType("relativeVector3", relativeVector3Type)
cmdr:RegisterType("relativeVector3s", Util.MakeListableType(relativeVector3Type))
end |
Like a
relative3
type that accepts~
coordinates like Minecraft does.to @ ~, ~500, ~
would teleport you 500 studs into the air.to @ ~, ~-500, ~
500 studs down.Interpreting what these coordinates are relative to would be at the command's discretion.
The text was updated successfully, but these errors were encountered: