Pinkstack/roblox-luau-corpus-text huggingface dataset:
-- Subtracting position from the CFrame leaves you with just the rotational elements of the CFrame


local rotationOffset = (npcModel.PrimaryPart.CFrame - npcModel.PrimaryPart.CFrame.Position):Inverse()
local Animations = {
	SuperheroIdle = 616111295,
	Wave = 507770239,
}
local NPC = {
	Waist = npcModel.UpperTorso.Waist,
	Root = npcModel.LowerTorso.Root,
	Neck = npcModel.Head.Neck,
}
local TwistProportions = {
	Root = .2,
	Waist = .3,
	Neck = .5,
	Full = 1,
}
--- Skill


local UIS = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local Mouse = plr:GetMouse()
local Debounce = true
Player = game.Players.LocalPlayer
local Track1 : Animation = script:WaitForChild("Anim01")
Track1 = Player.Character:WaitForChild("Humanoid"):LoadAnimation(script.Anim01)
local PrevWalkSpeed = nil
local PrevJumpPower = nil
local Tween = game:GetService("TweenService")
local Gui = Player.PlayerGui:WaitForChild("Mochi_Skill_List".. Player.Name):WaitForChild("Frame")

local Cooldown = 7

UIS.InputBegan:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.C and Debounce == true and Tool.Equip.Value == true and Tool.Active.Value == "None" then
		Tool.Active.Value = "3BuzzCutDough"
		Gui:FindFirstChild(Tool.Active.Value).Frame.Size = UDim2.new(1, 0, 1, 0)
		PrevWalkSpeed = Player.Character:WaitForChild("Humanoid").WalkSpeed
		PrevJumpPower = Player.Character:WaitForChild("Humanoid").JumpPower
		Player.Character:WaitForChild("Humanoid").WalkSpeed = 2.5
		Player.Character:WaitForChild("Humanoid").JumpPower = 0
		Track1:Play()
		Track1:AdjustSpeed(0)
		wait(0.15)
		script.Fire:FireServer("hold")
	end
end)

UIS.InputEnded:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.C and Debounce == true and Tool.Equip.Value == true and Tool.Active.Value == "3BuzzCutDough" then
		Debounce = false
		Tool.Active.Value = "3BuzzCutDough"
		Player.Character:WaitForChild("Humanoid").WalkSpeed = 0
		Track1:Stop()
		script.Fire:FireServer("unhold")
		wait(1.5)
		local hum =  Player.Character.Humanoid
		local CamOffsetMulti = 6
		for i = 1,20 do
			hum.CameraOffset = Vector3.new(
				math.random(-CamOffsetMulti,CamOffsetMulti),
				math.random(-CamOffsetMulti,CamOffsetMulti),
				math.random(-CamOffsetMulti,CamOffsetMulti))
			CamOffsetMulti = CamOffsetMulti/1.05
			wait()
		end
		hum.CameraOffset = Vector3.new(0,0,0)
		Tween:Create(Gui:FindFirstChild(Tool.Active.Value).Frame, TweenInfo.new(Cooldown), {Size = UDim2.new(0, 0, 1, 0)}):Play()
		Tool.Active.Value = "None"
		Player.Character:WaitForChild("Humanoid").WalkSpeed = PrevWalkSpeed
		Player.Character:WaitForChild("Humanoid").JumpPower = PrevJumpPower
		wait(Cooldown)
		Debounce = true
	end
end)
--]]




function getHumanoid(model)
	for _, v in pairs(model:GetChildren()) do
		if v:IsA'Humanoid' then
			return v
		end
	end
end


local ai = script.Parent
local human = getHumanoid(ai)
local hroot = ai.HumanoidRootPart
local zspeed = hroot.Velocity.magnitude


local pfs = game:GetService("PathfindingService")

function GetPlayerNames()
	local players = game:GetService('Players'):GetChildren()
	local name = nil
	for _, v in pairs(players) do
		if v:IsA'Player' then
			name = tostring(v.Name)
		end
	end
	return name
end


function GetPlayersBodyParts(t)
	local torso = t
	if torso then
		local figure = torso.Parent
		for _, v in pairs(figure:GetChildren()) do
			if v:IsA'Part' then
				return v.Name
			end
		end
	else
		return "HumanoidRootPart"
	end
end

function GetTorso(part)
	local chars = game.Workspace:GetChildren()
	local torso = nil
	for _, v in pairs(chars) do
		if v:IsA'Model' and v ~= script.Parent and v.Name == GetPlayerNames() then
			local charRoot = v:FindFirstChild'HumanoidRootPart'
			if (charRoot.Position - part).magnitude < SearchDistance then
				torso = charRoot
			end
		end
	end
	return torso
end

for _, zambieparts in pairs(ai:GetChildren()) do
	if zambieparts:IsA'Part' then
		zambieparts.Touched:connect(function(p)
			if p.Parent.Name == GetPlayerNames() and p.Parent.Name ~= ai.Name then -- damage
				local enemy = p.Parent
				local enemyhuman = getHumanoid(enemy)
				enemyhuman:TakeDamage(aiDamage)
			end
		end)
	end
end
-------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------




function onRunning(speed)
	if speed > 0.01 then
		playAnimation("walk", 0.1, Humanoid)
		if currentAnimInstance and currentAnimInstance.AnimationId == "http://www.roblox.com/asset/?id=180426354" then
			setAnimationSpeed(speed / 14.5)
		end
		pose = "Running"
	else
		if emoteNames[currentAnim] == nil then
			playAnimation("idle", 0.1, Humanoid)
			pose = "Standing"
		end
	end
end

function onDied()
	pose = "Dead"
end

function onJumping()
	playAnimation("jump", 0.1, Humanoid)
	jumpAnimTime = jumpAnimDuration
	pose = "Jumping"
end

function onClimbing(speed)
	playAnimation("climb", 0.1, Humanoid)
	setAnimationSpeed(speed / 12.0)
	pose = "Climbing"
end

function onGettingUp()
	pose = "GettingUp"
end

function onFreeFall()
	if (jumpAnimTime <= 0) then
		playAnimation("fall", fallTransitionTime, Humanoid)
	end
	pose = "FreeFall"
end

function onFallingDown()
	pose = "FallingDown"
end

function onSeated()
	pose = "Seated"
end

function onPlatformStanding()
	pose = "PlatformStanding"
end

function onSwimming(speed)
	if speed > 0 then
		pose = "Running"
	else
		pose = "Standing"
	end
end

function getTool()	
	for _, kid in ipairs(Figure:GetChildren()) do
		if kid.className == "Tool" then return kid end
	end
	return nil
end

function getToolAnim(tool)
	for _, c in ipairs(tool:GetChildren()) do
		if c.Name == "toolanim" and c.className == "StringValue" then
			return c
		end
	end
	return nil
end

function animateTool()
	
	if (toolAnim == "None") then
		playToolAnimation("toolnone", toolTransitionTime, Humanoid, Enum.AnimationPriority.Idle)
		return
	end

	if (toolAnim == "Slash") then
		playToolAnimation("toolslash", 0, Humanoid, Enum.AnimationPriority.Action)
		return
	end

	if (toolAnim == "Lunge") then
		playToolAnimation("toollunge", 0, Humanoid, Enum.AnimationPriority.Action)
		return
	end
end

function moveSit()
	RightShoulder.MaxVelocity = 0.15
	LeftShoulder.MaxVelocity = 0.15
	RightShoulder:SetDesiredAngle(3.14 /2)
	LeftShoulder:SetDesiredAngle(-3.14 /2)
	RightHip:SetDesiredAngle(3.14 /2)
	LeftHip:SetDesiredAngle(-3.14 /2)
end

local lastTick = 0

function move(time)
	local amplitude = 1
	local frequency = 1
  	local deltaTime = time - lastTick
  	lastTick = time

	local climbFudge = 0
	local setAngles = false

  	if (jumpAnimTime > 0) then
  		jumpAnimTime = jumpAnimTime - deltaTime
  	end

	if (pose == "FreeFall" and jumpAnimTime <= 0) then
		playAnimation("fall", fallTransitionTime, Humanoid)
	elseif (pose == "Seated") then
		playAnimation("sit", 0.5, Humanoid)
		return
	elseif (pose == "Running") then
		playAnimation("walk", 0.1, Humanoid)
	elseif (pose == "Dead" or pose == "GettingUp" or pose == "FallingDown" or pose == "Seated" or pose == "PlatformStanding") then
