HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #include <amxmodx>
  2. #include <amxmisc>
  3. #include <fun>
  4. #include <cstrike>
  5. #include <hamsandwich>
  6. #include <fakemeta>
  7. #include <engine>
  8. #include <nvault>
  9. #include <sqlx>
  10.  
  11. #define VERSION "2.3"
  12.  
  13. // Main includes
  14. #include "diablo2LOD/const.inl"
  15. #include "diablo2LOD/vars.inl"
  16. #include "diablo2LOD/nvault.inl"
  17. #include "diablo2LOD/events.inl"
  18. #include "diablo2LOD/forwards.inl"
  19. #include "diablo2LOD/cvars.inl"
  20. #include "diablo2LOD/messages.inl"
  21. #include "diablo2LOD/menu.inl"
  22. #include "diablo2LOD/motd.inl"
  23. #include "diablo2LOD/public.inl"
  24. #include "diablo2LOD/entity.inl"
  25. #include "diablo2LOD/commands.inl"
  26. #include "diablo2LOD/items.inl"
  27. #include "diablo2LOD/classes.inl"
  28. #include "diablo2LOD/effects.inl"
  29. #include "diablo2LOD/stocks.inl"
  30. #include "diablo2LOD/mysql.inl"
  31.  
  32. public plugin_init()
  33. {
  34. register_plugin("Diablo II : Lord of Destruction", VERSION, "xbatista");
  35.  
  36. register_cvar("d2lod_version", VERSION, FCVAR_SPONLY|FCVAR_SERVER)
  37. set_cvar_string("d2lod_version", VERSION)
  38.  
  39. // Loads all cvars
  40. LoadCvars();
  41.  
  42. // Events
  43. register_event("HLTV", "Event_New_Round", "a", "1=0", "2=0");
  44. register_event("CurWeapon", "Ev_CurWeapon", "be", "1=1");
  45. register_event( "TeamInfo", "Ev_JoinTeam", "a")
  46. register_logevent("Logevent_Round_Start", 2, "1=Round_Start");
  47. register_logevent("Event_Round_End", 2, "1=Round_End");
  48.  
  49. register_touch("Coins", "player", "Coins_Pickup")
  50. register_touch("ItemsDeath", "player", "Item_Touch")
  51. register_touch("PotionsDeath", "player", "Potion_Touch")
  52.  
  53. register_think("trigger_camera", "PlayerCamera_Think")
  54.  
  55. // Forwards
  56. RegisterHam(Ham_TakeDamage, "player", "fwd_PlayerDamaged");
  57. RegisterHam(Ham_TakeDamage, "func_wall", "fwd_PlayerDamagedMonster");
  58. RegisterHam(Ham_Spawn, "player", "fwd_PlayerSpawn", 1);
  59. RegisterHam(Ham_TraceAttack, "player", "fwd_TraceAttack");
  60. RegisterHam(Ham_Killed, "player", "fwd_Killed");
  61. RegisterHam(Ham_Killed, "player", "fwd_KilledPost", 1);
  62. RegisterHam(Ham_Touch, "weaponbox", "Fwd_Touch");
  63. RegisterHam(Ham_Touch, "armoury_entity", "Fwd_Touch");
  64. RegisterHam( Ham_Weapon_PrimaryAttack, "weapon_knife", "fwd_AttackSpeed" , 1 );
  65. RegisterHam( Ham_Item_Deploy , "weapon_knife", "fwd_AttackSpeed", 1);
  66. new szWeaponName[ 24 ];
  67. for ( new WeaponId = 1; WeaponId <= 30; WeaponId++ )
  68. {
  69. if ( get_weaponname ( WeaponId, szWeaponName, charsmax ( szWeaponName ) ) )
  70. {
  71. RegisterHam( Ham_CS_Item_GetMaxSpeed , szWeaponName, "fwd_ItemGetMaxSpeed", 1 );
  72. }
  73. }
  74.  
  75. register_forward(FM_ClientKill, "fwd_ClientKill");
  76. register_forward(FM_CmdStart, "fwd_CmdStart");
  77. register_forward(FM_GetGameDescription, "fwd_GameDescription");
  78. register_forward(FM_ClientUserInfoChanged, "ClientUserInfoChanged");
  79. register_forward(FM_Touch, "Entity_Touched");
  80.  
  81. // Get/register messages
  82. MsgSayText = get_user_msgid("SayText");
  83. MsgHideWeapon = get_user_msgid("HideWeapon")
  84. MsgHideCrosshair = get_user_msgid("Crosshair")
  85. gmsgClCorpse = get_user_msgid("ClCorpse")
  86.  
  87. register_message(get_user_msgid("StatusIcon"), "Message_StatusIcon")
  88. register_message(get_user_msgid("VGUIMenu"), "Message_VGUIMenu")
  89.  
  90. g_iItemTook = CreateMultiForward("D2_Item_Gone", ET_IGNORE, FP_CELL, FP_CELL);
  91. g_DamagedbySkill = CreateMultiForward("d2_skill_takedamage", ET_IGNORE, FP_CELL, FP_CELL, FP_ARRAY);
  92. g_SkillSelected = CreateMultiForward("d2_skill_selected", ET_IGNORE, FP_CELL, FP_CELL);
  93. g_SkillFired = CreateMultiForward("d2_skill_fired", ET_IGNORE, FP_CELL);
  94. g_TakeDamage = CreateMultiForward("d2_takedamage", ET_IGNORE, FP_CELL, FP_CELL, FP_ARRAY);
  95. g_iLog = CreateMultiForward("d2_logged", ET_IGNORE, FP_CELL, FP_CELL);
  96. g_RangedDamage = CreateMultiForward("d2_ranged_takedamage", ET_IGNORE, FP_CELL, FP_CELL, FP_ARRAY);
  97. g_DaggerPoisonDamage = CreateMultiForward("d2_dagger_poisondamage", ET_IGNORE, FP_CELL, FP_CELL, FP_ARRAY);
  98. g_ActRangedShoot = CreateMultiForward("d2_ranged_actshoot", ET_IGNORE, FP_CELL, FP_CELL);
  99.  
  100.  
  101. // Other
  102. g_iMaxPlayers = get_maxplayers();
  103. g_SyncHudCreate = CreateHudSyncObj();
  104. g_SyncHudCreate_Avade = CreateHudSyncObj();
  105.  
  106. if ( get_pcvar_num(d2_advert) )
  107. {
  108. set_task( get_pcvar_float(d2_advert_time), "Adv_Message", 0, _, _, "b");
  109. }
  110.  
  111. // Connect to MYSQL.
  112. set_task( 1.0, "MYSQLX_Init");
  113.  
  114. new Ent, Count;
  115.  
  116. while( ( Ent = find_ent_by_class( Ent, "info_player_start" ) ) > 0 )
  117. if( Count++ > 1 )
  118. break;
  119.  
  120. if( Count <= 1 )
  121. g_iFakeplayer = -1;
  122.  
  123. set_task( 2.0, "AddFakeClient" );
  124.  
  125. set_task( 1.0, "Spawn_Items");
  126. set_task( 1.0, "Spawn_Items_Charsi")
  127. set_task( 1.0, "Spawn_Items_Akara")
  128. }
  129.  
  130. public plugin_natives()
  131. {
  132. register_native("get_current_speed", "native_get_current_speed", 1);
  133. register_native("get_player_logged", "native_get_player_logged", 1);
  134. register_native("set_p_xp", "Set_Player_Xp", 1);
  135. register_native("get_p_xp", "native_get_p_xp", 1);
  136. register_native("get_p_hero", "native_get_p_hero", 1);
  137. register_native("get_p_level", "native_get_p_level", 1);
  138. register_native("set_p_mana", "Set_Player_Mana", 1);
  139. register_native("get_p_mana", "native_get_p_mana", 1);
  140. register_native("get_p_vitality", "native_get_p_vitality", 1);
  141. register_native("set_p_vitality", "native_set_p_vitality", 1);
  142. register_native("set_p_gold", "Set_Player_Coins", 1);
  143. register_native("set_p_gold_inventory", "Set_Player_CoinsInv", 1);
  144. register_native("get_p_gold_inventory", "native_get_p_gold_inventory", 1);
  145. register_native("get_p_gold", "native_get_p_gold", 1);
  146. register_native("get_p_item_wear_type", "Player_WItemType", 1);
  147. register_native("get_p_item_wear_data", "Player_WItemDataActive", 1);
  148. register_native("MAX_SKILLS_ACTIVE", "native_MAX_SKILLS_ACTIVE", 1);
  149. register_native("MAX_ITEMS_ACTIVE", "native_MAX_ITEMS_ACTIVE", 1);
  150. register_native("get_p_in_safezone", "native_get_p_in_safezone", 1);
  151. register_native("is_p_protected", "native_is_p_protected", 1);
  152. register_native("dmg_kill_player", "Native_Dmg_Kill_Player");
  153. register_native("get_p_skill", "native_get_p_skill", 1);
  154. register_native("is_freezetime", "native_is_freezetime", 1);
  155. register_native("reset_p_model", "Set_Custom_Model", 1);
  156. register_native("get_p_item_count", "native_get_p_item_count", 1);
  157. register_native("get_p_item_is_worn", "native_get_p_item_is_worn", 1);
  158. register_native("get_p_maxhealth", "native_get_p_maxhealth", 1);
  159. register_native("set_p_maxhealth", "native_set_p_maxhealth", 1);
  160. register_native("IsPlayerNearByMonster", "native_get_p_near_monster", 1);
  161. register_native("drop_coins", "Native_Create_Coins");
  162. register_native("set_user_model", "native_set_user_model");
  163. }
  164.  
  165. public client_connect(id)
  166. {
  167. set_user_info(id, "_vgui_menus", "1");
  168.  
  169. client_cmd(id, "cl_corpsestay %f", get_pcvar_float(d2_cl_corpsestay) );
  170.  
  171. g_Player_FirstTime_Connected[id] = true;
  172.  
  173. // Resets all players Data
  174. Reset_Data(id);
  175.  
  176. // Loads all player's Data
  177. if ( !is_user_bot(id) && g_iFakeplayer != id )
  178. {
  179. if ( !get_pcvar_num(d2_save_type) )
  180. {
  181. Load_Data(id);
  182. }
  183. else
  184. {
  185. set_task( 1.0, "MYSQLX_GetAllData", id);
  186. }
  187. }
  188. }
  189. public client_disconnect(id)
  190. {
  191. End_poison_damage(id);
  192.  
  193. // Remove some task
  194. remove_task( id + TASKID_FIRSTCONNECT );
  195.  
  196. if ( get_pcvar_num(d2_3rdperson) )
  197. {
  198. new iEnt = g_iCam[id]
  199. if( is_valid_ent(iEnt) )
  200. {
  201. g_iCam[id] = 0
  202. remove_entity(iEnt)
  203. }
  204. }
  205.  
  206. // Reset some bools
  207. g_Player_FirstTime_Connected[id] = false;
  208. g_Player_Info[id] = false;
  209. g_iLogged[id] = false;
  210.  
  211. if( g_iFakeplayer == id )
  212. {
  213. g_iFakeplayer = 0;
  214. set_task( 1.5, "AddFakeClient" );
  215. }
  216.  
  217. // Reset model's forwards
  218. g_szModel[id][0] = 0
  219. Set_Plugin_State(id, false)
  220.  
  221. // Saves all player's Data
  222. if ( !is_user_bot(id) && g_iFakeplayer != id )
  223. {
  224. if ( !get_pcvar_num(d2_save_type) )
  225. {
  226. Save_Data( id );
  227. }
  228. else
  229. {
  230.  
  231. MYSQLX_Save_T( id );
  232. }
  233. }
  234. }
  235.  
  236. public plugin_precache()
  237. {
  238. LoadIniItems();
  239.  
  240. engfunc(EngFunc_PrecacheSound, LevelUp);
  241. engfunc(EngFunc_PrecacheSound, g_crossbow_shoot_sound);
  242.  
  243. engfunc(EngFunc_PrecacheModel, "models/rpgrocket.mdl");
  244.  
  245. engfunc(EngFunc_PrecacheModel, g_w_mp);
  246. engfunc(EngFunc_PrecacheModel, g_w_hp);
  247. engfunc(EngFunc_PrecacheModel, g_w_coins);
  248. engfunc(EngFunc_PrecacheModel, g_w_item);
  249. engfunc(EngFunc_PrecacheModel, g_w_inventory);
  250. engfunc(EngFunc_PrecacheModel, g_w_charsi);
  251. engfunc(EngFunc_PrecacheModel, g_w_akara);
  252. engfunc(EngFunc_PrecacheModel, g_brassknuckles);
  253.  
  254. engfunc(EngFunc_PrecacheModel, g_w_crossbow);
  255. engfunc(EngFunc_PrecacheModel, g_v_crossbow);
  256. engfunc(EngFunc_PrecacheModel, g_p_crossbow);
  257.  
  258. // Forward to kill all entities :)
  259. register_forward(FM_Spawn, "fwd_Remove_Ents");
  260.  
  261. for (new item_id = 0; item_id <= g_charcounter; item_id++)
  262. {
  263. if ( item_data[item_id][CHAR_TYPE] != TYPE_WEAPON )
  264. continue;
  265.  
  266. if ( equal(item_vmodel[item_id], "models/", 7) )
  267. {
  268. engfunc(EngFunc_PrecacheModel, item_vmodel[item_id]);
  269. }
  270.  
  271. if ( equal(item_pmodel[item_id], "models/", 7) )
  272. {
  273. engfunc(EngFunc_PrecacheModel, item_pmodel[item_id]);
  274. }
  275. }
  276.  
  277. new Mdl_Path[100];
  278.  
  279. for(new i = 0; i < MAX_HEROES; i++)
  280. {
  281. formatex( Mdl_Path, sizeof Mdl_Path - 1, "models/player/%s/%s.mdl", Custom_Models[i], Custom_Models[i])
  282.  
  283. engfunc(EngFunc_PrecacheModel, Mdl_Path);
  284.  
  285. formatex( Mdl_Path, sizeof Mdl_Path - 1, "models/player/%s/%sT.mdl", Custom_Models[i], Custom_Models[i])
  286. if ( file_exists( Mdl_Path ) )
  287. {
  288. engfunc(EngFunc_PrecacheModel, Mdl_Path);
  289. }
  290.  
  291. }
  292. }
  293.  
  294. public plugin_cfg()
  295. {
  296. get_configsdir(g_ConfigsDir, 63);
  297. formatex(g_ItemOriginDir, 63, "%s/%s", g_ConfigsDir, inventory_dir_name);
  298.  
  299. new File[192];
  300.  
  301. formatex( File, charsmax( File ), "%s/d2conf.cfg", g_ConfigsDir );
  302.  
  303. if( !file_exists( File ) )
  304. {
  305. server_print( "File %s doesn't exist!", File );
  306. write_file( File, " ", -1 );
  307. }
  308. else
  309. {
  310. server_print( "%s successfully loaded.", File );
  311. server_cmd( "exec %s", File );
  312. }
  313.  
  314. if( !dir_exists(g_ItemOriginDir) )
  315. {
  316. mkdir(g_ItemOriginDir);
  317. }
  318. else
  319. {
  320. new CurMap[32];
  321. get_mapname(CurMap, 31);
  322. Load_Origins(CurMap);
  323. Load_Origins_Charsi(CurMap);
  324. Load_Origins_Akara(CurMap);
  325. }
  326.  
  327. //Open our vault and have g_Vault store the handle.
  328. g_Nvault = nvault_open( "d2lod" );
  329. g_Nvault2 = nvault_open( "d2lod2" );
  330. g_Nvault3 = nvault_open( "d2lod3" );
  331. }
  332.  
  333. public plugin_end()
  334. {
  335. //Close the vault when the plugin ends (map change\server shutdown\restart)
  336. nvault_close( g_Nvault );
  337. nvault_close( g_Nvault2 );
  338. nvault_close( g_Nvault3 );
  339. }
  340.  
  341. public Float:native_get_current_speed(id)
  342. {
  343. return Current_Speed[id];
  344. }
  345. public native_get_player_logged(id)
  346. {
  347. return g_iLogged[id];
  348. }
  349. public native_get_p_xp(id)
  350. {
  351. return g_PlayerXp[id][g_CurrentChar[id]];
  352. }
  353. public native_get_p_hero(id)
  354. {
  355. return g_PlayerHero[id][g_CurrentChar[id]];
  356. }
  357. public native_get_p_level(id)
  358. {
  359. return g_PlayerLevel[id][g_CurrentChar[id]];
  360. }
  361. public native_get_p_mana(id)
  362. {
  363. return g_CurrentMana[id];
  364. }
  365. public native_get_p_vitality(id)
  366. {
  367. return g_Vitality[id][g_CurrentChar[id]];
  368. }
  369. public native_set_p_vitality(id, value)
  370. {
  371. g_Vitality[id][g_CurrentChar[id]] = value;
  372. }
  373. public native_get_p_gold_inventory(id)
  374. {
  375. return g_CoinsInv[id][g_CurrentChar[id]];
  376. }
  377. public native_get_p_gold(id)
  378. {
  379. return g_Coins[id][g_CurrentChar[id]];
  380. }
  381. public native_MAX_SKILLS_ACTIVE()
  382. {
  383. return g_skillcounter + 1;
  384. }
  385. public native_MAX_ITEMS_ACTIVE()
  386. {
  387. return g_charcounter + 1;
  388. }
  389. public bool:native_get_p_in_safezone(id)
  390. {
  391. if ( !is_user_alive(id) || DISTANCE_INVENTORY_PLAYER <= 0.0 ) return false;
  392.  
  393. new Float:Porigin[3];
  394. entity_get_vector( id, EV_VEC_origin, Porigin);
  395.  
  396. new ent = -1
  397. while( (ent = find_ent_in_sphere( ent, Porigin, DISTANCE_INVENTORY_PLAYER)) != 0)
  398. {
  399. static classname[32];
  400. pev( ent, pev_classname, classname, charsmax(classname) );
  401.  
  402. if( equal(classname, "Inventory") || equal(classname, "Charsi")
  403. || equal(classname, "Akara") )
  404. {
  405. return true;
  406. }
  407. }
  408.  
  409. return false;
  410. }
  411. public bool:native_get_p_near_charsi(id)
  412. {
  413. if ( !is_user_alive(id) || DISTANCE_INVENTORY_PLAYER <= 0.0 ) return false;
  414.  
  415. new Float:Porigin[3];
  416. entity_get_vector( id, EV_VEC_origin, Porigin);
  417.  
  418. new ent = -1
  419. while( (ent = find_ent_in_sphere( ent, Porigin, DISTANCE_INVENTORY_PLAYER)) != 0)
  420. {
  421. static classname[32];
  422. pev( ent, pev_classname, classname, charsmax(classname) );
  423.  
  424. if( equal(classname, "Charsi") )
  425. {
  426. return true;
  427. }
  428. }
  429.  
  430. return false;
  431. }
  432. public bool:native_get_p_near_akara(id)
  433. {
  434. if ( !is_user_alive(id) || DISTANCE_INVENTORY_PLAYER <= 0.0 ) return false;
  435.  
  436. new Float:Porigin[3];
  437. entity_get_vector( id, EV_VEC_origin, Porigin);
  438.  
  439. new ent = -1
  440. while( (ent = find_ent_in_sphere( ent, Porigin, DISTANCE_INVENTORY_PLAYER)) != 0)
  441. {
  442. static classname[32];
  443. pev( ent, pev_classname, classname, charsmax(classname) );
  444.  
  445. if( equal(classname, "Akara") )
  446. {
  447. return true;
  448. }
  449. }
  450.  
  451. return false;
  452. }
  453. public bool:native_get_p_near_inventory(id)
  454. {
  455. if ( !is_user_alive(id) || DISTANCE_INVENTORY_PLAYER <= 0.0 ) return false;
  456.  
  457. new Float:Porigin[3];
  458. entity_get_vector( id, EV_VEC_origin, Porigin);
  459.  
  460. new ent = -1
  461. while( (ent = find_ent_in_sphere( ent, Porigin, DISTANCE_INVENTORY_PLAYER)) != 0)
  462. {
  463. static classname[32];
  464. pev( ent, pev_classname, classname, charsmax(classname) );
  465.  
  466. if( equal(classname, "Inventory") )
  467. {
  468. return true;
  469. }
  470. }
  471.  
  472. return false;
  473. }
  474. public bool:native_is_p_protected(id)
  475. {
  476. if ( g_PlayerProtected[id] )
  477. return true;
  478.  
  479. return false;
  480. }
  481. public native_get_p_skill(id, skill_id)
  482. {
  483. return g_iSkills[id][g_CurrentChar[id]][skill_id];
  484. }
  485. public native_is_freezetime()
  486. {
  487. return g_FreezeTime;
  488. }
  489. public native_get_p_item_count(id, item_id)
  490. {
  491. return g_iPlayerItem[id][g_CurrentChar[id]][item_id];
  492. }
  493. public native_get_p_item_is_worn(id, item_id)
  494. {
  495. return g_iPlayerItemWorn[id][g_CurrentChar[id]][item_id];
  496. }
  497. public native_get_p_maxhealth(id)
  498. {
  499. return g_MaxHealth[id];
  500. }
  501. public native_set_p_maxhealth(id, value)
  502. {
  503. g_MaxHealth[id] = value;
  504.  
  505. if ( g_MaxHealth[id] < 0 )
  506. {
  507. g_MaxHealth[id] = 0;
  508. }
  509. }
  510. // Checks if is player near monster
  511. public bool:native_get_p_near_monster(id)
  512. {
  513. if ( !is_user_alive(id) || DISTANCE_NEAR_MONSTER <= 0.0 ) return false;
  514.  
  515. new Float:Porigin[3];
  516. entity_get_vector( id, EV_VEC_origin, Porigin);
  517.  
  518. new ent = -1
  519. while( (ent = find_ent_in_sphere( ent, Porigin, DISTANCE_NEAR_MONSTER)) != 0)
  520. {
  521. if ( pev( ent, pev_flags ) & FL_MONSTER )
  522. {
  523. return true;
  524. }
  525. }
  526.  
  527. return false;
  528. }