forked from Tencent/UnLua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBP_CharacterBase_C.lua
More file actions
73 lines (61 loc) · 1.69 KB
/
BP_CharacterBase_C.lua
File metadata and controls
73 lines (61 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
require "UnLua"
local BP_CharacterBase_C = Class()
function BP_CharacterBase_C:Initialize(Initializer)
self.IsDead = false
self.BodyDuration = 3.0
self.BoneName = nil
local Health = 100
self.Health = Health
self.MaxHealth = Health
end
--function BP_CharacterBase_C:UserConstructionScript()
--end
function BP_CharacterBase_C:ReceiveBeginPlay()
local Weapon = self:SpawnWeapon()
if Weapon then
Weapon:K2_AttachToComponent(self.WeaponPoint, nil, UE4.EAttachmentRule.SnapToTarget, UE4.EAttachmentRule.SnapToTarget, UE4.EAttachmentRule.SnapToTarget)
self.Weapon = Weapon
end
end
function BP_CharacterBase_C:SpawnWeapon()
return nil
end
function BP_CharacterBase_C:StartFire()
if self.Weapon then
self.Weapon:StartFire()
end
end
function BP_CharacterBase_C:StopFire()
if self.Weapon then
self.Weapon:StopFire()
end
end
function BP_CharacterBase_C:ReceiveAnyDamage(Damage, DamageType, InstigatedBy, DamageCauser)
if not self.IsDead then
local Health = self.Health - Damage
self.Health = math.max(Health, 0)
if Health <= 0.0 then
self:Died(DamageType)
local co = coroutine.create(BP_CharacterBase_C.Destroy)
coroutine.resume(co, self, self.BodyDuration)
end
end
end
function BP_CharacterBase_C:Died(DamageType)
self.IsDead = true
self.CapsuleComponent:SetCollisionEnabled(UE4.ECollisionEnabled.NoCollision)
self:StopFire()
local Controller = self:GetController()
Controller:UnPossess()
end
function BP_CharacterBase_C:Destroy(Duration)
UE4.UKismetSystemLibrary.Delay(self, Duration)
if self.Weapon then
self.Weapon:K2_DestroyActor()
end
self:K2_DestroyActor()
end
function BP_CharacterBase_C:ChangeToRagdoll()
self.Mesh:SetSimulatePhysics(true)
end
return BP_CharacterBase_C