-- Written by Coercii



local Verifier = {}

function Verifier.typeValid(data)
	return type(data) ~= "userdata", typeof(data)
end

function Verifier.scanValidity(tbl, passed, path)
	if type(tbl) ~= "table" then
		return Verifier.scanValidity({input = tbl}, {}, {})
	end
	passed, path = passed or {}, path or {"input"}
	passed[tbl] = true
	local tblType
	do
		local key = next(tbl)
		if type(key) == "number" then
			tblType = "Array"
		else
			tblType = "Dictionary"
		end
	end
	local last = 0
	for key, value in next, tbl do
		path[#path + 1] = tostring(key)
		if type(key) == "number" then
			if tblType == "Dictionary" then
				return false, path, "Mixed Array/Dictionary"
			elseif key%1 ~= 0 then  -- if not an integer
				return false, path, "Non-integer index"
			elseif key == math.huge or key == -math.huge then
				return false, path, "(-)Infinity index"
			end
		elseif type(key) ~= "string" then
			return false, path, "Non-string key", typeof(key)
		elseif tblType == "Array" then
			return false, path, "Mixed Array/Dictionary"
		end
		if tblType == "Array" then
			if last ~= key - 1 then
				return false, path, "Array with non-sequential indexes"
			end
			last = key
		end
		local isTypeValid, valueType = Verifier.typeValid(value)
		if not isTypeValid then
			return false, path, "Invalid type", valueType
		end
		if type(value) == "table" then
			if passed[value] then
				return false, path, "Cyclic"
			end
			local isValid, keyPath, reason, extra = Verifier.scanValidity(value, passed, path)
			if not isValid then
				return isValid, keyPath, reason, extra
			end
		end
		path[#path] = nil
	end
	passed[tbl] = nil
	return true
end

function Verifier.getStringPath(path)
	return table.concat(path, ".")
end

function Verifier.testValidity(input)
	local isValid, keyPath, reason, extra = Verifier.scanValidity(input)
	if not isValid then
		if extra then
			return "Invalid at "..Verifier.getStringPath(keyPath).." because: "..reason.." ("..tostring(extra)..")"
		else
			return "Invalid at "..Verifier.getStringPath(keyPath).." because: "..reason
		end
	end
end

return Verifier
----- NO EDITING BELOW -----


local weldedParts = {}
table.insert(weldedParts,mainPart)

function Weld(x, y)
	weld = Instance.new("Weld") 
	weld.Part0 = x
	weld.Part1 = y
	local CJ = CFrame.new(x.Position) 
	weld.C0 = x.CFrame:inverse() * CJ  
	weld.C1 = y.CFrame:inverse() * CJ  
	weld.Parent = x	
	table.insert(weldedParts,y)
end

function WeldRec(instance)
	local childs = instance:GetChildren()
	for _,v in pairs(childs) do
		if  v:IsA("BasePart") or v:IsA("MeshPart") then
			if v.Name ~= "WeldPart" and v.Name ~= "A" and v.Name ~= "B" then
				Weld(mainPart, v)
			end
		end
		if v.Name ~= "AnimationParts" then
			WeldRec(v)
		end
	end	
end
wait(1)

WeldRec(P)
--DO NOT CHANGE ANYTHING INSIDE OF THIS SCRIPT BESIDES WHAT YOU ARE TOLD TO UNLESS YOU KNOW WHAT YOU'RE DOING OR THE SCRIPT WILL NOT WORK!!


local hitPart = script.Parent
local debounce = true
local tool = game.ServerStorage.TimeToFly-- Change "Sword" to the name of your tool, make sure your tool is in ServerStorage

hitPart.Touched:Connect(function(hit)
	if debounce == true then
		if hit.Parent:FindFirstChild("Humanoid") then
			local plr = game.Players:FindFirstChild(hit.Parent.Name)
			if plr then
				debounce = false
				hitPart.BrickColor = BrickColor.new("Bright red")
				tool:Clone().Parent = plr.Backpack
				wait(3) -- Change "3" to however long you want the player to have to wait before they can get the tool again
				debounce = true
				hitPart.BrickColor = BrickColor.new("Bright green")
			end
		end
	end
end)
-------------------------


function onClicked()
R.Function1.Disabled = true
FX.CRUSH.BrickColor = BrickColor.new("Really red")
FX.CRUSH.loop.Disabled = true

FX.JET.BrickColor = BrickColor.new("Really red")
FX.JET.loop.Disabled = true

FX.LPF.BrickColor = BrickColor.new("Really red")
FX.LPF.loop.Disabled = true

FX.NOISE.BrickColor = BrickColor.new("Really red")
FX.NOISE.loop.Disabled = true

FX.HPF.BrickColor = BrickColor.new("Really red")
FX.HPF.loop.Disabled = true
R.loop.Disabled = false
R.Function2.Disabled = false
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
-- constants



local PLAYER	= Players.LocalPlayer

local NUM_SLASHES		= 10
local SLASH_SIZE		= 10
local SLASH_DISTANCE	= 6
local SLASH_TIME		= 0.1

return function(character)
	local effects	= character.Effects
	local rootPart	= character.HumanoidRootPart
	
	for i = 1, NUM_SLASHES do
		spawn(function()
			local center	= rootPart.Position + Vector3.new(0, 1, 0)
			
			local slice		= script.Slice:Clone()
				slice.CFrame	= CFrame.new(center) * CFrame.Angles(math.rad(math.random(360)), math.rad(math.random(360)), math.rad(math.random(360)))
				slice.Size		= Vector3.new(0.3, 1, 1)
				
				slice.Mesh.Scale	= Vector3.new(1, 0, 0)
				slice.Mesh.Offset	= Vector3.new(0, 0, SLASH_DISTANCE)
				
				slice.Parent	= effects
			
			rootPart.Velocity	= slice.CFrame.LookVector * 50
				
			local infoA	= TweenInfo.new(SLASH_TIME/2, Enum.EasingStyle.Quad, Enum.EasingDirection.In)
			local infoB	= TweenInfo.new(SLASH_TIME/2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
			
			local tweenA	= TweenService:Create(slice.Mesh, infoA, {Scale = Vector3.new(1, 1, SLASH_SIZE); Offset = Vector3.new()})
			tweenA:Play()
			wait(SLASH_TIME/2)
			local tweenB	= TweenService:Create(slice.Mesh, infoA, {Scale = Vector3.new(1, 0, 0); Offset = Vector3.new(0, 0, -SLASH_DISTANCE)})
			tweenB:Play()
			wait(SLASH_TIME/2)
			slice:Destroy()
		end)
		
		wait(SLASH_TIME/2)
	end
end
-- functions



function stopAllAnimations()
	local oldAnim = currentAnim

	-- return to idle if finishing an emote
	if (emoteNames[oldAnim] ~= nil and emoteNames[oldAnim] == false) then
		oldAnim = "idle"
	end

	currentAnim = ""
	currentAnimInstance = nil
	if (currentAnimKeyframeHandler ~= nil) then
		currentAnimKeyframeHandler:disconnect()
	end

	if (currentAnimTrack ~= nil) then
		currentAnimTrack:Stop()
		currentAnimTrack:Destroy()
		currentAnimTrack = nil
	end
	return oldAnim
end

function setAnimationSpeed(speed)
	if speed ~= currentAnimSpeed then
		currentAnimSpeed = speed
		currentAnimTrack:AdjustSpeed(currentAnimSpeed)
	end
end

function keyFrameReachedFunc(frameName)
	if (frameName == "End") then

		local repeatAnim = currentAnim
		-- return to idle if finishing an emote
		if (emoteNames[repeatAnim] ~= nil and emoteNames[repeatAnim] == false) then
			repeatAnim = "idle"
		end

		local animSpeed = currentAnimSpeed
		playAnimation(repeatAnim, 0.0, Humanoid)
		setAnimationSpeed(animSpeed)
	end
end
--// SS3.33T Police Edit originally for 2017 Mercedes-Benz E300 by Itzt and MASERATl, base SS by Inspare



wait(0.1)
local player = game.Players.LocalPlayer
local HUB = script.Parent.HUB
local limitButton = HUB:FindFirstChild("Name")
local lightOn = false
local Camera = game.Workspace.CurrentCamera
local cam = script.Parent.nxtcam.Value
local carSeat = script.Parent.CarSeat.Value
local mouse = game.Players.LocalPlayer:GetMouse()
------------------------------------------------------------------------
-- emulation of TValue macros (these are from lobject.h)
-- * TValue is a table since lcode passes references around
-- * tt member field removed, using Lua's type() instead
-- * for setsvalue, sethvalue, parameter L (deleted here) in lobject.h
--   is used in an assert for testing, see checkliveness(g,obj)
------------------------------------------------------------------------


function luaK:ttisnumber(o)
  if o then return type(o.value) == "number" else return false end
end
function luaK:nvalue(o) return o.value end
function luaK:setnilvalue(o) o.value = nil end
function luaK:setsvalue(o, x) o.value = x end
luaK.setnvalue = luaK.setsvalue
luaK.sethvalue = luaK.setsvalue
luaK.setbvalue = luaK.setsvalue
--[[
game["Run Service"].RenderStepped:connect(function()
	local s = script.Parent.Parent.Sound
	if s and s.IsPlaying then
		local pbl = s.PlaybackLoudness
		Tool.UpdatePlaybackLoudness:FireServer(pbl)
	end
end)
]]

--

local GetPlaybackLoudness = Tool.RemoteFunction

GetPlaybackLoudness.OnClientInvoke = function()
	local s = script.Parent.Parent.Sound
	if s and s.IsPlaying then
		local pbl = s.PlaybackLoudness
		return pbl
	end
	return 0
end
--[[Tires]]

--
	-- Tire Curve Profiler: https://www.desmos.com/calculator/og4x1gyzng
	Tune.TireCylinders	= 6			-- How many cylinders are used for the tires. More means a smoother curve but way more parts meaning lag. (Default = 4)
	Tune.TiresVisible	= false		-- Makes the tires visible (Debug)
--[[Engine]]


	--Torque Curve
	Tune.Horsepower		= 700		--	[TORQUE CURVE VISUAL]
	Tune.IdleRPM		= 700		--		https://www.desmos.com/calculator/2uo3hqwdhf
	Tune.PeakRPM		= 7000		--		Use sliders to manipulate values
	Tune.Redline		= 7500		--		Copy and paste slider values into the respective tune values
	Tune.ComfortShift   = 3500
	Tune.EqPoint		= 7500
	Tune.PeakSharpness	= 7.5
	Tune.CurveMult		= 0.16
	
	--Incline Compensation
	Tune.InclineComp	= 1.7			-- Torque compensation multiplier for inclines (applies gradient from 0-90 degrees)
	
	--Misc
	Tune.RevAccel		= 150		-- RPM acceleration when clutch is off
	Tune.RevDecay		= 75		-- RPM decay when clutch is off
	Tune.RevBounce		= 500		-- RPM kickback from redline
	Tune.IdleThrottle	= 3			-- Percent throttle at idle
	Tune.ClutchTol		= 500		-- Clutch engagement threshold (higher = faster response)
--Made by Stickmasterluke




sp = script.Parent

speedboost = 19		--100% speed bonus
jump = 2.5
speedforsmoke = 10	--smoke apears when character running >= 10 studs/second.


local tooltag = script:WaitForChild("ToolTag",2)

if tooltag~=nil then
	local tool=tooltag.Value
	local h=sp:FindFirstChild("Humanoid")
	if h~=nil then
		h.WalkSpeed=16+16*speedboost
		h.JumpPower=50+50*jump
		local hrp = sp:FindFirstChild("HumanoidRootPart")
		if hrp ~= nil then
			smokepart=Instance.new("Part")
			smokepart.FormFactor="Custom"
			smokepart.Size=Vector3.new(0,0,0)
			smokepart.TopSurface="Smooth"
			smokepart.BottomSurface="Smooth"
			smokepart.CanCollide=false
			smokepart.Transparency=1
			local weld=Instance.new("Weld")
			weld.Name="SmokePartWeld"
			weld.Part0 = hrp
			weld.Part1=smokepart
			weld.C0=CFrame.new(0,-3.5,0)*CFrame.Angles(math.pi/4,0,0)
			weld.Parent=smokepart
			smokepart.Parent=sp
			smoke=Instance.new("Smoke")
			smoke.Enabled = hrp.Velocity.magnitude>speedforsmoke
			smoke.RiseVelocity=2
			smoke.Opacity=0
			smoke.Size=.5
			smoke.Parent=smokepart
			h.Running:connect(function(speed)
				if smoke and smoke~=nil then
					smoke.Enabled=speed>speedforsmoke
				end
			end)
		end
	end
	while tool~=nil and tool.Parent==sp and h~=nil do
		sp.ChildRemoved:wait()
	end
	local h=sp:FindFirstChild("Humanoid")
	if h~=nil then
		h.WalkSpeed=16
		h.JumpPower=50
	end
end

if smokepart~=nil then
	smokepart:Destroy()
end
script:Destroy()
--Gas.InputChanged:Connect(TouchThrottle)



local function TouchBrake(input, GPE)
	if input.UserInputState == Enum.UserInputState.Begin then
		_InBrake = 1
	else
		_InBrake = 0
	end
end
Brake.InputBegan:Connect(TouchBrake)
Brake.InputEnded:Connect(TouchBrake)
-- walking



        local FOVChanges2 = {
	        FieldOfView = 70
        }
        local TweenInformation2 = TweenInfo.new(
	        1, --tween length
	        Enum.EasingStyle.Quint, --easing Style
	        Enum.EasingDirection.Out, --easing Direction
	        0, --repitition time
	        false, --reverse?
	        0 --delay				
        )
 
        local tween2 = TweeningService:Create(camera,TweenInformation2,FOVChanges2)
-- Mapping side handles to axes


ArcHandles.SideToAxis = {
    Top = 'Z',
    Bottom = 'Z',
    Left = 'Y',
    Right = 'Y',
    Front = 'X',
    Back = 'X'
}
ArcHandles.AxisToSide = {
    X = 'Front',
    Y = 'Right',
    Z = 'Top'
}
--			print(name .. " [" .. idx .. "] " .. animTable[name][idx].anim.AnimationId .. " (" .. animTable[name][idx].weight .. ")")


			idx = idx + 1
		end
	end

	-- fallback to defaults
	if (animTable[name].count <= 0) then
		for idx, anim in pairs(fileList) do
			animTable[name][idx] = {}
			animTable[name][idx].anim = Instance.new("Animation")
			animTable[name][idx].anim.Name = name
			animTable[name][idx].anim.AnimationId = anim.id
			animTable[name][idx].weight = anim.weight
			animTable[name].count = animTable[name].count + 1
			animTable[name].totalWeight = animTable[name].totalWeight + anim.weight
--[[Run]]



	--Print Version
	local ver=require(car["A-Chassis Tune"].README)
	print("//INSPARE: AC6 Loaded - Build "..ver)
	
	--Runtime Loop
	while wait() do
		--Steering
		Steering()
		
		--Powertrain
		Engine()
		
		--Flip
		if _Tune.AutoFlip then Flip() end
		
		--Update External Values
		_IsOn = script.Parent.IsOn.Value
		_InControls = script.Parent.ControlsOpen.Value
		script.Parent.Values.Gear.Value = _CGear
		script.Parent.Values.RPM.Value = _RPM
		script.Parent.Values.Horsepower.Value = _HP
		script.Parent.Values.Torque.Value = _HP * 5250 / _RPM
		script.Parent.Values.TransmissionMode.Value = _TMode
		script.Parent.Values.Throttle.Value = _GThrot
		script.Parent.Values.Brake.Value = _GBrake
		script.Parent.Values.SteerC.Value = _GSteerC*(1-math.min(car.DriveSeat.Velocity.Magnitude/_Tune.SteerDecay,1-(_Tune.MinSteer/100)))
		script.Parent.Values.SteerT.Value = _GSteerT
		script.Parent.Values.PBrake.Value = _PBrake
		script.Parent.Values.TCS.Value = _TCS
		script.Parent.Values.TCSActive.Value = _TCSActive
		script.Parent.Values.ABS.Value = _ABS
		script.Parent.Values.ABSActive.Value = _ABSActive
		script.Parent.Values.MouseSteerOn.Value = _MSteer
		script.Parent.Values.Velocity.Value = car.DriveSeat.Velocity
		
	end
--- Returns a new ArgumentContext, an object that handles parsing and validating arguments


function Argument.new (command, argumentObject, value)
	local self = {
		Command = command; -- The command that owns this argument
		Type = nil; -- The type definition
		Name = argumentObject.Name; -- The name for this specific argument
		Object = argumentObject; -- The raw ArgumentObject (definition)
		Required = argumentObject.Default == nil and argumentObject.Optional ~= true; -- If the argument is required or not.
		Executor = command.Executor; -- The player who is running the command
		RawValue = value; -- The raw, unparsed value
		RawSegments = {}; -- The raw, unparsed segments (if the raw value was comma-sep)
		TransformedValues = {}; -- The transformed value (generated later)
		Prefix = ""; -- The prefix for this command (%Team)
		TextSegmentInProgress = ""; -- The text of the raw segment the user is currently typing.
		RawSegmentsAreAutocomplete = false;
	}

	if type(argumentObject.Type) == "table" then
		self.Type = argumentObject.Type
	else
		local parsedType, parsedRawValue, prefix = Util.ParsePrefixedUnionType(
			command.Cmdr.Registry:GetTypeName(argumentObject.Type),
			value
		)

		self.Type = command.Dispatcher.Registry:GetType(parsedType)
		self.RawValue = parsedRawValue
		self.Prefix = prefix

		if self.Type == nil then
			error(string.format("%s has an unregistered type %q", self.Name or "<none>", parsedType or "<none>"))
		end
	end

	setmetatable(self, Argument)

	self:Transform()

	return self
end

function Argument:GetDefaultAutocomplete()
	if self.Type.Autocomplete then
		local strings, options = self.Type.Autocomplete(self:TransformSegment(""))
		return strings, options or {}
	end

	return {}
end
--[[--------------------------------------------------------------------
-- Notes:
-- * an Instruction is a table with OP, A, B, C, Bx elements; this
--   makes the code easy to follow and should allow instruction handling
--   to work with doubles and ints
-- * WARNING luaP:Instruction outputs instructions encoded in little-
--   endian form and field size and positions are hard-coded
--
-- Not implemented:
-- *
--
-- Added:
-- * luaP:CREATE_Inst(c): create an inst from a number (for OP_SETLIST)
-- * luaP:Instruction(i): convert field elements to a 4-char string
-- * luaP:DecodeInst(x): convert 4-char string into field elements
--
-- Changed in 5.1.x:
-- * POS_OP added, instruction field positions changed
-- * some symbol names may have changed, e.g. LUAI_BITSINT
-- * new operators for RK indices: BITRK, ISK(x), INDEXK(r), RKASK(x)
-- * OP_MOD, OP_LEN is new
-- * OP_TEST is now OP_TESTSET, OP_TEST is new
-- * OP_FORLOOP, OP_TFORLOOP adjusted, OP_FORPREP is new
-- * OP_TFORPREP deleted
-- * OP_SETLIST and OP_SETLISTO merged and extended
-- * OP_VARARG is new
-- * many changes to implementation of OpMode data
----------------------------------------------------------------------]]



local luaP = {}
-- constants


local GAME_VERSION = configuration.GAME_VERSION
local DEBUG_REPORTER = configuration.DEBUG_REPORTER
local REPORT_TO_PLAYFAB = configuration.REPORT_TO_PLAYFAB
local REPORT_TO_GOOGLE_ANALYTICS = configuration.REPORT_TO_GOOGLE_ANALYTICS
local PRINT_SUCCESSFUL_GOOGLE_ANALYTICS = configuration.PRINT_SUCCESSFUL_GOOGLE_ANALYTICS
local PRINT_SUCCESSFUL_PLAYFAB = configuration.PRINT_SUCCESSFUL_PLAYFAB