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
|
extends RigidBody
class_name NetChar
# Game
export var team = 0
export var health: int = 100
export var weapon_slot1: Resource = null
export var weapon_slot2: Resource = null
export var weapon_slot3: Resource = null
export var weapon_slot4: Resource = null
export var weapon_slot5: Resource = null
var weapons = [null,null,null,null,null]
var weapon: Resource = null
var world: Spatial = null
var carrying: bool = false
var carrying_object: NetObject = null
var loading: bool = false
var load_target: RigidBody = null
var load_ammo: String
# Control
var controlling_machine: bool = false #whether character is riding/controlling something
var machine: RigidBody = null
var is_player: bool = false #whether character is currently controlled by a player
var ladder_m: Spatial = null
const inventory_caps: Dictionary = {"cannonball" : 1}
remote var inventory: Dictionary = {"cannonball" : 0} #
func get_init_info() -> Dictionary:
return {"linear_velocity" : linear_velocity, "angular_velocity" : angular_velocity, "controlling_machine" : controlling_machine, "team" : team, "health" : health, "inventory": inventory, "nametag" : $Nametag.text}
func mp_init(init_info: Dictionary):
for variable in init_info.keys():
set(variable, init_info[variable])
$Nametag.text = init_info["nametag"]
remote func set_phys_transform(trfrm: Transform, lvel: Vector3):
transform = trfrm
linear_velocity = lvel
remotesync func set_net_owner(owner_id: int, singleplayer_reset: bool = false):
$Nametag.text = ""
set_network_master(owner_id)
if owner_id != 1:
$Nametag.text = world.players_info[owner_id][0]
if get_tree().get_network_unique_id() != 1:
if owner_id == world.client_id:
$Nametag.visible = false
world.player_char = self
is_player = true
world.cam.attach(self, "FIRSTPERSON", "./Neck/Head")
else:
$Nametag.visible = true
is_player = false
world.get_node("HUD").update_characters()
elif world.is_local:
if singleplayer_reset:
is_player = false
else:
world.player_char = self
is_player = true
world.cam.attach(self, "FIRSTPERSON", "./Neck/Head")
func deselect_character():
if is_network_master() and world.player_char == self:
world.player_char = null
world.cam.attach(world, "STATIC", "./DEFAULTCAM")
rpc("set_net_owner", 1, true)
func take_control_of_machine(slave_machine: RigidBody):
machine = slave_machine
controlling_machine = true
func lose_machine():
if is_network_master() and get_network_master() != 1: world.cam.attach(self, "FIRSTPERSON", "./Neck/Head")
controlling_machine = false
machine = null
#args format
#attacker_net_id
#attacker_name
#damage_type
#weapon_name
remotesync func damage(dmg_amt: int, args: Dictionary):
print(dmg_amt)
health -= dmg_amt
if health <= 0 and is_network_master():
if args["attacker_net_id"] != get_network_master() and args["attacker_net_id"] != 1: world.rpc_id(args["attacker_net_id"], "game_killsound")
if get_network_master() == 1:
world._call_on_server("_character_death", {"killer_id" : args["attacker_net_id"], "killer_name" : args["attacker_name"], "victim_mp_id" : get_network_master(), "victim_name" : name, "extra" : args["weapon_name"]})
else:
world.rpc_id(1, "_call_on_server", "_character_death", {"killer_id" : args["attacker_net_id"], "killer_name" : args["attacker_name"], "victim_mp_id" : get_network_master(), "victim_name" : name, "extra" : args["weapon_name"]})
elif is_network_master():
if args["attacker_net_id"] != get_network_master() and args["attacker_net_id"] != 1: world.rpc_id(args["attacker_net_id"], "game_hitsound")
remotesync func remove_dead_character():
if is_network_master() and machine != null:
machine.relinquish_control()
deselect_character()
queue_free()
remotesync func net_apply_impulse(impulse_v: Vector3):
apply_central_impulse(impulse_v)
|