Approved Stun Rifle

Zombies/Humans Extra-Items
User avatar
Raheem
Mod Developer
Mod Developer
Egypt
Posts: 1720
Joined: 1 Year Ago
Location: Egypt
Has thanked: 28 times
Been thanked: 78 times
Age: 21
Contact:

Re: Stun Rifle

#11

Post by Raheem » 4 Months Ago

Working for me without issues, you always get this crash?
You don't know? Learn and you will know.

User avatar
DarkZombie
Member
Member
Hungary
Posts: 68
Joined: 5 Months Ago
Donation: 1x donated in total €6.00
Has thanked: 16 times
Been thanked: 0
Contact:

#12

Post by DarkZombie » 4 Months Ago

This error occurred twice.

User avatar
Raheem
Mod Developer
Mod Developer
Egypt
Posts: 1720
Joined: 1 Year Ago
Location: Egypt
Has thanked: 28 times
Been thanked: 78 times
Age: 21
Contact:

#13

Post by Raheem » 4 Months Ago

I don't know but this weapon never crashes me. Can you post your ReHLDS, ReGameDLL,ReAPI, AMXMODX versions?
You don't know? Learn and you will know.

User avatar
DarkZombie
Member
Member
Hungary
Posts: 68
Joined: 5 Months Ago
Donation: 1x donated in total €6.00
Has thanked: 16 times
Been thanked: 0
Contact:

#14

Post by DarkZombie » 4 Months Ago

AMX Mod X version 1.8.3-dev+5188
ReGameDLL version: 5.7.0.312-dev
reapi_5.6.0.157-dev
rehlds-dist-3.4.0.658

User avatar
Raheem
Mod Developer
Mod Developer
Egypt
Posts: 1720
Joined: 1 Year Ago
Location: Egypt
Has thanked: 28 times
Been thanked: 78 times
Age: 21
Contact:

#15

Post by Raheem » 4 Months Ago

Latest, i don't know why this happens. But maybe there is another thing cause this. Try disable all and try only this gun and see results.
You don't know? Learn and you will know.

User avatar
Mark
Senior Member
Senior Member
United States of America
Posts: 258
Joined: 4 Months Ago
Location: Des Moines/USA
Donation: 1x donated in total €10.00
Has thanked: 6 times
Been thanked: 19 times
Age: 33
Contact:

#16

Post by Mark » 3 Months Ago

Yep as all said above gun is broken.

User avatar
Raheem
Mod Developer
Mod Developer
Egypt
Posts: 1720
Joined: 1 Year Ago
Location: Egypt
Has thanked: 28 times
Been thanked: 78 times
Age: 21
Contact:

#17

Post by Raheem » 3 Months Ago

