Skip to content
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

Add Relative Vector3 Type #328

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cmdr/BuiltInCommands/Admin/teleport.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ return {
Group = "DefaultAdmin",
AutoExec = {
'alias "bring|Brings a player or set of players to you." teleport $1{players|players|The players to bring} ${me}',
'alias "to|Teleports you to another player or location." teleport ${me} $1{player @ vector3|Destination|The player or location to teleport to}',
'alias "to|Teleports you to another player or location." teleport ${me} $1{player @ relativeVector3|Destination|The player or location to teleport to}',
},
Args = {
{
Expand All @@ -14,7 +14,7 @@ return {
Description = "The players to teleport",
},
{
Type = "player @ vector3",
Type = "player @ relativeVector3",
Name = "Destination",
Description = "The player to teleport to",
},
Expand Down
42 changes: 41 additions & 1 deletion Cmdr/BuiltInTypes/Vector.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local Util = require(script.Parent.Parent.Shared.Util)

local function validateVector(value, i)
if value == nil then
return false, ("Invalid or missing number at position %d in Vector type."):format(i)
return false, `Invalid or missing number at position {i} in Vector type.`
end

return true
Expand All @@ -22,10 +22,50 @@ local vector2Type = Util.MakeSequenceType({
Length = 2,
})

local relativeVector3Type = {
Transform = function(text, executor)
local currentPosition = 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 currentComponent =
currentPosition[if index == 1 then "X" elseif index == 2 then "Y" elseif index == 3 then "Z" else 0]

return currentComponent + if value == "~" then 0 else tonumber(value:sub(2))
end)
end,

Validate = function(components)
if #components > 3 then
return false, "Maximum of 3 values allowed in sequence"
end

for i = 1, 3 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("vector3", vector3Type)
cmdr:RegisterType("vector3s", Util.MakeListableType(vector3Type))

cmdr:RegisterType("vector2", vector2Type)
cmdr:RegisterType("vector2s", Util.MakeListableType(vector2Type))

cmdr:RegisterType("relativeVector3", relativeVector3Type)
cmdr:RegisterType("relativeVector3s", Util.MakeListableType(relativeVector3Type))
end
Loading