-
Notifications
You must be signed in to change notification settings - Fork 0
/
CPlayer.lua
2202 lines (1967 loc) · 81.4 KB
/
CPlayer.lua
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
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--============================================================================
CPlayer =
{
Name = "No Name",
Model = "",
IsMovedByExplosions = true,
Weapons = {nil,nil,nil,nil,nil},
ExplosiveFired = false,
State = 0, -- do animacji i efektow na kliencie
EnabledWeapons = {"PainKiller","Shotgun","StakeGunGL","MiniGunRL","DriverElectro","RifleFlameThrower","BoltGunHeater"},
ForwardVector = Vector:New(0,0,0),
RightVector = Vector:New(0,0,0),
Health = 1999,
HealthWarning = 25,
Armor = 0,
ArmorWarning = 25,
ArmorType = 0,
ArmorRescueFactor = 0,
ArmorFound = 0,
FrozenArmor = false,
WalkBobSpeed = 10,
QuadedEnemies = 0, -- for MP
_CamDisplacement = 0,
--BodyCount = 0,
Money = 0,
HolyItems = 0,
BonusItems = 0,
SecretsFound = 0,
CurAction = 0,
LastAction = 0,
Comments = 0,
_lava = -1;
_waitingForFirstFire = false,
ClientID = ServerID,
LevelBodyCount = 0,
HasQuad = false,
HasWeaponModifier = false,
HasPentagram = false,
SoulsCount = 0,
TotalSoulsCount = 0,
MinimalHealth = 9999,
WasHurt = false,
_CurWeaponIndex = 1,
_RunTime = 0,
_JumpSndDelay = -1,
_GroundSndDelay = -1,
_LastStep = Vector:New(100,0,0),
_LastStepTime = -1,
_LastPos = Vector:New(100,0,0),
_Leg = 1,
_Walking = false,
_WalkTime = 0,
_yaw = 0,
_healthDecCnt = 0,
_Class = "CPlayer",
-- for logic
_slowDown = nil,
_velocity = 0,
_velocityx = 0,
_velocityy = 0,
_velocityz = 0,
_groundx = 0,
_groundy = 0,
_groundz = 0,
_orientation = 0,
_slowDownTime = nil,
_lastPosHit = Vector:New(0,0,0),
_lastTimeHit = -100,
_lastHealthInc = -1000,
_lastTimeHitInc = 0,
_col = 0,
_lastTimePlayedSoundHit = 0,
minTimeBetweenHit = 15, -- mimalny czas pomiedzy graniem sampla dostawania (ale tylko od broni dalekich)
sndHit = {"impacts/bullet-body","impacts/bullet-body2",},
collisionMinSpeed = 25,
collisionMaxSpeed = 75,
collisionDamageModif = 1.0, -- damage = (speed - collisionSpeedMin) * collisionDamageModif
s_SubClass =
{
Ammo =
{
Shotgun = 999,
MiniGun = 999,
Grenades = 999,
Stakes = 999,
IceBullets = 999,
Shurikens = 999,
Electro = 999,
Rifle = 999,
FlameThrower = 999,
Bolt = 999,
HeaterBomb = 999,
},
MPAmmo =
{
Shotgun = 0,
MiniGun = 0,
Grenades = 0,
Stakes = 0,
IceBullets = 0,
Shurikens = 0,
Electro = 0,
Rifle = 0,
FlameThrower = 0,
Bolt = 0,
HeaterBomb = 0,
},
MPStartAmmo =
{
[1] = {},
[2] = {
Shotgun = 20,
IceBullets = 0,
},
[3] = {
Stakes = 10,
Grenades = 0,
},
[4] = {
Grenades = 5,
MiniGun = 0,
},
[5] = {
Shurikens = 25,
Electro = 0,
},
[6] = {
Rifle = 25,
FlameThrower = 0,
},
[7] = {
Bolt = 50,
HeaterBomb = 0,
},
},
AmmoWarning =
{
Shotgun = 5,
MiniGun = 10,
Grenades = 5,
Stakes = 5,
IceBullets = 5,
Shurikens = 5,
Electro = 10,
Rifle = 10,
FlameThrower = 10,
Bolt = 5,
HeaterBomb = 10,
},
MaxAmmo =
{
Shotgun = 100,
MiniGun = 500,
Grenades = 100,
Stakes = 100,
IceBullets = 100,
Shurikens = 250,
Electro = 500,
Rifle = 250,
FlameThrower = 500,
Bolt = 500,
HeaterBomb = 250,
},
MPMaxAmmo =
{
Shotgun = 100,
MiniGun = 250,
Grenades = 100,
Stakes = 100,
IceBullets = 100,
Shurikens = 200,
Electro = 250,
Rifle = 250,
FlameThrower = 0,
Bolt = 500,
HeaterBomb = 250,
},
_666Ammo =
{
Shotgun = 666,
MiniGun = 666,
Grenades = 666,
Stakes = 666,
IceBullets = 666,
Shurikens = 666,
Electro = 666,
Rifle = 666,
FlameThrower = 666,
Bolt = 666,
HeaterBomb = 666,
},
SoundsDefinitions =
{
path = "multiplayer/player",
dist1 = 10,
dist2 = 50,
Death =
{
dist1 = 15,
dist2 = 75,
samples = {"manplayer_death1", "manplayer_death2", "manplayer_death3", "manplayer_death4",
"manplayer_death5", "manplayer_death6", "manplayer_death7"},
},
Death_Gib =
{
dist1 = 15,
dist2 = 75,
samples = {"manplayer_telefrag2"},
},
Death_Telefrag =
{
dist1 = 10,
dist2 = 30,
samples = {"manplayer_telefrag1","manplayer_telefrag2","manplayer_telefrag3"},
},
Hurt_Small =
{
samples = {"manplayer_hurt_small1","manplayer_hurt_small2","manplayer_hurt_small3",
"manplayer_hurt_small4","manplayer_hurt_small5"}
},
Hurt_Medium =
{
samples = {"manplayer_hurt_medium1","manplayer_hurt_medium2",
"manplayer_hurt_medium3","manplayer_hurt_medium4"}
},
Hurt_Big =
{
samples = {"manplayer_hurt_big1","manplayer_hurt_big2","manplayer_hurt_big3"}
},
Hurt_OnHitGround =
{
samples = {"manplayer_jump_end-hurt1","manplayer_jump_end-hurt2"}
},
Hurt_Pent = {
samples = {"$/actor/leper_monk/lepper-odrzut"},
},
Hurt_Lava = { -- TODO
samples = {"$/actor/evilmonkv3/evil-fire-hit"},
},
Body_Falls =
{
dist1 = 10,
dist2 = 30,
samples = {"manplayer_bodyfalls"}
},
Jump =
{
dist1 = 10,
dist2 = 30,
samples = {"manplayer_jump_1","manplayer_jump_2"}
},
Jump_Double =
{
dist1 = 10,
dist2 = 30,
samples = {"manplayer_double_1","manplayer_double_2"}
},
Jump_End =
{
dist1 = 10,
dist2 = 30,
samples = {"manplayer-jump_end1","manplayer-jump_end2"}
},
}
}
}
Inherit(CPlayer,CActor)
--MPTEST = true
--============================================================================
function CPlayer:New()
local p = Clone(CPlayer)
return p
end
--============================================================================
Model2Player =
{
["mp-model-demon"] = "Demon.CPlayer",
["mp-model-fallenangel"] = "FallenAngel.CPlayer",
["mp-model-knight"] = "Knight.CPlayer",
["mp-model-beast"] = "Beast.CPlayer",
["mp-model-painkiller"] = "Painkiller.CPlayer",
["mp-model-player6"] = "HellKing.CPlayer",
["mp-model-player7"] = "Commando.CPlayer",
}
--============================================================================
function CPlayer:SndEnt(id,entity)
if Game.GMode == GModes.SingleGame then
CObject.SndEnt(self,id,entity)
else
local model = ENTITY.GetFileName(entity)
local tml = Model2Player[model]
if tml then
--Game:Print(tml)
CObject.SndEnt(Templates[tml],id,entity)
else
CObject.SndEnt(self,id,entity)
end
end
end
--============================================================================
function CPlayer:AddWeapon(slot)
if not self.Weapons[slot] then
local w = CloneTemplate(self.EnabledWeapons[slot] .. ".CWeapon")
if not w then MsgBox("?????") end
w.ObjOwner = self
w:Apply()
w:ForceAnim("idle",true,nil,0)
self.Weapons[slot] = w
end
return self.Weapons[slot]
end
--============================================================================
function CPlayer:Apply(old)
if self.Model ~= "" and (not old or self.Model ~= old.Model) then
ENTITY.Release(self._Entity)
self._Entity = CreatePlayer(self.Model,true)
ENTITY.EnableDraw(self._Entity,true)
EntityToObject[self._Entity] = self
ENTITY.SetPosition(self._Entity,self.Pos.X,self.Pos.Y,self.Pos.Z)
end
self:ForceAnim(self.Animation)
end
--============================================================================
function CPlayer:Delete()
--MsgBox("CPlayer:Delete():.."..self._Name.."\n")
Log("CPlayer:Delete():.."..self._Name.."\n")
self:FreeBlockedObjects()
Log("CPlayer:Delete #1():.."..self._Name.."\n")
self._Entity = nil
CActor.Delete(self)
Log("CPlayer:Delete #2():.."..self._Name.."\n")
for i=1,7 do
if self.Weapons[i] then
self.Weapons[i]:Delete()
end
end
Log("CPlayer:Delete #3():.."..self._Name.."\n")
end
--============================================================================
function CPlayer:SelectBestWeapon(priorityList)
for i,o in priorityList do
if o == 0 then
-- end of active weapons in list
return -1,-1
end
local slot = tonumber(string.sub(tostring(o),1,1))
local fire = tonumber(string.sub(tostring(o),2,2))
if self.EnabledWeapons[slot] then
local ammoname = Weapon2Ammo[o]
if ammoname == "Full" or self.Ammo[ammoname] > 0 then
return slot,fire
end
end
end
return -1,-1
end
--============================================================================
function CPlayer:TryToSelectNextWeaponWithAmmo(slot,fire)
local newslot = slot
if fire then
local weapon = tonumber(tostring(slot)..tostring(fire))
local ammoname = Weapon2Ammo[weapon]
if ammoname == "Full" or self.Ammo[ammoname] > 0 then
return newslot
end
for i,o in Cfg.WeaponPriority do
if o == 0 then
-- end of active weapons in list
return newslot
end
local slot = tonumber(string.sub(tostring(o),1,1))
local fire = tonumber(string.sub(tostring(o),2,2))
if self.EnabledWeapons[slot] then
local ammoname = Weapon2Ammo[o]
if ammoname == "Full" or self.Ammo[ammoname] > 0 then
return slot,fire
end
end
end
end
return newslot
end
--============================================================================
function CPlayer:Client_OnTakeWeapon(slot)
if Cfg.AutoChangeWeapon then
for i,o in Cfg.WeaponPriority do
if o == 0 then return end
local sl = tonumber(string.sub(tostring(o),1,1))
local ammoname = Weapon2Ammo[o]
if ammoname == "Full" or self.Ammo[ammoname] > 0 then
if self._CurWeaponIndex == sl then return end -- i have it or better
if slot == sl then
CPlayer.WeaponChangeRequest(self._Entity,slot) -- i found better
return
end
end
end
end
end
--============================================================================
-- [ CLIENT ] --
function CPlayer:ClientTick(delta)
--Game:Print("ENTITY.PO_GetCollisionGroup: "..ENTITY.PO_GetCollisionGroup(self._Entity))
--Game:Print("MDL.GetRagdollCollisionGroup: "..MDL.GetRagdollCollisionGroup(self._Entity))
if self._died or not self._Entity then
return
end
local ax,ay,az = CAM.GetAngRad()
ax = math.mod(math.pi*2 + math.mod(ax,math.pi*2),math.pi*2) -- (0 - 2PI)
ay = ay + math.pi/2 -- (0-PI)
ax = ax*(65535/(math.pi*2))
ay = ay*(65535/math.pi)
if Game.GMode ~= GModes.SingleGame and Game._procStats then -- warmup
CPlayer:SetupAction(self.ClientID,0,ax,ay)
return
end
self:Synchronize()
-- update timeout'ow
if self._JumpSndDelay > 0 then self._JumpSndDelay = self._JumpSndDelay - delta end
if self._GroundSndDelay > 0 then self._GroundSndDelay = self._GroundSndDelay - delta end
local action = INP.GetActionStatus(self._Entity)
--====================== WEAPONS STUFF - CLIENT SIDE ===============================
local nextSlot = -1
local fire = 0
local checkSwitchedFire = true
-- select best weapon 1
if INP.Action(Actions.SelectBestWeapon1) or INP.Action(Actions.FireBestWeapon1) then
nextSlot,fire = self:SelectBestWeapon(Cfg.BestWeapons1)
end
-- select best weapon 2
if INP.Action(Actions.SelectBestWeapon2) or INP.Action(Actions.FireBestWeapon2) then
nextSlot,fire = self:SelectBestWeapon(Cfg.BestWeapons2)
end
-- fire best weapon 1
if nextSlot ~= -1 and (INP.Action(Actions.FireBestWeapon1) or INP.Action(Actions.FireBestWeapon2)) then
action = ReplaceBitFlag(action,Actions.Fire,0)
action = ReplaceBitFlag(action,Actions.AltFire,0)
if fire == 1 then action = AddBitFlag(action, Actions.Fire) end
if fire == 2 then action = AddBitFlag(action, Actions.AltFire) end
checkSwitchedFire = false
end
-- switched fire
if checkSwitchedFire and (IsBitFlag(action,Actions.Fire) or IsBitFlag(action,Actions.AltFire)) then
local curSlot = self._CurWeaponIndex
if nextSlot ~= -1 then curSlot = nextSlot end
if (Cfg.SwitchFire[curSlot] and not Game.SwitchFire[curSlot]) or (Game.SwitchFire[curSlot] and not Cfg.SwitchFire[curSlot]) then
if IsBitFlag(action,Actions.Fire) then
action = ReplaceBitFlag(action,Actions.Fire,Actions.AltFire)
elseif IsBitFlag(action,Actions.AltFire) then
action = ReplaceBitFlag(action,Actions.AltFire,Actions.Fire)
end
end
end
local cw = self:GetCurWeapon()
-- next/prev weapon
if not (cw and cw._zoom and cw._zoom>0) and (INP.Action(Actions.NextWeapon) or INP.Action(Actions.PrevWeapon)) then
-- find current weapon
local slot = self._CurWeaponIndex
if INP.Action(Actions.NextWeapon) then
repeat
slot = slot + 1
if slot > 7 then slot = 1 end
until self.EnabledWeapons[slot]
nextSlot = slot
elseif INP.Action(Actions.PrevWeapon) then
repeat
slot = slot - 1
if slot < 1 then slot = 7 end
until self.EnabledWeapons[slot]
nextSlot = slot
end
end
if Game.GMode ~= GModes.SingleGame and Cfg.NoAmmoSwitch and nextSlot == -1 then
local fire = nil
if IsBitFlag(action,Actions.Fire) then fire = 1 end
if IsBitFlag(action,Actions.AltFire) then fire = 2 end
if fire then
nextSlot = self:TryToSelectNextWeaponWithAmmo(self._CurWeaponIndex,fire)
end
end
-- Game:Print(Slot2Action[curSlot])
if nextSlot ~= -1 then
--Game:Print(nextSlot)
action = AddBitFlag(action,Slot2Action[nextSlot])
end
--====================== WEAPONS STUFF =======================================
if self._waitingForFirstFire then
if not IsBitFlag(action,Actions.Fire) then
self._waitingForFirstFire = false
end
action = ReplaceBitFlag(action,Actions.Fire,0)
action = ReplaceBitFlag(action,Actions.AltFire,0)
end
if cw then
if (not IsFinalBuild() and INP.Key(Keys.G)==2) or Game.TPP or Cfg.ViewWeaponModel == false or (cw._zoom and cw._zoom>0)then
ENTITY.EnableDraw(self:GetCurWeapon()._Entity,false,true)
else
ENTITY.EnableDraw(self:GetCurWeapon()._Entity,true,true)
end
end
local ax,ay,az = CAM.GetAngRad()
ax = math.mod(math.pi*2 + math.mod(ax,math.pi*2),math.pi*2) -- (0 - 2PI)
ay = ay + math.pi/2 -- (0-PI)
ax = ax*(65535/(math.pi*2))
ay = ay*(65535/math.pi)
-- na kliencie ustawiam akcje non-stop
CPlayer:SetupAction(self.ClientID,action,ax,ay)
if Game._loonyProc then
self.ForwardVector:Set(CAM.GetForwardVector())
self.RightVector:Set(CAM.GetRightVector())
end
if IsBitFlag(self.CurAction,Actions.Jump) then
if not self.autoJumped and PLAYER.FloorCheck(self._Entity) then
self.CurAction = AddBitFlag(self.CurAction,Actions.Jump)
self.autoJumped = true
else
self.CurAction = ReplaceBitFlag(self.CurAction,Actions.Jump,0)
self.autoJumped = nil
end
end
-- na serwer przesylam nie czejsciej niz ustawiona ilosc fpsow lub przy kazdej zmianie stanu
if Game.GMode == GModes.MultiplayerClient then
-- predykcja na kliencie
local fv = self.ForwardVector
local rv = self.RightVector
ENTITY.PO_SetAction(self._Entity,self.CurAction)
PLAYER.ExecMultiPlayerAction(self._Entity,0,fv.X,fv.Y,fv.Z,rv.X,rv.Y,rv.Z)
end
local cw = self:GetCurWeapon()
if cw then
if Game.Active and Game.GMode == GModes.MultiplayerClient then
if nextSlot == -1 or nextSlot == self._CurWeaponIndex and cw._ActionState == "Idle" then
--Game:Print("CurWeaponIndex: "..self._CurWeaponIndex..", nextSlot:".. nextSlot)
WEAPON_PREDICTION = true
cw:InterpretAction()
WEAPON_PREDICTION = nil
end
end
cw:ClientTick(delta)
end
end
--============================================================================
-- [ SERVER ]
function CPlayer:ServerTick(delta)
if self._sendRagdollImpulse then
local a = self._sendRagdollImpulse
if LastExplosion and (a == AttackTypes.Explosion or a == AttackTypes.Grenade or a == AttackTypes.Rocket) then
CPlayer.RagdollSelfExplosion(self._OldEntity,unpack(LastExplosion))
end
self._OldEntity = nil
self._sendRagdollImpulse = nil
end
if self._died then
if Game.GMode ~= GModes.SingleGame then
-- autorespawn or waiting for free respawn point
if self._timeToRespawn then
self._timeToRespawn = self._timeToRespawn - delta
if self._timeToRespawn <= 0 then
Game.PlayerRespawnRequest(self.ClientID)
end
end
end
return
end
if not self._Entity then return end
if MPTEST or MPCfg.GameState ~= GameStates.Playing or MPCfg.GameMode == "Voosh" then
self.Ammo.Shotgun = 999
self.Ammo.MiniGun = 999
self.Ammo.Grenades = 999
self.Ammo.Stakes = 999
self.Ammo.IceBullets = 999
self.Ammo.Shurikens = 999
self.Ammo.Electro = 999
self.Ammo.Rifle = 999
self.Ammo.FlameThrower = 999
self.Ammo.Bolt = 999
self.Ammo.HeaterBomb = 999
end
if MPCfg.GameMode == "People Can Fly" then
self.Ammo.MiniGun = 0
self.Ammo.Grenades = 999
end
-- ForwardRocketJump
if self._frjump and self._frjump == 0 then
--self.CurAction = AddBitFlag(self.CurAction,Actions.Jump)
self._frjump = 1
local vx,vy,vz = ENTITY.GetVelocity(self._Entity)
local jump = 8.0 * Tweak.MultiPlayerMove.JumpStrength
if jump > vy and PLAYER.FloorCheck(self._Entity) then
Game:Print("FRJ")
ENTITY.SetVelocity(self._Entity, vx,jump,vz )
end
end
-- ustawiam biezaca akcje dla entity
ENTITY.PO_SetAction(self._Entity,self.CurAction)
--Game:Print(self.CurAction)
local fv = self.ForwardVector
local rv = self.RightVector
--Game:Print(fv.X.." "..fv.Y.." "..fv.Z.." "..rv.X.." "..rv.Y.." "..rv.Z)
--if Tweak.PlayerMove.QWPhysics then
if Game.GMode ~= GModes.SingleGame then
PLAYER.ExecMultiPlayerAction(self._Entity,0,fv.X,fv.Y,fv.Z,rv.X,rv.Y,rv.Z)
else
PLAYER.ExecAction(self._Entity,0,fv.X,fv.Y,fv.Z,rv.X,rv.Y,rv.Z)
end
self:InterpretAction(delta)
--Game:Print("SetMPByte: "..self.State)
PLAYER.SetMPByte(self._Entity,self.State)
end
--============================================================================
function CPlayer:TryToChangeWeapon(slot)
if not slot then return end
if MPCfg.GameMode == "Voosh" or MPCfg.GameMode == "People Can Fly" then return end
--MsgBox(slot)
local specialFire = false
if ENTITY.PO_IsActionState(self._Entity,Actions.FireBestWeapon1) or
ENTITY.PO_IsActionState(self._Entity,Actions.FireBestWeapon2) or
ENTITY.PO_IsActionState(self._Entity,Actions.ForwardRocketJump) or
ENTITY.PO_IsActionState(self._Entity,Actions.RocketJump)
then
specialFire = true
end
if Game.IsDemon then return end
if self.EnabledWeapons[slot] and slot ~= self._CurWeaponIndex then
local cw = self:GetCurWeapon()
if not cw or cw.ShotTimeOut < 0 then --and not ENTITY.PO_IsActionState(self._Entity,Actions.Fire) and not ENTITY.PO_IsActionState(self._Entity,Actions.AltFire) then
local prev = self._CurWeaponIndex
if self._SwitchToWeapon then prev = self._SwitchToWeapon end
self._SwitchToWeapon = nil
self.WeaponChangeConfirmation(self.ClientID,self._Entity,slot)
-- po best fire wracamy do poprzedniej broni
if specialFire and slot ~= prev then
self._SwitchToWeapon = prev
Game:Print("1 Pozniej przelaczyc na: "..self._SwitchToWeapon)
end
else -- zakolejkowalem
if not self._SwitchToWeapon and not specialFire and slot ~= self._CurWeaponIndex then
self._SwitchToWeapon = slot
Game:Print("2 Pozniej przelaczyc na:"..self._SwitchToWeapon)
end
end
end
--if self._SwitchToWeapon then Game:Print(self._SwitchToWeapon) end
--Game
end
--============================================================================
-- [ SERVER ]
function CPlayer:InterpretAction(delta)
if not Game.Active then return end
local prevWeap = self._CurWeaponIndex
-- weapons 1-5
if ENTITY.PO_IsActionState(self._Entity,Actions.ForwardRocketJump) then
self:TryToChangeWeapon(4)
elseif ENTITY.PO_IsActionState(self._Entity,Actions.RocketJump) then
self:TryToChangeWeapon(4)
elseif ENTITY.PO_IsActionState(self._Entity,Actions.Weapon1) then
self:TryToChangeWeapon(1)
elseif ENTITY.PO_IsActionState(self._Entity,Actions.Weapon2) then
self:TryToChangeWeapon(2)
elseif ENTITY.PO_IsActionState(self._Entity,Actions.Weapon3) then
self:TryToChangeWeapon(3)
elseif ENTITY.PO_IsActionState(self._Entity,Actions.Weapon4) then
self:TryToChangeWeapon(4)
elseif ENTITY.PO_IsActionState(self._Entity,Actions.Weapon5) then
self:TryToChangeWeapon(5)
elseif ENTITY.PO_IsActionState(self._Entity,Actions.Weapon6) then
self:TryToChangeWeapon(6)
elseif ENTITY.PO_IsActionState(self._Entity,Actions.Weapon7) then
self:TryToChangeWeapon(7)
end
if prevWeap == self._CurWeaponIndex
and not (ENTITY.PO_IsActionState(self._Entity,Actions.FireBestWeapon1) or ENTITY.PO_IsActionState(self._Entity,Actions.FireBestWeapon2))
and self._SwitchToWeapon and not self._frjump
then -- queued weapon switch
--Game:Print("self:TryToChangeWeapon(self._SwitchToWeapon)")
self:TryToChangeWeapon(self._SwitchToWeapon)
end
local cw = self:GetCurWeapon()
if cw then
-- Forward/RocketJump - Step 1
if cw.ShotTimeOut <= 0 then
if not self._frjump and (ENTITY.PO_IsActionState(self._Entity,Actions.ForwardRocketJump) or ENTITY.PO_IsActionState(self._Entity,Actions.RocketJump))
and cw.BaseObj == "MiniGunRL.CWeapon" then
-- physics jump
--Game:Print("1")
self._frjump = 0
end
end
-- ForwardRocketJump - Step 2
if self._frjump and self._frjump == 1 then
-- rocket
if ENTITY.PO_IsActionState(self._Entity,Actions.ForwardRocketJump) then
self.ForwardVector.X = -self.ForwardVector.X
self.ForwardVector.Z = -self.ForwardVector.Z
end
ENTITY.PO_AddAction(self._Entity,Actions.Fire)
--Game:Print("2")
end
cw:InterpretAction()
-- ForwardRocketJump - Step 3
if self._frjump and self._frjump == 1 then
self._frjump = nil
--Game:Print("3")
if ENTITY.PO_IsActionState(self._Entity,Actions.ForwardRocketJump) then
self.ForwardVector.X = -self.ForwardVector.X
self.ForwardVector.Z = -self.ForwardVector.Z
end
end
end
end
--============================================================================
-- [ CLIENT & SERVER ] --
function CPlayer:Tick(delta)
if self._died then return end
local cw = self:GetCurWeapon()
if cw then cw:Tick(delta) end
if Game.GMode == GModes.SingleGame then
self._groundx, self._groundy, self._groundz = ENTITY.PO_GetPawnFloorPos(self._Entity)
local jumped = ENTITY.PO_JumpedInLastAction(self._Entity)
--if jumped then Game:Print("jumped") else Game:Print("not jumped") end
if self._JumpSndDelay <= 0 and jumped then
PlaySound2D("hero/hero_jump_"..math.random(1,2),nil,nil,true)
self._JumpSndDelay = 0.5
end
end
end
-- [ CLIENT & SERVER ] --
--============================================================================
function CPlayer:ClientTick2(delta)
self:Steps(delta)
if not self._died then
local cw = self:GetCurWeapon()
if cw then cw:ClientTick2(delta) end
end
if Game._EarthQuakeProc and Game._EarthQuakeProc._noEquake and not (self._CurWeaponIndex == 6 and self:GetCurWeapon()._altfire) then
--Game:Print(self._CamDisplacement)
CAM.SetPositionDisplacement(0,self._CamDisplacement,0)
end
end
--============================================================================
function CPlayer:RagdollSelfExplosion(e,x,y,z,explosionStrength,explosionRange)
if Game.GMode == GModes.MultiplayerClient then -- na MPServer bedzie widac normalna eksplozje
Game:Print(x..","..y..","..z..","..explosionStrength..","..explosionRange)
Game:Print("Name:")
Game:Print(ENTITY.GetFileName(e))
MDL.RagdollSelfExplosion(e,x,y,z,explosionStrength,explosionRange)
Game:Print("MDL.RagdollSelfExplosion - exit")
end
end
Network:RegisterMethod("CPlayer.RagdollSelfExplosion", NCallOn.AllClients, NMode.Reliable, "efffuu")
--============================================================================
-- [ CLIENT & SERVER ] --
function CPlayer:Update()
if not self._died then
if Game:IsServer() then
if self._lava < 0 then
--Game:Print("lava 1")
-- lawa
local is, e = self:IsOnGround()
if is and e then
--Game:Print("lava 2")
if string.find(ENTITY.GetName(e),"fire_hurt") then
--Game:Print(ENTITY.GetName(e))
--Game:Print("lava 3")
self:OnDamage(5, nil, AttackTypes.Lava)
self._lava = 10
end
if string.find(ENTITY.GetName(e),"lava_hurt") then
--Game:Print(ENTITY.GetName(e))
--Game:Print("lava 3")
self:OnDamage(10, nil, AttackTypes.Lava)
self._lava = 10
end
if string.find(ENTITY.GetName(e),"acid_hurt") then
--Game:Print(ENTITY.GetName(e))
self:OnDamage(15, nil, AttackTypes.Lava)
self._lava = 10
end
end
else
self._lava = self._lava - 1
end
end
-- health dec
if Game.GMode ~= GModes.SingleGame and self.Health > 100 then
if self._healthDecCnt >= 30 then
self.Health = self.Health - 1
self._healthDecCnt = 0
else
self._healthDecCnt = self._healthDecCnt + 1
end
end
-- health inc
if Game.GMode == GModes.SingleGame and self.Health < 75 and INP.GetTime() - self._lastTimeHitInc > 10 and Game.HealthRegen then
if INP.GetTime() - self._lastHealthInc >= 0.3 then
self.Health = self.Health + 1
self._lastHealthInc = INP.GetTime()
end
end
-- armor inc
if Game.GMode == GModes.SingleGame and self.Armor < 75 and self.ArmorType ~= 0 and INP.GetTime() - self._lastTimeHitInc > 10 and Game.ArmorRegen then
if INP.GetTime() - self._lastHealthInc >= 0.3 then
self.Armor = self.Armor + 1
self._lastHealthInc = INP.GetTime()
end
end
-- weapon tick
local cw = self:GetCurWeapon()
if cw then cw:Update() end
--------------------------------------------------------
-- Marek SinglePlayer stuff
if Game.GMode == GModes.SingleGame then
-- add default weapon
if cw == nil then
-- wybieram najsilniejsza bron
local mx = 1
for i,o in self.EnabledWeapons do mx = i end
cw = self:AddWeapon(mx)
WORLD.AddEntity(cw._Entity)
self._CurWeaponIndex = mx
end
-- jammed
if self._jammed then
self._jammed = self._jammed - 1
if self._jammed < 0 then
self._jammed = nil
end
end
-- poisoned
if self._poisoned then
self._poisoned = self._poisoned - 1
self._poisonedTime = self._poisonedTime - 1
if self._poisonedTime <= 0 then
self._poisonedTime = self._poison.Freq
if self._poison.DamageHp then
self:OnDamage(self._poison.DamageHp, nil, AttackTypes.Poison)
end
if self._poison.SlowDown then
self._slowDown = true
SetPlayerSpeed(self.PlayerSpeed * self._poison.SlowDown)
end
end
if self._poisoned < 0 then
--if self._poison.SlowDown then
self._slowDown = nil
SetPlayerSpeed(self.PlayerSpeed)
--end
self._poisoned = nil
self._poisonedTime = nil
self._poison = nil
end
end
if Game._loonyProc then
else
self._velocityx,self._velocityy,self._velocityz,self._velocity = ENTITY.GetVelocity(self._Entity)
end
self._orientation = ENTITY.GetOrientation(self._Entity)
-- energy sucker
if self.EnergySucker then
for i,o in GObjects.UpdateListItems do
if o.BaseObj == "Energy.CItem" or o.BaseObj == "Energyred.CItem" then
local diff = o.Pos:Copy()
diff:Sub(PX,PY+1.5,PZ)
o.Pos.X = o.Pos.X - diff.X * 0.4
o.Pos.Y = o.Pos.Y - diff.Y * 0.4
o.Pos.Z = o.Pos.Z - diff.Z * 0.4
end
end
end
end
--------------------------------------------------------
end
end
--============================================================================
function CPlayer:Synchronize()
if self._died or not self._Entity then return end
self.Pos:Set(ENTITY.GetPosition(self._Entity))
self.angle = ENTITY.GetOrientation(self._Entity)
end
--============================================================================
function CPlayer:ClientRender(delta)
if not Hud.Enabled then return end
if MPTEST or MPCfg.GameState ~= GameStates.Playing or MPCfg.GameMode == "Voosh" then
self.Ammo.Shotgun = 999
self.Ammo.MiniGun = 999
self.Ammo.Grenades = 999
self.Ammo.Stakes = 999
self.Ammo.IceBullets = 999
self.Ammo.Shurikens = 999
self.Ammo.Electro = 999
self.Ammo.Rifle = 999
self.Ammo.FlameThrower = 999
self.Ammo.Bolt = 999
self.Ammo.HeaterBomb = 999
end
if MPCfg.GameMode == "People Can Fly" then
self.Ammo.MiniGun = 0
self.Ammo.Grenades = 999
end
if Game.Active then
if not self._died and not self.Visible then
local cw = self:GetCurWeapon()
if cw then cw:ClientRender(delta) end
end
end
if self._DrawColorQuad then
if self._poisoned or self._jammed then
--self._poisonedTime < 30 or self._jammed < 30
self._col = self._col + delta
if self._col > 1 then
self._col = 1
end
else
self._col = self._col - delta
if self._col < 0 then
self._DrawColorQuad = nil
self._col = 0