I'm using this without any problem:
    1. /*
    2. *   Stun Rifle is a CSO weapon, More information about it: http://cso.wikia.com/wiki/Stun_Rifle
    3. *  
    4. *   This plugin written by me: Raheem (The basic things for any weapon not written by me)
    5. *
    6. *   I tried to simulate it same as in CSO, I think it's nearly same else simple things
    7. *   That will be done in next versions.
    8. *
    9. *   Version 1.0 creation date: 16-6-2018
    10. *   Version 1.0 publication date: 20-6-2018
    11. *
    12. *   TODO List: Fix any problem, include good ideas
    13. */
    14.  
    15. #include <zombie_escape>
    16. #include <fakemeta_util>
    17.  
    18. #define CustomItem(%0) (pev(%0, pev_impulse) == WEAPON_KEY)
    19.  
    20. // CWeaponBox
    21. #define m_rgpPlayerItems_CWeaponBox 34
    22.  
    23. // CBasePlayerItem
    24. #define m_pPlayer 41
    25. #define m_pNext 42
    26. #define m_iId 43
    27.  
    28. // CBasePlayerWeapon
    29. #define m_flNextPrimaryAttack 46
    30. #define m_flNextSecondaryAttack 47
    31. #define m_flTimeWeaponIdle 48
    32. #define m_iPrimaryAmmoType 49
    33. #define m_iClip 51
    34. #define m_fInReload 54
    35. #define m_iWeaponState 74
    36.  
    37. // CBaseMonster
    38. #define m_flNextAttack 83
    39.  
    40. // CBasePlayer
    41. #define m_iFOV 363
    42. #define m_rpgPlayerItems 367
    43. #define m_pActiveItem 373
    44. #define m_rgAmmo 376
    45.  
    46. /*-----------------------------------------------------*/
    47.  
    48. #define WEAPON_KEY 776544229
    49. #define WEAPON_OLD "weapon_ak47"
    50. #define WEAPON_NEW "weapon_stunrifle"
    51.  
    52. /*-----------------------------------------------------*/
    53.  
    54. new const WPN_SPRITES[][] =
    55. {
    56.     "sprites/weapon_stunrifle.txt",
    57.     "sprites/640hud169.spr",
    58.     "sprites/640hud7.spr"
    59. }
    60.  
    61. new const g_szSounds[][] =
    62. {
    63.     "weapons/stunrifle-1.wav",
    64.     "weapons/stunrifle_drawa.wav",
    65.     "weapons/stunrifle_drawb.wav",
    66.     "weapons/stunrifle_drawc.wav",
    67.     "weapons/stunrifle_reloada.wav",
    68.     "weapons/stunrifle_reloadb.wav",
    69.     "weapons/stunrifle_reloadc.wav",
    70.     "weapons/stunrifle_idlea.wav",
    71.     "weapons/stunrifle_idleb.wav",
    72.     "weapons/stunrifle_idlec.wav",
    73.     "weapons/stunrifle_lowbattery.wav",
    74.     "weapons/stunrifle-2.wav"
    75. }
    76.  
    77. new const iWeaponList[] =
    78. {  
    79.     2, 30, -1, -1, 0, 1, CSW_AK47, 0
    80. }
    81.  
    82. #define WEAPON_MODEL_V "models/stunrifle/v_stunrifle.mdl"
    83. #define WEAPON_MODEL_P "models/stunrifle/p_stunrifle.mdl"
    84. #define WEAPON_MODEL_W "models/stunrifle/w_stunrifle.mdl"
    85. #define WEAPON_BODY 0
    86.  
    87. /*-----------------------------------------------------*/
    88.  
    89. #define WEAPON_COST 0
    90.  
    91. #define WEAPON_CLIP 30
    92. #define WEAPON_AMMO 90
    93. #define WEAPON_RATE 0.098
    94. #define WEAPON_RECOIL 0.96
    95. #define WEAPON_DAMAGE 1.0 // AK47 damage multiplied by this factor
    96.  
    97. #define WEAPON_RATE_EX 0.169
    98. #define WEAPON_RECOIL_EX 0.79
    99. #define WEAPON_DAMAGE_EX 1.3
    100. #define WEAPON_NATIVE "native_give_weapon_stunrifle"
    101.  
    102. /*-----------------------------------------------------*/
    103.  
    104. // Animations
    105. #define ANIM_IDLE_A 0
    106. #define ANIM_IDLE_B 1
    107. #define ANIM_IDLE_C 2
    108. #define ANIM_ATTACK_A 3
    109. #define ANIM_ATTACK_B 4
    110. #define ANIM_ATTACK_C 5
    111. #define ANIM_RELOAD_A 6
    112. #define ANIM_RELOAD_B 7
    113. #define ANIM_RELOAD_C 8
    114. #define ANIM_DRAW_A 9
    115. #define ANIM_DRAW_B 10
    116. #define ANIM_DRAW_C 11
    117.  
    118. // from model: Frames / FPS
    119. #define ANIM_IDLE_TIME_A 90/30.0
    120. #define ANIM_SHOOT_TIME_A 31/30.0
    121. #define ANIM_RELOAD_TIME_A 101/30.0
    122. #define ANIM_DRAW_TIME_A 46/30.0
    123. #define ANIM_IDLE_TIME_B 90/30.0
    124. #define ANIM_SHOOT_TIME_B 31/30.0
    125. #define ANIM_RELOAD_TIME_B 101/30.0
    126. #define ANIM_DRAW_TIME_B 46/30.0
    127. #define ANIM_IDLE_TIME_C 90/30.0
    128. #define ANIM_SHOOT_TIME_C 31/30.0
    129. #define ANIM_RELOAD_TIME_C 101/30.0
    130. #define ANIM_DRAW_TIME_C 46/30.0
    131.  
    132. new g_AllocString_V,
    133.     g_AllocString_P,
    134.     g_AllocString_E,
    135.  
    136.     HamHook: g_fw_TraceAttack[4],
    137.    
    138.     g_iMsgID_Weaponlist,
    139.     g_iStoredEnergy[33],
    140.     bool:g_bHasStunRifle[33],
    141.     g_pCvarBarFillTime,
    142.     g_pCvarRadius,
    143.     g_pCvarElecDmg,
    144.     g_iLigSpr,
    145.     g_iEffSpr,
    146.     g_iEff2Spr,
    147.     bool:g_bReloading[33],
    148.     g_iAppearTimes[33],
    149.     g_iItemID
    150.  
    151. public plugin_init()
    152. {
    153.     register_plugin("[ZE] Stun Rifle", "1.0", "Raheem");
    154.  
    155.     // Register our item
    156.     g_iItemID = ze_register_item("Stun Rifle", 300, 0) // It's cost 300 Coins
    157.     ze_set_item_vip(g_iItemID, "VIP_C")
    158.    
    159.     RegisterHam(Ham_Item_Deploy, WEAPON_OLD, "fw_Item_Deploy_Post", 1);
    160.     RegisterHam(Ham_Item_PostFrame, WEAPON_OLD, "fw_Item_PostFrame");
    161.     RegisterHam(Ham_Item_AddToPlayer, WEAPON_OLD, "fw_Item_AddToPlayer_Post", 1);
    162.     RegisterHam(Ham_Weapon_Reload, WEAPON_OLD, "fw_Weapon_Reload");
    163.     RegisterHam(Ham_Weapon_WeaponIdle, WEAPON_OLD, "fw_Weapon_WeaponIdle");
    164.     RegisterHam(Ham_Weapon_PrimaryAttack, WEAPON_OLD, "fw_Weapon_PrimaryAttack");
    165.    
    166.     g_fw_TraceAttack[0] = RegisterHam(Ham_TraceAttack, "func_breakable", "fw_TraceAttack");
    167.     g_fw_TraceAttack[1] = RegisterHam(Ham_TraceAttack, "info_target",    "fw_TraceAttack");
    168.     g_fw_TraceAttack[2] = RegisterHam(Ham_TraceAttack, "player",         "fw_TraceAttack");
    169.     g_fw_TraceAttack[3] = RegisterHam(Ham_TraceAttack, "hostage_entity", "fw_TraceAttack");
    170.     fm_ham_hook(false);
    171.     register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1);
    172.     register_forward(FM_PlaybackEvent, "fw_PlaybackEvent");
    173.     register_forward(FM_SetModel, "fw_SetModel");
    174.    
    175.     g_pCvarBarFillTime = register_cvar("stunrifle_barfill_time", "5") // Bar fill time in seconds
    176.     g_pCvarRadius = register_cvar("stunrifle_radius", "500") // elec radius
    177.     g_pCvarElecDmg = register_cvar("stunrifle_electricity_dmg", "10") // electricity damage - lowest damage for 1 bar only
    178.    
    179.     register_clcmd(WEAPON_NEW, "HookSelect");
    180.     g_iMsgID_Weaponlist = get_user_msgid("WeaponList");
    181. }
    182.  
    183. public plugin_precache()
    184. {
    185.     g_AllocString_V = engfunc(EngFunc_AllocString, WEAPON_MODEL_V);
    186.     g_AllocString_P = engfunc(EngFunc_AllocString, WEAPON_MODEL_P);
    187.     g_AllocString_E = engfunc(EngFunc_AllocString, WEAPON_OLD);
    188.     engfunc(EngFunc_PrecacheModel, WEAPON_MODEL_V);
    189.     engfunc(EngFunc_PrecacheModel, WEAPON_MODEL_P);
    190.     engfunc(EngFunc_PrecacheModel, WEAPON_MODEL_W);
    191.    
    192.     for (new i = 0; i < sizeof g_szSounds; i++) engfunc(EngFunc_PrecacheSound, g_szSounds[i]);
    193.    
    194.     for(new i = 0; i < sizeof WPN_SPRITES;i++) precache_generic(WPN_SPRITES[i]);
    195.    
    196.     g_iLigSpr = precache_model("sprites/lightning.spr");
    197.     g_iEffSpr = precache_model("sprites/ef_buffak_hit.spr");
    198.     g_iEff2Spr = precache_model("sprites/muzzleflash67.spr");
    199. }
    200.  
    201. public HookSelect(iPlayer)
    202. {
    203.     engclient_cmd(iPlayer, WEAPON_OLD);
    204. }
    205.  
    206. public give(id)
    207. {
    208.     give_weapon_stunrifle(id)
    209. }
    210.  
    211. public give_weapon_stunrifle(iPlayer)
    212. {
    213.     static iEnt; iEnt = engfunc(EngFunc_CreateNamedEntity, g_AllocString_E);
    214.     if(iEnt <= 0) return 0;
    215.     set_pev(iEnt, pev_spawnflags, SF_NORESPAWN);
    216.     set_pev(iEnt, pev_impulse, WEAPON_KEY);
    217.     ExecuteHam(Ham_Spawn, iEnt);
    218.     UTIL_DropWeapon(iPlayer, 1);
    219.     if(!ExecuteHamB(Ham_AddPlayerItem, iPlayer, iEnt)) {
    220.         engfunc(EngFunc_RemoveEntity, iEnt);
    221.         return 0;
    222.     }
    223.     ExecuteHamB(Ham_Item_AttachToPlayer, iEnt, iPlayer);
    224.     set_pdata_int(iEnt, m_iClip, WEAPON_CLIP, 4);
    225.     new iAmmoType = m_rgAmmo +get_pdata_int(iEnt, m_iPrimaryAmmoType, 4);
    226.     if(get_pdata_int(iPlayer, m_rgAmmo, 5) < WEAPON_AMMO)
    227.     set_pdata_int(iPlayer, iAmmoType, WEAPON_AMMO, 5);
    228.     emit_sound(iPlayer, CHAN_ITEM, "items/gunpickup2.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
    229.     g_iStoredEnergy[iPlayer] = 0;
    230.     g_bHasStunRifle[iPlayer] = true;
    231.     set_task(get_pcvar_float(g_pCvarBarFillTime), "RechargeTask", iPlayer, _, _, "a", 6)
    232.     return 1;
    233. }
    234.  
    235. public plugin_natives()
    236. {
    237.     register_native(WEAPON_NATIVE, "give_weapon_stunrifle", 1);
    238. }
    239.  
    240. public ze_select_item_pre(id, itemid)
    241. {
    242.     // Return Available and we will block it in Post, So it dosen't affect other plugins
    243.     if (itemid != g_iItemID)
    244.         return ZE_ITEM_AVAILABLE
    245.    
    246.     // Available for Humans only, So don't show it for zombies
    247.     if (ze_is_user_zombie(id))
    248.         return ZE_ITEM_DONT_SHOW
    249.    
    250.     return ZE_ITEM_AVAILABLE
    251. }
    252.  
    253. public ze_select_item_post(player, itemid)
    254. {
    255.     if (itemid != g_iItemID)
    256.         return
    257.    
    258.     give_weapon_stunrifle(player)
    259. }
    260.  
    261. public fw_Item_Deploy_Post(iItem)
    262. {
    263.     if(!CustomItem(iItem)) return;
    264.     static iPlayer; iPlayer = get_pdata_cbase(iItem, m_pPlayer, 4);
    265.  
    266.     set_pev_string(iPlayer, pev_viewmodel2, g_AllocString_V);
    267.     set_pev_string(iPlayer, pev_weaponmodel2, g_AllocString_P);
    268.    
    269.     if (g_iStoredEnergy[iPlayer] == 0)
    270.     {
    271.         // Draw A
    272.         UTIL_SendWeaponAnim(iPlayer, ANIM_DRAW_A);
    273.         emit_sound(iPlayer, CHAN_WEAPON, g_szSounds[1], VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
    274.         set_pdata_float(iPlayer, m_flNextAttack, ANIM_DRAW_TIME_A, 5);
    275.         set_pdata_float(iItem, m_flTimeWeaponIdle, ANIM_DRAW_TIME_A, 4);
    276.     }
    277.     else if (g_iStoredEnergy[iPlayer] > 0 && g_iStoredEnergy[iPlayer] <= 3)
    278.     {
    279.         // Draw B
    280.         UTIL_SendWeaponAnim(iPlayer, ANIM_DRAW_B);
    281.         emit_sound(iPlayer, CHAN_WEAPON, g_szSounds[2], VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
    282.         set_pdata_float(iPlayer, m_flNextAttack, ANIM_DRAW_TIME_B, 5);
    283.         set_pdata_float(iItem, m_flTimeWeaponIdle, ANIM_DRAW_TIME_B, 4);
    284.     }
    285.     else if (g_iStoredEnergy[iPlayer] > 3 && g_iStoredEnergy[iPlayer] <= 6)
    286.     {
    287.         // Draw C
    288.         UTIL_SendWeaponAnim(iPlayer, ANIM_DRAW_C);
    289.         emit_sound(iPlayer, CHAN_WEAPON, g_szSounds[3], VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
    290.         set_pdata_float(iPlayer, m_flNextAttack, ANIM_DRAW_TIME_C, 5);
    291.         set_pdata_float(iItem, m_flTimeWeaponIdle, ANIM_DRAW_TIME_C, 4);
    292.     }
    293. }
    294.  
    295. public fw_Item_PostFrame(iItem)
    296. {
    297.     if(!CustomItem(iItem)) return HAM_IGNORED;
    298.     static iPlayer; iPlayer = get_pdata_cbase(iItem, m_pPlayer, 4);
    299.     if(get_pdata_int(iItem, m_fInReload, 4) == 1) {
    300.         static iClip; iClip = get_pdata_int(iItem, m_iClip, 4);
    301.         static iAmmoType; iAmmoType = m_rgAmmo + get_pdata_int(iItem, m_iPrimaryAmmoType, 4);
    302.         static iAmmo; iAmmo = get_pdata_int(iPlayer, iAmmoType, 5);
    303.         static j; j = min(WEAPON_CLIP - iClip, iAmmo);
    304.         set_pdata_int(iItem, m_iClip, iClip+j, 4);
    305.         set_pdata_int(iPlayer, iAmmoType, iAmmo-j, 5);
    306.         set_pdata_int(iItem, m_fInReload, 0, 4);
    307.     }
    308.     else switch(get_pdata_int(iItem, m_iWeaponState, 4) ) {
    309.         case 0: {
    310.             if(get_pdata_float(iItem, m_flNextSecondaryAttack, 4) <= 0.0)
    311.             if(pev(iPlayer, pev_button) & IN_ATTACK2) {
    312.                 set_pdata_int(iPlayer, m_iFOV, get_pdata_int(iPlayer, m_iFOV, 5) == 90 ? 60 : 90);
    313.                 set_pdata_float(iItem, m_flNextSecondaryAttack, 0.3, 4);
    314.             }
    315.         }
    316.     }
    317.    
    318.     return HAM_IGNORED;
    319. }
    320.  
    321. public fw_Item_AddToPlayer_Post(iItem, iPlayer)
    322. {
    323.     switch(pev(iItem, pev_impulse)) {
    324.         case WEAPON_KEY: {
    325.         s_weaponlist(iPlayer, true);
    326.         g_bHasStunRifle[iPlayer] = true;
    327.        
    328.         if (g_iStoredEnergy[iPlayer] < 6)
    329.         {
    330.             set_task(101/30.0, "OnReloadFinished", iPlayer);
    331.         }
    332.         else if (g_iStoredEnergy[iPlayer] == 6)
    333.         {
    334.             client_print(iPlayer, print_center, "Your Stun Rifle is fully charged!")
    335.         }
    336.         }
    337.         case 0: s_weaponlist(iPlayer, false);
    338.     }
    339. }
    340.  
    341. public ze_user_infected(infected)
    342. {
    343.     if (g_bHasStunRifle[infected])
    344.     {
    345.         g_bHasStunRifle[infected] = false
    346.         g_iStoredEnergy[infected] = 0;
    347.     }
    348. }
    349.  
    350. public ze_user_humanized(id)
    351. {
    352.     g_bHasStunRifle[id] = false
    353.     g_iStoredEnergy[id] = 0;
    354. }
    355.  
    356. public fw_Weapon_Reload(iItem)
    357. {
    358.     if(!CustomItem(iItem)) return HAM_IGNORED;
    359.     static iClip; iClip = get_pdata_int(iItem, m_iClip, 4);
    360.     if(iClip >= WEAPON_CLIP) return HAM_SUPERCEDE;
    361.     static iPlayer; iPlayer = get_pdata_cbase(iItem, m_pPlayer, 4);
    362.     static iAmmoType; iAmmoType = m_rgAmmo + get_pdata_int(iItem, m_iPrimaryAmmoType, 4);
    363.     if(get_pdata_int(iPlayer, iAmmoType, 5) <= 0) return HAM_SUPERCEDE
    364.     if(get_pdata_int(iPlayer, m_iFOV, 5) != 90) set_pdata_int(iPlayer, m_iFOV, 90, 5);
    365.  
    366.     set_pdata_int(iItem, m_iClip, 0, 4);
    367.     ExecuteHam(Ham_Weapon_Reload, iItem);
    368.     set_pdata_int(iItem, m_iClip, iClip, 4);
    369.  
    370.     set_pdata_int(iItem, m_fInReload, 1, 4);
    371.    
    372.     g_bReloading[iPlayer] = true;
    373.     set_task(3.0, "AttackTask", iPlayer+444)
    374.    
    375.     server_print("%i", isEmpty(iPlayer))
    376.  
    377.     if (g_iStoredEnergy[iPlayer] == 0)
    378.     {
    379.         // Reload A
    380.         set_pdata_float(iItem, m_flNextPrimaryAttack, ANIM_RELOAD_TIME_A, 4);
    381.         set_pdata_float(iItem, m_flNextSecondaryAttack, ANIM_RELOAD_TIME_A, 4);
    382.         set_pdata_float(iItem, m_flTimeWeaponIdle, ANIM_RELOAD_TIME_A, 4);
    383.         set_pdata_float(iPlayer, m_flNextAttack, ANIM_RELOAD_TIME_A, 5);
    384.        
    385.         UTIL_SendWeaponAnim(iPlayer, ANIM_RELOAD_A);
    386.        
    387.         emit_sound(iPlayer, CHAN_WEAPON, g_szSounds[4], VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
    388.         emit_sound(iPlayer, CHAN_WEAPON, g_szSounds[10], VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
    389.     }
    390.     else if (g_iStoredEnergy[iPlayer] > 0 && g_iStoredEnergy[iPlayer] <= 3)
    391.     {
    392.         // Reload B
    393.         set_pdata_float(iItem, m_flNextPrimaryAttack, ANIM_RELOAD_TIME_B, 4);
    394.         set_pdata_float(iItem, m_flNextSecondaryAttack, ANIM_RELOAD_TIME_B, 4);
    395.         set_pdata_float(iItem, m_flTimeWeaponIdle, ANIM_RELOAD_TIME_B, 4);
    396.         set_pdata_float(iPlayer, m_flNextAttack, ANIM_RELOAD_TIME_B, 5);
    397.        
    398.         UTIL_SendWeaponAnim(iPlayer, ANIM_RELOAD_B);
    399.        
    400.         emit_sound(iPlayer, CHAN_WEAPON, g_szSounds[5], VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
    401.        
    402.         if (!isEmpty(iPlayer))
    403.         {
    404.             emit_sound(iPlayer, CHAN_WEAPON, g_szSounds[11], VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
    405.         }
    406.     }
    407.     else if (g_iStoredEnergy[iPlayer] > 3 && g_iStoredEnergy[iPlayer] <= 6)
    408.     {
    409.         // Reload C
    410.         set_pdata_float(iItem, m_flNextPrimaryAttack, ANIM_RELOAD_TIME_C, 4);
    411.         set_pdata_float(iItem, m_flNextSecondaryAttack, ANIM_RELOAD_TIME_C, 4);
    412.         set_pdata_float(iItem, m_flTimeWeaponIdle, ANIM_RELOAD_TIME_C, 4);
    413.         set_pdata_float(iPlayer, m_flNextAttack, ANIM_RELOAD_TIME_C, 5);
    414.        
    415.         UTIL_SendWeaponAnim(iPlayer, ANIM_RELOAD_C);
    416.        
    417.         emit_sound(iPlayer, CHAN_WEAPON, g_szSounds[6], VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
    418.        
    419.         if (!isEmpty(iPlayer))
    420.         {
    421.             emit_sound(iPlayer, CHAN_WEAPON, g_szSounds[11], VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
    422.         }
    423.     }
    424.    
    425.     // Set task to recharge the battary
    426.     remove_task(iPlayer)
    427.     set_task(101/30.0, "OnReloadFinished", iPlayer)
    428.  
    429.     return HAM_SUPERCEDE;
    430. }
    431.  
    432. public AttackTask(taskid)
    433. {
    434.     g_bReloading[taskid - 444] = false;
    435.        
    436.     // After reload reset the stored energy
    437.     g_iStoredEnergy[taskid - 444] = 0;
    438.    
    439.     g_iAppearTimes[taskid - 444] = 0;
    440. }
    441.  
    442. public client_PreThink(id)
    443. {
    444.     if (g_bReloading[id] && g_bHasStunRifle[id] && (get_user_weapon(id) == CSW_AK47))
    445.     {
    446.         if (g_iStoredEnergy[id] == 0)
    447.         {
    448.             // Reload A
    449.            
    450.         }
    451.         else if (g_iStoredEnergy[id] > 0 && g_iStoredEnergy[id] <= 3)
    452.         {
    453.             // Reload B
    454.             static Float:flOrigin[3]
    455.             pev(id, pev_origin, flOrigin)
    456.             new iVictim = -1;
    457.            
    458.             while ((iVictim = engfunc(EngFunc_FindEntityInSphere, iVictim, flOrigin, get_pcvar_float(g_pCvarRadius))) != 0)
    459.             {
    460.                 if (!is_user_alive(iVictim) || !ze_is_user_zombie(iVictim))
    461.                     continue
    462.                
    463.                 static Float:flVecOrigin[3];
    464.                 pev(iVictim, pev_origin, flVecOrigin);
    465.                    
    466.                 ElectricBeam(id, flVecOrigin);
    467.                    
    468.                 ExecuteHam(Ham_TakeDamage, iVictim, id, id, get_pcvar_float(g_pCvarElecDmg) * g_iStoredEnergy[id], DMG_SLASH);
    469.            
    470.                 fm_set_user_rendering(iVictim, kRenderFxGlowShell, 51, 51, 225, kRenderNormal, 10);
    471.                 set_task(101/30.0, "Delete_Glow", iVictim+4444);
    472.             }
    473.         }
    474.         else if (g_iStoredEnergy[id] > 3 && g_iStoredEnergy[id] <= 6)
    475.         {
    476.             // Reload C
    477.             static Float:flOrigin[3]
    478.             pev(id, pev_origin, flOrigin)
    479.             new iVictim = -1;
    480.            
    481.             while ((iVictim = engfunc(EngFunc_FindEntityInSphere, iVictim, flOrigin, get_pcvar_float(g_pCvarRadius))) != 0)
    482.             {
    483.                 if (!is_user_alive(iVictim) || !ze_is_user_zombie(iVictim))
    484.                     continue
    485.                
    486.                 static Float:flVecOrigin[3]
    487.                 pev(iVictim, pev_origin, flVecOrigin)
    488.                
    489.                 ElectricBeam(id, flVecOrigin)
    490.                
    491.                 ExecuteHam(Ham_TakeDamage, iVictim, id, id, get_pcvar_float(g_pCvarElecDmg) * g_iStoredEnergy[id], DMG_SLASH);
    492.                
    493.                 fm_set_user_rendering(iVictim, kRenderFxGlowShell, 51, 51, 225, kRenderNormal, 10);
    494.                 set_task(101/30.0, "Delete_Glow", iVictim+4444);
    495.             }
    496.         }
    497.     }
    498. }
    499.  
    500. public Delete_Glow(taskid)
    501. {
    502.     new id = taskid - 4444;
    503.     fm_set_user_rendering(id);
    504. }
    505.  
    506. public OnReloadFinished(id)
    507. {
    508.     remove_task(id)
    509.     set_task(get_pcvar_float(g_pCvarBarFillTime), "RechargeTask", id, _, _, "a", 6)
    510. }
    511.  
    512. public RechargeTask(id)
    513. {
    514.     if (!g_bHasStunRifle[id])
    515.         return
    516.    
    517.     // Increase one bar every x time
    518.     g_iStoredEnergy[id]++
    519.    
    520.     new szBars[100];
    521.    
    522.     switch(g_iStoredEnergy[id])
    523.     {
    524.         case 1:
    525.         {
    526.             szBars = "[ |           ]";
    527.         }
    528.         case 2:
    529.         {
    530.             szBars = "[ | |         ]";
    531.         }
    532.         case 3:
    533.         {
    534.             szBars = "[ | | |       ]";
    535.         }
    536.         case 4:
    537.         {
    538.             szBars = "[ | | | |     ]";
    539.         }
    540.         case 5:
    541.         {
    542.             szBars = "[ | | | | |   ]";
    543.         }
    544.         case 6:
    545.         {
    546.             szBars = "[ | | | | | | ]";
    547.         }
    548.     }
    549.    
    550.     set_dhudmessage(51, 153, 255, -1.0, -0.16, 0, 0.0, get_pcvar_float(g_pCvarBarFillTime) - 0.2)
    551.     show_dhudmessage(id, "Stun Rifle Battary: %s", szBars)
    552.    
    553.     if (g_iStoredEnergy[id] == 6)
    554.     {
    555.         client_print(id, print_center, "Your Stun Rifle is fully charged!")
    556.         remove_task(id)
    557.     }
    558. }
    559.  
    560. public fw_Weapon_WeaponIdle(iItem)
    561. {
    562.     if(!CustomItem(iItem) || get_pdata_float(iItem, m_flTimeWeaponIdle, 4) > 0.0) return HAM_IGNORED;
    563.     static iPlayer; iPlayer = get_pdata_cbase(iItem, m_pPlayer, 4);
    564.  
    565.     if (g_iStoredEnergy[iPlayer] == 0)
    566.     {
    567.         // Idle A
    568.         UTIL_SendWeaponAnim(iPlayer, ANIM_IDLE_A);
    569.         set_pdata_float(iItem, m_flTimeWeaponIdle, ANIM_IDLE_TIME_A, 4);
    570.        
    571.         emit_sound(iPlayer, CHAN_WEAPON, g_szSounds[7], VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
    572.     }
    573.     else if (g_iStoredEnergy[iPlayer] > 0 && g_iStoredEnergy[iPlayer] <= 3)
    574.     {
    575.         // Idle B
    576.         UTIL_SendWeaponAnim(iPlayer, ANIM_IDLE_B);
    577.         set_pdata_float(iItem, m_flTimeWeaponIdle, ANIM_IDLE_TIME_B, 4);
    578.        
    579.         emit_sound(iPlayer, CHAN_WEAPON, g_szSounds[8], VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
    580.     }
    581.     else if (g_iStoredEnergy[iPlayer] > 3 && g_iStoredEnergy[iPlayer] <= 6)
    582.     {
    583.         // Idle C
    584.         UTIL_SendWeaponAnim(iPlayer, ANIM_IDLE_C);
    585.         set_pdata_float(iItem, m_flTimeWeaponIdle, ANIM_IDLE_TIME_C, 4);
    586.        
    587.         emit_sound(iPlayer, CHAN_WEAPON, g_szSounds[9], VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
    588.     }
    589.    
    590.     return HAM_SUPERCEDE;
    591. }
    592.  
    593. public fw_Weapon_PrimaryAttack(iItem)
    594. {
    595.     if(!CustomItem(iItem)) return HAM_IGNORED;
    596.     static iPlayer; iPlayer = get_pdata_cbase(iItem, m_pPlayer, 4);
    597.     static iFOV; iFOV = (get_pdata_int(iPlayer, m_iFOV, 5) != 90);
    598.     if(get_pdata_int(iItem, m_iClip, 4) == 0) {
    599.         ExecuteHam(Ham_Weapon_PlayEmptySound, iItem);
    600.         set_pdata_float(iItem, m_flNextPrimaryAttack, 0.2, 4);
    601.         return HAM_SUPERCEDE;
    602.     }
    603.     static fw_TraceLine; fw_TraceLine = register_forward(FM_TraceLine, "fw_TraceLine_Post", 1);
    604.     fm_ham_hook(true);
    605.     state FireBullets: Enabled;
    606.     ExecuteHam(Ham_Weapon_PrimaryAttack, iItem);
    607.     state FireBullets: Disabled;
    608.     unregister_forward(FM_TraceLine, fw_TraceLine, 1);
    609.     fm_ham_hook(false);
    610.     static Float:vecPunchangle[3];
    611.  
    612.     pev(iPlayer, pev_punchangle, vecPunchangle);
    613.     vecPunchangle[0] *= iFOV ? WEAPON_RECOIL_EX : WEAPON_RECOIL;
    614.     vecPunchangle[1] *= iFOV ? WEAPON_RECOIL_EX : WEAPON_RECOIL;
    615.     vecPunchangle[2] *= iFOV ? WEAPON_RECOIL_EX : WEAPON_RECOIL;
    616.     set_pev(iPlayer, pev_punchangle, vecPunchangle);
    617.  
    618.     emit_sound(iPlayer, CHAN_WEAPON, g_szSounds[0], VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
    619.    
    620.     if (g_iStoredEnergy[iPlayer] == 0)
    621.     {
    622.         // Idle A
    623.         UTIL_SendWeaponAnim(iPlayer, ANIM_ATTACK_A);
    624.         set_pdata_float(iItem, m_flTimeWeaponIdle, ANIM_SHOOT_TIME_A, 4);
    625.     }
    626.     else if (g_iStoredEnergy[iPlayer] > 0 && g_iStoredEnergy[iPlayer] <= 3)
    627.     {
    628.         // Idle B
    629.         UTIL_SendWeaponAnim(iPlayer, ANIM_ATTACK_B);
    630.         set_pdata_float(iItem, m_flTimeWeaponIdle, ANIM_SHOOT_TIME_B, 4);
    631.     }
    632.     else if (g_iStoredEnergy[iPlayer] > 3 && g_iStoredEnergy[iPlayer] <= 6)
    633.     {
    634.         // Idle C
    635.         UTIL_SendWeaponAnim(iPlayer, ANIM_ATTACK_C);
    636.         set_pdata_float(iItem, m_flTimeWeaponIdle, ANIM_SHOOT_TIME_C, 4);
    637.     }
    638.    
    639.     Make_Muzzleflash(iPlayer)
    640.  
    641.     set_pdata_float(iItem, m_flNextPrimaryAttack, iFOV ? WEAPON_RATE_EX : WEAPON_RATE, 4);
    642.  
    643.     return HAM_SUPERCEDE;
    644. }
    645.  
    646. public fw_PlaybackEvent() <FireBullets: Enabled> { return FMRES_SUPERCEDE; }
    647. public fw_PlaybackEvent() <FireBullets: Disabled> { return FMRES_IGNORED; }
    648. public fw_PlaybackEvent() <> { return FMRES_IGNORED; }
    649. public fw_TraceAttack(iVictim, iAttacker, Float:flDamage) {
    650.     if(!is_user_connected(iAttacker)) return;
    651.     static iItem; iItem = get_pdata_cbase(iAttacker, m_pActiveItem, 5);
    652.     static iFOV; iFOV = (get_pdata_int(iAttacker, m_iFOV, 5) != 90);
    653.     static Float: flWeaponDamage; flWeaponDamage = (iFOV ? WEAPON_DAMAGE_EX : WEAPON_DAMAGE);
    654.     if(iItem <= 0 || !CustomItem(iItem)) return;
    655.         SetHamParamFloat(3, flDamage * flWeaponDamage);
    656. }
    657.  
    658. public fw_UpdateClientData_Post(iPlayer, SendWeapons, CD_Handle)
    659. {
    660.     if(get_cd(CD_Handle, CD_DeadFlag) != DEAD_NO) return;
    661.     static iItem; iItem = get_pdata_cbase(iPlayer, m_pActiveItem, 5);
    662.     if(iItem <= 0 || !CustomItem(iItem)) return;
    663.     set_cd(CD_Handle, CD_flNextAttack, 999999.0);
    664. }
    665.  
    666. public fw_SetModel(iEnt)
    667. {
    668.     static i, szClassname[32], iItem;
    669.     pev(iEnt, pev_classname, szClassname, 31);
    670.     if(!equal(szClassname, "weaponbox")) return FMRES_IGNORED;
    671.     for(i = 0; i < 6; i++) {
    672.         iItem = get_pdata_cbase(iEnt, m_rgpPlayerItems_CWeaponBox + i, 4);
    673.         if(iItem > 0 && CustomItem(iItem)) {
    674.             engfunc(EngFunc_SetModel, iEnt, WEAPON_MODEL_W);
    675.             set_pev(iEnt, pev_body, WEAPON_BODY);
    676.             new iPlayer = pev(iEnt, pev_owner);
    677.             g_bHasStunRifle[iPlayer] = false;
    678.             remove_task(iPlayer)
    679.             return FMRES_SUPERCEDE;
    680.         }
    681.     }
    682.     return FMRES_IGNORED;
    683. }
    684.  
    685. public fw_TraceLine_Post(const Float:flOrigin1[3], const Float:flOrigin2[3], iFrag, iIgnore, tr)
    686. {
    687.     if(iFrag & IGNORE_MONSTERS) return FMRES_IGNORED;
    688.     static pHit; pHit = get_tr2(tr, TR_pHit);
    689.     static Float:flvecEndPos[3]; get_tr2(tr, TR_vecEndPos, flvecEndPos);
    690.     if(pHit > 0) {
    691.         if(pev(pHit, pev_solid) != SOLID_BSP) return FMRES_IGNORED;
    692.     }
    693.     engfunc(EngFunc_MessageBegin, MSG_PAS, SVC_TEMPENTITY, flvecEndPos, 0);
    694.     write_byte(TE_GUNSHOTDECAL);
    695.     engfunc(EngFunc_WriteCoord, flvecEndPos[0]);
    696.     engfunc(EngFunc_WriteCoord, flvecEndPos[1]);
    697.     engfunc(EngFunc_WriteCoord, flvecEndPos[2]);
    698.     write_short(pHit > 0 ? pHit : 0);
    699.     write_byte(random_num(41, 45));
    700.     message_end();
    701.  
    702.     return FMRES_IGNORED;
    703. }
    704.  
    705. public fm_ham_hook(bool:on) {
    706.     if(on) {
    707.         EnableHamForward(g_fw_TraceAttack[0]);
    708.         EnableHamForward(g_fw_TraceAttack[1]);
    709.         EnableHamForward(g_fw_TraceAttack[2]);
    710.         EnableHamForward(g_fw_TraceAttack[3]);
    711.     }
    712.     else {
    713.         DisableHamForward(g_fw_TraceAttack[0]);
    714.         DisableHamForward(g_fw_TraceAttack[1]);
    715.         DisableHamForward(g_fw_TraceAttack[2]);
    716.         DisableHamForward(g_fw_TraceAttack[3]);
    717.     }
    718. }
    719.  
    720. stock UTIL_SendWeaponAnim(iPlayer, iAnim)
    721. {
    722.     set_pev(iPlayer, pev_weaponanim, iAnim);
    723.  
    724.     message_begin(MSG_ONE, SVC_WEAPONANIM, _, iPlayer);
    725.     write_byte(iAnim);
    726.     write_byte(0);
    727.     message_end();
    728. }
    729.  
    730. stock UTIL_DropWeapon(iPlayer, iSlot) {
    731.     static iEntity, iNext, szWeaponName[32];
    732.     iEntity = get_pdata_cbase(iPlayer, m_rpgPlayerItems + iSlot, 5);
    733.     if(iEntity > 0) {      
    734.         do {
    735.             iNext = get_pdata_cbase(iEntity, m_pNext, 4)
    736.             if(get_weaponname(get_pdata_int(iEntity, m_iId, 4), szWeaponName, 31)) {  
    737.                 engclient_cmd(iPlayer, "drop", szWeaponName);
    738.             }
    739.         } while(( iEntity = iNext) > 0);
    740.     }
    741. }
    742.  
    743. stock s_weaponlist(iPlayer, bool:on)
    744. {
    745.     message_begin(MSG_ONE, g_iMsgID_Weaponlist, {0,0,0}, iPlayer);
    746.     write_string(on ? WEAPON_NEW : WEAPON_OLD);
    747.     write_byte(iWeaponList[0]);
    748.     write_byte(on ? WEAPON_AMMO : iWeaponList[1]);
    749.     write_byte(iWeaponList[2]);
    750.     write_byte(iWeaponList[3]);
    751.     write_byte(iWeaponList[4]);
    752.     write_byte(iWeaponList[5]);
    753.     write_byte(iWeaponList[6]);
    754.     write_byte(iWeaponList[7]);
    755.     message_end();
    756. }
    757.  
    758. stock ElectricBeam(id, Float:flOrigin[3])
    759. {
    760.     message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
    761.     write_byte(TE_BEAMENTPOINT)
    762.     write_short(id | 0x1000)
    763.     engfunc(EngFunc_WriteCoord, flOrigin[0])
    764.     engfunc(EngFunc_WriteCoord, flOrigin[1])
    765.     engfunc(EngFunc_WriteCoord, flOrigin[2])
    766.     write_short(g_iLigSpr)
    767.     write_byte(1); // framestart
    768.     write_byte(100); // framerate - 5
    769.     write_byte(1) // life - 30
    770.     write_byte(30); // width
    771.     write_byte(random_num(0, 10)); // noise
    772.     write_byte(51); // r, g, b
    773.     write_byte(51); // r, g, b
    774.     write_byte(255); // r, g, b
    775.     write_byte(200); // brightness
    776.     write_byte(200); // speed
    777.     message_end()
    778.    
    779.     if (g_iAppearTimes[id] >= 2)
    780.         return
    781.    
    782.     message_begin(MSG_BROADCAST, SVC_TEMPENTITY);
    783.     write_byte(TE_EXPLOSION);
    784.     engfunc(EngFunc_WriteCoord, flOrigin[0]);
    785.     engfunc(EngFunc_WriteCoord, flOrigin[1]);
    786.     engfunc(EngFunc_WriteCoord, flOrigin[2]);
    787.     write_short(g_iEffSpr);
    788.     write_byte(10);
    789.     write_byte(10);
    790.     write_byte(TE_EXPLFLAG_NOSOUND|TE_EXPLFLAG_NOPARTICLES|TE_EXPLFLAG_NODLIGHTS);
    791.     message_end();
    792.    
    793.     g_iAppearTimes[id]++
    794. }
    795.  
    796. stock isEmpty(id)
    797. {
    798.     static Float:flOrigin[3]
    799.     pev(id, pev_origin, flOrigin)
    800.     new iVictim = -1;
    801.            
    802.     while ((iVictim = engfunc(EngFunc_FindEntityInSphere, iVictim, flOrigin, get_pcvar_float(g_pCvarRadius))) != 0)
    803.     {
    804.         if (!is_user_alive(iVictim) || !ze_is_user_zombie(iVictim))
    805.             continue
    806.        
    807.         return true;
    808.     }
    809.    
    810.     return false;
    811. }
    812.  
    813. public Make_Muzzleflash(id)
    814. {
    815.     static Float:Origin[3], TE_FLAG
    816.     get_position(id, 32.0, 6.0, -15.0, Origin)
    817.    
    818.     TE_FLAG |= TE_EXPLFLAG_NODLIGHTS
    819.     TE_FLAG |= TE_EXPLFLAG_NOSOUND
    820.     TE_FLAG |= TE_EXPLFLAG_NOPARTICLES
    821.    
    822.     engfunc(EngFunc_MessageBegin, MSG_ONE_UNRELIABLE, SVC_TEMPENTITY, Origin, id)
    823.     write_byte(TE_EXPLOSION)
    824.     engfunc(EngFunc_WriteCoord, Origin[0])
    825.     engfunc(EngFunc_WriteCoord, Origin[1])
    826.     engfunc(EngFunc_WriteCoord, Origin[2])
    827.     write_short(g_iEff2Spr)
    828.     write_byte(2)
    829.     write_byte(30)
    830.     write_byte(TE_FLAG)
    831.     message_end()
    832. }
    833.  
    834. stock get_position(id,Float:forw, Float:right, Float:up, Float:vStart[])
    835. {
    836.     static Float:vOrigin[3], Float:vAngle[3], Float:vForward[3], Float:vRight[3], Float:vUp[3]
    837.    
    838.     pev(id, pev_origin, vOrigin)
    839.     pev(id, pev_view_ofs, vUp) //for player
    840.     xs_vec_add(vOrigin, vUp, vOrigin)
    841.     pev(id, pev_v_angle, vAngle) // if normal entity ,use pev_angles
    842.    
    843.     angle_vector(vAngle,ANGLEVECTOR_FORWARD, vForward) //or use EngFunc_AngleVectors
    844.     angle_vector(vAngle,ANGLEVECTOR_RIGHT, vRight)
    845.     angle_vector(vAngle,ANGLEVECTOR_UP, vUp)
    846.    
    847.     vStart[0] = vOrigin[0] + vForward[0] * forw + vRight[0] * right + vUp[0] * up
    848.     vStart[1] = vOrigin[1] + vForward[1] * forw + vRight[1] * right + vUp[1] * up
    849.     vStart[2] = vOrigin[2] + vForward[2] * forw + vRight[2] * right + vUp[2] * up
    850. }
Please state what issue you found.
You don't know? Learn and you will know.

User avatar
Mark
Senior Member
Senior Member
United States of America
Posts: 258
Joined: 4 Months Ago
Location: Des Moines/USA
Donation: 1x donated in total €10.00
Has thanked: 6 times
Been thanked: 19 times
Age: 33
Contact:

#18

Post by Mark » 3 Months Ago

Raheem wrote:
3 Months Ago
I'm using this without any problem:
    1. /*
    2. *   Stun Rifle is a CSO weapon, More information about it: http://cso.wikia.com/wiki/Stun_Rifle
    3. *  
    4. *   This plugin written by me: Raheem (The basic things for any weapon not written by me)
    5. *
    6. *   I tried to simulate it same as in CSO, I think it's nearly same else simple things
    7. *   That will be done in next versions.
    8. *
    9. *   Version 1.0 creation date: 16-6-2018
    10. *   Version 1.0 publication date: 20-6-2018
    11. *
    12. *   TODO List: Fix any problem, include good ideas
    13. */
    14.  
    15. #include <zombie_escape>
    16. #include <fakemeta_util>
    17.  
    18. #define CustomItem(%0) (pev(%0, pev_impulse) == WEAPON_KEY)
    19.  
    20. // CWeaponBox
    21. #define m_rgpPlayerItems_CWeaponBox 34
    22.  
    23. // CBasePlayerItem
    24. #define m_pPlayer 41
    25. #define m_pNext 42
    26. #define m_iId 43
    27.  
    28. // CBasePlayerWeapon
    29. #define m_flNextPrimaryAttack 46
    30. #define m_flNextSecondaryAttack 47
    31. #define m_flTimeWeaponIdle 48
    32. #define m_iPrimaryAmmoType 49
    33. #define m_iClip 51
    34. #define m_fInReload 54
    35. #define m_iWeaponState 74
    36.  
    37. // CBaseMonster
    38. #define m_flNextAttack 83
    39.  
    40. // CBasePlayer
    41. #define m_iFOV 363
    42. #define m_rpgPlayerItems 367
    43. #define m_pActiveItem 373
    44. #define m_rgAmmo 376
    45.  
    46. /*-----------------------------------------------------*/
    47.  
    48. #define WEAPON_KEY 776544229
    49. #define WEAPON_OLD "weapon_ak47"
    50. #define WEAPON_NEW "weapon_stunrifle"
    51.  
    52. /*-----------------------------------------------------*/
    53.  
    54. new const WPN_SPRITES[][] =
    55. {
    56.     "sprites/weapon_stunrifle.txt",
    57.     "sprites/640hud169.spr",
    58.     "sprites/640hud7.spr"
    59. }
    60.  
    61. new const g_szSounds[][] =
    62. {
    63.     "weapons/stunrifle-1.wav",
    64.     "weapons/stunrifle_drawa.wav",
    65.     "weapons/stunrifle_drawb.wav",
    66.     "weapons/stunrifle_drawc.wav",
    67.     "weapons/stunrifle_reloada.wav",
    68.     "weapons/stunrifle_reloadb.wav",
    69.     "weapons/stunrifle_reloadc.wav",
    70.     "weapons/stunrifle_idlea.wav",
    71.     "weapons/stunrifle_idleb.wav",
    72.     "weapons/stunrifle_idlec.wav",
    73.     "weapons/stunrifle_lowbattery.wav",
    74.     "weapons/stunrifle-2.wav"
    75. }
    76.  
    77. new const iWeaponList[] =
    78. {  
    79.     2, 30, -1, -1, 0, 1, CSW_AK47, 0
    80. }
    81.  
    82. #define WEAPON_MODEL_V "models/stunrifle/v_stunrifle.mdl"
    83. #define WEAPON_MODEL_P "models/stunrifle/p_stunrifle.mdl"
    84. #define WEAPON_MODEL_W "models/stunrifle/w_stunrifle.mdl"
    85. #define WEAPON_BODY 0
    86.  
    87. /*-----------------------------------------------------*/
    88.  
    89. #define WEAPON_COST 0
    90.  
    91. #define WEAPON_CLIP 30
    92. #define WEAPON_AMMO 90
    93. #define WEAPON_RATE 0.098
    94. #define WEAPON_RECOIL 0.96
    95. #define WEAPON_DAMAGE 1.0 // AK47 damage multiplied by this factor
    96.  
    97. #define WEAPON_RATE_EX 0.169
    98. #define WEAPON_RECOIL_EX 0.79
    99. #define WEAPON_DAMAGE_EX 1.3
    100. #define WEAPON_NATIVE "native_give_weapon_stunrifle"
    101.  
    102. /*-----------------------------------------------------*/
    103.  
    104. // Animations
    105. #define ANIM_IDLE_A 0
    106. #define ANIM_IDLE_B 1
    107. #define ANIM_IDLE_C 2
    108. #define ANIM_ATTACK_A 3
    109. #define ANIM_ATTACK_B 4
    110. #define ANIM_ATTACK_C 5
    111. #define ANIM_RELOAD_A 6
    112. #define ANIM_RELOAD_B 7
    113. #define ANIM_RELOAD_C 8
    114. #define ANIM_DRAW_A 9
    115. #define ANIM_DRAW_B 10
    116. #define ANIM_DRAW_C 11
    117.  
    118. // from model: Frames / FPS
    119. #define ANIM_IDLE_TIME_A 90/30.0
    120. #define ANIM_SHOOT_TIME_A 31/30.0
    121. #define ANIM_RELOAD_TIME_A 101/30.0
    122. #define ANIM_DRAW_TIME_A 46/30.0
    123. #define ANIM_IDLE_TIME_B 90/30.0
    124. #define ANIM_SHOOT_TIME_B 31/30.0
    125. #define ANIM_RELOAD_TIME_B 101/30.0
    126. #define ANIM_DRAW_TIME_B 46/30.0
    127. #define ANIM_IDLE_TIME_C 90/30.0
    128. #define ANIM_SHOOT_TIME_C 31/30.0
    129. #define ANIM_RELOAD_TIME_C 101/30.0
    130. #define ANIM_DRAW_TIME_C 46/30.0
    131.  
    132. new g_AllocString_V,
    133.     g_AllocString_P,
    134.     g_AllocString_E,
    135.  
    136.     HamHook: g_fw_TraceAttack[4],
    137.    
    138.     g_iMsgID_Weaponlist,
    139.     g_iStoredEnergy[33],
    140.     bool:g_bHasStunRifle[33],
    141.     g_pCvarBarFillTime,
    142.     g_pCvarRadius,
    143.     g_pCvarElecDmg,
    144.     g_iLigSpr,
    145.     g_iEffSpr,
    146.     g_iEff2Spr,
    147.     bool:g_bReloading[33],
    148.     g_iAppearTimes[33],
    149.     g_iItemID
    150.  
    151. public plugin_init()
    152. {
    153.     register_plugin("[ZE] Stun Rifle", "1.0", "Raheem");
    154.  
    155.     // Register our item
    156.     g_iItemID = ze_register_item("Stun Rifle", 300, 0) // It's cost 300 Coins
    157.     ze_set_item_vip(g_iItemID, "VIP_C")
    158.    
    159.     RegisterHam(Ham_Item_Deploy, WEAPON_OLD, "fw_Item_Deploy_Post", 1);
    160.     RegisterHam(Ham_Item_PostFrame, WEAPON_OLD, "fw_Item_PostFrame");
    161.     RegisterHam(Ham_Item_AddToPlayer, WEAPON_OLD, "fw_Item_AddToPlayer_Post", 1);
    162.     RegisterHam(Ham_Weapon_Reload, WEAPON_OLD, "fw_Weapon_Reload");
    163.     RegisterHam(Ham_Weapon_WeaponIdle, WEAPON_OLD, "fw_Weapon_WeaponIdle");
    164.     RegisterHam(Ham_Weapon_PrimaryAttack, WEAPON_OLD, "fw_Weapon_PrimaryAttack");
    165.    
    166.     g_fw_TraceAttack[0] = RegisterHam(Ham_TraceAttack, "func_breakable", "fw_TraceAttack");
    167.     g_fw_TraceAttack[1] = RegisterHam(Ham_TraceAttack, "info_target",    "fw_TraceAttack");
    168.     g_fw_TraceAttack[2] = RegisterHam(Ham_TraceAttack, "player",         "fw_TraceAttack");
    169.     g_fw_TraceAttack[3] = RegisterHam(Ham_TraceAttack, "hostage_entity", "fw_TraceAttack");
    170.     fm_ham_hook(false);
    171.     register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1);
    172.     register_forward(FM_PlaybackEvent, "fw_PlaybackEvent");
    173.     register_forward(FM_SetModel, "fw_SetModel");
    174.    
    175.     g_pCvarBarFillTime = register_cvar("stunrifle_barfill_time", "5") // Bar fill time in seconds
    176.     g_pCvarRadius = register_cvar("stunrifle_radius", "500") // elec radius
    177.     g_pCvarElecDmg = register_cvar("stunrifle_electricity_dmg", "10") // electricity damage - lowest damage for 1 bar only
    178.    
    179.     register_clcmd(WEAPON_NEW, "HookSelect");
    180.     g_iMsgID_Weaponlist = get_user_msgid("WeaponList");
    181. }
    182.  
    183. public plugin_precache()
    184. {
    185.     g_AllocString_V = engfunc(EngFunc_AllocString, WEAPON_MODEL_V);
    186.     g_AllocString_P = engfunc(EngFunc_AllocString, WEAPON_MODEL_P);
    187.     g_AllocString_E = engfunc(EngFunc_AllocString, WEAPON_OLD);
    188.     engfunc(EngFunc_PrecacheModel, WEAPON_MODEL_V);
    189.     engfunc(EngFunc_PrecacheModel, WEAPON_MODEL_P);
    190.     engfunc(EngFunc_PrecacheModel, WEAPON_MODEL_W);
    191.    
    192.     for (new i = 0; i < sizeof g_szSounds; i++) engfunc(EngFunc_PrecacheSound, g_szSounds[i]);
    193.    
    194.     for(new i = 0; i < sizeof WPN_SPRITES;i++) precache_generic(WPN_SPRITES[i]);
    195.    
    196.     g_iLigSpr = precache_model("sprites/lightning.spr");
    197.     g_iEffSpr = precache_model("sprites/ef_buffak_hit.spr");
    198.     g_iEff2Spr = precache_model("sprites/muzzleflash67.spr");
    199. }
    200.  
    201. public HookSelect(iPlayer)
    202. {
    203.     engclient_cmd(iPlayer, WEAPON_OLD);
    204. }
    205.  
    206. public give(id)
    207. {
    208.     give_weapon_stunrifle(id)
    209. }
    210.  
    211. public give_weapon_stunrifle(iPlayer)
    212. {
    213.     static iEnt; iEnt = engfunc(EngFunc_CreateNamedEntity, g_AllocString_E);
    214.     if(iEnt <= 0) return 0;
    215.     set_pev(iEnt, pev_spawnflags, SF_NORESPAWN);
    216.     set_pev(iEnt, pev_impulse, WEAPON_KEY);
    217.     ExecuteHam(Ham_Spawn, iEnt);
    218.     UTIL_DropWeapon(iPlayer, 1);
    219.     if(!ExecuteHamB(Ham_AddPlayerItem, iPlayer, iEnt)) {
    220.         engfunc(EngFunc_RemoveEntity, iEnt);
    221.         return 0;
    222.     }
    223.     ExecuteHamB(Ham_Item_AttachToPlayer, iEnt, iPlayer);
    224.     set_pdata_int(iEnt, m_iClip, WEAPON_CLIP, 4);
    225.     new iAmmoType = m_rgAmmo +get_pdata_int(iEnt, m_iPrimaryAmmoType, 4);
    226.     if(get_pdata_int(iPlayer, m_rgAmmo, 5) < WEAPON_AMMO)
    227.     set_pdata_int(iPlayer, iAmmoType, WEAPON_AMMO, 5);
    228.     emit_sound(iPlayer, CHAN_ITEM, "items/gunpickup2.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
    229.     g_iStoredEnergy[iPlayer] = 0;
    230.     g_bHasStunRifle[iPlayer] = true;
    231.     set_task(get_pcvar_float(g_pCvarBarFillTime), "RechargeTask", iPlayer, _, _, "a", 6)
    232.     return 1;
    233. }
    234.  
    235. public plugin_natives()
    236. {
    237.     register_native(WEAPON_NATIVE, "give_weapon_stunrifle", 1);
    238. }
    239.  
    240. public ze_select_item_pre(id, itemid)
    241. {
    242.     // Return Available and we will block it in Post, So it dosen't affect other plugins
    243.     if (itemid != g_iItemID)
    244.         return ZE_ITEM_AVAILABLE
    245.    
    246.     // Available for Humans only, So don't show it for zombies
    247.     if (ze_is_user_zombie(id))
    248.         return ZE_ITEM_DONT_SHOW
    249.    
    250.     return ZE_ITEM_AVAILABLE
    251. }
    252.  
    253. public ze_select_item_post(player, itemid)
    254. {
    255.     if (itemid != g_iItemID)
    256.         return
    257.    
    258.     give_weapon_stunrifle(player)
    259. }
    260.  
    261. public fw_Item_Deploy_Post(iItem)
    262. {
    263.     if(!CustomItem(iItem)) return;
    264.     static iPlayer; iPlayer = get_pdata_cbase(iItem, m_pPlayer, 4);
    265.  
    266.     set_pev_string(iPlayer, pev_viewmodel2, g_AllocString_V);
    267.     set_pev_string(iPlayer, pev_weaponmodel2, g_AllocString_P);
    268.    
    269.     if (g_iStoredEnergy[iPlayer] == 0)
    270.     {
    271.         // Draw A
    272.         UTIL_SendWeaponAnim(iPlayer, ANIM_DRAW_A);
    273.         emit_sound(iPlayer, CHAN_WEAPON, g_szSounds[1], VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
    274.         set_pdata_float(iPlayer, m_flNextAttack, ANIM_DRAW_TIME_A, 5);
    275.         set_pdata_float(iItem, m_flTimeWeaponIdle, ANIM_DRAW_TIME_A, 4);
    276.     }
    277.     else if (g_iStoredEnergy[iPlayer] > 0 && g_iStoredEnergy[iPlayer] <= 3)
    278.     {
    279.         // Draw B
    280.         UTIL_SendWeaponAnim(iPlayer, ANIM_DRAW_B);
    281.         emit_sound(iPlayer, CHAN_WEAPON, g_szSounds[2], VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
    282.         set_pdata_float(iPlayer, m_flNextAttack, ANIM_DRAW_TIME_B, 5);
    283.         set_pdata_float(iItem, m_flTimeWeaponIdle, ANIM_DRAW_TIME_B, 4);
    284.     }
    285.     else if (g_iStoredEnergy[iPlayer] > 3 && g_iStoredEnergy[iPlayer] <= 6)
    286.     {
    287.         // Draw C
    288.         UTIL_SendWeaponAnim(iPlayer, ANIM_DRAW_C);
    289.         emit_sound(iPlayer, CHAN_WEAPON, g_szSounds[3], VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
    290.         set_pdata_float(iPlayer, m_flNextAttack, ANIM_DRAW_TIME_C, 5);
    291.         set_pdata_float(iItem, m_flTimeWeaponIdle, ANIM_DRAW_TIME_C, 4);
    292.     }
    293. }
    294.  
    295. public fw_Item_PostFrame(iItem)
    296. {
    297.     if(!CustomItem(iItem)) return HAM_IGNORED;
    298.     static iPlayer; iPlayer = get_pdata_cbase(iItem, m_pPlayer, 4);
    299.     if(get_pdata_int(iItem, m_fInReload, 4) == 1) {
    300.         static iClip; iClip = get_pdata_int(iItem, m_iClip, 4);
    301.         static iAmmoType; iAmmoType = m_rgAmmo + get_pdata_int(iItem, m_iPrimaryAmmoType, 4);
    302.         static iAmmo; iAmmo = get_pdata_int(iPlayer, iAmmoType, 5);
    303.         static j; j = min(WEAPON_CLIP - iClip, iAmmo);
    304.         set_pdata_int(iItem, m_iClip, iClip+j, 4);
    305.         set_pdata_int(iPlayer, iAmmoType, iAmmo-j, 5);
    306.         set_pdata_int(iItem, m_fInReload, 0, 4);
    307.     }
    308.     else switch(get_pdata_int(iItem, m_iWeaponState, 4) ) {
    309.         case 0: {
    310.             if(get_pdata_float(iItem, m_flNextSecondaryAttack, 4) <= 0.0)
    311.             if(pev(iPlayer, pev_button) & IN_ATTACK2) {
    312.                 set_pdata_int(iPlayer, m_iFOV, get_pdata_int(iPlayer, m_iFOV, 5) == 90 ? 60 : 90);
    313.                 set_pdata_float(iItem, m_flNextSecondaryAttack, 0.3, 4);
    314.             }
    315.         }
    316.     }
    317.    
    318.     return HAM_IGNORED;
    319. }
    320.  
    321. public fw_Item_AddToPlayer_Post(iItem, iPlayer)
    322. {
    323.     switch(pev(iItem, pev_impulse)) {
    324.         case WEAPON_KEY: {
    325.         s_weaponlist(iPlayer, true);
    326.         g_bHasStunRifle[iPlayer] = true;
    327.        
    328.         if (g_iStoredEnergy[iPlayer] < 6)
    329.         {
    330.             set_task(101/30.0, "OnReloadFinished", iPlayer);
    331.         }
    332.         else if (g_iStoredEnergy[iPlayer] == 6)
    333.         {
    334.             client_print(iPlayer, print_center, "Your Stun Rifle is fully charged!")
    335.         }
    336.         }
    337.         case 0: s_weaponlist(iPlayer, false);
    338.     }
    339. }
    340.  
    341. public ze_user_infected(infected)
    342. {
    343.     if (g_bHasStunRifle[infected])
    344.     {
    345.         g_bHasStunRifle[infected] = false
    346.         g_iStoredEnergy[infected] = 0;
    347.     }
    348. }
    349.  
    350. public ze_user_humanized(id)
    351. {
    352.     g_bHasStunRifle[id] = false
    353.     g_iStoredEnergy[id] = 0;
    354. }
    355.  
    356. public fw_Weapon_Reload(iItem)
    357. {
    358.     if(!CustomItem(iItem)) return HAM_IGNORED;
    359.     static iClip; iClip = get_pdata_int(iItem, m_iClip, 4);
    360.     if(iClip >= WEAPON_CLIP) return HAM_SUPERCEDE;
    361.     static iPlayer; iPlayer = get_pdata_cbase(iItem, m_pPlayer, 4);
    362.     static iAmmoType; iAmmoType = m_rgAmmo + get_pdata_int(iItem, m_iPrimaryAmmoType, 4);
    363.     if(get_pdata_int(iPlayer, iAmmoType, 5) <= 0) return HAM_SUPERCEDE
    364.     if(get_pdata_int(iPlayer, m_iFOV, 5) != 90) set_pdata_int(iPlayer, m_iFOV, 90, 5);
    365.  
    366.     set_pdata_int(iItem, m_iClip, 0, 4);
    367.     ExecuteHam(Ham_Weapon_Reload, iItem);
    368.     set_pdata_int(iItem, m_iClip, iClip, 4);
    369.  
    370.     set_pdata_int(iItem, m_fInReload, 1, 4);
    371.    
    372.     g_bReloading[iPlayer] = true;
    373.     set_task(3.0, "AttackTask", iPlayer+444)
    374.    
    375.     server_print("%i", isEmpty(iPlayer))
    376.  
    377.     if (g_iStoredEnergy[iPlayer] == 0)
    378.     {
    379.         // Reload A
    380.         set_pdata_float(iItem, m_flNextPrimaryAttack, ANIM_RELOAD_TIME_A, 4);
    381.         set_pdata_float(iItem, m_flNextSecondaryAttack, ANIM_RELOAD_TIME_A, 4);
    382.         set_pdata_float(iItem, m_flTimeWeaponIdle, ANIM_RELOAD_TIME_A, 4);
    383.         set_pdata_float(iPlayer, m_flNextAttack, ANIM_RELOAD_TIME_A, 5);
    384.        
    385.         UTIL_SendWeaponAnim(iPlayer, ANIM_RELOAD_A);
    386.        
    387.         emit_sound(iPlayer, CHAN_WEAPON, g_szSounds[4], VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
    388.         emit_sound(iPlayer, CHAN_WEAPON, g_szSounds[10], VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
    389.     }
    390.     else if (g_iStoredEnergy[iPlayer] > 0 && g_iStoredEnergy[iPlayer] <= 3)
    391.     {
    392.         // Reload B
    393.         set_pdata_float(iItem, m_flNextPrimaryAttack, ANIM_RELOAD_TIME_B, 4);
    394.         set_pdata_float(iItem, m_flNextSecondaryAttack, ANIM_RELOAD_TIME_B, 4);
    395.         set_pdata_float(iItem, m_flTimeWeaponIdle, ANIM_RELOAD_TIME_B, 4);
    396.         set_pdata_float(iPlayer, m_flNextAttack, ANIM_RELOAD_TIME_B, 5);
    397.        
    398.         UTIL_SendWeaponAnim(iPlayer, ANIM_RELOAD_B);
    399.        
    400.         emit_sound(iPlayer, CHAN_WEAPON, g_szSounds[5], VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
    401.        
    402.         if (!isEmpty(iPlayer))
    403.         {
    404.             emit_sound(iPlayer, CHAN_WEAPON, g_szSounds[11], VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
    405.         }
    406.     }
    407.     else if (g_iStoredEnergy[iPlayer] > 3 && g_iStoredEnergy[iPlayer] <= 6)
    408.     {
    409.         // Reload C
    410.         set_pdata_float(iItem, m_flNextPrimaryAttack, ANIM_RELOAD_TIME_C, 4);
    411.         set_pdata_float(iItem, m_flNextSecondaryAttack, ANIM_RELOAD_TIME_C, 4);
    412.         set_pdata_float(iItem, m_flTimeWeaponIdle, ANIM_RELOAD_TIME_C, 4);
    413.         set_pdata_float(iPlayer, m_flNextAttack, ANIM_RELOAD_TIME_C, 5);
    414.        
    415.         UTIL_SendWeaponAnim(iPlayer, ANIM_RELOAD_C);
    416.        
    417.         emit_sound(iPlayer, CHAN_WEAPON, g_szSounds[6], VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
    418.        
    419.         if (!isEmpty(iPlayer))
    420.         {
    421.             emit_sound(iPlayer, CHAN_WEAPON, g_szSounds[11], VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
    422.         }
    423.     }
    424.    
    425.     // Set task to recharge the battary
    426.     remove_task(iPlayer)
    427.     set_task(101/30.0, "OnReloadFinished", iPlayer)
    428.  
    429.     return HAM_SUPERCEDE;
    430. }
    431.  
    432. public AttackTask(taskid)
    433. {
    434.     g_bReloading[taskid - 444] = false;
    435.        
    436.     // After reload reset the stored energy
    437.     g_iStoredEnergy[taskid - 444] = 0;
    438.    
    439.     g_iAppearTimes[taskid - 444] = 0;
    440. }
    441.  
    442. public client_PreThink(id)
    443. {
    444.     if (g_bReloading[id] && g_bHasStunRifle[id] && (get_user_weapon(id) == CSW_AK47))
    445.     {
    446.         if (g_iStoredEnergy[id] == 0)
    447.         {
    448.             // Reload A
    449.            
    450.         }
    451.         else if (g_iStoredEnergy[id] > 0 && g_iStoredEnergy[id] <= 3)
    452.         {
    453.             // Reload B
    454.             static Float:flOrigin[3]
    455.             pev(id, pev_origin, flOrigin)
    456.             new iVictim = -1;
    457.            
    458.             while ((iVictim = engfunc(EngFunc_FindEntityInSphere, iVictim, flOrigin, get_pcvar_float(g_pCvarRadius))) != 0)
    459.             {
    460.                 if (!is_user_alive(iVictim) || !ze_is_user_zombie(iVictim))
    461.                     continue
    462.                
    463.                 static Float:flVecOrigin[3];
    464.                 pev(iVictim, pev_origin, flVecOrigin);
    465.                    
    466.                 ElectricBeam(id, flVecOrigin);
    467.                    
    468.                 ExecuteHam(Ham_TakeDamage, iVictim, id, id, get_pcvar_float(g_pCvarElecDmg) * g_iStoredEnergy[id], DMG_SLASH);
    469.            
    470.                 fm_set_user_rendering(iVictim, kRenderFxGlowShell, 51, 51, 225, kRenderNormal, 10);
    471.                 set_task(101/30.0, "Delete_Glow", iVictim+4444);
    472.             }
    473.         }
    474.         else if (g_iStoredEnergy[id] > 3 && g_iStoredEnergy[id] <= 6)
    475.         {
    476.             // Reload C
    477.             static Float:flOrigin[3]
    478.             pev(id, pev_origin, flOrigin)
    479.             new iVictim = -1;
    480.            
    481.             while ((iVictim = engfunc(EngFunc_FindEntityInSphere, iVictim, flOrigin, get_pcvar_float(g_pCvarRadius))) != 0)
    482.             {
    483.                 if (!is_user_alive(iVictim) || !ze_is_user_zombie(iVictim))
    484.                     continue
    485.                
    486.                 static Float:flVecOrigin[3]
    487.                 pev(iVictim, pev_origin, flVecOrigin)
    488.                
    489.                 ElectricBeam(id, flVecOrigin)
    490.                
    491.                 ExecuteHam(Ham_TakeDamage, iVictim, id, id, get_pcvar_float(g_pCvarElecDmg) * g_iStoredEnergy[id], DMG_SLASH);
    492.                
    493.                 fm_set_user_rendering(iVictim, kRenderFxGlowShell, 51, 51, 225, kRenderNormal, 10);
    494.                 set_task(101/30.0, "Delete_Glow", iVictim+4444);
    495.             }
    496.         }
    497.     }
    498. }
    499.  
    500. public Delete_Glow(taskid)
    501. {
    502.     new id = taskid - 4444;
    503.     fm_set_user_rendering(id);
    504. }
    505.  
    506. public OnReloadFinished(id)
    507. {
    508.     remove_task(id)
    509.     set_task(get_pcvar_float(g_pCvarBarFillTime), "RechargeTask", id, _, _, "a", 6)
    510. }
    511.  
    512. public RechargeTask(id)
    513. {
    514.     if (!g_bHasStunRifle[id])
    515.         return
    516.    
    517.     // Increase one bar every x time
    518.     g_iStoredEnergy[id]++
    519.    
    520.     new szBars[100];
    521.    
    522.     switch(g_iStoredEnergy[id])
    523.     {
    524.         case 1:
    525.         {
    526.             szBars = "[ |           ]";
    527.         }
    528.         case 2:
    529.         {
    530.             szBars = "[ | |         ]";
    531.         }
    532.         case 3:
    533.         {
    534.             szBars = "[ | | |       ]";
    535.         }
    536.         case 4:
    537.         {
    538.             szBars = "[ | | | |     ]";
    539.         }
    540.         case 5:
    541.         {
    542.             szBars = "[ | | | | |   ]";
    543.         }
    544.         case 6:
    545.         {
    546.             szBars = "[ | | | | | | ]";
    547.         }
    548.     }
    549.    
    550.     set_dhudmessage(51, 153, 255, -1.0, -0.16, 0, 0.0, get_pcvar_float(g_pCvarBarFillTime) - 0.2)
    551.     show_dhudmessage(id, "Stun Rifle Battary: %s", szBars)
    552.    
    553.     if (g_iStoredEnergy[id] == 6)
    554.     {
    555.         client_print(id, print_center, "Your Stun Rifle is fully charged!")
    556.         remove_task(id)
    557.     }
    558. }
    559.  
    560. public fw_Weapon_WeaponIdle(iItem)
    561. {
    562.     if(!CustomItem(iItem) || get_pdata_float(iItem, m_flTimeWeaponIdle, 4) > 0.0) return HAM_IGNORED;
    563.     static iPlayer; iPlayer = get_pdata_cbase(iItem, m_pPlayer, 4);
    564.  
    565.     if (g_iStoredEnergy[iPlayer] == 0)
    566.     {
    567.         // Idle A
    568.         UTIL_SendWeaponAnim(iPlayer, ANIM_IDLE_A);
    569.         set_pdata_float(iItem, m_flTimeWeaponIdle, ANIM_IDLE_TIME_A, 4);
    570.        
    571.         emit_sound(iPlayer, CHAN_WEAPON, g_szSounds[7], VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
    572.     }
    573.     else if (g_iStoredEnergy[iPlayer] > 0 && g_iStoredEnergy[iPlayer] <= 3)
    574.     {
    575.         // Idle B
    576.         UTIL_SendWeaponAnim(iPlayer, ANIM_IDLE_B);
    577.         set_pdata_float(iItem, m_flTimeWeaponIdle, ANIM_IDLE_TIME_B, 4);
    578.        
    579.         emit_sound(iPlayer, CHAN_WEAPON, g_szSounds[8], VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
    580.     }
    581.     else if (g_iStoredEnergy[iPlayer] > 3 && g_iStoredEnergy[iPlayer] <= 6)
    582.     {
    583.         // Idle C
    584.         UTIL_SendWeaponAnim(iPlayer, ANIM_IDLE_C);
    585.         set_pdata_float(iItem, m_flTimeWeaponIdle, ANIM_IDLE_TIME_C, 4);
    586.        
    587.         emit_sound(iPlayer, CHAN_WEAPON, g_szSounds[9], VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
    588.     }
    589.    
    590.     return HAM_SUPERCEDE;
    591. }
    592.  
    593. public fw_Weapon_PrimaryAttack(iItem)
    594. {
    595.     if(!CustomItem(iItem)) return HAM_IGNORED;
    596.     static iPlayer; iPlayer = get_pdata_cbase(iItem, m_pPlayer, 4);
    597.     static iFOV; iFOV = (get_pdata_int(iPlayer, m_iFOV, 5) != 90);
    598.     if(get_pdata_int(iItem, m_iClip, 4) == 0) {
    599.         ExecuteHam(Ham_Weapon_PlayEmptySound, iItem);
    600.         set_pdata_float(iItem, m_flNextPrimaryAttack, 0.2, 4);
    601.         return HAM_SUPERCEDE;
    602.     }
    603.     static fw_TraceLine; fw_TraceLine = register_forward(FM_TraceLine, "fw_TraceLine_Post", 1);
    604.     fm_ham_hook(true);
    605.     state FireBullets: Enabled;
    606.     ExecuteHam(Ham_Weapon_PrimaryAttack, iItem);
    607.     state FireBullets: Disabled;
    608.     unregister_forward(FM_TraceLine, fw_TraceLine, 1);
    609.     fm_ham_hook(false);
    610.     static Float:vecPunchangle[3];
    611.  
    612.     pev(iPlayer, pev_punchangle, vecPunchangle);
    613.     vecPunchangle[0] *= iFOV ? WEAPON_RECOIL_EX : WEAPON_RECOIL;
    614.     vecPunchangle[1] *= iFOV ? WEAPON_RECOIL_EX : WEAPON_RECOIL;
    615.     vecPunchangle[2] *= iFOV ? WEAPON_RECOIL_EX : WEAPON_RECOIL;
    616.     set_pev(iPlayer, pev_punchangle, vecPunchangle);
    617.  
    618.     emit_sound(iPlayer, CHAN_WEAPON, g_szSounds[0], VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
    619.    
    620.     if (g_iStoredEnergy[iPlayer] == 0)
    621.     {
    622.         // Idle A
    623.         UTIL_SendWeaponAnim(iPlayer, ANIM_ATTACK_A);
    624.         set_pdata_float(iItem, m_flTimeWeaponIdle, ANIM_SHOOT_TIME_A, 4);
    625.     }
    626.     else if (g_iStoredEnergy[iPlayer] > 0 && g_iStoredEnergy[iPlayer] <= 3)
    627.     {
    628.         // Idle B
    629.         UTIL_SendWeaponAnim(iPlayer, ANIM_ATTACK_B);
    630.         set_pdata_float(iItem, m_flTimeWeaponIdle, ANIM_SHOOT_TIME_B, 4);
    631.     }
    632.     else if (g_iStoredEnergy[iPlayer] > 3 && g_iStoredEnergy[iPlayer] <= 6)
    633.     {
    634.         // Idle C
    635.         UTIL_SendWeaponAnim(iPlayer, ANIM_ATTACK_C);
    636.         set_pdata_float(iItem, m_flTimeWeaponIdle, ANIM_SHOOT_TIME_C, 4);
    637.     }
    638.    
    639.     Make_Muzzleflash(iPlayer)
    640.  
    641.     set_pdata_float(iItem, m_flNextPrimaryAttack, iFOV ? WEAPON_RATE_EX : WEAPON_RATE, 4);
    642.  
    643.     return HAM_SUPERCEDE;
    644. }
    645.  
    646. public fw_PlaybackEvent() <FireBullets: Enabled> { return FMRES_SUPERCEDE; }
    647. public fw_PlaybackEvent() <FireBullets: Disabled> { return FMRES_IGNORED; }
    648. public fw_PlaybackEvent() <> { return FMRES_IGNORED; }
    649. public fw_TraceAttack(iVictim, iAttacker, Float:flDamage) {
    650.     if(!is_user_connected(iAttacker)) return;
    651.     static iItem; iItem = get_pdata_cbase(iAttacker, m_pActiveItem, 5);
    652.     static iFOV; iFOV = (get_pdata_int(iAttacker, m_iFOV, 5) != 90);
    653.     static Float: flWeaponDamage; flWeaponDamage = (iFOV ? WEAPON_DAMAGE_EX : WEAPON_DAMAGE);
    654.     if(iItem <= 0 || !CustomItem(iItem)) return;
    655.         SetHamParamFloat(3, flDamage * flWeaponDamage);
    656. }
    657.  
    658. public fw_UpdateClientData_Post(iPlayer, SendWeapons, CD_Handle)
    659. {
    660.     if(get_cd(CD_Handle, CD_DeadFlag) != DEAD_NO) return;
    661.     static iItem; iItem = get_pdata_cbase(iPlayer, m_pActiveItem, 5);
    662.     if(iItem <= 0 || !CustomItem(iItem)) return;
    663.     set_cd(CD_Handle, CD_flNextAttack, 999999.0);
    664. }
    665.  
    666. public fw_SetModel(iEnt)
    667. {
    668.     static i, szClassname[32], iItem;
    669.     pev(iEnt, pev_classname, szClassname, 31);
    670.     if(!equal(szClassname, "weaponbox")) return FMRES_IGNORED;
    671.     for(i = 0; i < 6; i++) {
    672.         iItem = get_pdata_cbase(iEnt, m_rgpPlayerItems_CWeaponBox + i, 4);
    673.         if(iItem > 0 && CustomItem(iItem)) {
    674.             engfunc(EngFunc_SetModel, iEnt, WEAPON_MODEL_W);
    675.             set_pev(iEnt, pev_body, WEAPON_BODY);
    676.             new iPlayer = pev(iEnt, pev_owner);
    677.             g_bHasStunRifle[iPlayer] = false;
    678.             remove_task(iPlayer)
    679.             return FMRES_SUPERCEDE;
    680.         }
    681.     }
    682.     return FMRES_IGNORED;
    683. }
    684.  
    685. public fw_TraceLine_Post(const Float:flOrigin1[3], const Float:flOrigin2[3], iFrag, iIgnore, tr)
    686. {
    687.     if(iFrag & IGNORE_MONSTERS) return FMRES_IGNORED;
    688.     static pHit; pHit = get_tr2(tr, TR_pHit);
    689.     static Float:flvecEndPos[3]; get_tr2(tr, TR_vecEndPos, flvecEndPos);
    690.     if(pHit > 0) {
    691.         if(pev(pHit, pev_solid) != SOLID_BSP) return FMRES_IGNORED;
    692.     }
    693.     engfunc(EngFunc_MessageBegin, MSG_PAS, SVC_TEMPENTITY, flvecEndPos, 0);
    694.     write_byte(TE_GUNSHOTDECAL);
    695.     engfunc(EngFunc_WriteCoord, flvecEndPos[0]);
    696.     engfunc(EngFunc_WriteCoord, flvecEndPos[1]);
    697.     engfunc(EngFunc_WriteCoord, flvecEndPos[2]);
    698.     write_short(pHit > 0 ? pHit : 0);
    699.     write_byte(random_num(41, 45));
    700.     message_end();
    701.  
    702.     return FMRES_IGNORED;
    703. }
    704.  
    705. public fm_ham_hook(bool:on) {
    706.     if(on) {
    707.         EnableHamForward(g_fw_TraceAttack[0]);
    708.         EnableHamForward(g_fw_TraceAttack[1]);
    709.         EnableHamForward(g_fw_TraceAttack[2]);
    710.         EnableHamForward(g_fw_TraceAttack[3]);
    711.     }
    712.     else {
    713.         DisableHamForward(g_fw_TraceAttack[0]);
    714.         DisableHamForward(g_fw_TraceAttack[1]);
    715.         DisableHamForward(g_fw_TraceAttack[2]);
    716.         DisableHamForward(g_fw_TraceAttack[3]);
    717.     }
    718. }
    719.  
    720. stock UTIL_SendWeaponAnim(iPlayer, iAnim)
    721. {
    722.     set_pev(iPlayer, pev_weaponanim, iAnim);
    723.  
    724.     message_begin(MSG_ONE, SVC_WEAPONANIM, _, iPlayer);
    725.     write_byte(iAnim);
    726.     write_byte(0);
    727.     message_end();
    728. }
    729.  
    730. stock UTIL_DropWeapon(iPlayer, iSlot) {
    731.     static iEntity, iNext, szWeaponName[32];
    732.     iEntity = get_pdata_cbase(iPlayer, m_rpgPlayerItems + iSlot, 5);
    733.     if(iEntity > 0) {      
    734.         do {
    735.             iNext = get_pdata_cbase(iEntity, m_pNext, 4)
    736.             if(get_weaponname(get_pdata_int(iEntity, m_iId, 4), szWeaponName, 31)) {  
    737.                 engclient_cmd(iPlayer, "drop", szWeaponName);
    738.             }
    739.         } while(( iEntity = iNext) > 0);
    740.     }
    741. }
    742.  
    743. stock s_weaponlist(iPlayer, bool:on)
    744. {
    745.     message_begin(MSG_ONE, g_iMsgID_Weaponlist, {0,0,0}, iPlayer);
    746.     write_string(on ? WEAPON_NEW : WEAPON_OLD);
    747.     write_byte(iWeaponList[0]);
    748.     write_byte(on ? WEAPON_AMMO : iWeaponList[1]);
    749.     write_byte(iWeaponList[2]);
    750.     write_byte(iWeaponList[3]);
    751.     write_byte(iWeaponList[4]);
    752.     write_byte(iWeaponList[5]);
    753.     write_byte(iWeaponList[6]);
    754.     write_byte(iWeaponList[7]);
    755.     message_end();
    756. }
    757.  
    758. stock ElectricBeam(id, Float:flOrigin[3])
    759. {
    760.     message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
    761.     write_byte(TE_BEAMENTPOINT)
    762.     write_short(id | 0x1000)
    763.     engfunc(EngFunc_WriteCoord, flOrigin[0])
    764.     engfunc(EngFunc_WriteCoord, flOrigin[1])
    765.     engfunc(EngFunc_WriteCoord, flOrigin[2])
    766.     write_short(g_iLigSpr)
    767.     write_byte(1); // framestart
    768.     write_byte(100); // framerate - 5
    769.     write_byte(1) // life - 30
    770.     write_byte(30); // width
    771.     write_byte(random_num(0, 10)); // noise
    772.     write_byte(51); // r, g, b
    773.     write_byte(51); // r, g, b
    774.     write_byte(255); // r, g, b
    775.     write_byte(200); // brightness
    776.     write_byte(200); // speed
    777.     message_end()
    778.    
    779.     if (g_iAppearTimes[id] >= 2)
    780.         return
    781.    
    782.     message_begin(MSG_BROADCAST, SVC_TEMPENTITY);
    783.     write_byte(TE_EXPLOSION);
    784.     engfunc(EngFunc_WriteCoord, flOrigin[0]);
    785.     engfunc(EngFunc_WriteCoord, flOrigin[1]);
    786.     engfunc(EngFunc_WriteCoord, flOrigin[2]);
    787.     write_short(g_iEffSpr);
    788.     write_byte(10);
    789.     write_byte(10);
    790.     write_byte(TE_EXPLFLAG_NOSOUND|TE_EXPLFLAG_NOPARTICLES|TE_EXPLFLAG_NODLIGHTS);
    791.     message_end();
    792.    
    793.     g_iAppearTimes[id]++
    794. }
    795.  
    796. stock isEmpty(id)
    797. {
    798.     static Float:flOrigin[3]
    799.     pev(id, pev_origin, flOrigin)
    800.     new iVictim = -1;
    801.            
    802.     while ((iVictim = engfunc(EngFunc_FindEntityInSphere, iVictim, flOrigin, get_pcvar_float(g_pCvarRadius))) != 0)
    803.     {
    804.         if (!is_user_alive(iVictim) || !ze_is_user_zombie(iVictim))
    805.             continue
    806.        
    807.         return true;
    808.     }
    809.    
    810.     return false;
    811. }
    812.  
    813. public Make_Muzzleflash(id)
    814. {
    815.     static Float:Origin[3], TE_FLAG
    816.     get_position(id, 32.0, 6.0, -15.0, Origin)
    817.    
    818.     TE_FLAG |= TE_EXPLFLAG_NODLIGHTS
    819.     TE_FLAG |= TE_EXPLFLAG_NOSOUND
    820.     TE_FLAG |= TE_EXPLFLAG_NOPARTICLES
    821.    
    822.     engfunc(EngFunc_MessageBegin, MSG_ONE_UNRELIABLE, SVC_TEMPENTITY, Origin, id)
    823.     write_byte(TE_EXPLOSION)
    824.     engfunc(EngFunc_WriteCoord, Origin[0])
    825.     engfunc(EngFunc_WriteCoord, Origin[1])
    826.     engfunc(EngFunc_WriteCoord, Origin[2])
    827.     write_short(g_iEff2Spr)
    828.     write_byte(2)
    829.     write_byte(30)
    830.     write_byte(TE_FLAG)
    831.     message_end()
    832. }
    833.  
    834. stock get_position(id,Float:forw, Float:right, Float:up, Float:vStart[])
    835. {
    836.     static Float:vOrigin[3], Float:vAngle[3], Float:vForward[3], Float:vRight[3], Float:vUp[3]
    837.    
    838.     pev(id, pev_origin, vOrigin)
    839.     pev(id, pev_view_ofs, vUp) //for player
    840.     xs_vec_add(vOrigin, vUp, vOrigin)
    841.     pev(id, pev_v_angle, vAngle) // if normal entity ,use pev_angles
    842.    
    843.     angle_vector(vAngle,ANGLEVECTOR_FORWARD, vForward) //or use EngFunc_AngleVectors
    844.     angle_vector(vAngle,ANGLEVECTOR_RIGHT, vRight)
    845.     angle_vector(vAngle,ANGLEVECTOR_UP, vUp)
    846.    
    847.     vStart[0] = vOrigin[0] + vForward[0] * forw + vRight[0] * right + vUp[0] * up
    848.     vStart[1] = vOrigin[1] + vForward[1] * forw + vRight[1] * right + vUp[1] * up
    849.     vStart[2] = vOrigin[2] + vForward[2] * forw + vRight[2] * right + vUp[2] * up
    850. }
Please state what issue you found.
Here with your code i made a demo and got banned from server :D
The last part of the demo shows it best so watch the whole thing.......

Banned for move commands flooding (burst)
Completed demo
You can get it here as i can't upload demos on this site..

http://ugamers.site.nfoservers.com/FastDL/stundemo.dem

User avatar
Raheem
Mod Developer
Mod Developer
Egypt
Posts: 1720
Joined: 1 Year Ago
Location: Egypt
Has thanked: 28 times
Been thanked: 78 times
Age: 21
Contact:

#19

Post by Raheem » 3 Months Ago

OK, will check it. And i allowed .dem extension.

EDIT: I can't play this demo i'm missing resources:
    1. Warning! File sprites/weapon_zombj1_sisa.txt missing during demo playback.
    2. Warning! File sprites/640hud61.spr missing during demo playback.
    3. Warning! File sprites/640hud7x.spr missing during demo playback.
    4. Warning! File sprites/weapon_sfpistol.txt missing during demo playback.
    5. Warning! File sprites/640hud104_3.spr missing during demo playback.
    6. Warning! File sprites/weapon_tknifeex2.txt missing during demo playback.
    7. Warning! File sprites/weapon_dual_infinity2.txt missing during demo playback.
    8. Warning! File sprites/arwel/640hud42.spr missing during demo playback.
    9. Warning! File sprites/arwel/640hud43.spr missing during demo playback.
    10. Warning! File sprites/arwel/640hud7.spr missing during demo playback.
    11. Warning! File sprites/weapon_balrog11.txt missing during demo playback.
    12. Warning! File sprites/weapon_bow.txt missing during demo playback.
    13. Warning! File sprites/cso/scope_vip_grenade.spr missing during demo playback.
    14. Warning! File sprites/weapon_thanatos7.txt missing during demo playback.
    15. Warning! File sprites/640hud99_2.spr missing during demo playback.
    16. Error: could not load file sprites/fire_kurukafa.spr
    17. Model sprites/fire_kurukafa.spr not found and not available from server
    18. Cannot continue without model sprites/fire_kurukafa.spr, disconnecting.
Can you pack all resources in your server and upload it here?
You don't know? Learn and you will know.

User avatar
Mark
Senior Member
Senior Member
United States of America
Posts: 258
Joined: 4 Months Ago
Location: Des Moines/USA
Donation: 1x donated in total €10.00
Has thanked: 6 times
Been thanked: 19 times
Age: 33
Contact:

#20

Post by Mark » 3 Months Ago

doing it now


Here
Marks Resources.zip
(167.26 MiB) Downloaded 7 times
Marks Resources.zip
(167.26 MiB) Downloaded 7 times

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest