HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /*
  2. * _______ _ _ __ __
  3. * | _____/ | | | | \ \ __ / /
  4. * | | | | | | | | / \ | |
  5. * | | | |____| | | |/ __ \| |
  6. * | | ___ | ______ | | / \ |
  7. * | | |_ | | | | | | / \ |
  8. * | | | | | | | | | | | |
  9. * | |____| | | | | | | | | |
  10. * |_______/ |_| |_| \_/ \_/
  11. *
  12. *
  13. *
  14. * Last Edited: 06-12-08
  15. *
  16. * ============
  17. * Changelog:
  18. * ============
  19. *
  20. * v1.3
  21. * -Bug Fixes
  22. *
  23. * v1.0
  24. * -Initial Release
  25. *
  26. */
  27.  
  28. #define VERSION "1.3"
  29.  
  30. #include <amxmodx>
  31. #include <amxmisc>
  32. #include <fakemeta>
  33.  
  34. #define MAX_SOUNDS 50
  35. #define MAX_p_MODELS 50
  36. #define MAX_v_MODELS 50
  37. #define MAX_w_MODELS 50
  38.  
  39. #define MAP_CONFIGS 1
  40.  
  41. new new_sounds[MAX_SOUNDS][48]
  42. new old_sounds[MAX_SOUNDS][48]
  43. new sounds_team[MAX_SOUNDS]
  44. new soundsnum
  45.  
  46. new new_p_models[MAX_p_MODELS][48]
  47. new old_p_models[MAX_p_MODELS][48]
  48. new p_models_team[MAX_p_MODELS]
  49. new p_modelsnum
  50.  
  51. new new_v_models[MAX_v_MODELS][48]
  52. new old_v_models[MAX_v_MODELS][48]
  53. new v_models_team[MAX_p_MODELS]
  54. new v_modelsnum
  55.  
  56. new new_w_models[MAX_w_MODELS][48]
  57. new old_w_models[MAX_w_MODELS][48]
  58. new w_models_team[MAX_p_MODELS]
  59. new w_modelsnum
  60.  
  61. new maxplayers
  62.  
  63. public plugin_init()
  64. {
  65. register_plugin("Weapon Model + Sound Replacement",VERSION,"GHW_Chronic")
  66. register_forward(FM_EmitSound,"Sound_Hook")
  67. register_forward(FM_SetModel,"W_Model_Hook",1)
  68. register_logevent("newround",2,"1=Round_Start")
  69. register_event("CurWeapon","Changeweapon_Hook","be","1=1")
  70. maxplayers = get_maxplayers()
  71. }
  72.  
  73. public plugin_precache()
  74. {
  75. new configfile[200]
  76. new configsdir[200]
  77. new map[32]
  78. get_configsdir(configsdir,199)
  79. get_mapname(map,31)
  80. format(configfile,199,"%s/new_weapons_%s.ini",configsdir,map)
  81. if(file_exists(configfile))
  82. {
  83. load_models(configfile)
  84. }
  85. else
  86. {
  87. format(configfile,199,"%s/new_weapons.ini",configsdir)
  88. load_models(configfile)
  89. }
  90. }
  91.  
  92. public load_models(configfile[])
  93. {
  94. if(file_exists(configfile))
  95. {
  96. new read[96], left[48], right[48], right2[32], trash, team
  97. for(new i=0;i<file_size(configfile,1);i++)
  98. {
  99. read_file(configfile,i,read,95,trash)
  100. if(containi(read,";")!=0 && containi(read," ")!=-1)
  101. {
  102. strbreak(read,left,47,right,47)
  103. team=0
  104. if(containi(right," ")!=-1)
  105. {
  106. strbreak(right,right,47,right2,31)
  107. replace_all(right2,31,"^"","")
  108. if(
  109. equali(right2,"T") ||
  110. equali(right2,"Terrorist") ||
  111. equali(right2,"Terrorists") ||
  112. equali(right2,"Blue") ||
  113. equali(right2,"B") ||
  114. equali(right2,"Allies") ||
  115. equali(right2,"1")
  116. ) team=1
  117. else if(
  118. equali(right2,"CT") ||
  119. equali(right2,"Counter") ||
  120. equali(right2,"Counter-Terrorist") ||
  121. equali(right2,"Counter-Terrorists") ||
  122. equali(right2,"CounterTerrorists") ||
  123. equali(right2,"CounterTerrorist") ||
  124. equali(right2,"Red") ||
  125. equali(right2,"R") ||
  126. equali(right2,"Axis") ||
  127. equali(right2,"2")
  128. ) team=2
  129. else if(
  130. equali(right2,"Yellow") ||
  131. equali(right2,"Y") ||
  132. equali(right2,"3")
  133. ) team=3
  134. else if(
  135. equali(right2,"Green") ||
  136. equali(right2,"G") ||
  137. equali(right2,"4")
  138. ) team=4
  139. }
  140. replace_all(right,47,"^"","")
  141. if(file_exists(right))
  142. {
  143. if(containi(right,".mdl")==strlen(right)-4)
  144. {
  145. if(!precache_model(right))
  146. {
  147. log_amx("Error attempting to precache model: ^"%s^" (Line %d of new_weapons.ini)",right,i+1)
  148. }
  149. else if(containi(left,"models/p_")==0)
  150. {
  151. format(new_p_models[p_modelsnum],47,right)
  152. format(old_p_models[p_modelsnum],47,left)
  153. p_models_team[p_modelsnum]=team
  154. p_modelsnum++
  155. }
  156. else if(containi(left,"models/v_")==0)
  157. {
  158. format(new_v_models[v_modelsnum],47,right)
  159. format(old_v_models[v_modelsnum],47,left)
  160. v_models_team[v_modelsnum]=team
  161. v_modelsnum++
  162. }
  163. else if(containi(left,"models/w_")==0)
  164. {
  165. format(new_w_models[w_modelsnum],47,right)
  166. format(old_w_models[w_modelsnum],47,left)
  167. w_models_team[w_modelsnum]=team
  168. w_modelsnum++
  169. }
  170. else
  171. {
  172. log_amx("Model type(p_ / v_ / w_) unknown for model: ^"%s^" (Line %d of new_weapons.ini)",right,i+1)
  173. }
  174. }
  175. else if(containi(right,".wav")==strlen(right)-4 || containi(right,".mp3")==strlen(right)-4)
  176. {
  177. replace(right,47,"sound/","")
  178. replace(left,47,"sound/","")
  179. if(!precache_sound(right))
  180. {
  181. log_amx("Error attempting to precache sound: ^"%s^" (Line %d of new_weapons.ini)",right,i+1)
  182. }
  183. else
  184. {
  185. format(new_sounds[soundsnum],47,right)
  186. format(old_sounds[soundsnum],47,left)
  187. sounds_team[soundsnum]=team
  188. soundsnum++
  189. }
  190. }
  191. else
  192. {
  193. log_amx("Invalid File: ^"%s^" (Line %d of new_weapons.ini)",right,i+1)
  194. }
  195. }
  196. else
  197. {
  198. log_amx("File Inexistent: ^"%s^" (Line %d of new_weapons.ini)",right,i+1)
  199. }
  200. /*if(!file_exists(left))
  201. {
  202. log_amx("Warning: File Inexistent: ^"%s^" (Line %d of new_weapons.ini). ONLY A WARNING. PLUGIN WILL STILL WORK!!!!",left,i+1)
  203. }*/
  204. }
  205. }
  206. }
  207. }
  208.  
  209. public Changeweapon_Hook(id)
  210. {
  211. if(!is_user_alive(id))
  212. {
  213. return PLUGIN_CONTINUE
  214. }
  215. static model[32], i, team
  216.  
  217. team = get_user_team(id)
  218.  
  219. pev(id,pev_viewmodel2,model,31)
  220. for(i=0;i<v_modelsnum;i++)
  221. {
  222. if(equali(model,old_v_models[i]))
  223. {
  224. if(v_models_team[i]==team || !v_models_team[i])
  225. {
  226. set_pev(id,pev_viewmodel2,new_v_models[i])
  227. break;
  228. }
  229. }
  230. }
  231.  
  232. pev(id,pev_weaponmodel2,model,31)
  233. for(i=0;i<p_modelsnum;i++)
  234. {
  235. if(equali(model,old_p_models[i]))
  236. {
  237. if(p_models_team[i]==team || !p_models_team[i])
  238. {
  239. set_pev(id,pev_weaponmodel2,new_p_models[i])
  240. break;
  241. }
  242. }
  243. }
  244. return PLUGIN_CONTINUE
  245. }
  246.  
  247. public Sound_Hook(id,channel,sample[])
  248. {
  249. if(!is_user_alive(id))
  250. {
  251. return FMRES_IGNORED
  252. }
  253. if(channel!=CHAN_WEAPON && channel!=CHAN_ITEM)
  254. {
  255. return FMRES_IGNORED
  256. }
  257.  
  258. static i, team
  259.  
  260. team = get_user_team(id)
  261.  
  262. for(i=0;i<soundsnum;i++)
  263. {
  264. if(equali(sample,old_sounds[i]))
  265. {
  266. if(sounds_team[i]==team || !sounds_team[i])
  267. {
  268. engfunc(EngFunc_EmitSound,id,CHAN_WEAPON,new_sounds[i],1.0,ATTN_NORM,0,PITCH_NORM)
  269. return FMRES_SUPERCEDE
  270. }
  271. }
  272. }
  273. return FMRES_IGNORED
  274. }
  275.  
  276. public W_Model_Hook(ent,model[])
  277. {
  278. if(!pev_valid(ent))
  279. {
  280. return FMRES_IGNORED
  281. }
  282. static i
  283. for(i=0;i<w_modelsnum;i++)
  284. {
  285. if(equali(model,old_w_models[i]))
  286. {
  287. engfunc(EngFunc_SetModel,ent,new_w_models[i])
  288. return FMRES_SUPERCEDE
  289. }
  290. }
  291. return FMRES_IGNORED
  292. }
  293.  
  294. public newround()
  295. {
  296. static ent, classname[8], model[32]
  297. ent = engfunc(EngFunc_FindEntityInSphere,maxplayers,Float:{0.0,0.0,0.0},4800.0)
  298. while(ent)
  299. {
  300. if(pev_valid(ent))
  301. {
  302. pev(ent,pev_classname,classname,7)
  303. if(containi(classname,"armoury")!=-1)
  304. {
  305. pev(ent,pev_model,model,31)
  306. W_Model_Hook(ent,model)
  307. }
  308. }
  309. ent = engfunc(EngFunc_FindEntityInSphere,ent,Float:{0.0,0.0,0.0},4800.0)
  310. }
  311. }
  312.