Witamy w Nieoficjalnym polskim support'cie AMX Mod X
Witamy w Nieoficjalnym polskim support'cie AMX Mod X, jak w większości społeczności internetowych musisz się zarejestrować aby móc odpowiadać lub zakładać nowe tematy, ale nie bój się to jest prosty proces w którym wymagamy minimalnych informacji.
|
Guest Message by DevFuse
Wklejka 1lfsuty64lrcy dodana przez Robiin, 01.01.2019 17:26
buyzone
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.
/*================================================================================
---------------------
-*- [ZP] Buyzones -*-
---------------------
This plugin is part of Zombie Plague Mod and is distributed under the
terms of the GNU General Public License. Check ZP_ReadMe.txt for details.
================================================================================*/
#include <amxmodx>
#include <cstrike>
#include <fakemeta>
#include <hamsandwich>
#include <zp50_core>
#define LIBRARY_SURVIVOR "zp50_class_survivor"
#include <zp50_class_survivor>
#define LIBRARY_SNIPER "zp50_class_sniper"
#include <zp50_class_sniper>
#define LIBRARY_AMMOPACKS "zp50_ammopacks"
#include <zp50_ammopacks>
#include <zp50_colorchat>
#define MAXPLAYERS 32
#define TASK_WELCOMEMSG 100
new const CS_BUYZONE_ENT[] = "func_buyzone"
// CS sounds
new const g_sound_buyammo[] = "items/9mmclip1.wav"
// CS Player CBase Offsets (win32)
const PDATA_SAFE = 2
const OFFSET_MAPZONE = 235
const PLAYER_IN_BUYZONE = (1<<0)
// Weapon IDs for ammo types
new const AMMOWEAPON[] = { 0, CSW_AWP, CSW_SCOUT, CSW_M249, CSW_AUG, CSW_XM1014, CSW_MAC10, CSW_FIVESEVEN, CSW_DEAGLE,
CSW_P228, CSW_ELITE, CSW_FLASHBANG, CSW_HEGRENADE, CSW_SMOKEGRENADE, CSW_C4 }
// Max BP ammo for weapons
new const MAXBPAMMO[] = { -1, 52, -1, 90, 1, 32, 1, 100, 90, 1, 120, 100, 100, 90, 90, 90, 100, 120,
30, 120, 200, 32, 90, 120, 90, 2, 35, 90, 90, -1, 100 }
// Amount of ammo to give when buying additional clips for weapons
new const BUYAMMO[] = { -1, 13, -1, 30, -1, 8, -1, 12, 30, -1, 30, 50, 12, 30, 30, 30, 12, 30,
10, 30, 30, 8, 30, 30, 30, -1, 7, 30, 30, -1, 50 }
// Ammo Type Names for weapons
new const AMMOTYPE[][] = { "", "357sig", "", "762nato", "", "buckshot", "", "45acp", "556nato", "", "9mm", "57mm", "45acp",
"556nato", "556nato", "556nato", "45acp", "9mm", "338magnum", "9mm", "556natobox", "buckshot",
"556nato", "9mm", "762nato", "", "50ae", "556nato", "762nato", "", "57mm" }
new g_fwSpawn
new g_BuyzoneEnt
new Float:g_BuyTimeStart[MAXPLAYERS+1]
new cvar_buyzone_time, cvar_buyzone_humans, cvar_buyzone_zombies
new cvar_buy_ammo_human, cvar_buy_ammo_cost_ammopacks, cvar_buy_ammo_cost_money
public plugin_init()
{
register_plugin("[ZP] Buyzones", ZP_VERSION_STRING, "ZP Dev Team")
register_event("HLTV", "event_round_start", "a", "1=0", "2=0")
unregister_forward(FM_Spawn, g_fwSpawn)
register_forward(FM_PlayerPreThink, "fw_PlayerPreThink")
register_message(get_user_msgid("StatusIcon"), "message_status_icon")
// Client commands
register_clcmd("buyammo1", "clcmd_buyammo")
register_clcmd("buyammo2", "clcmd_buyammo")
cvar_buyzone_time = register_cvar("zp_buyzone_time", "15")
cvar_buyzone_humans = register_cvar("zp_buyzone_humans", "1")
cvar_buyzone_zombies = register_cvar("zp_buyzone_zombies", "0")
cvar_buy_ammo_human = register_cvar("zp_buy_ammo_human", "1")
cvar_buy_ammo_cost_ammopacks = register_cvar("zp_buy_ammo_cost_ammopacks", "1")
cvar_buy_ammo_cost_money = register_cvar("zp_buy_ammo_cost_money", "100")
// Bots buy ammo automatically
register_event("AmmoX", "event_ammo_x", "be")
}
public plugin_precache()
{
// Custom buyzone for all players
g_BuyzoneEnt = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, CS_BUYZONE_ENT))
if (pev_valid(g_BuyzoneEnt))
{
dllfunc(DLLFunc_Spawn, g_BuyzoneEnt)
set_pev(g_BuyzoneEnt, pev_solid, SOLID_NOT)
}
if (!pev_valid(g_BuyzoneEnt))
{
set_fail_state("Unable to spawn custom buyzone.")
return;
}
// Prevent some entities from spawning
g_fwSpawn = register_forward(FM_Spawn, "fw_Spawn")
// Precache sounds
precache_sound(g_sound_buyammo)
}
public plugin_natives()
{
set_module_filter("module_filter")
set_native_filter("native_filter")
}
public module_filter(const module[])
{
if (equal(module, LIBRARY_SURVIVOR) || equal(module, LIBRARY_SNIPER) || equal(module, LIBRARY_AMMOPACKS))
return PLUGIN_HANDLED;
return PLUGIN_CONTINUE;
}
public native_filter(const name[], index, trap)
{
if (!trap)
return PLUGIN_HANDLED;
return PLUGIN_CONTINUE;
}
public plugin_cfg()
{
// Prevents CS buytime messing up ZP buytime cvar
server_cmd("mp_buytime 99")
}
// Event Round Start
public event_round_start()
{
// Show buyammo message?
if (get_pcvar_num(cvar_buy_ammo_human))
{
remove_task(TASK_WELCOMEMSG)
set_task(2.2, "task_welcome_msg", TASK_WELCOMEMSG)
}
}
// Welcome Message Task
public task_welcome_msg()
{
zp_colored_print(0, "%L", LANG_PLAYER, "NOTICE_INFO2")
}
// Bots buy ammo automatically
public event_ammo_x(id)
{
if (!is_user_bot(id) || !is_user_alive(id) || zp_core_is_zombie(id))
return;
// Get ammo type
new type = read_data(1)
// Unknown ammo type
if (type >= sizeof AMMOWEAPON)
return;
// Get weapon's id
new weapon = AMMOWEAPON[type]
// Primary and secondary only
if (MAXBPAMMO[weapon] <= 2)
return;
// Get ammo amount
new amount = read_data(2)
if (amount <= BUYAMMO[weapon])
{
// Task needed
remove_task(id)
set_task(0.1, "clcmd_buyammo", id)
}
}
// Entity Spawn Forward
public fw_Spawn(entity)
{
// Invalid entity
if (!pev_valid(entity))
return FMRES_IGNORED;
// Get classname
new classname[32]
pev(entity, pev_classname, classname, charsmax(classname))
// Check whether it needs to be removed
if (equal(classname, CS_BUYZONE_ENT))
{
engfunc(EngFunc_RemoveEntity, entity)
return FMRES_SUPERCEDE;
}
return FMRES_IGNORED;
}
public zp_fw_core_cure_post(id, attacker)
{
if (get_pcvar_num(cvar_buyzone_humans) && (!LibraryExists(LIBRARY_SURVIVOR, LibType_Library) || !zp_class_survivor_get(id)) && (!LibraryExists(LIBRARY_SNIPER, LibType_Library) || !zp_class_sniper_get(id)))
{
// Buyzone time starts when player is set to human
g_BuyTimeStart[id] = get_gametime()
}
else
{
// Buyzone time ends when player is set to human/survivor/sniper
g_BuyTimeStart[id] = get_gametime() - get_pcvar_float(cvar_buyzone_time)
}
}
public zp_fw_core_infect_post(id, attacker)
{
if (get_pcvar_num(cvar_buyzone_zombies))
{
// Buyzone time starts when player is set to zombie
g_BuyTimeStart[id] = get_gametime()
}
else
{
// Buyzone time ends when player is set to zombie
g_BuyTimeStart[id] = get_gametime() - get_pcvar_float(cvar_buyzone_time)
}
}
// Forward Player PreThink
public fw_PlayerPreThink(id)
{
// Not alive
if (!is_user_alive(id))
return;
// Enable custom buyzone for player during buytime, unless time expired
if (get_gametime() < g_BuyTimeStart[id] + get_pcvar_float(cvar_buyzone_time))
dllfunc(DLLFunc_Touch, g_BuyzoneEnt, id)
// Remove offset immediately after buyzone time ends (bugfix)
else if (cs_get_user_buyzone(id))
fm_cs_set_user_buyzone_offset(id, false)
}
public message_status_icon(msg_id, msg_dest, msg_entity)
{
if (!is_user_alive(msg_entity) || get_msg_arg_int(1) != 1)
return;
static sprite[10]
get_msg_arg_string(2, sprite, charsmax(sprite))
if (!equal(sprite, "buyzone"))
return;
if (get_gametime() < g_BuyTimeStart[msg_entity] + get_pcvar_float(cvar_buyzone_time))
return;
// Hide buyzone icon after buyzone time is over (bugfix)
set_msg_arg_int(1, get_msg_argtype(1), 0)
}
// Buy BP Ammo
public clcmd_buyammo(id)
{
// Setting disabled, player dead or zombie
if (!get_pcvar_num(cvar_buy_ammo_human) || !is_user_alive(id) || zp_core_is_zombie(id))
return;
// Player standing in buyzone, allow buying weapon's ammo normally instead
if ((get_gametime() < g_BuyTimeStart[id] + get_pcvar_float(cvar_buyzone_time)) && cs_get_user_buyzone(id))
return;
// Not enough money/ammo packs
if (LibraryExists(LIBRARY_AMMOPACKS, LibType_Library))
{
if (zp_ammopacks_get(id) < get_pcvar_num(cvar_buy_ammo_cost_ammopacks))
{
zp_colored_print(id, "%L (%L)", id, "NOT_ENOUGH_AMMO", id, "REQUIRED_AMOUNT", get_pcvar_num(cvar_buy_ammo_cost_ammopacks))
return;
}
}
else
{
if (cs_get_user_money(id) < get_pcvar_num(cvar_buy_ammo_cost_money))
{
zp_colored_print(id, "%L (%L)", id, "NOT_ENOUGH_MONEY", id, "REQUIRED_AMOUNT", get_pcvar_num(cvar_buy_ammo_cost_money))
return;
}
}
// Get user weapons
new weapons[32], num_weapons, index, weaponid, bpammo_before, refilled
get_user_weapons(id, weapons, num_weapons)
// Loop through them and give the right ammo type
for (index = 0; index < num_weapons; index++)
{
// Prevents re-indexing the array
weaponid = weapons[index]
// Primary and secondary only
if (MAXBPAMMO[weaponid] > 2)
{
bpammo_before = cs_get_user_bpammo(id, weaponid)
// Give additional ammo
ExecuteHamB(Ham_GiveAmmo, id, BUYAMMO[weaponid], AMMOTYPE[weaponid], MAXBPAMMO[weaponid])
// Check whether we actually refilled the weapon's ammo
if (cs_get_user_bpammo(id, weaponid) - bpammo_before > 0)
refilled = true
}
}
// Weapons already have full ammo
if (!refilled)
return;
// Deduce cost
if (LibraryExists(LIBRARY_AMMOPACKS, LibType_Library))
zp_ammopacks_set(id, zp_ammopacks_get(id) - get_pcvar_num(cvar_buy_ammo_cost_ammopacks))
else
cs_set_user_money(id, cs_get_user_money(id) - get_pcvar_num(cvar_buy_ammo_cost_money))
// Play clip purchase sound, and notify player
emit_sound(id, CHAN_ITEM, g_sound_buyammo, 1.0, ATTN_NORM, 0, PITCH_NORM)
zp_colored_print(id, "%L", id, "AMMO_BOUGHT")
}
stock fm_cs_set_user_buyzone_offset(id, set = true)
{
// Prevent server crash if entity's private data not initalized
if (pev_valid(id) != PDATA_SAFE)
return false;
if (set)
set_pdata_int(id, OFFSET_MAPZONE, get_pdata_int(id, OFFSET_MAPZONE) | PLAYER_IN_BUYZONE)
else
set_pdata_int(id, OFFSET_MAPZONE, get_pdata_int(id, OFFSET_MAPZONE) & ~PLAYER_IN_BUYZONE)
return true;
}
Dodanych wklejek: 15354
Powered By (Pav32) Pastebin © 2011


Dodatki SourceMod


