Skip to content

Commit

Permalink
Convert PC, character and model to scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
kbarber committed May 22, 2018
1 parent e8e0954 commit 75a9cce
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 109 deletions.
6 changes: 3 additions & 3 deletions src/Models/Core/MainModule/BTKPlugin/MainToolBar.lua
Expand Up @@ -39,11 +39,11 @@ MainToolBar.AssetsToInstall = {
},
{
Parent = game.StarterPlayer.StarterCharacterScripts,
Name = "BTKComponent",
Name = "BTK:PC",
Type = "Script",
Local = {
Folder = "CharacterScripts",
Name = "BTKComponent"
Folder = "Init",
Name = "BTK:Script"
}
},
{
Expand Down
106 changes: 0 additions & 106 deletions src/Models/Core/MainModule/components/PC.lua

This file was deleted.

50 changes: 50 additions & 0 deletions src/Models/Core/MainModule/scripts/Character.lua
@@ -0,0 +1,50 @@
local Model = require(script.Parent.Model)
local Schema = require(script.Parent.Schema)

local Character = Model:subclass(script.Name)
Character:AddProperty({
Name = "AttackDistance",
Type = "NumberValue",
Value = 5.0,
SchemaFn = Schema.AttackDistance,
AllowOverride = false,
})
Character:AddProperty({
Name = "Humanoid",
Type = "ObjectValue",
ValueFn = function(self2)
return self2:GetModel():FindFirstChildOfClass("Humanoid")
end,
SchemaFn = Schema:IsA("Humanoid"),
AllowOverride = true,
})
Character:AddProperty({
Name = "RootPart",
Type = "ObjectValue",
ValueFn = function(self2)
return self2:GetHumanoid().RootPart
end,
SchemaFn = Schema:IsA("BasePart"),
AllowOverride = true,
})

function Character:initialize(input)
Model.initialize(self, input)

local humanoid = self:GetHumanoid()
local inputEventData = self:GetInputEvent()
if humanoid then
inputEventData.Event:Connect(function(input2)
if input2.Type == Schema.Enums.InputEventType.Damage then
self:Dbg("Received damage")
if humanoid.RigType == Enum.HumanoidRigType.R15 then
humanoid.Health = humanoid.Health - input2.Payload.Damage
else
humanoid:TakeDamage(input2.Payload.Damage)
end
end
end)
end
end

return Character
28 changes: 28 additions & 0 deletions src/Models/Core/MainModule/scripts/Model.lua
@@ -0,0 +1,28 @@
local BaseScript = require(script.Parent.Parent.BaseScript)
local Schema = require(script.Parent.Parent.Schema)

local Model = BaseScript:subclass(script.Name)
Model:AddProperty({
Name = "Model",
Type = "ObjectValue",
ValueFn = function(self2)
return self2:GetScript().Parent
end,
SchemaFn = Schema:IsA("Model"),
AllowOverride = true,
})
Model:AddProperty({
Name = "PrimaryPart",
Type = "ObjectValue",
ValueFn = function(self2)
return self2:GetModel().PrimaryPart
end,
SchemaFn = Schema:IsA("BasePart"),
AllowOverride = false,
})

function Model:initialize(input)
BaseScript.initialize(self, input)
end

return Model
87 changes: 87 additions & 0 deletions src/Models/Core/MainModule/scripts/PC.lua
@@ -0,0 +1,87 @@
local Character = require(script.Parent.Character)
local Schema = require(script.Parent.Parent.Schema)

local PC = Character:subclass(script.Name)
PC:AddProperty({
Name = "Player",
Type = "ObjectValue",
ValueFn = function(self2)
return game.Players:GetPlayerFromCharacter(self2:GetModel())
end,
SchemaFn = Schema:IsA("Player"),
AllowOverride = false,
})
PC:AddProperty({
Name = "Currency",
Type = "NumberValue",
Value = 0,
SchemaFn = Schema.Currency,
AllowOverride = true,
})
PC:AddProperty({
Name = "CollectCollision",
Type = "ObjectValue",
SchemaFn = Schema.Optional(Schema:IsA("Part")),
AllowOverride = true,
})
PC:AddProperty({
Name = "CollectAttachment",
Type = "ObjectValue",
ValueFn = function(self2)
return Instance.new("Attachment", self2:GetRootPart())
end,
SchemaFn = Schema:IsA("Attachment"),
AllowOverride = true,
})

function PC:initialize(input)
Character.initialize(self, input)

local zeroMaterial = PhysicalProperties.new(0,0,0)

local cc = Instance.new("Part", self:GetModel())
cc.Name = "CollectCollision"
cc.Shape = Enum.PartType.Ball
cc.Anchored = false
cc.CanCollide = false
cc.Size = Vector3.new(18, 18, 18)
cc.Transparency = 1.0
cc.CustomPhysicalProperties = zeroMaterial
cc.Touched:Connect(function(hit)
local comp = self:GetComponentData({
Inst = hit,
})
if not comp then
return
end

local colAttachment = comp:GetData("CollectableAttachment")
if not colAttachment then
return
end

self:Debug("Hit someting with CollectableAttachment",
{
HitName = hit.Name,
}
)

local cf = Instance.new("AlignPosition", colAttachment)
cf.Name = "CollectableForce"
cf.Attachment0 = colAttachment
cf.Attachment1 = self:GetCollectAttachment()

delay(4, function()
cf:Destroy()
end)
end)

local weld = Instance.new("Weld", self:GetRootPart())
weld.Name = "CollectCollisionWeld"
weld.Part0 = self:GetRootPart()
weld.Part1 = cc

self:SetCollectCollision(cc)
end

return PC

0 comments on commit 75a9cce

Please sign in to comment.