-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathYPUBG_8.py
1940 lines (1776 loc) · 60.2 KB
/
YPUBG_8.py
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
"""
PUBG
script by yuyasato 20170722
"""
from pyspades.server import fog_color
from pyspades.common import make_color
from pyspades.world import Grenade
from math import floor,sin,cos,degrees,radians,atan2
from pyspades.common import Vertex3
from random import randint
from twisted.internet.reactor import callLater, seconds
from twisted.internet.task import LoopingCall
from pyspades.contained import BlockAction, SetColor
from pyspades.contained import *
from pyspades.server import *
from pyspades.common import *
from pyspades.constants import *
from pyspades.server import set_tool, weapon_reload, create_player, set_hp, block_action
from pyspades.server import ServerConnection
from random import randint, uniform, choice,triangular
from copy import deepcopy
from commands import alias, admin, add, name, get_team, get_player
TOW_MAN_CELL = True
BLACKOUTNEEDHIT=20
NOFF=True
CPS = 20 #calclation per sec
AREA_DAMAGE = 1 #dmg per 1/CPS sec
MAP_DESTROY_TIME = 60 #sec
VVTIME = 0.5 # sec
ARMOR_RATIO=0.95
MACHINEGUN_SPEED=0.12 #sec per bullet
BLOCK_SET_SPEED=0.01 #sec
ITEM_NUM=500
FOG_NORMAL = (128, 232, 255)
FOG_WARNING = (255,255,0)
FOG_WARNING_HIGH = (255,128,0)
FOG_DAMAGE = (255,0,0)
FOG_BLACKOUT = (20, 20, 0)
DESTROYED_MARGIN=5 #sec
MED_TIME=5 #sec
HMG_TIME=1 #sec
BOMBER_SPEED=0.5
BOMBER_TURNING=0.5
BOMBING_INTERVAL=60 #sec
MESSAGE_NEXTDESTROY = "[ C A U T I O N ] koko tugi sinu"
MESSAGE_NEXTDESTROY_HIGH = "[ W A R N I N G ] koko sinu"
MESSAGE_DESTROYED = "[ D A N G E R ] koko damage"
@alias('b')
@name('bombstart')
def bombstart(connection):
if connection.protocol.final_type!=0:
return "moudame"
if connection.hp>0:
return "dead only"
if seconds() - connection.bombingtime<BOMBING_INTERVAL:
return "wait %d sec"%(BOMBING_INTERVAL-(seconds() - connection.bombingtime))
connection.bombingtime=seconds()
connection.bombing()
callLater(BOMBING_INTERVAL, connection.bomb_enable)
return "bomb release"
add(bombstart)
@alias('hp')
@name('hpshow')
def hpshow(connection, name = None):
if name is None:
player = connection
else:
player = get_player(connection.protocol, name)
return "%s HP:%s"%(player.name, player.hp)
add(hpshow)
@alias('sq')
@name('squadteam')
def squadteam(connection, name = None):
if TOW_MAN_CELL:
if name is None:
return "hairu squad no namae kake!!"
else:
connection.sq = name
return "you joined squad '%s'"%name
return "this is not squad mode"
add(squadteam)
@alias('tms')
@name('toggletwomancell')
def toggletwomancell(connection):
if connection.protocol.prestart_time:
global TOW_MAN_CELL
TOW_MAN_CELL = not TOW_MAN_CELL
return connection.protocol.send_chat("TOW_MAN_CELL : %s"%TOW_MAN_CELL)
return "owatte kara yatte"
add(toggletwomancell)
@alias('chk')
@name('squadcheck')
def squadcheck(connection, name = None):
if TOW_MAN_CELL:
if name == "full":
usename=[]
for playera in connection.protocol.blue_team.get_players():
if not playera.name in usename:
samesqmem = []
for playerb in connection.protocol.blue_team.get_players():
if playera.sq == playerb.sq:
usename.append(playerb.name)
samesqmem.append(playerb.name)
connection.protocol.send_chat('%s : "%s"'%(samesqmem, playera.sq) )
return
else:
sqmem=False
for player in connection.protocol.blue_team.get_players():
if player != connection:
if connection.sq==player.sq:
connection.send_chat("%s : %s"%(player.name, player.sq))
sqmem=True
if not sqmem:
connection.send_chat("no one in your squad")
return
return "this is not squad mode"
add(squadcheck)
@alias('start')
@name('startpubg')
def startpubg(connection):
if TOW_MAN_CELL:
if connection.protocol.prestart_time:
usename=[]
bottisq=0
for playera in connection.protocol.blue_team.get_players():
if not playera.name in usename:
samesqmem = []
for playerb in connection.protocol.blue_team.get_players():
if playera.sq == playerb.sq:
usename.append(playerb.name)
samesqmem.append(playerb.name)
connection.protocol.send_chat('%s : "%s"'%(samesqmem, playera.sq) )
if len(samesqmem) <=1:
bottisq +=1
if bottisq >=2:
return connection.protocol.send_chat('botti 2nin ijou iruzo. ti-mu tukure')
if len(samesqmem)>2:
return connection.protocol.send_chat('3nin ijou iru kumi aruzo')
connection.protocol.start_pubg()
connection.protocol.send_chat("Ctrl : open parachute")
return connection.protocol.send_chat('-- game start --')
else:
return connection.protocol.send_chat('already started')
else:
if connection.protocol.prestart_time:
connection.protocol.start_pubg()
connection.protocol.send_chat("Ctrl : open parachute")
return connection.protocol.send_chat('-- game start --')
else:
return connection.protocol.send_chat('already started')
add(startpubg)
@alias('main')
@alias('m')
@name('main_weapon_change')
def main_weapon_change(connection,weapon):
weapon = int(weapon)
if weapon<len(weapon_name):
if not connection.weapon_have[weapon]:
return "you dont have this weapon now"
if connection.main_weapon == weapon:
return "main_weapon is already %s"%weapon
connection.main_weapon = weapon
if connection.weapon_ms_now==0:
connection.resend_tool()
connection.ammo[connection.weapon_now][0]=connection.weapon_object.current_ammo
connection.ammo[connection.weapon_now][1]=connection.weapon_object.current_stock
connection.weapon_now = weapon
connection.weapon_change_pubg()
return "main_weapon_change %s"%weapon
return "num over"
add(main_weapon_change)
@alias('sub')
@alias('s')
@name('sub_weapon_change')
def sub_weapon_change(connection,weapon):
weapon = int(weapon)
if weapon<len(weapon_name):
if not connection.weapon_have[weapon]:
return "you dont have this weapon now"
if connection.sub_weapon == weapon:
return "sub_weapon is already %s"%weapon
connection.sub_weapon = weapon
if connection.weapon_ms_now==1:
connection.resend_tool()
connection.ammo[connection.weapon_now][0]=connection.weapon_object.current_ammo
connection.ammo[connection.weapon_now][1]=connection.weapon_object.current_stock
connection.weapon_now = weapon
connection.weapon_change_pubg()
return "sub_weapon_change %s"%weapon
return "num over"
add(sub_weapon_change)
color_bolt =(255, 190, 190)
color_rifle =(255, 120, 120)
color_hmg =(255, 0, 0)
color_hand =(180, 180, 255)
color_smg =(125, 125, 255)
color_ar =(0, 0, 255)
color_sg =(170,255, 170)
color_med =(255,255,255)
color_armor =(120, 121, 119)
color_helmet =(27,81,5)
color_box=[
color_bolt ,
color_rifle ,
color_hmg ,
color_hand ,
color_smg ,
color_ar ,
color_sg ,
color_med ,
color_armor,
color_helmet]
item_probability=[
30 , #bolt
10 , #rifle
5 , #hmg
30 , #hand
10 , #smg
5 , #ar
10 , #sg
20 , #med
10, #armor
10] #helmet
weapon_name=[
"SPADE",
"BOLTACT",
"RIFLE",
"HMG",
"HANDGUN",
"SMG",
"AR",
"SHOTGUN"]
DEF_AMMO = [[0,0], [1,0],[10,0],[2,20],[6,0],[30,0],[20,0],[2,0]]
DEF_UNLOCK =[True,False,False,False,False,False,False,False]
class PUBGTerritory(Territory):
def add_player(self, player):
return
def update_rate(self):
return
def send_progress(self):
return
def finish(self):
return
def get_progress(self, set = False):
return
def apply_script(protocol, connection, config):
class PUBGConnection(connection):
weapon_change_killing = False
ammo=deepcopy(DEF_AMMO)
weapon_now=0 #0 spade, 1 bolt ,2 rifle, 3hmg 4hand , 5 smg ,6AR, 7 sg
weapon_ms_now = 0 # 0:main , 1:sub
main_weapon=0
sub_weapon=0
weapon_have=deepcopy(DEF_UNLOCK)
medkit=0
the_hp=100
sneaktime=0
armor = 0
helmet=0
rapid_loop = None
static_loop = None
in_area = 0 #0:normal 1:next_destroy 2:next_destroy_yabai 3:destroyed
destroyed_margin = 0
static = False
static_time=0
hmg_can = False
spawn_first=True
bombingtime=0
sq=None
blackout=False
blackhit=0
def on_join(self):
self.state_reset()
return connection.on_join(self)
def state_reset(self):
self.weapon_change_killing = False
self.ammo=deepcopy(DEF_AMMO)
self.weapon_now=0
self.weapon_ms_now = 0
self.main_weapon=0
self.sub_weapon=0
self.weapon_have=deepcopy(DEF_UNLOCK)
self.medkit=0
self.sneaktime=0
self.armor = 0
self.helmet=0
self.the_hp=100
self.in_area=0
self.destroyed_margin = 0
self.static = False
self.static_time=0
self.hmg_can = False
self.bombingtime=0
self.blackout=False
self.blackhit=0
def bomb_enable(self):
if self:
if self.hp<=0:
if self.bombingtime!=0:
self.send_chat("airstrike readied.")
def bombing(self):
for t in range(15):
callLater(t/5.0,self.air_bombdrop)
def air_bombdrop(self):
x=self.protocol.ac_x-cos(radians(self.protocol.deg))*6
y=self.protocol.ac_y-sin(radians(self.protocol.deg))*6
z=-80
a=(cos(radians(self.protocol.deg)))*(BOMBER_SPEED+uniform(-5,5))/31.5
b=(sin(radians(self.protocol.deg)))*(BOMBER_SPEED+uniform(-5,5))/31.5
c=0
t=0
while t<1000:
xg=x+a*t
yg=y+b*t
zg=0.0315*(t**2)/2.0 + c*t + z
t+=0.1
if self.protocol.map.get_solid(xg,yg,zg) or (not 0<xg<511) or (not 0<yg<511) or (zg>63) :
t=t/32.1
break
grenade_packet.value = t
grenade_packet.player_id = self.player_id
grenade_packet.position = (x,y,z)
grenade_packet.velocity = (a,b,c)
self.protocol.send_contained(grenade_packet)
reactor.callLater(t, self.high_explosive, xg, yg, zg)
def high_explosive(self,x,y,z):
count = 0
grenade = self.protocol.world.create_object(Grenade,count,Vertex3(x,y,z),None,Vertex3(0,0,0.001),self.grenade_exploded)
grenade.name = 'airst_HE'
grenade_packet.value=count
grenade_packet.player_id=self.player_id
grenade_packet.position=(x,y,z)
grenade_packet.velocity=(0,0,0.001)
self.protocol.send_contained(grenade_packet)
while count<5:
callLater(count/10000.0, self.makegre,x,y,z,count<3)
count+=1
def makegre(self,x,y,z,exp):
sigma=1.1
(xg,yg,zg)=(random.gauss(0, sigma),random.gauss(0, sigma),random.gauss(0, sigma))
xp, yp, zp = x+xg, y+yg, z+zg
grenade = self.protocol.world.create_object(Grenade,0,Vertex3(xp,yp,zp),None,Vertex3(0,0,0),self.grenade_exploded)
grenade.name = 'airst_HE'
if exp:
grenade_packet.value=0
grenade_packet.player_id=self.player_id
grenade_packet.position=(xp,yp,zp)
grenade_packet.velocity=(0,0,0)
self.protocol.send_contained(grenade_packet)
def check_refill(self):
pass
def flight(self,x,y,z,zvel=0.015,para=False):
if self.world_object and self.hp>0:
ox,oy,oz = self.world_object.orientation.get()
r = (ox**2+oy**2)**(1/2.0)
if not para:
para = self.world_object.crouch
if para:
self.send_chat("para opened")
zvel=0.008
else:
if zvel>0.003:
zvel -=0.000001
hvel=0.025-zvel
ax=ox/r
ay=oy/r
cx=x+ax
cy=y+ay
npcl= not(self.protocol.map.get_solid(cx, cy, z+2) or self.protocol.map.get_solid(cx, cy, z+1) or self.protocol.map.get_solid(cx, cy, z))
isgr= self.protocol.map.get_solid(x, y, z+3) and self.protocol.map.get_solid(cx, cy, z+3)
xbuff=x+ax*hvel
ybuff=y+ay*hvel
if 0<xbuff<511:
x=xbuff
if 0<ybuff<511:
y=ybuff
z+=zvel
if npcl and (not isgr) and z<62:
self.world_object.set_position(x, y, z)
position_data.x = x
position_data.y = y
position_data.z = z
self.send_contained(position_data)
callLater(0.001, self.flight,x,y,z,zvel,para)
return
if isgr and npcl and zvel<=0.003:
dmg = 0
elif isgr and npcl:
dmg = ((zvel-0.002)*1000)**2
elif not npcl and zvel<=0.003:
dmg =50
else:
dmg = ((zvel-0.002)*1000)**2 + 50
hpset=self.hp-dmg
self.set_hp(max(hpset,1),type = FALL_KILL)
def weapon_change_pubg(self):
self.the_hp=self.hp
if (self.weapon==0 and 1<=self.weapon_now<=3) or (self.weapon==1 and 4<=self.weapon_now<=6) or (self.weapon==2 and 7<=self.weapon_now):
self.reload_after(True)
self.resend_tool()
else:
x,y,z = self.world_object.position.get()
pos = Vertex3(x,y,z+2)
self.on_spawn(pos)
self.resend_tool()
def set_weapon(self, weapon, local = False, no_kill = True):
self.weapon = weapon
if self.weapon_object is not None:
self.weapon_object.reset()
self.weapon_object = WEAPONS[weapon](self._on_reload)
if not local:
self.protocol.send_contained(change_weapon, save = True)
if not no_kill:
self.kill(type = CLASS_CHANGE_KILL)
def respawn(self):
if self.team.spectator or self.weapon_change_killing:
if self.weapon_change_killing:
self.weapon_change_killing=False
self.spawn_call = callLater(0.01, self.spawn)
else:
if self.spawn_call is None:
self.spawn_call = callLater(114514,None)
return False
return connection.respawn(self)
def checkend(self):
allplayer=0
livingplayer=0
living=self
for player in self.protocol.blue_team.get_players():
allplayer+=1
if not player.world_object.dead:
livingplayer+=1
living= player
self.protocol.send_chat("now surviver %s/%s"%(livingplayer, allplayer))
if TOW_MAN_CELL:
if livingplayer<=2:
winsq="defaultnamedayo"
if livingplayer==2:
winsq="none1145141919"
samesq=False
for player in self.protocol.blue_team.get_players():
if not player.world_object.dead:
if winsq != player.sq:
winsq = player.sq
else:
samesq=True
else:
winsq=living.sq
samesq=True
if samesq:
self.protocol.reset_game(self)
self.protocol.on_game_end()
kome=""
for len in winsq:
kome+="*"
self.protocol.send_chat("********%s*****************"%kome)
self.protocol.send_chat("****** %s win !!!! ******"%winsq)
self.protocol.send_chat("********%s*****************"%kome)
else:
if livingplayer<=1:
self.protocol.reset_game(self)
self.protocol.on_game_end()
kome=""
for len in living.name:
kome+="*"
self.protocol.send_chat("********%s*****************"%kome)
self.protocol.send_chat("****** %s win !!!! ******"%living.name)
self.protocol.send_chat("********%s*****************"%kome)
def on_kill(self, killer, type, grenade):
if type>=5:
self.weapon_change_killing=True
else:
self.respawn_time = -1
callLater(0.001, self.checkend)
player = self
weapon = player.weapon_object
x, y, z = player.world_object.position.get()
create_player.weapon = player.weapon
create_player.player_id = player.player_id
create_player.name = player.name
create_player.team = player.team.id
create_player.x = x
create_player.y = y
create_player.z = z
player.protocol.send_contained(create_player)
zz = self.protocol.map.get_z(x,y,z)-1
x=int(x)
y=int(y)
zz=int(zz)
self.make_drop(x,y,zz)
if killer:
if killer!=self:
if killer.hp<=0:
if grenade is not None:
if grenade.name == 'airst_HE':
x=self.protocol.ac_x-cos(radians(self.protocol.deg))*6
y=self.protocol.ac_y-sin(radians(self.protocol.deg))*6
z=-80
killer.spawn_first=True
killer.spawn((x,y,z))
return connection.on_kill(self, killer, type, grenade)
def make_drop(self,x,y,z):
box_num=self.weapon_now-1
color = color_box[box_num]
block_action = BlockAction()
set_color = SetColor()
set_color.value = make_color(*color)
set_color.player_id = 32
self.protocol.send_contained(set_color)
block_action.player_id = 32
block_action.value=BUILD_BLOCK
block_action.x = x
block_action.y = y
block_action.z = z
self.protocol.send_contained(block_action)
self.protocol.map.set_point(x, y, z, color)
self.protocol.drop_items[(x,y,z)] = (self.weapon_now,sum(self.ammo[self.weapon_now]), self.medkit,self.armor,self.helmet)
def on_team_join(self,team):
if team==self.protocol.green_team:
return self.protocol.blue_team
return connection.on_team_join(self,team)
def _on_reload(self):
callLater(0.01, self.reload_after)
return connection._on_reload(self)
def reload_after(self, change=False,spade=False):
if spade:
weapon_reload.player_id = self.player_id
weapon_reload.clip_ammo = self.weapon_object.current_ammo = 0
weapon_reload.reserve_ammo = self.weapon_object.current_stock = 0
self.send_contained(weapon_reload)
else:
if self.weapon_now==1:
mag=1
stock=5
if change:
mag=self.ammo[self.weapon_now][0]
stock=self.ammo[self.weapon_now][1]
elif self.weapon_now==2:
mag=10
stock=0
if change:
mag=self.ammo[self.weapon_now][0]
stock=self.ammo[self.weapon_now][1]
elif self.weapon_now==3:
mag=0
stock=20
if change:
mag=0
stock=self.ammo[self.weapon_now][1]
elif self.weapon_now==4:
mag=6
stock=0
if change:
mag=self.ammo[self.weapon_now][0]
stock=self.ammo[self.weapon_now][1]
elif self.weapon_now==5:
mag=30
stock=0
if change:
mag=self.ammo[self.weapon_now][0]
stock=self.ammo[self.weapon_now][1]
elif self.weapon_now==6:
mag=20
stock=0
if change:
mag=self.ammo[self.weapon_now][0]
stock=self.ammo[self.weapon_now][1]
elif self.weapon_now==7:
mag=2
stock=0
if change:
mag=self.ammo[self.weapon_now][0]
stock=self.ammo[self.weapon_now][1]
self.weapon_object.slow_reload=False
weapon_reload.player_id = self.player_id
if not change:
stock = self.weapon_object.current_stock + self.weapon_object.current_ammo - mag
if stock<0:
mag+=stock
stock=0
weapon_reload.clip_ammo = self.weapon_object.current_ammo = mag
weapon_reload.reserve_ammo = self.weapon_object.current_stock = stock
self.send_contained(weapon_reload)
if 1<=self.weapon_now<=6:
self.ammo[self.weapon_now][0]=mag
self.ammo[self.weapon_now][1]=stock
def on_spawn(self,pos):
if not self.protocol.prestart_time:
if self.spawn_first:
player = self
weapon = player.weapon_object
x=self.protocol.ac_x-cos(radians(self.protocol.deg))*6
y=self.protocol.ac_y-sin(radians(self.protocol.deg))*6
z=-80
create_player.weapon = player.weapon
create_player.player_id = player.player_id
create_player.name = player.name
create_player.x = x
create_player.y = y
create_player.z = z
if TOW_MAN_CELL:
for other_player in self.protocol.players.values():
if other_player.sq == player.sq:
create_player.team = player.team.other.id
else:
create_player.team = player.team.id
other_player.send_contained(create_player)
else:
for other_player in self.protocol.players.values():
if other_player == player:
create_player.team = player.team.other.id
else:
create_player.team = player.team.id
other_player.send_contained(create_player)
self.reload_after(True,self.weapon_now==0)
self.spawn_first=False
self.send_chat("Ctrl : open parachute")
self.flight(x,y,z)
return connection.on_spawn(self,pos)
self.spawn_first=False
if self.weapon_now<=3:
self.set_weapon(RIFLE_WEAPON,False,True)
self.weapon=0
self.weapon_object = WEAPONS[0](self._on_reload)
elif 4<=self.weapon_now<=6:
self.set_weapon(SMG_WEAPON,False,True)
self.weapon=1
elif 7<=self.weapon_now:
self.set_weapon(SHOTGUN_WEAPON,False,True)
self.weapon=2
player = self
weapon = player.weapon_object
x, y, z = player.world_object.position.get()
create_player.weapon = player.weapon
create_player.player_id = player.player_id
create_player.name = player.name
create_player.x = x
create_player.y = y
create_player.z = z+2
if TOW_MAN_CELL:
for other_player in self.protocol.players.values():
if other_player.sq == player.sq:
create_player.team = player.team.other.id
else:
create_player.team = player.team.id
other_player.send_contained(create_player)
else:
for other_player in self.protocol.players.values():
if other_player == player:
create_player.team = player.team.other.id
else:
create_player.team = player.team.id
other_player.send_contained(create_player)
self.reload_after(True,self.weapon_now==0)
self.set_hp(self.the_hp,type = FALL_KILL)
return connection.on_spawn(self,pos)
def on_animation_update(self, jump, crouch, sneak, sprint):
if sneak and not self.world_object.sneak:
if seconds() - self.sneaktime < VVTIME:
self.VV()
self.sneaktime=0
else:
self.sneaktime = seconds()
if not sneak and self.world_object.sneak:
if self.sneaktime >0:
if seconds() - self.sneaktime > VVTIME:
self.V_V()
vz = (self.world_object.velocity.z)**2
vw = self.world_object.up
vs = self.world_object.down
va = self.world_object.left
vd = self.world_object.right
vel = vz+va+vs+vd+vw
if vel<0.001 and (self.world_object.crouch or crouch):
self.static_start()
elif vel>=0.001 or (not self.world_object.crouch) or (not crouch )or jump:
self.static_end()
return connection.on_animation_update(self, jump, crouch, sneak, sprint)
def hmg_ok(self):
if not self.hmg_ready:
if self.weapon_now==3:
if self.ammo[3][1]>1 and self.weapon_object.current_ammo<2:
weapon_reload.player_id = self.player_id
stock = self.ammo[3][1] - 2
self.weapon_object.reset()
weapon_reload.clip_ammo = self.weapon_object.current_ammo = 2
weapon_reload.reserve_ammo = self.weapon_object.current_stock = self.ammo[3][1] = stock
self.weapon_object.set_shoot(True)
self.send_contained(weapon_reload)
if self.ammo[3][1]==1 and self.weapon_object.current_ammo<2:
weapon_reload.player_id = self.player_id
stock = 0
self.weapon_object.reset()
weapon_reload.clip_ammo = self.weapon_object.current_ammo = 1
weapon_reload.reserve_ammo = self.weapon_object.current_stock = self.ammo[3][1] = stock
self.weapon_object.set_shoot(True)
self.send_contained(weapon_reload)
self.hmg_ready=True
def static_start(self):
self.static = True
def static_end(self):
self.static = False
self.hmg_ready=False
if self.weapon_now==3:
weapon_reload.player_id = self.player_id
stock = self.ammo[3][1] + self.weapon_object.current_ammo
self.weapon_object.reset()
weapon_reload.clip_ammo = self.weapon_object.current_ammo = 0
weapon_reload.reserve_ammo = self.weapon_object.current_stock = self.ammo[3][1] = stock
self.weapon_object.set_shoot(False)
self.send_contained(weapon_reload)
def VV(self):
self.resend_tool()
self.weapon_ms_now = not self.weapon_ms_now
self.send_chat("-----------------------------------")
self.send_chat("main:%s sub:%s"%(weapon_name[self.main_weapon],weapon_name[self.sub_weapon]))
self.send_chat("%sNow"%[" "," "][self.weapon_ms_now])
if self.sub_weapon == self.main_weapon:
return
self.ammo[self.weapon_now][0]=self.weapon_object.current_ammo
self.ammo[self.weapon_now][1]=self.weapon_object.current_stock
if self.weapon_ms_now==0:
self.weapon_now = self.main_weapon
else:
self.weapon_now = self.sub_weapon
self.weapon_change_pubg()
def V_V(self):
self.send_chat("main:%s (%d) sub:%s (%d) "%(weapon_name[self.main_weapon],sum(self.ammo[self.main_weapon]),weapon_name[self.sub_weapon],sum(self.ammo[self.sub_weapon])))
s=""
for weapon in [1,2,3]:
if self.weapon_have[weapon]:
s+="%d:%s(%d), "%(weapon,weapon_name[weapon],sum(self.ammo[weapon]))
self.send_chat(s)
s=""
for weapon in [4,5,6]:
if self.weapon_have[weapon]:
s+="%d:%s(%d), "%(weapon,weapon_name[weapon],sum(self.ammo[weapon]))
self.send_chat(s)
s=""
if self.weapon_have[7]:
s+="7:%s(%d), "%(weapon_name[7],sum(self.ammo[7]))
armor = self.armor/2.0
helm = self.helmet/2.0
s+="Medkit(%d), ARMOR (%d), HELMET (%d)"%(self.medkit,armor,helm)
self.send_chat(s)
allplayer=0
livingplayer=0
living=self
for player in self.protocol.blue_team.get_players():
allplayer+=1
if not player.world_object.dead:
livingplayer+=1
living= player
self.send_chat("now surviver %s/%s"%(livingplayer, allplayer))
def grenade_exploded(self, grenade):
if self.name is None or self.team.spectator:
return
if grenade.team is not None and grenade.team is not self.team:
# could happen if the player changed team
return
position = grenade.position
x = position.x
y = position.y
z = position.z
if x < 0 or x > 512 or y < 0 or y > 512 or z < 0 or z > 63:
return
x = int(x)
y = int(y)
z = int(z)
for player_list in (self.team.other.get_players(), self.team.get_players()):
for player in player_list:
if not player.hp:
continue
damage = grenade.get_damage(player.world_object.position)
if damage == 0:
continue
returned = self.on_hit(damage, player, GRENADE_KILL, grenade)
if returned == False:
continue
elif returned is not None:
damage = returned
player.set_hp(player.hp - damage, self,
hit_indicator = position.get(), type = GRENADE_KILL,
grenade = grenade)
if self.on_block_destroy(x, y, z, GRENADE_DESTROY) == False:
return
map = self.protocol.map
for nade_x in xrange(x - 1, x + 2):
for nade_y in xrange(y - 1, y + 2):
for nade_z in xrange(z - 1, z + 2):
if map.destroy_point(nade_x, nade_y, nade_z):
self.on_block_removed(nade_x, nade_y, nade_z)
block_action.x = x
block_action.y = y
block_action.z = z
block_action.value = GRENADE_DESTROY
block_action.player_id = self.player_id
self.protocol.send_contained(block_action, save = True)
self.protocol.update_entities()
def on_hit(self, hit_amount, hit_player, type, grenade):
if self.protocol.prestart_time:
return False
if self.blackout:
return False
if TOW_MAN_CELL:
if self.sq==hit_player.sq:
if type ==2 and hit_player.blackout:
hit_player.blackhit+=1
if hit_player.blackhit>=BLACKOUTNEEDHIT:
hit_player.blackout=False
hit_player.set_hp(10)
hit_player.blackhit=0
x,y,z=hit_player.world_object.position.get()
color = FOG_NORMAL
fog_color.color = make_color(*color)
hit_player.send_contained(fog_color)
hit_player.world_object.set_position(x, y, z-3)
return False
if NOFF and self!=hit_player:
return False
connection.on_hit(self, hit_amount, hit_player, type, grenade)
xp,yp,zp=self.world_object.position.get()
xv,yv,zv=hit_player.world_object.position.get()
dist = ((xp-xv)**2+(yp-yv)**2+(zp-zv)**2)**(1/2.0)
if type <=3:
hit_amount*=0.25
if type <=1: #1:HS,0:body
dmgdef = 0
drange = 0
Attenuation = 0
if self.weapon_now == 1:
dmgdef = 50.0
drange = 180.0
Attenuation = 0.03
elif self.weapon_now == 2 :
dmgdef = 35.0
drange = 180.0
Attenuation = 0.02
elif self.weapon_now == 3 :
dmgdef = 40.0
drange = 150.0
Attenuation = 0.03
elif self.weapon_now == 4 :
dmgdef = 35.0
drange = 15.0
Attenuation = 0.4
elif self.weapon_now == 5 :
dmgdef = 25.0
drange = 50.0
Attenuation = 0.07
elif self.weapon_now == 6 :
dmgdef = 25.0
drange = 90.0
Attenuation = 0.05
elif self.weapon_now == 7 :
dmgdef = 10.0
drange = 10.0
Attenuation = 0.03
hit_amount = dmgdef / (1.0+((1.0+Attenuation)**(dist-drange)))-1.0
if type==0:
hit_amount/=3
hit_amount = min(100,max(0,hit_amount))
if type ==2: #spade
if self.weapon_now == 0:
hit_amount = 10
else:
hit_amount = 0
if type ==3: #gre
hit_amount=min(250, hit_amount)
hit_amount/=2.0
if type==0 or type==3:
reduce = hit_amount*hit_player.armor/200.0
hit_player.armor-=reduce
if hit_player.armor<=0:
hit_player.armor=0
elif type==1 or type==2:
if type==2:
reduce = hit_player.helmet - 50
else:
reduce = hit_amount*hit_player.helmet/200.0
hit_player.helmet-=reduce
if hit_player.helmet<=0:
hit_player.helmet=0
hit_amount-=min(100,max(0,reduce))
hit_amount = min(100,max(0,hit_amount))
if TOW_MAN_CELL:
after_hp = hit_player.hp - hit_amount
if after_hp<=0:
if not hit_player.blackout:
for playerb in self.protocol.blue_team.get_players():
if playerb.blackout:
if playerb.sq == hit_player.sq:
playerb.blackout=False
playerb.set_hp(0)
playerb.blackhit=0
color = FOG_NORMAL
fog_color.color = make_color(*color)
playerb.send_contained(fog_color)
return hit_amount
hit_amount= hit_player.hp - 20
hit_player.blackout = True
x,y,z=hit_player.world_object.position.get()
z = self.protocol.map.get_z(x,y,z)-1
color = FOG_BLACKOUT
fog_color.color = make_color(*color)
hit_player.send_contained(fog_color)
for xx in range(-3,4):
for yy in range(-3,4):
for zz in range(-3,4):
r = xx**2+yy**2+zz**2
if (-1<=xx<=1 and -1<=yy<=1 and -1<=zz<=1) or randint(0,30)>r:
blood_red=randint(170,255)
if z+zz<63: