-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnturned zombie in E2
396 lines (349 loc) · 12 KB
/
Unturned zombie in E2
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
@name Zombie by Naki
@inputs [Torso Head Left_Arm Right_Arm Left_Leg Right_Leg]:entity [DMGTorso DMGHead DMGLeft_Arm DMGRight_Arm DMGLeft_Leg DMGRight_Leg LastDMGEnt]:entity LastDMGNum DMGClk
@persist [MOVEMODE MOVETYPE]:string [TIME_DELTA TIME_CURRENT] [DIR_UP ViewPos]:vector [EYE]:angle [CONTROLLER TARGET]:entity Health MoveVal Attacking CanAttack InRange HAS_TARGET MovingVal HandAng AttackTiming Spin Space
@persist [POSITION VELOCITY TARGET_VELOCITY GRAVITY]:vector [DIR_MOVE DIR_LOOK]:vector [BBOX_MIN BBOX_MAX]:vector [BBOX_RAD]
@persist [HIT_BELOW HIT_ABOVE HIT_BBOX RADIUS]
@persist [HEIGHT_STAND HEIGHT_CROUCH HEIGHT_JUMP HEIGHT_CURRENT MOVE_SPEED] [K_GRAVITY] On
@outputs On Health
interval(100)
if(dupefinished()){reset()}
if(first()){
On=1
Health=70
function number vector:isInCone(Origin:vector,Dir:angle,ConeAng,Dist){
local TargPos = This
local Dang = bearing(Origin,Dir,TargPos)
local Fang = elevation(Origin,Dir,TargPos)
local Tdist = TargPos:distance(Origin)
if(abs(Fang)<=ConeAng && abs( Dang ) <= ConeAng && Tdist <= Dist){
return 1
}else{
return 0
}
}
HEIGHT_STAND = 72 # height at top (head for bipeds) when standing
HEIGHT_CROUCH = 0 # height at top (head for bipeds) when crouching,set to 0 to disable crouching
HEIGHT_JUMP = 50 # height at top (head for bipeds) at apex of jump,set to 0 to disable jumping
MOVE_SPEED = 100
RADIUS = 18 # radius of bbox collider
K_GRAVITY = -1200 # accleration of gravity (gmod units per second)
function recalc_bbox(Radius,Height){
HEIGHT_CURRENT = Height
BBOX_RAD = Radius
BBOX_MIN = vec(-Radius,-Radius,-Height*0.5)
BBOX_MAX = vec(Radius,Radius,0)
}
recalc_bbox(RADIUS,HEIGHT_STAND)
CONTROLLER = holoCreate(1,entity():pos() + vec(0,0,HEIGHT_CURRENT),vec())
POSITION = CONTROLLER:pos()
MOVEMODE = "GROUND"
local I = 2
local E = holoEntity(1)
local T = Torso
holoCreate(I)
holoPos(I,T:toWorld(vec()))
holoAng(I,T:toWorld(ang()))
T:parentTo(holoEntity(I))
holoPos(I,E:toWorld(vec(0,0,-35)))
holoAng(I,E:toWorld(ang(0,0,0)))
holoParent(I,E)
rangerFilter(T:children())
local I = 3
local E = holoEntity(2)
local T = Head
holoCreate(I)
holoPos(I,T:toWorld(vec()))
holoAng(I,T:toWorld(ang()))
T:parentTo(holoEntity(I))
holoPos(I,E:toWorld(vec(0,0,23)))
holoAng(I,E:toWorld(ang(0,0,0)))
holoParent(I,E)
rangerFilter(T:children())
local I = 4
local E = holoEntity(2)
local T = Left_Leg
holoCreate(I)
holoPos(I,T:toWorld(vec()))
holoAng(I,T:toWorld(ang()))
T:parentTo(holoEntity(I))
holoPos(I,E:toWorld(vec(0,-5,-1)))
holoAng(I,E:toWorld(ang(0,0,0)))
holoParent(I,E)
rangerFilter(T:children())
local I = 5
local E = holoEntity(2)
local T = Right_Leg
holoCreate(I)
holoPos(I,T:toWorld(vec()))
holoAng(I,T:toWorld(ang()))
T:parentTo(holoEntity(I))
holoPos(I,E:toWorld(vec(0,5,-1)))
holoAng(I,E:toWorld(ang(0,0,0)))
holoParent(I,E)
rangerFilter(T:children())
local I = 6
local E = holoEntity(2)
local T = Left_Arm
holoCreate(I)
holoPos(I,T:toWorld(vec()))
holoAng(I,T:toWorld(ang()))
T:parentTo(holoEntity(I))
holoPos(I,E:toWorld(vec(0,-11,20)))
holoAng(I,E:toWorld(ang(0,0,0)))
holoParent(I,E)
rangerFilter(T:children())
local I = 7
local E = holoEntity(2)
local T = Right_Arm
holoCreate(I)
holoPos(I,T:toWorld(vec()))
holoAng(I,T:toWorld(ang()))
T:parentTo(holoEntity(I))
holoPos(I,E:toWorld(vec(0,11,20)))
holoAng(I,E:toWorld(ang(0,0,0)))
holoParent(I,E)
rangerFilter(T:children())
#rangerHitEntities(0)
rangerHitWater(0)
findIncludePlayerProps(owner())
findInSphere(entity():pos(),200)
rangerFilter(findToArray())
rangerFilter(array(Head,Torso,Left_Arm,Right_Arm,Left_Leg,Right_Leg))
rangerPersist(1)
for(I=1,7){
holoScale(I,vec())
}
# SETUP -> SIM
DIR_UP = vec(0,0,1)
TIME_CURRENT = curtime()
CanAttack=1
Spin=0
timer("main",1)
runOnKeys(owner(),1)
}
if(clk("main")){
# SIM
timer("main",60)
TIME_DELTA = curtime() - TIME_CURRENT
TIME_CURRENT = curtime()
# GROUND MOVEMODE
if(MOVEMODE == "GROUND"){
#[
COLLISION -> LINEAR
- REFLECT BBOX HITPOS ALONG BBOX HITNORMAL
- CORRECT VELOCITY FOR THIS REFLECTION
FLAGS -> HIT_BBOX:1
]#
local Trace_BBox = rangerOffsetHull(POSITION,POSITION + VELOCITY,BBOX_MIN,BBOX_MAX)
if(Trace_BBox:hit()){
local CheckPos = POSITION + VELOCITY
local CheckHit = Trace_BBox:position()
local CheckDir = Trace_BBox:hitNormal():setZ(0)*1.05
Trace_BBox = rangerOffsetHull(CheckHit,CheckPos - CheckDir*(CheckPos - CheckHit):dot(CheckDir),BBOX_MIN,BBOX_MAX)
VELOCITY = (Trace_BBox:position() - POSITION):setZ(0)
HIT_BBOX = 1
}else{
HIT_BBOX = 0
}
POSITION += VELOCITY
#[
COLLISION -> VERTICAL
- TRACE IN DIRECTION OF VERTICAL MOVEMENT
]#
local Dir_Z = sign(GRAVITY[3]) ?: -1
local Trace_Z = rangerOffset(9999999,POSITION,vec(0,0,Dir_Z))
#[
COLLISION -> VERTICAL -> SLOPE
- DETECT DOWNWARD SLOPES USING DOT PRODUCT
- CORRECT HEIGHT TO STICK TO THEM INSTEAD OF FLYING OFF
FLAGS -> HIT_BELOW:2
]#
if(HIT_BELOW == 1){
local Dot_Z = VELOCITY:normalized():dot(Trace_Z:hitNormal())
if(Dot_Z){
if(Trace_Z:distance() < HEIGHT_CURRENT*1.5){
POSITION[3] = Trace_Z:position()[3] + HEIGHT_CURRENT
HIT_BELOW = 2
}
}
}
#[
COLLISION -> VERTICAL -> BELOW
- ADD GRAVITY AND CORRECT HEIGHT
FLAGS -> HIT_BELOW:1
]#
if(Dir_Z == -1){
POSITION = POSITION + GRAVITY*TIME_DELTA + vec(0,0,0.5*K_GRAVITY*TIME_DELTA*TIME_DELTA)
local Hit_Z = Trace_Z:position()[3] + HEIGHT_CURRENT
if(POSITION[3] <= Hit_Z){
POSITION[3] = Hit_Z
GRAVITY[3] = 0
HIT_BELOW = 1
}else{
HIT_BELOW = 0
}
}
#[
COLLISION -> VERTICAL -> ABOVE
- ADD GRAVITY AND CORRECT HEIGHT
FLAGS -> HIT_ABOVE:1
]#
if(Dir_Z == 1){
POSITION = POSITION + GRAVITY*TIME_DELTA + vec(0,0,0.5*K_GRAVITY*TIME_DELTA*TIME_DELTA)
local Hit_Z = Trace_Z:position()[3]
if(POSITION[3] >= Hit_Z){
POSITION[3] = Hit_Z
GRAVITY[3] = 0
HIT_ABOVE = 1
}else{
HIT_ABOVE = 0
}
}
HAS_TARGET=TARGET:isAlive()&TARGET:isValid()
if(HAS_TARGET){
if(TARGET:pos():distance(CONTROLLER:pos())>1000){
TARGET=noentity()
}
}else{
timer("find",500)
}
TARGET_POS=TARGET:shootPos()
TargAng=(TARGET_POS-CONTROLLER:pos()):toAngle()
TargAngLocal=CONTROLLER:toLocal(TargAng)
# PLAYER -> EYE
EYE = TARGET:isAlive() ? TargAng : CONTROLLER:angles()
DIR_LOOK = EYE:forward()
if((TargAngLocal:yaw()>-45)&(TargAngLocal:yaw()<45)){
W=1
}
if((TargAngLocal:yaw()>-45+90)&(TargAngLocal:yaw()<45+90)){
A=1
D=0
}
if((TargAngLocal:yaw()>-45-90)&(TargAngLocal:yaw()<45-90)){
A=0
D=1
}
W=W*(CONTROLLER:pos():distance(TARGET_POS)>RADIUS*3)*HAS_TARGET
S=(CONTROLLER:pos():distance(TARGET_POS)<RADIUS*1)*HAS_TARGET
A=A*HAS_TARGET
D=D*HAS_TARGET
Moving=(W|A|S|D)&!Attacking
MoveVal+=0.1*(Moving-!Moving)
MoveVal=clamp(MoveVal,0,1)
InRange=(CONTROLLER:pos():distance(TARGET_POS)<RADIUS*3.5)
if(InRange&HAS_TARGET&CanAttack){
timer("canAttack",1000)
timer("dealDamage",100)
CanAttack=0
AttackTiming=1
CONTROLLER:emitSound("npc/zombie/claw_miss1.wav",80,100,1)
}
MovingVal+=0.1*(Moving-!Moving)
MovingVal=clamp(MovingVal,0,1)
HandAng+=0.2*(HAS_TARGET-!HAS_TARGET)
HandAng=clamp(HandAng,0,1)
Spin2=clamp((systime()-Spin)*360*2,0,360)*(Spin>0)
if(Spin2>=360){
Spin=0
}
holoPos(2,holoEntity(1):toWorld(vec(0,0,-35)))
holoAng(2,holoEntity(1):toWorld(ang(8,3,1*(1-HandAng))+ang(0,Spin2,0)))
holoAng(3,holoEntity(2):toWorld(ang(5,2,-1)*(1-HandAng))+ang(clamp(TargAngLocal:pitch()*0.5,-25,25),clamp(TargAngLocal:yaw()*0.8,-50,50),0)*HandAng)
holoAng(4,holoEntity(1):toWorld(ang(-25*sin(systime()*180*1.75)*MovingVal,-8*(1-MovingVal),0)))
holoAng(5,holoEntity(1):toWorld(ang(25*sin(systime()*180*1.75)*MovingVal,6*(1-MovingVal),0)))
AttackTiming-=0.25
AttackTiming=clamp(AttackTiming,0,1)
if(AttackTiming>0.5){
AttackTiming2=1-AttackTiming
}else{
AttackTiming2=AttackTiming
}
holoAng(6,holoEntity(2):toWorld(ang(-8-(90*HandAng),-8*(1-HandAng),-2*(1-HandAng))+ang(-45*AttackTiming2,-5*HandAng,0)))
holoAng(7,holoEntity(2):toWorld(ang(-8-(90*HandAng),6*(1-HandAng),2*(1-HandAng))+ang(-45*AttackTiming2,-1*HandAng,0)))
# PLAYER -> MOVEMENT DIRECTION
if(W|A|S|D){
if(W|S){
DIR_MOVE += (W - S)*DIR_LOOK:setZ(0)
}
if(A|D){
DIR_MOVE += (D - A)*DIR_LOOK:setZ(0):cross(DIR_UP)
}
DIR_MOVE=DIR_MOVE:normalized()
}
DIR_MOVE=DIR_MOVE*MoveVal
# CONTROLLER -> VELOCITY AND GRAVITY
if(HIT_BELOW){
SPEED_MOVE = MOVE_SPEED*TIME_DELTA
VELOCITY = DIR_MOVE*SPEED_MOVE
if(HEIGHT_JUMP & changed(Space)&Space){
GRAVITY = vec(0,0,sqrt(-2*K_GRAVITY*HEIGHT_JUMP))
HIT_BBOX = HIT_ABOVE = HIT_BELOW = 0
Space=0
}
}else{
SPEED_MOVE = MOVE_SPEED*TIME_DELTA
VELOCITY = DIR_MOVE*SPEED_MOVE
GRAVITY += vec(0,0,K_GRAVITY*TIME_DELTA)
Val=0
}
# OUTPUT
holoPos(1,POSITION)
holoAng(1,ang(0,EYE:yaw(),0))
}
}
if(changed(DMGClk)){
if(LastDMGNum>0){
if(LastDMGEnt==DMGHead){
Health-=LastDMGNum*1.5
}
if(LastDMGEnt==DMGTorso){
Health-=LastDMGNum*1.1
}
if(LastDMGEnt==DMGLeft_Arm){
Health-=LastDMGNum*0.2
}
if(LastDMGEnt==DMGRight_Arm){
Health-=LastDMGNum*0.2
}
if(LastDMGEnt==DMGLeft_Leg){
Health-=LastDMGNum*0.8
}
if(LastDMGEnt==DMGRight_Leg){
Health-=LastDMGNum*0.8
}
CONTROLLER:emitSound("npc/zombie/zombie_pain3.wav",80,100,1)
if(Health<=0){
entity():propDelete()
}
}
}
if(clk("find")){
findClearWhiteList()
findClearBlackList()
foreach(I,E:entity=players()){
if(!E:isAlive()|E:inNoclip()){
findExcludeEntity(E)
}
}
findExcludeClass("*_pickup")
findIncludeEntities(players())
findInSphere(CONTROLLER:toWorld(vec(200,0,0)),400)
findSortByDistance(CONTROLLER:pos())
TARGET=findResult(1)
if(TARGET:isValid()){
CONTROLLER:emitSound("npc/zombie/zombie_alert2.wav",80,100,1)
if(randint(0,3)==2){
Spin=systime()
Space=1
}
}
}
if(clk("canAttack")){
CanAttack=1
}
if(clk("dealDamage")){
if(InRange&HAS_TARGET){
TARGET:takeDamage(25,entity())
}
}