Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert PC, character and model to scripts
- Loading branch information
Showing
5 changed files
with
168 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |