-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsh_ops_medic.sma
214 lines (183 loc) · 4.99 KB
/
sh_ops_medic.sma
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
#include <amxmod>
#include <superheromod>
// cvars:
// medic_level 0
// medic_health 150
// medic_healthregen 2
// medic_armor 150
// medic_cooldown 3
// medic_powerusage 8
// medic_distance 150
// medic_medipackhp 100
new gHeroName[]="Medic"
new bool:gHasMedicPower[SH_MAXSLOTS+1]
new gMedicUsage[SH_MAXSLOTS+1]
new gMedicPowerSound[] = "player/sprayer.wav"
new Float:gMedicPowerVolume = 0.7
new gPlayerMaxHealth[SH_MAXSLOTS+1]
public plugin_init()
{
register_plugin("SUPERHERO Medic", "1.0", "ops")
shCreateHero(gHeroName, "Regeneration, MP & MEDIPACK", "+Power key to use MEDIPACK on nearby team member", true, "medic_level")
register_srvcmd("medic_init", "medic_init")
shRegHeroInit(gHeroName, "medic_init")
// register cvars
register_cvar("medic_level", "0")
register_cvar("medic_health", "150")
register_cvar("medic_armor", "150")
register_cvar("medic_powerusage", "8")
register_cvar("medic_cooldown", "3")
register_cvar("medic_distance", "150")
register_cvar("medic_medipackhp", "100")
register_cvar("medic_healthregen", "2")
// collect max healths
register_srvcmd("medic_maxhealth", "medic_maxhealth")
shRegMaxHealth(gHeroName, "medic_maxhealth")
// set values
shSetMaxHealth(gHeroName, "medic_health")
shSetMaxArmor(gHeroName, "medic_armor")
shSetShieldRestrict(gHeroName)
// register events
register_event("ResetHUD", "event_spawn","b")
register_event("CurWeapon", "event_weapon","be","1=1")
register_srvcmd("medic_kd", "medic_kd")
shRegKeyDown(gHeroName, "medic_kd")
// loop function
set_task(1.0, "medic_loop", 0, "", 0, "b")
}
public medic_maxhealth(id)
{
new id[6]
new health[9]
read_argv(1, id, 5)
read_argv(2, health, 8)
gPlayerMaxHealth[str_to_num(id)] = str_to_num(health)
}
public medic_loop()
{
if(shModActive())
for(new id = 1; id <= SH_MAXSLOTS; id++)
if(gHasMedicPower[id] && is_user_alive(id))
shAddHPs(id, get_cvar_num("medic_healthregen"), gPlayerMaxHealth[id])
}
public medic_weapons(id)
{
if(is_user_alive(id) && shModActive())
shGiveWeapon(id ,"weapon_mp5navy")
}
public medic_reset(id)
{
remove_task(id)
gPlayerUltimateUsed[id] = false
gMedicUsage[id] = get_cvar_num("medic_powerusage")
}
public medic_end(id)
{
medic_reset(id)
shRemHealthPower(id)
shRemArmorPower(id)
engclient_cmd(id, "drop", "weapon_mp5navy")
}
public medic_init()
{
new temp[6]
read_argv(1, temp, 5)
new id = str_to_num(temp)
read_argv(2,temp,5)
new hasPower = str_to_num(temp)
if(!is_user_connected(id))
return
gHasMedicPower[id] = (hasPower != 0)
gPlayerMaxHealth[id] = get_cvar_num("medic_health")
shResetShield(id)
if(hasPower)
{
medic_reset(id)
medic_weapons(id)
}
else if(is_user_connected(id))
medic_end(id)
}
public medic_kd()
{
new temp[6]
read_argv(1, temp, 5)
new id = str_to_num(temp)
new idteam = get_user_team(id)
if(!is_user_alive(id) || !gHasMedicPower[id] || !hasRoundStarted())
return PLUGIN_HANDLED
if(gMedicUsage[id] == 0)
{
playSoundDenySelect(id)
client_print(id, print_chat, "You can use MEDIPACK only %ix per round!", get_cvar_num("medic_powerusage"))
return PLUGIN_HANDLED
}
if(gPlayerUltimateUsed[id])
{
playSoundDenySelect(id)
client_print(id, print_chat, "You can use MEDIPACK only every %isec!", get_cvar_num("medic_cooldown"))
return PLUGIN_HANDLED
}
new maxtoheal = 0
new usertoheal = 0
new selfheal = true
for(new i = 1; i <= SH_MAXSLOTS; i++)
{
new vec1[3]
new vec2[3]
get_user_origin(id, vec1)
if((i != id || selfheal) && is_user_alive(id) && idteam == get_user_team(i))
{
get_user_origin(i, vec2)
new dist = get_distance(vec1, vec2)
new toheal = gPlayerMaxHealth[i] - get_user_health(i)
if(dist <= get_cvar_num("medic_distance") && toheal > 0 && toheal > maxtoheal)
{
maxtoheal = toheal
usertoheal = i
}
}
}
maxtoheal = min(maxtoheal, get_cvar_num("medic_medipackhp"))
if(maxtoheal > 0)
{
gMedicUsage[id]--
if(get_cvar_float("medic_cooldown") > 0.0)
ultimateTimer(id, get_cvar_float("medic_cooldown"))
shAddHPs(usertoheal, maxtoheal, gPlayerMaxHealth[usertoheal])
emit_sound(id, CHAN_STATIC, gMedicPowerSound, gMedicPowerVolume, ATTN_NORM, 0, PITCH_NORM)
emit_sound(usertoheal, CHAN_STATIC, gMedicPowerSound, gMedicPowerVolume, ATTN_NORM, 0, PITCH_NORM)
new medicname[32]
new username[32]
get_user_name(id, medicname, 31)
get_user_name(usertoheal, username, 31)
if(usertoheal == id)
client_print(id, print_chat, "Used MEDIPACK, %i left", gMedicUsage[id])
else
client_print(id, print_chat, "Used MEDIPACK on %s, %i left (restored %i HP)", username, gMedicUsage[id], maxtoheal)
}
else
{
client_print(id, print_chat, "No injured team member nearby!")
playSoundDenySelect(id)
}
return PLUGIN_HANDLED
}
public event_spawn(id)
{
if(gHasMedicPower[id] && is_user_alive(id) && shModActive())
{
medic_reset(id)
set_task(0.1, "medic_weapons", id)
}
}
public event_weapon(id)
{
if(gHasMedicPower[id] && is_user_alive(id) && shModActive())
{
new weapon = read_data(2)
new clip = read_data(3)
if(clip == 0 && weapon == CSW_MP5NAVY)
shReloadAmmo(id)
}
}