Plugin Available Vip extra Item Discounts

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

Vip extra Item Discounts

#1

Post by Mark » 2 Months Ago

Raheem,

As we talked about in chat lets see if we can do this with the vip system.

If player is vip he will get a discount on buying extra items.

This is for reference as the plugin that somewhat does this.
https://forums.alliedmods.net/showthrea ... ost2155009

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

#2

Post by Raheem » 2 Months Ago

The deduction of coins done in ze_items_escape_coins.sma so we will check in it:

  1. #include <zombie_escape>
  2. #include <ze_vip>
  3.  
  4. new g_iCurrentEC,
  5.     g_iRequiredEC
  6.  
  7. public plugin_init()
  8. {
  9.     register_plugin("[ZE] Items Manager: Escape Coins", ZE_VERSION, AUTHORS)
  10. }
  11.  
  12. public ze_select_item_pre(id, itemid, ignorecost)
  13. {
  14.     if (ignorecost)
  15.         return ZE_ITEM_AVAILABLE
  16.    
  17.     g_iCurrentEC = ze_get_escape_coins(id)
  18.    
  19.     if (ze_is_user_vip(id))
  20.     {
  21.         g_iRequiredEC = floatround(ze_get_item_cost(itemid) * 0.5) // 50 % discount
  22.     }
  23.     else
  24.     {
  25.         g_iRequiredEC = ze_get_item_cost(itemid)
  26.     }
  27.    
  28.     if (g_iCurrentEC < g_iRequiredEC)
  29.         return ZE_ITEM_UNAVAILABLE
  30.    
  31.     return ZE_ITEM_AVAILABLE
  32. }
  33.  
  34. public ze_select_item_post(id, itemid, ignorecost)
  35. {
  36.     if (ignorecost)
  37.         return
  38.    
  39.     g_iCurrentEC = ze_get_escape_coins(id)
  40.    
  41.     if (ze_is_user_vip(id))
  42.     {
  43.         g_iRequiredEC = floatround(ze_get_item_cost(itemid) * 0.5) // 50 % discount
  44.     }
  45.     else
  46.     {
  47.         g_iRequiredEC = ze_get_item_cost(itemid)
  48.     }
  49.    
  50.     ze_set_escape_coins(id, g_iCurrentEC - g_iRequiredEC)
  51. }

By this it will add 50% discount for all VIPS, so they will buy it with half price. Next thing we will need is to add extra-text maybe for VIPS? that say 50% discount?
Last edited by Raheem on 16 Sep 2018, 00:53, edited 1 time in total.
Reason: Convert to integer --> floatround()
You don't know? Learn and you will know.

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

#3

Post by Mark » 2 Months Ago

Raheem wrote:
2 Months Ago
The deduction of coins done in ze_items_escape_coins.sma so we will check in it:

  1. #include <zombie_escape>
  2. #include <ze_vip>
  3.  
  4. new g_iCurrentEC,
  5.     g_iRequiredEC
  6.  
  7. public plugin_init()
  8. {
  9.     register_plugin("[ZE] Items Manager: Escape Coins", ZE_VERSION, AUTHORS)
  10. }
  11.  
  12. public ze_select_item_pre(id, itemid, ignorecost)
  13. {
  14.     if (ignorecost)
  15.         return ZE_ITEM_AVAILABLE
  16.    
  17.     g_iCurrentEC = ze_get_escape_coins(id)
  18.    
  19.     if (ze_is_user_vip(id))
  20.     {
  21.         g_iRequiredEC = ze_get_item_cost(itemid) * 0.5 // 50 % discount
  22.     }
  23.     else
  24.     {
  25.         g_iRequiredEC = ze_get_item_cost(itemid)
  26.     }
  27.    
  28.     if (g_iCurrentEC < g_iRequiredEC)
  29.         return ZE_ITEM_UNAVAILABLE
  30.    
  31.     return ZE_ITEM_AVAILABLE
  32. }
  33.  
  34. public ze_select_item_post(id, itemid, ignorecost)
  35. {
  36.     if (ignorecost)
  37.         return
  38.    
  39.     g_iCurrentEC = ze_get_escape_coins(id)
  40.    
  41.     if (ze_is_user_vip(id))
  42.     {
  43.         g_iRequiredEC = ze_get_item_cost(itemid) * 0.5 // 50 % discount
  44.     }
  45.     else
  46.     {
  47.         g_iRequiredEC = ze_get_item_cost(itemid)
  48.     }
  49.    
  50.     ze_set_escape_coins(id, g_iCurrentEC - g_iRequiredEC)
  51. }

By this it will add 50% discount for all VIPS, so they will buy it with half price. Next thing we will need is to add extra-text maybe for VIPS? that say 50% discount?
Yea thats a good idea!

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

#4

Post by Mark » 2 Months Ago

Raheem wrote:
2 Months Ago
The deduction of coins done in ze_items_escape_coins.sma so we will check in it:

  1. #include <zombie_escape>
  2. #include <ze_vip>
  3.  
  4. new g_iCurrentEC,
  5.     g_iRequiredEC
  6.  
  7. public plugin_init()
  8. {
  9.     register_plugin("[ZE] Items Manager: Escape Coins", ZE_VERSION, AUTHORS)
  10. }
  11.  
  12. public ze_select_item_pre(id, itemid, ignorecost)
  13. {
  14.     if (ignorecost)
  15.         return ZE_ITEM_AVAILABLE
  16.    
  17.     g_iCurrentEC = ze_get_escape_coins(id)
  18.    
  19.     if (ze_is_user_vip(id))
  20.     {
  21.         g_iRequiredEC = ze_get_item_cost(itemid) * 0.5 // 50 % discount
  22.     }
  23.     else
  24.     {
  25.         g_iRequiredEC = ze_get_item_cost(itemid)
  26.     }
  27.    
  28.     if (g_iCurrentEC < g_iRequiredEC)
  29.         return ZE_ITEM_UNAVAILABLE
  30.    
  31.     return ZE_ITEM_AVAILABLE
  32. }
  33.  
  34. public ze_select_item_post(id, itemid, ignorecost)
  35. {
  36.     if (ignorecost)
  37.         return
  38.    
  39.     g_iCurrentEC = ze_get_escape_coins(id)
  40.    
  41.     if (ze_is_user_vip(id))
  42.     {
  43.         g_iRequiredEC = ze_get_item_cost(itemid) * 0.5 // 50 % discount
  44.     }
  45.     else
  46.     {
  47.         g_iRequiredEC = ze_get_item_cost(itemid)
  48.     }
  49.    
  50.     ze_set_escape_coins(id, g_iCurrentEC - g_iRequiredEC)
  51. }

By this it will add 50% discount for all VIPS, so they will buy it with half price. Next thing we will need is to add extra-text maybe for VIPS? that say 50% discount?
  1. //// ze_items_escape_coins.sma
  2. //
  3. // C:\Users\marcu\Desktop\Compiler v1.8.3\Compiler v1.8.3\scripting\ze_items_escape_coins.sma(21 -- 22) : warning 213: tag mismatch
  4. // C:\Users\marcu\Desktop\Compiler v1.8.3\Compiler v1.8.3\scripting\ze_items_escape_coins.sma(43 -- 44) : warning 213: tag mismatch
  5. // Header size:            780 bytes
  6. // Code size:             1696 bytes
  7. // Data size:              764 bytes
  8. // Stack/heap size:      16384 bytes
  9. // Total requirements:   19624 bytes
  10. //
  11. // 2 Warnings.
  12. // Done.

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

#5

Post by Raheem » 2 Months Ago

FIXED, updated the code. Try now.
You don't know? Learn and you will know.

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

#6

Post by Mark » 2 Months Ago

Raheem wrote:
2 Months Ago
FIXED, updated the code. Try now.
Yep works!

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

#7

Post by Mark » 2 Months Ago

For test

  1. #include <zombie_escape>
  2. #include <engine>
  3. #include <fakemeta_util>
  4. #include <cstrike>
  5. #include <fun>
  6. #include <xs>
  7.  
  8. #define PLUGIN "[CSO] Dual Uzi"
  9. #define VERSION "1.0"
  10. #define AUTHOR "Dias Pendragon"
  11.  
  12. // Data Config
  13. #define MODEL_V "models/v_dualuzi.mdl"
  14. #define MODEL_P "models/p_dualuzi.mdl"
  15. #define MODEL_W "models/w_dualuzi.mdl"
  16. #define MODEL_W_OLD "models/w_mp5.mdl"
  17.  
  18. #define CSW_BASE CSW_MP5NAVY
  19. #define weapon_base "weapon_mp5navy"
  20.  
  21. #define SUBMODEL -1 // can -1
  22. #define WEAPON_CODE 2102015
  23. #define WEAPON_EVENT "events/mp5n.sc"
  24. #define ANIM_EXT "dualpistols"
  25.  
  26. #define ANIME_SHOOT 3
  27. #define ANIME_RELOAD 15 // can -1
  28. #define ANIME_DRAW 16 // can -1
  29. #define ANIME_IDLE random_num(0, 1) // can -1
  30.  
  31. const PRIMARY_WEAPONS_BIT_SUM = (1<<CSW_AK47)|(1<<CSW_M4A1)|(1<<CSW_FAMAS)|(1<<CSW_GALIL)|(1<<CSW_SCOUT)|(1<<CSW_AWP)|(1<<CSW_M249)|(1<<CSW_MP5NAVY)|(1<<CSW_P90)|(1<<CSW_MAC10)|(1<<CSW_TMP)|(1<<CSW_XM1014)|(1<<CSW_M3)|(1<<CSW_G3SG1)|(1<<CSW_SG550)|(1<<CSW_SG552)|(1<<CSW_AUG)|(1<<CSW_UMP45);
  32.  
  33.  
  34. new const WeaponSounds[10][] =
  35. {
  36.     "weapons/dualuzi-1.wav",
  37.     "weapons/dualuzi_draw.wav",
  38.     "weapons/dualuzi_idle2_1.wav",
  39.     "weapons/dualuzi_idle2_2.wav",
  40.     "weapons/dualuzi_clipin1.wav",
  41.     "weapons/dualuzi_clipout1.wav",
  42.     "weapons/dualuzi_off_shoulder.wav",
  43.     "weapons/dualuzi_on_shoulder.wav",
  44.     "weapons/dualuzi_on_shoulder_reload1.wav",
  45.     "weapons/dualuzi_on_shoulder_reload2.wav"
  46. }
  47.  
  48. enum
  49. {
  50.     ANIME_IDLEX = 0,
  51.     ANIME_IDLE2,
  52.     ANIME_LEFT_EMPTY,
  53.     ANIME_SHOOT_L1,
  54.     ANIME_SHOOT_L2,
  55.     ANIME_SHOOT_L3,
  56.     ANIME_SHOOT_L4,
  57.     ANIME_SHOOT_L5,
  58.     ANIME_SHOOT_LLAST,
  59.     ANIME_SHOOT_R1,
  60.     ANIME_SHOOT_R2,
  61.     ANIME_SHOOT_R3,
  62.     ANIME_SHOOT_R4,
  63.     ANIME_SHOOT_R5,
  64.     ANIME_SHOOT_RLAST,
  65.     ANIME_RELOADX,
  66.     ANIME_DRAWX,
  67.     ANIME_CHANGE_TO_B,
  68.     ANIME_B_IDLE,
  69.     ANIME_B_SHOOT_L,
  70.     ANIME_B_SHOOT_LLAST,
  71.     ANIME_B_LEFT_EMPTY,
  72.     ANIME_B_SHOOT_R,
  73.     ANIME_B_SHOOT_RLAST,
  74.     ANIME_B_RELOAD,
  75.     ANIME_CHANGE_TO_A
  76. }
  77.  
  78. // Weapon Config
  79. #define DAMAGE 26 // 52 for Zombie
  80. #define ACCURACY 70 // 0 - 100 ; -1 Default
  81. #define CLIP 80
  82. #define BPAMMO 240
  83. #define SPEED 0.05
  84. #define RECOIL 0.5
  85. #define RELOAD_TIME 3.0
  86.  
  87. // MACROS
  88. #define Get_BitVar(%1,%2) (%1 & (1 << (%2 & 31)))
  89. #define Set_BitVar(%1,%2) %1 |= (1 << (%2 & 31))
  90. #define UnSet_BitVar(%1,%2) %1 &= ~(1 << (%2 & 31))
  91.  
  92. //new g_Base
  93. new g_Had_Base, g_Clip[33], g_OldWeapon[33], Float:g_Recoil[33][3]
  94. new g_Event_Base, g_SmokePuff_SprId, g_MsgCurWeapon, g_ShellId, g_iItemID
  95.  
  96. // Safety
  97. new g_HamBot
  98. new g_IsConnected, g_IsAlive, g_PlayerWeapon[33]
  99.  
  100. public plugin_init()
  101. {
  102.     register_plugin(PLUGIN, VERSION, AUTHOR)
  103.    
  104.     // Safety
  105.     Register_SafetyFunc()
  106.    
  107.     // Event
  108.     register_event("CurWeapon", "Event_CurWeapon", "be", "1=1")
  109.    
  110.     // Forward
  111.     register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)
  112.     register_forward(FM_PlaybackEvent, "fw_PlaybackEvent")
  113.     register_forward(FM_SetModel, "fw_SetModel")    
  114.     register_forward(FM_CmdStart, "fw_CmdStart")
  115.  
  116.     // Ham
  117.     RegisterHam(Ham_Item_Deploy, weapon_base, "fw_Item_Deploy_Post", 1)
  118.     RegisterHam(Ham_Item_AddToPlayer, weapon_base, "fw_Item_AddToPlayer_Post", 1)
  119.     RegisterHam(Ham_Weapon_WeaponIdle, weapon_base, "fw_Weapon_WeaponIdle_Post", 1)
  120.     RegisterHam(Ham_Item_PostFrame, weapon_base, "fw_Item_PostFrame")  
  121.     RegisterHam(Ham_Weapon_Reload, weapon_base, "fw_Weapon_Reload")
  122.     RegisterHam(Ham_Weapon_Reload, weapon_base, "fw_Weapon_Reload_Post", 1)
  123.     RegisterHam(Ham_Weapon_PrimaryAttack, weapon_base, "fw_Weapon_PrimaryAttack")
  124.     RegisterHam(Ham_Weapon_PrimaryAttack, weapon_base, "fw_Weapon_PrimaryAttack_Post", 1)
  125.    
  126.     RegisterHam(Ham_TraceAttack, "worldspawn", "fw_TraceAttack_World")
  127.     RegisterHam(Ham_TraceAttack, "player", "fw_TraceAttack_Player")
  128.    
  129.     // Cache
  130.     g_MsgCurWeapon = get_user_msgid("CurWeapon")
  131.    
  132.     // Get
  133.     g_iItemID = ze_register_item("Dual Uzi", 0, 0)
  134. }
  135.  
  136. public plugin_precache()
  137. {
  138.     precache_model(MODEL_V)
  139.     precache_model(MODEL_P)
  140.     precache_model(MODEL_W)
  141.    
  142.     for(new i = 0; i < sizeof(WeaponSounds); i++)
  143.         precache_sound(WeaponSounds[i])
  144.    
  145.     g_ShellId = engfunc(EngFunc_PrecacheModel, "models/pshell.mdl")
  146.     g_SmokePuff_SprId = engfunc(EngFunc_PrecacheModel, "sprites/wall_puff1.spr")
  147.     register_forward(FM_PrecacheEvent, "fw_PrecacheEvent_Post", 1)
  148. }
  149.  
  150. public fw_PrecacheEvent_Post(type, const name[])
  151. {
  152.     if(equal(WEAPON_EVENT, name)) g_Event_Base = get_orig_retval()      
  153. }
  154.  
  155. public client_putinserver(id)
  156. {
  157.     Safety_Connected(id)
  158.    
  159.     if(!g_HamBot && is_user_bot(id))
  160.     {
  161.         g_HamBot = 1
  162.         set_task(0.1, "Register_HamBot", id)
  163.     }
  164. }
  165.  
  166. public Register_HamBot(id)
  167. {
  168.     Register_SafetyFuncBot(id)
  169.     RegisterHamFromEntity(Ham_TraceAttack, id, "fw_TraceAttack_Player")
  170. }
  171.  
  172. public client_disconnected(id)
  173. {
  174.         Safety_Disconnected(id)
  175. }
  176. /*
  177. public Mileage_WeaponGet(id, ItemID)
  178. {
  179.     if(ItemID == g_Base) Get_Base(id)
  180. }
  181.  
  182. public Mileage_WeaponRefillAmmo(id, ItemID)
  183. {
  184.     if(ItemID == g_Base) cs_set_user_bpammo(id, CSW_BASE, BPAMMO)
  185. }
  186.  
  187. public Mileage_WeaponRemove(id, ItemID)
  188. {
  189.     if(ItemID == g_Base) Remove_Base(id)
  190. }*/
  191.  
  192. public ze_select_item_pre(id, itemid)
  193. {
  194.     if (itemid != g_iItemID)
  195.         return ZE_ITEM_AVAILABLE
  196.  
  197.     if (ze_is_user_zombie(id))
  198.         return ZE_ITEM_DONT_SHOW
  199.  
  200.     return ZE_ITEM_AVAILABLE
  201. }
  202.  
  203. public ze_select_item_post(id, itemid)
  204. {
  205.     if (itemid != g_iItemID)
  206.         return
  207.  
  208.     Get_Base(id)
  209. }
  210.  
  211. public ze_user_humanized(id)
  212. {
  213.     Remove_Base(id)
  214. }
  215.  
  216. public Get_Base(id)
  217. {
  218.     drop_weapons(id, 1);
  219.     Set_BitVar(g_Had_Base, id)
  220.     give_item(id, weapon_base)
  221.    
  222.     // Clip & Ammo
  223.     static Ent; Ent = fm_get_user_weapon_entity(id, CSW_BASE)
  224.     if(!pev_valid(Ent)) return
  225.    
  226.     cs_set_weapon_ammo(Ent, CLIP)
  227.     cs_set_user_bpammo(id, CSW_BASE, BPAMMO)
  228.    
  229.     message_begin(MSG_ONE_UNRELIABLE, g_MsgCurWeapon, _, id)
  230.     write_byte(1)
  231.     write_byte(CSW_BASE)
  232.     write_byte(CLIP)
  233.     message_end()
  234.    
  235.     cs_set_weapon_silen(Ent, 0, 0)
  236. }
  237.  
  238. public Remove_Base(id)
  239. {
  240.     UnSet_BitVar(g_Had_Base, id)
  241. }
  242.  
  243. public Event_CurWeapon(id)
  244. {
  245.     static CSWID; CSWID = read_data(2)
  246.     static SubModel; SubModel = SUBMODEL
  247.    
  248.     if((CSWID == CSW_BASE && g_OldWeapon[id] != CSW_BASE) && Get_BitVar(g_Had_Base, id))
  249.     {
  250.         if(SubModel != -1) Draw_NewWeapon(id, CSWID)
  251.     } else if((CSWID == CSW_BASE && g_OldWeapon[id] == CSW_BASE) && Get_BitVar(g_Had_Base, id)) {
  252.         static Ent; Ent = fm_get_user_weapon_entity(id, CSW_BASE)
  253.         if(!pev_valid(Ent))
  254.         {
  255.             g_OldWeapon[id] = get_user_weapon(id)
  256.             return
  257.         }
  258.        
  259.         set_pdata_float(Ent, 46, SPEED, 4)
  260.         set_pdata_float(Ent, 47, SPEED, 4)
  261.     } else if(CSWID != CSW_BASE && g_OldWeapon[id] == CSW_BASE) {
  262.         if(SubModel != -1) Draw_NewWeapon(id, CSWID)
  263.     }
  264.    
  265.     g_OldWeapon[id] = get_user_weapon(id)
  266. }
  267.  
  268. public Draw_NewWeapon(id, CSW_ID)
  269. {
  270.     if(CSW_ID == CSW_BASE)
  271.     {
  272.         static ent
  273.         ent = fm_get_user_weapon_entity(id, CSW_BASE)
  274.        
  275.         if(pev_valid(ent) && Get_BitVar(g_Had_Base, id))
  276.         {
  277.             set_pev(ent, pev_effects, pev(ent, pev_effects) &~ EF_NODRAW)
  278.             engfunc(EngFunc_SetModel, ent, MODEL_P)
  279.             set_pev(ent, pev_body, SUBMODEL)
  280.         }
  281.     } else {
  282.         static ent
  283.         ent = fm_get_user_weapon_entity(id, CSW_BASE)
  284.        
  285.         if(pev_valid(ent)) set_pev(ent, pev_effects, pev(ent, pev_effects) | EF_NODRAW)            
  286.     }
  287. }
  288.  
  289. public fw_UpdateClientData_Post(id, sendweapons, cd_handle)
  290. {
  291.     if(!is_alive(id))
  292.         return FMRES_IGNORED    
  293.     if(get_user_weapon(id) == CSW_BASE && Get_BitVar(g_Had_Base, id))
  294.         set_cd(cd_handle, CD_flNextAttack, get_gametime() + 0.001)
  295.    
  296.     return FMRES_HANDLED
  297. }
  298.  
  299. public fw_PlaybackEvent(flags, invoker, eventid, Float:delay, Float:origin[3], Float:angles[3], Float:fparam1, Float:fparam2, iParam1, iParam2, bParam1, bParam2)
  300. {
  301.     if (!is_connected(invoker))
  302.         return FMRES_IGNORED    
  303.     if(get_player_weapon(invoker) != CSW_BASE || !Get_BitVar(g_Had_Base, invoker))
  304.         return FMRES_IGNORED
  305.     if(eventid != g_Event_Base)
  306.         return FMRES_IGNORED
  307.    
  308.     engfunc(EngFunc_PlaybackEvent, flags | FEV_HOSTONLY, invoker, eventid, delay, origin, angles, fparam1, fparam2, iParam1, iParam2, bParam1, bParam2)
  309.     DualAttack(invoker)
  310.    
  311.     return FMRES_SUPERCEDE
  312. }
  313. public DualAttack(id)
  314. {
  315.     static iFlags, iAnimDesired, iWeaponState, iItem, szAnimation[64]
  316.    
  317.     #define WEAPONSTATE_ELITE_LEFT (1 << 3)
  318.    
  319.     iItem = fm_get_user_weapon_entity(id, CSW_BASE)
  320.     if(!pev_valid(iItem)) return
  321.    
  322.     iFlags = pev(id, pev_flags);
  323.     iWeaponState = get_pdata_int(iItem, 74, 4)
  324.    
  325.     if(iWeaponState & WEAPONSTATE_ELITE_LEFT)
  326.     {  
  327.         iWeaponState &= ~ WEAPONSTATE_ELITE_LEFT;
  328.    
  329.         Set_WeaponAnim(id, ANIME_SHOOT_L1)
  330.         Make_Shell(id, 1)
  331.        
  332.         formatex(szAnimation, charsmax(szAnimation), iFlags & FL_DUCKING ? "crouch_shoot_%s" : "ref_shoot_%s", ANIM_EXT);
  333.     } else {
  334.         iWeaponState |= WEAPONSTATE_ELITE_LEFT;
  335.        
  336.         Set_WeaponAnim(id, ANIME_SHOOT_R1)
  337.         Make_Shell(id, 0)
  338.        
  339.         formatex(szAnimation, charsmax(szAnimation), iFlags & FL_DUCKING ? "crouch_shoot2_%s" : "ref_shoot2_%s", ANIM_EXT);
  340.     }
  341.    
  342.     if((iAnimDesired = lookup_sequence(id, szAnimation)) == -1)
  343.         iAnimDesired = 0;
  344.    
  345.     set_pev(id, pev_sequence, iAnimDesired)
  346.     set_pdata_int(iItem, 74, iWeaponState, 4)
  347.    
  348.     emit_sound(id, CHAN_WEAPON, WeaponSounds[0], 1.0, 0.4, 0, 94 + random_num(0, 15))
  349. }
  350.  
  351. public Make_Shell(id, Right)
  352. {
  353.     static Float:player_origin[3], Float:origin[3], Float:origin2[3], Float:gunorigin[3], Float:oldangles[3], Float:v_forward[3], Float:v_forward2[3], Float:v_up[3], Float:v_up2[3], Float:v_right[3], Float:v_right2[3], Float:viewoffsets[3];
  354.    
  355.     pev(id, pev_v_angle, oldangles); pev(id,pev_origin,player_origin); pev(id, pev_view_ofs, viewoffsets);
  356.  
  357.     engfunc(EngFunc_MakeVectors, oldangles)
  358.    
  359.     global_get(glb_v_forward, v_forward); global_get(glb_v_up, v_up); global_get(glb_v_right, v_right);
  360.     global_get(glb_v_forward, v_forward2); global_get(glb_v_up, v_up2); global_get(glb_v_right, v_right2);
  361.    
  362.     xs_vec_add(player_origin, viewoffsets, gunorigin);
  363.    
  364.     if(!Right)
  365.     {
  366.         xs_vec_mul_scalar(v_forward, 10.3, v_forward); xs_vec_mul_scalar(v_right, 2.0, v_right);
  367.         xs_vec_mul_scalar(v_up, -2.7, v_up);
  368.         xs_vec_mul_scalar(v_forward2, 10.0, v_forward2); xs_vec_mul_scalar(v_right2, 4.0, v_right2);
  369.         xs_vec_mul_scalar(v_up2, -3.0, v_up2);
  370.     } else {
  371.         xs_vec_mul_scalar(v_forward, 10.3, v_forward); xs_vec_mul_scalar(v_right, -4.0, v_right);
  372.         xs_vec_mul_scalar(v_up, -3.7, v_up);
  373.         xs_vec_mul_scalar(v_forward2, 10.0, v_forward2); xs_vec_mul_scalar(v_right2, 2.0, v_right2);
  374.         xs_vec_mul_scalar(v_up2, -4.0, v_up2);
  375.     }
  376.    
  377.     xs_vec_add(gunorigin, v_forward, origin);
  378.     xs_vec_add(gunorigin, v_forward2, origin2);
  379.     xs_vec_add(origin, v_right, origin);
  380.     xs_vec_add(origin2, v_right2, origin2);
  381.     xs_vec_add(origin, v_up, origin);
  382.     xs_vec_add(origin2, v_up2, origin2);
  383.  
  384.     static Float:velocity[3]
  385.     get_speed_vector(origin2, origin, random_float(140.0, 160.0), velocity)
  386.  
  387.     static angle; angle = random_num(0, 360)
  388.  
  389.     message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  390.     write_byte(TE_MODEL)
  391.     engfunc(EngFunc_WriteCoord, origin[0])
  392.     engfunc(EngFunc_WriteCoord,origin[1])
  393.     engfunc(EngFunc_WriteCoord,origin[2])
  394.     engfunc(EngFunc_WriteCoord,velocity[0])
  395.     engfunc(EngFunc_WriteCoord,velocity[1])
  396.     engfunc(EngFunc_WriteCoord,velocity[2])
  397.     write_angle(angle)
  398.     write_short(g_ShellId)
  399.     write_byte(1)
  400.     write_byte(20)
  401.     message_end()
  402. }
  403.  
  404. public fw_SetModel(entity, model[])
  405. {
  406.     if(!pev_valid(entity))
  407.         return FMRES_IGNORED
  408.    
  409.     static Classname[32]
  410.     pev(entity, pev_classname, Classname, sizeof(Classname))
  411.    
  412.     if(!equal(Classname, "weaponbox"))
  413.         return FMRES_IGNORED
  414.    
  415.     static iOwner
  416.     iOwner = pev(entity, pev_owner)
  417.    
  418.     if(equal(model, MODEL_W_OLD))
  419.     {
  420.         static weapon; weapon = find_ent_by_owner(-1, weapon_base, entity)
  421.        
  422.         if(!pev_valid(weapon))
  423.             return FMRES_IGNORED;
  424.        
  425.         if(Get_BitVar(g_Had_Base, iOwner))
  426.         {
  427.             set_pev(weapon, pev_impulse, WEAPON_CODE)
  428.             engfunc(EngFunc_SetModel, entity, MODEL_W)
  429.             set_pev(entity, pev_body, SUBMODEL)
  430.        
  431.             Remove_Base(iOwner)
  432.            
  433.             return FMRES_SUPERCEDE
  434.         }
  435.     }
  436.  
  437.     return FMRES_IGNORED;
  438. }
  439.  
  440. public fw_CmdStart(id, uc_handle, seed)
  441. {
  442.     if (!is_alive(id))
  443.         return FMRES_IGNORED    
  444.     if(get_player_weapon(id) != CSW_BASE || !Get_BitVar(g_Had_Base, id))
  445.         return FMRES_IGNORED
  446.        
  447.     static Button; Button = get_uc(uc_handle, UC_Buttons)  
  448.    
  449.     if(Button & IN_ATTACK2)
  450.     {
  451.         static Float:Time; Time = get_pdata_float(id, 83, 5)
  452.         if(Time > 0.0) return FMRES_IGNORED
  453.        
  454.         if(cs_get_user_zoom(id) != CS_SET_AUGSG552_ZOOM) cs_set_user_zoom(id, CS_SET_AUGSG552_ZOOM, 1)
  455.         else cs_set_user_zoom(id, CS_RESET_ZOOM, 0)
  456.        
  457.         Time = 0.25
  458.         set_pdata_float(id, 83, Time, 5)
  459.     }
  460.    
  461.     return FMRES_IGNORED
  462. }
  463.  
  464. public fw_Item_Deploy_Post(Ent)
  465. {
  466.     if(pev_valid(Ent) != 2)
  467.         return
  468.     static Id; Id = get_pdata_cbase(Ent, 41, 4)
  469.     if(get_pdata_cbase(Id, 373) != Ent)
  470.         return
  471.     if(!Get_BitVar(g_Had_Base, Id))
  472.         return
  473.        
  474.     static SubModel; SubModel = SUBMODEL
  475.    
  476.     set_pev(Id, pev_viewmodel2, MODEL_V)
  477.     set_pev(Id, pev_weaponmodel2, SubModel != -1 ? "" : MODEL_P)
  478.    
  479.     static Draw; Draw = ANIME_DRAW
  480.     if(Draw != -1) Set_WeaponAnim(Id, ANIME_DRAW)
  481.    
  482.     set_pdata_string(Id, (492) * 4, ANIM_EXT, -1 , 20)
  483. }
  484.  
  485. public fw_Item_AddToPlayer_Post(Ent, id)
  486. {
  487.     if(!pev_valid(Ent))
  488.         return HAM_IGNORED
  489.        
  490.     if(pev(Ent, pev_impulse) == WEAPON_CODE)
  491.     {
  492.         Set_BitVar(g_Had_Base, id)
  493.         set_pev(Ent, pev_impulse, 0)
  494.     }
  495.    
  496.     return HAM_HANDLED  
  497. }
  498.  
  499. public fw_Item_PostFrame(ent)
  500. {
  501.     static id; id = pev(ent, pev_owner)
  502.     if(!is_user_alive(id))
  503.         return HAM_IGNORED
  504.     if(!Get_BitVar(g_Had_Base, id))
  505.         return HAM_IGNORED  
  506.    
  507.     static Float:flNextAttack; flNextAttack = get_pdata_float(id, 83, 5)
  508.     static bpammo; bpammo = cs_get_user_bpammo(id, CSW_BASE)
  509.    
  510.     static iClip; iClip = get_pdata_int(ent, 51, 4)
  511.     static fInReload; fInReload = get_pdata_int(ent, 54, 4)
  512.    
  513.     if(fInReload && flNextAttack <= 0.0)
  514.     {
  515.         static temp1
  516.         temp1 = min(CLIP - iClip, bpammo)
  517.  
  518.         set_pdata_int(ent, 51, iClip + temp1, 4)
  519.         cs_set_user_bpammo(id, CSW_BASE, bpammo - temp1)        
  520.        
  521.         set_pdata_int(ent, 54, 0, 4)
  522.        
  523.         fInReload = 0
  524.     }      
  525.    
  526.     return HAM_IGNORED
  527. }
  528.  
  529. public fw_Weapon_Reload(ent)
  530. {
  531.     static id; id = pev(ent, pev_owner)
  532.     if(!is_user_alive(id))
  533.         return HAM_IGNORED
  534.     if(!Get_BitVar(g_Had_Base, id))
  535.         return HAM_IGNORED  
  536.  
  537.     g_Clip[id] = -1
  538.        
  539.     static BPAmmo; BPAmmo = cs_get_user_bpammo(id, CSW_BASE)
  540.     static iClip; iClip = get_pdata_int(ent, 51, 4)
  541.        
  542.     if(BPAmmo <= 0)
  543.         return HAM_SUPERCEDE
  544.     if(iClip >= CLIP)
  545.         return HAM_SUPERCEDE        
  546.            
  547.     g_Clip[id] = iClip  
  548.    
  549.     return HAM_HANDLED
  550. }
  551.  
  552. public fw_Weapon_Reload_Post(ent)
  553. {
  554.     static id; id = pev(ent, pev_owner)
  555.     if(!is_user_alive(id))
  556.         return HAM_IGNORED
  557.     if(!Get_BitVar(g_Had_Base, id))
  558.         return HAM_IGNORED  
  559.    
  560.     if((get_pdata_int(ent, 54, 4) == 1))
  561.     { // Reload
  562.         if(g_Clip[id] == -1)
  563.             return HAM_IGNORED
  564.        
  565.         set_pdata_int(ent, 51, g_Clip[id], 4)
  566.        
  567.         static Reload; Reload = ANIME_RELOAD
  568.         if(Reload != -1) Set_WeaponAnim(id, ANIME_RELOAD)
  569.         Set_PlayerNextAttack(id, RELOAD_TIME)
  570.     }
  571.    
  572.     return HAM_HANDLED
  573. }
  574.  
  575. public fw_Weapon_WeaponIdle_Post( iEnt )
  576. {
  577.     if(pev_valid(iEnt) != 2)
  578.         return
  579.     static Id; Id = get_pdata_cbase(iEnt, 41, 4)
  580.     if(get_pdata_cbase(Id, 373) != iEnt)
  581.         return
  582.     if(!Get_BitVar(g_Had_Base, Id))
  583.         return
  584.        
  585.     static Idle; Idle = ANIME_IDLE
  586.    
  587.     if(Idle != -1 && get_pdata_float(iEnt, 48, 4) <= 0.25)
  588.     {
  589.         Set_WeaponAnim(Id, ANIME_IDLE)
  590.         set_pdata_float(iEnt, 48, 20.0, 4)
  591.     }  
  592. }
  593.  
  594. public fw_TraceAttack_World(Victim, Attacker, Float:Damage, Float:Direction[3], Ptr, DamageBits)
  595. {
  596.     if(!is_connected(Attacker))
  597.         return HAM_IGNORED  
  598.     if(get_player_weapon(Attacker) != CSW_BASE || !Get_BitVar(g_Had_Base, Attacker))
  599.         return HAM_IGNORED
  600.        
  601.     static Float:flEnd[3], Float:vecPlane[3]
  602.        
  603.     get_tr2(Ptr, TR_vecEndPos, flEnd)
  604.     get_tr2(Ptr, TR_vecPlaneNormal, vecPlane)      
  605.            
  606.     Make_BulletHole(Attacker, flEnd, Damage)
  607.     Make_BulletSmoke(Attacker, Ptr)
  608.  
  609.     SetHamParamFloat(3, float(DAMAGE))
  610.    
  611.     return HAM_HANDLED
  612. }
  613.  
  614. public fw_TraceAttack_Player(Victim, Attacker, Float:Damage, Float:Direction[3], Ptr, DamageBits)
  615. {
  616.     if(!is_connected(Attacker))
  617.         return HAM_IGNORED  
  618.     if(get_player_weapon(Attacker) != CSW_BASE || !Get_BitVar(g_Had_Base, Attacker))
  619.         return HAM_IGNORED
  620.  
  621.     static Float:flEnd[3]
  622.     get_tr2(Ptr, TR_vecEndPos, flEnd)  
  623.        
  624.     SetHamParamFloat(3, float(DAMAGE))
  625.    
  626.     return HAM_HANDLED
  627. }
  628.  
  629. public fw_Weapon_PrimaryAttack(Ent)
  630. {
  631.     static id; id = pev(Ent, pev_owner)
  632.     if(!is_alive(id))
  633.         return
  634.     if(!Get_BitVar(g_Had_Base, id))
  635.         return
  636.  
  637.     pev(id, pev_punchangle, g_Recoil[id])
  638. }
  639.  
  640. public fw_Weapon_PrimaryAttack_Post(Ent)
  641. {
  642.     static id; id = pev(Ent, pev_owner)
  643.     if(!is_alive(id))
  644.         return
  645.     if(!Get_BitVar(g_Had_Base, id))
  646.         return
  647.  
  648.     static Float:Push[3]
  649.     pev(id, pev_punchangle, Push)
  650.     xs_vec_sub(Push, g_Recoil[id], Push)
  651.    
  652.     xs_vec_mul_scalar(Push, RECOIL, Push)
  653.     xs_vec_add(Push, g_Recoil[id], Push)
  654.    
  655.     set_pev(id, pev_punchangle, Push)
  656.  
  657.     // Acc
  658.     static Accena; Accena = ACCURACY
  659.     if(Accena != -1)
  660.     {
  661.         static Float:Accuracy
  662.         Accuracy = (float(100 - ACCURACY) * 1.5) / 100.0
  663.  
  664.         set_pdata_float(Ent, 62, Accuracy, 4);
  665.     }
  666. }
  667.  
  668. /* ===============================
  669. ------------- SAFETY -------------
  670. =================================*/
  671. public Register_SafetyFunc()
  672. {
  673.     register_event("CurWeapon", "Safety_CurWeapon", "be", "1=1")
  674.    
  675.     RegisterHam(Ham_Spawn, "player", "fw_Safety_Spawn_Post", 1)
  676.     RegisterHam(Ham_Killed, "player", "fw_Safety_Killed_Post", 1)
  677. }
  678.  
  679. public Register_SafetyFuncBot(id)
  680. {
  681.     RegisterHamFromEntity(Ham_Spawn, id, "fw_Safety_Spawn_Post", 1)
  682.     RegisterHamFromEntity(Ham_Killed, id, "fw_Safety_Killed_Post", 1)
  683. }
  684.  
  685. public Safety_Connected(id)
  686. {
  687.     Set_BitVar(g_IsConnected, id)
  688.     UnSet_BitVar(g_IsAlive, id)
  689.    
  690.     g_PlayerWeapon[id] = 0
  691. }
  692.  
  693. public Safety_Disconnected(id)
  694. {
  695.     UnSet_BitVar(g_IsConnected, id)
  696.     UnSet_BitVar(g_IsAlive, id)
  697.    
  698.     g_PlayerWeapon[id] = 0
  699. }
  700.  
  701. public Safety_CurWeapon(id)
  702. {
  703.     if(!is_alive(id))
  704.         return
  705.        
  706.     static CSW; CSW = read_data(2)
  707.     if(g_PlayerWeapon[id] != CSW) g_PlayerWeapon[id] = CSW
  708. }
  709.  
  710. public fw_Safety_Spawn_Post(id)
  711. {
  712.     if(!is_user_alive(id))
  713.         return
  714.        
  715.     Set_BitVar(g_IsAlive, id)
  716. }
  717.  
  718. public fw_Safety_Killed_Post(id)
  719. {
  720.     UnSet_BitVar(g_IsAlive, id)
  721. }
  722.  
  723. public is_connected(id)
  724. {
  725.     if(!(1 <= id <= 32))
  726.         return 0
  727.     if(!Get_BitVar(g_IsConnected, id))
  728.         return 0
  729.  
  730.     return 1
  731. }
  732.  
  733. public is_alive(id)
  734. {
  735.     if(!is_connected(id))
  736.         return 0
  737.     if(!Get_BitVar(g_IsAlive, id))
  738.         return 0
  739.        
  740.     return 1
  741. }
  742.  
  743. public get_player_weapon(id)
  744. {
  745.     if(!is_alive(id))
  746.         return 0
  747.    
  748.     return g_PlayerWeapon[id]
  749. }
  750.  
  751. /* ===============================
  752. --------- END OF SAFETY  ---------
  753. =================================*/
  754.  
  755. stock Set_WeaponAnim(id, anim)
  756. {
  757.     set_pev(id, pev_weaponanim, anim)
  758.    
  759.     message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, {0, 0, 0}, id)
  760.     write_byte(anim)
  761.     write_byte(pev(id, pev_body))
  762.     message_end()
  763. }
  764.  
  765. stock Make_BulletHole(id, Float:Origin[3], Float:Damage)
  766. {
  767.     // Find target
  768.     static Decal; Decal = random_num(41, 45)
  769.     static LoopTime;
  770.    
  771.     if(Damage > 100.0) LoopTime = 2
  772.     else LoopTime = 1
  773.    
  774.     for(new i = 0; i < LoopTime; i++)
  775.     {
  776.         // Put decal on "world" (a wall)
  777.         message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  778.         write_byte(TE_WORLDDECAL)
  779.         engfunc(EngFunc_WriteCoord, Origin[0])
  780.         engfunc(EngFunc_WriteCoord, Origin[1])
  781.         engfunc(EngFunc_WriteCoord, Origin[2])
  782.         write_byte(Decal)
  783.         message_end()
  784.        
  785.         // Show sparcles
  786.         message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  787.         write_byte(TE_GUNSHOTDECAL)
  788.         engfunc(EngFunc_WriteCoord, Origin[0])
  789.         engfunc(EngFunc_WriteCoord, Origin[1])
  790.         engfunc(EngFunc_WriteCoord, Origin[2])
  791.         write_short(id)
  792.         write_byte(Decal)
  793.         message_end()
  794.     }
  795. }
  796.  
  797. stock Make_BulletSmoke(id, TrResult)
  798. {
  799.     static Float:vecSrc[3], Float:vecEnd[3], TE_FLAG
  800.    
  801.     get_weapon_attachment(id, vecSrc)
  802.     global_get(glb_v_forward, vecEnd)
  803.    
  804.     xs_vec_mul_scalar(vecEnd, 8192.0, vecEnd)
  805.     xs_vec_add(vecSrc, vecEnd, vecEnd)
  806.  
  807.     get_tr2(TrResult, TR_vecEndPos, vecSrc)
  808.     get_tr2(TrResult, TR_vecPlaneNormal, vecEnd)
  809.    
  810.     xs_vec_mul_scalar(vecEnd, 2.5, vecEnd)
  811.     xs_vec_add(vecSrc, vecEnd, vecEnd)
  812.    
  813.     TE_FLAG |= TE_EXPLFLAG_NODLIGHTS
  814.     TE_FLAG |= TE_EXPLFLAG_NOSOUND
  815.     TE_FLAG |= TE_EXPLFLAG_NOPARTICLES
  816.    
  817.     engfunc(EngFunc_MessageBegin, MSG_PAS, SVC_TEMPENTITY, vecEnd, 0)
  818.     write_byte(TE_EXPLOSION)
  819.     engfunc(EngFunc_WriteCoord, vecEnd[0])
  820.     engfunc(EngFunc_WriteCoord, vecEnd[1])
  821.     engfunc(EngFunc_WriteCoord, vecEnd[2] - 10.0)
  822.     write_short(g_SmokePuff_SprId)
  823.     write_byte(2)
  824.     write_byte(50)
  825.     write_byte(TE_FLAG)
  826.     message_end()
  827. }
  828.  
  829. stock get_weapon_attachment(id, Float:output[3], Float:fDis = 40.0)
  830. {
  831.     static Float:vfEnd[3], viEnd[3]
  832.     get_user_origin(id, viEnd, 3)  
  833.     IVecFVec(viEnd, vfEnd)
  834.    
  835.     static Float:fOrigin[3], Float:fAngle[3]
  836.    
  837.     pev(id, pev_origin, fOrigin)
  838.     pev(id, pev_view_ofs, fAngle)
  839.    
  840.     xs_vec_add(fOrigin, fAngle, fOrigin)
  841.    
  842.     static Float:fAttack[3]
  843.    
  844.     xs_vec_sub(vfEnd, fOrigin, fAttack)
  845.     xs_vec_sub(vfEnd, fOrigin, fAttack)
  846.    
  847.     static Float:fRate
  848.    
  849.     fRate = fDis / vector_length(fAttack)
  850.     xs_vec_mul_scalar(fAttack, fRate, fAttack)
  851.    
  852.     xs_vec_add(fOrigin, fAttack, output)
  853. }
  854.  
  855. stock get_position(id,Float:forw, Float:right, Float:up, Float:vStart[])
  856. {
  857.     new Float:vOrigin[3], Float:vAngle[3], Float:vForward[3], Float:vRight[3], Float:vUp[3]
  858.    
  859.     pev(id, pev_origin, vOrigin)
  860.     pev(id, pev_view_ofs,vUp) //for player
  861.     xs_vec_add(vOrigin,vUp,vOrigin)
  862.     pev(id, pev_v_angle, vAngle) // if normal entity ,use pev_angles
  863.    
  864.     angle_vector(vAngle,ANGLEVECTOR_FORWARD,vForward) //or use EngFunc_AngleVectors
  865.     angle_vector(vAngle,ANGLEVECTOR_RIGHT,vRight)
  866.     angle_vector(vAngle,ANGLEVECTOR_UP,vUp)
  867.    
  868.     vStart[0] = vOrigin[0] + vForward[0] * forw + vRight[0] * right + vUp[0] * up
  869.     vStart[1] = vOrigin[1] + vForward[1] * forw + vRight[1] * right + vUp[1] * up
  870.     vStart[2] = vOrigin[2] + vForward[2] * forw + vRight[2] * right + vUp[2] * up
  871. }
  872.  
  873. stock get_speed_vector(const Float:origin1[3],const Float:origin2[3],Float:speed, Float:new_velocity[3])
  874. {
  875.     new_velocity[0] = origin2[0] - origin1[0]
  876.     new_velocity[1] = origin2[1] - origin1[1]
  877.     new_velocity[2] = origin2[2] - origin1[2]
  878.     new Float:num = floatsqroot(speed*speed / (new_velocity[0]*new_velocity[0] + new_velocity[1]*new_velocity[1] + new_velocity[2]*new_velocity[2]))
  879.     new_velocity[0] *= num
  880.     new_velocity[1] *= num
  881.     new_velocity[2] *= num
  882.    
  883.     return 1;
  884. }
  885.  
  886. stock Set_WeaponIdleTime(id, WeaponId ,Float:TimeIdle)
  887. {
  888.     static entwpn; entwpn = fm_get_user_weapon_entity(id, WeaponId)
  889.     if(!pev_valid(entwpn))
  890.         return
  891.        
  892.     set_pdata_float(entwpn, 46, TimeIdle, 4)
  893.     set_pdata_float(entwpn, 47, TimeIdle, 4)
  894.     set_pdata_float(entwpn, 48, TimeIdle + 0.5, 4)
  895. }
  896.  
  897. stock Set_PlayerNextAttack(id, Float:nexttime)
  898. {
  899.     set_pdata_float(id, 83, nexttime, 5)
  900. }
  901.  
  902. stock Get_Position(id,Float:forw, Float:right, Float:up, Float:vStart[])
  903. {
  904.     static Float:vOrigin[3], Float:vAngle[3], Float:vForward[3], Float:vRight[3], Float:vUp[3]
  905.    
  906.     pev(id, pev_origin, vOrigin)
  907.     pev(id, pev_view_ofs,vUp) //for player
  908.     xs_vec_add(vOrigin,vUp,vOrigin)
  909.     pev(id, pev_v_angle, vAngle) // if normal entity ,use pev_angles
  910.    
  911.     angle_vector(vAngle,ANGLEVECTOR_FORWARD,vForward) //or use EngFunc_AngleVectors
  912.     angle_vector(vAngle,ANGLEVECTOR_RIGHT,vRight)
  913.     angle_vector(vAngle,ANGLEVECTOR_UP,vUp)
  914.    
  915.     vStart[0] = vOrigin[0] + vForward[0] * forw + vRight[0] * right + vUp[0] * up
  916.     vStart[1] = vOrigin[1] + vForward[1] * forw + vRight[1] * right + vUp[1] * up
  917.     vStart[2] = vOrigin[2] + vForward[2] * forw + vRight[2] * right + vUp[2] * up
  918. }
  919.  
  920. stock drop_weapons(id, dropwhat)
  921. {
  922.     static weapons[32], num, i, weaponid
  923.     num = 0
  924.     get_user_weapons(id, weapons, num)
  925.    
  926.     for (i = 0; i < num; i++)
  927.     {
  928.         weaponid = weapons[i]
  929.        
  930.         if (dropwhat == 1 && ((1<<weaponid) & PRIMARY_WEAPONS_BIT_SUM))
  931.         {
  932.             static wname[32]
  933.             get_weaponname(weaponid, wname, sizeof wname - 1)
  934.            
  935.             engclient_cmd(id, "drop", wname)
  936.         }
  937.     }
  938.    
  939. }
  940. /* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
  941. *{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1042\\ f0\\ fs16 \n\\ par }
  942. */

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

#8

Post by Raheem » 2 Months Ago

OK TRY:

1. ze_items_manager.sma
    1. #include <zombie_escape>
    2.  
    3. // Setting File
    4. new const ZE_EXTRAITEM_FILE[] = "ze_extraitems.ini"
    5.  
    6. // Defines
    7. #define MENU_PAGE_ITEMS g_iMenuData[id]
    8.  
    9. // Const
    10. const OFFSET_CSMENUCODE = 205
    11.  
    12. // Forwards
    13. enum _:TOTAL_FORWARDS
    14. {
    15.     FW_ITEM_SELECT_PRE = 0,
    16.     FW_ITEM_SELECT_POST
    17. }
    18.  
    19. new g_iForwards[TOTAL_FORWARDS],
    20.     g_iForwardReturn
    21.  
    22. // Variables
    23. new Array:g_szItemRealName,
    24.     Array:g_szItemName,  
    25.     Array:g_iItemCost,
    26.     Array:g_iItemLimit
    27.  
    28. new g_iItemCount,
    29.     g_szAdditionalMenuText[32],
    30.     g_iMenuData[33],
    31.     bool:g_bHasDiscount[MAX_EXTRA_ITEMS],
    32.     Float:g_flDiscountValue[MAX_EXTRA_ITEMS]
    33.  
    34. public plugin_init()
    35. {
    36.     register_plugin("[ZE] Items Manager", ZE_VERSION, AUTHORS)
    37.    
    38.     // Commands
    39.     register_clcmd("say /items", "Cmd_Items")
    40.    
    41.     // Forwards (In Pre Return Values important)
    42.     g_iForwards[FW_ITEM_SELECT_PRE] = CreateMultiForward("ze_select_item_pre", ET_CONTINUE, FP_CELL, FP_CELL, FP_CELL)
    43.     g_iForwards[FW_ITEM_SELECT_POST] = CreateMultiForward("ze_select_item_post", ET_IGNORE, FP_CELL, FP_CELL, FP_CELL)
    44. }
    45.  
    46. public plugin_natives()
    47. {
    48.     register_native("ze_register_item", "native_ze_register_item")
    49.     register_native("ze_show_items_menu", "native_ze_show_items_menu")
    50.     register_native("ze_force_buy_item", "native_ze_force_buy_item")
    51.     register_native("ze_get_item_id", "native_ze_get_item_id")
    52.     register_native("ze_get_item_cost", "native_ze_get_item_cost")
    53.     register_native("ze_add_text_to_item", "native_ze_add_text_to_item")
    54.     register_native("ze_get_item_limit", "native_ze_get_item_limit")
    55.     register_native("ze_is_valid_itemid", "native_ze_is_valid_itemid")
    56.     register_native("ze_get_item_name", "native_ze_get_item_name")
    57.     register_native("ze_set_vip_discount", "native_ze_set_vip_discount", 1)
    58.     register_native("ze_has_vip_discount", "native_ze_has_vip_discount", 1)
    59.     register_native("ze_has_vip_discount", "native_ze_has_vip_discount", 1)
    60.     register_native("ze_get_item_discount", "native_ze_get_item_discount", 1)
    61.    
    62.     g_szItemRealName = ArrayCreate(32, 1)
    63.     g_szItemName = ArrayCreate(32, 1)
    64.     g_iItemCost = ArrayCreate(1, 1)
    65.     g_iItemLimit = ArrayCreate(1, 1)
    66. }
    67.  
    68. public client_disconnected(id)
    69. {
    70.     MENU_PAGE_ITEMS = 0
    71. }
    72.  
    73. public Cmd_Items(id)
    74. {
    75.     if (!is_user_alive(id))
    76.         return
    77.    
    78.     Show_Items_Menu(id)
    79. }
    80.  
    81. // Items Menu
    82. Show_Items_Menu(id)
    83. {
    84.     static menu[128], name[32], cost, transkey[64]
    85.     new menuid, index, itemdata[2]
    86.    
    87.     // Title
    88.     formatex(menu, charsmax(menu), "%L:\r", id, "BUY_EXTRAITEM")
    89.     menuid = menu_create(menu, "Extra_Items_Menu")
    90.    
    91.     // Item List
    92.     for (index = 0; index < g_iItemCount; index++)
    93.     {
    94.         // Additional text to display
    95.         g_szAdditionalMenuText[0] = 0
    96.        
    97.         // Execute item select attempt forward
    98.         ExecuteForward(g_iForwards[FW_ITEM_SELECT_PRE], g_iForwardReturn, id, index, 0)
    99.        
    100.         // Show item to player?
    101.         if (g_iForwardReturn >= ZE_ITEM_DONT_SHOW)
    102.             continue;
    103.        
    104.         // Add Item Name and Cost
    105.         ArrayGetString(g_szItemName, index, name, charsmax(name))
    106.         cost = ArrayGetCell(g_iItemCost, index)
    107.        
    108.         // ML support for item name
    109.         formatex(transkey, charsmax(transkey), "ITEMNAME %s", name)
    110.         if (GetLangTransKey(transkey) != TransKey_Bad) formatex(name, charsmax(name), "%L", id, transkey)
    111.        
    112.         // Item available to player?
    113.         if (g_iForwardReturn >= ZE_ITEM_UNAVAILABLE)
    114.             formatex(menu, charsmax(menu), "\d%s %d %s", name, cost, g_szAdditionalMenuText)
    115.         else
    116.             formatex(menu, charsmax(menu), "%s \y%d \w%s", name, cost, g_szAdditionalMenuText)
    117.        
    118.         itemdata[0] = index
    119.         itemdata[1] = 0
    120.         menu_additem(menuid, menu, itemdata)
    121.     }
    122.    
    123.     // No items to display?
    124.     if (menu_items(menuid) <= 0)
    125.     {
    126.         ze_colored_print(id, "%L", id, "NO_EXTRA_ITEMS")
    127.         menu_destroy(menuid)
    128.         return;
    129.     }
    130.    
    131.     // Back - Next - Exit
    132.     formatex(menu, charsmax(menu), "%L", id, "BACK")
    133.     menu_setprop(menuid, MPROP_BACKNAME, menu)
    134.     formatex(menu, charsmax(menu), "%L", id, "NEXT")
    135.     menu_setprop(menuid, MPROP_NEXTNAME, menu)
    136.     formatex(menu, charsmax(menu), "%L", id, "EXIT")
    137.     menu_setprop(menuid, MPROP_EXITNAME, menu)
    138.    
    139.     // If remembered page is greater than number of pages, clamp down the value
    140.     MENU_PAGE_ITEMS = min(MENU_PAGE_ITEMS, menu_pages(menuid)-1)
    141.    
    142.     // Fix for AMXX custom menus
    143.     set_pdata_int(id, OFFSET_CSMENUCODE, 0)
    144.     menu_display(id, menuid, MENU_PAGE_ITEMS)
    145. }
    146.  
    147. // Items Menu
    148. public Extra_Items_Menu(id, menuid, item)
    149. {
    150.     // Menu was closed
    151.     if (item == MENU_EXIT)
    152.     {
    153.         MENU_PAGE_ITEMS = 0
    154.         menu_destroy(menuid)
    155.         return PLUGIN_HANDLED;
    156.     }
    157.    
    158.     // Remember items menu page
    159.     MENU_PAGE_ITEMS = item / 7
    160.    
    161.     // Dead players are not allowed to buy items
    162.     if (!is_user_alive(id))
    163.     {
    164.         menu_destroy(menuid)
    165.         return PLUGIN_HANDLED;
    166.     }
    167.    
    168.     // Retrieve item id
    169.     new itemdata[2], dummy, itemid
    170.     menu_item_getinfo(menuid, item, dummy, itemdata, charsmax(itemdata), _, _, dummy)
    171.     itemid = itemdata[0]
    172.    
    173.     // Attempt to buy the item
    174.     Buy_Item(id, itemid)
    175.     menu_destroy(menuid)
    176.     return PLUGIN_HANDLED;
    177. }
    178.  
    179. // Buy Item
    180. Buy_Item(id, itemid, ignorecost = 0)
    181. {
    182.     // Execute item select attempt forward
    183.     ExecuteForward(g_iForwards[FW_ITEM_SELECT_PRE], g_iForwardReturn, id, itemid, ignorecost)
    184.    
    185.     // Item available to player?
    186.     if (g_iForwardReturn >= ZE_ITEM_UNAVAILABLE)
    187.         return;
    188.    
    189.     // Execute item selected forward
    190.     ExecuteForward(g_iForwards[FW_ITEM_SELECT_POST], g_iForwardReturn, id, itemid, ignorecost)
    191. }
    192.  
    193. // Natives
    194. public native_ze_register_item(plugin_id, num_params)
    195. {
    196.     new szItem_Name[32], iItem_Cost, iItem_Limit
    197.    
    198.     // Get the Data from first Parameter in the native (Item Name)
    199.     get_string(1, szItem_Name, charsmax(szItem_Name))
    200.    
    201.     // Get the Second Parameter (Item Cost)
    202.     iItem_Cost = get_param(2)
    203.    
    204.     // Get limit third parameter
    205.     iItem_Limit = get_param(3)
    206.    
    207.     if (strlen(szItem_Name) < 1)
    208.     {
    209.         // Can't leave item name empty
    210.         log_error(AMX_ERR_NATIVE, "[ZE] Can't register item with an empty name")
    211.         return ZE_WRONG_ITEM // Same as return -1
    212.     }
    213.    
    214.     new iIndex, szItemName[32]
    215.    
    216.     // Loop from 0 to max items amount
    217.     for (iIndex = 0; iIndex < g_iItemCount; iIndex++)
    218.     {
    219.         ArrayGetString(g_szItemRealName, iIndex, szItemName, charsmax(szItemName))
    220.        
    221.         if (equali(szItem_Name, szItemName))
    222.         {
    223.             log_error(AMX_ERR_NATIVE, "[ZE] Item already registered (%s)", szItemName)
    224.             return ZE_WRONG_ITEM; // Return -1
    225.         }
    226.     }
    227.    
    228.     // Load settings from extra items file
    229.     new szItemRealName[32]
    230.     copy(szItemRealName, charsmax(szItemRealName), szItem_Name)
    231.     ArrayPushString(g_szItemRealName, szItemRealName)
    232.    
    233.     // Name
    234.     if (!amx_load_setting_string(ZE_EXTRAITEM_FILE, szItemRealName, "NAME", szItem_Name, charsmax(szItem_Name)))
    235.         amx_save_setting_string(ZE_EXTRAITEM_FILE, szItemRealName, "NAME", szItem_Name)
    236.     ArrayPushString(g_szItemName, szItem_Name)
    237.    
    238.     // Cost
    239.     if (!amx_load_setting_int(ZE_EXTRAITEM_FILE, szItemRealName, "COST", iItem_Cost))
    240.         amx_save_setting_int(ZE_EXTRAITEM_FILE, szItemRealName, "COST", iItem_Cost)
    241.     ArrayPushCell(g_iItemCost, iItem_Cost)
    242.    
    243.     // Limit
    244.     if (!amx_load_setting_int(ZE_EXTRAITEM_FILE, szItemRealName, "LIMIT", iItem_Limit))
    245.         amx_save_setting_int(ZE_EXTRAITEM_FILE, szItemRealName, "LIMIT", iItem_Limit)
    246.     ArrayPushCell(g_iItemLimit, iItem_Limit)
    247.    
    248.     g_iItemCount++
    249.     return g_iItemCount - 1
    250. }
    251.  
    252. public native_ze_show_items_menu(plugin_id, num_params)
    253. {
    254.     new id = get_param(1)
    255.    
    256.     if (!is_user_connected(id))
    257.     {
    258.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player (%d)", id)
    259.         return false;
    260.     }
    261.    
    262.     Cmd_Items(id)
    263.     return true
    264. }
    265.  
    266. public native_ze_force_buy_item(plugin_id, num_params)
    267. {
    268.     new id = get_param(1)
    269.    
    270.     if (!is_user_connected(id))
    271.     {
    272.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player (%d)", id)
    273.         return false;
    274.     }
    275.    
    276.     new item_id = get_param(2)
    277.    
    278.     if (item_id < 0 || item_id >= g_iItemCount)
    279.     {
    280.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid item id (%d)", item_id)
    281.         return false;
    282.     }
    283.    
    284.     new ignorecost = get_param(3)
    285.    
    286.     Buy_Item(id, item_id, ignorecost)
    287.     return true;
    288. }
    289.  
    290. public native_ze_get_item_id(plugin_id, num_params)
    291. {
    292.     new szRealName[32]
    293.     get_string(1, szRealName, charsmax(szRealName))
    294.  
    295.     new index, szItemName[32]
    296.    
    297.     for (index = 0; index < g_iItemCount; index++)
    298.     {
    299.         ArrayGetString(g_szItemRealName, index, szItemName, charsmax(szItemName))
    300.        
    301.         if (equali(szRealName, szItemName))
    302.             return index
    303.     }
    304.    
    305.     return ZE_WRONG_ITEM
    306. }
    307.  
    308. public native_ze_get_item_cost(plugin_id, num_params)
    309. {
    310.     new item_id = get_param(1)
    311.    
    312.     if (item_id < 0 || item_id >= g_iItemCount)
    313.     {
    314.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid item id (%d)", item_id)
    315.         return ZE_WRONG_ITEM;
    316.     }
    317.    
    318.     return ArrayGetCell(g_iItemCost, item_id);
    319. }
    320.  
    321. public native_ze_add_text_to_item(plugin_id, num_params)
    322. {
    323.     new szText[32]
    324.     get_string(1, szText, charsmax(szText))
    325.     format(g_szAdditionalMenuText, charsmax(g_szAdditionalMenuText), "%s%s", g_szAdditionalMenuText, szText)
    326. }
    327.  
    328. public native_ze_get_item_limit(plugin_id, num_params)
    329. {
    330.     new item_id = get_param(1)
    331.    
    332.     if (item_id < 0 || item_id >= g_iItemCount)
    333.     {
    334.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid item id (%d)", item_id)
    335.         return ZE_WRONG_ITEM;
    336.     }
    337.    
    338.     return ArrayGetCell(g_iItemLimit, item_id);
    339. }
    340.  
    341. public native_ze_is_valid_itemid(plugin_id, num_params)
    342. {
    343.     new item_id = get_param(1)
    344.    
    345.     if (item_id < 0 || item_id >= g_iItemCount)
    346.     {
    347.         return false;
    348.     }
    349.    
    350.     return true;
    351. }
    352.  
    353. public native_ze_get_item_name(plugin_id, num_params)
    354. {
    355.     new item_id = get_param(1)
    356.    
    357.     if (item_id < 0 || item_id >= g_iItemCount)
    358.     {
    359.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid item id (%d)", item_id)
    360.         return ZE_WRONG_ITEM;
    361.     }
    362.    
    363.     new szName[32]
    364.     ArrayGetString(g_szItemName, item_id, szName, charsmax(szName))
    365.    
    366.     new iLen = get_param(3)
    367.     set_string(2, szName, iLen)
    368.     return true;
    369. }
    370.  
    371. public native_ze_set_vip_discount(iItemid, bool:bSet, Float:flDiscount)
    372. {
    373.     g_bHasDiscount[iItemid] = bSet;
    374.     g_flDiscountValue[iItemid] = flDiscount;
    375. }
    376.  
    377. public native_ze_has_vip_discount(iItemid)
    378. {
    379.     return g_bHasDiscount[iItemid]
    380. }
    381.  
    382. public Float:native_ze_get_item_discount(iItemid)
    383. {
    384.     return g_flDiscountValue[iItemid]
    385. }
2. ze_items_escape_coins.sma
    1. #include <zombie_escape>
    2. #include <ze_vip>
    3.  
    4. native ze_has_vip_discount(iItemid)
    5. native Float:ze_get_item_discount(iItemid)
    6.  
    7. new g_iCurrentEC,
    8.     g_iRequiredEC
    9.  
    10. public plugin_init()
    11. {
    12.     register_plugin("[ZE] Items Manager: Escape Coins", ZE_VERSION, AUTHORS)
    13. }
    14.  
    15. public ze_select_item_pre(id, itemid, ignorecost)
    16. {
    17.     if (ignorecost)
    18.         return ZE_ITEM_AVAILABLE
    19.    
    20.     g_iCurrentEC = ze_get_escape_coins(id)
    21.    
    22.     if (ze_is_user_vip(id) && ze_has_vip_discount(itemid))
    23.     {
    24.         g_iRequiredEC = floatround(ze_get_item_cost(itemid) * ze_get_item_discount(itemid)) // 50 % discount
    25.     }
    26.     else
    27.     {
    28.         g_iRequiredEC = ze_get_item_cost(itemid)
    29.     }
    30.    
    31.     if (g_iCurrentEC < g_iRequiredEC)
    32.         return ZE_ITEM_UNAVAILABLE
    33.    
    34.     return ZE_ITEM_AVAILABLE
    35. }
    36.  
    37. public ze_select_item_post(id, itemid, ignorecost)
    38. {
    39.     if (ignorecost)
    40.         return
    41.    
    42.     g_iCurrentEC = ze_get_escape_coins(id)
    43.    
    44.     if (ze_is_user_vip(id) && ze_has_vip_discount(itemid))
    45.     {
    46.         g_iRequiredEC = floatround(ze_get_item_cost(itemid) * ze_get_item_discount(itemid)) // 50 % discount
    47.     }
    48.     else
    49.     {
    50.         g_iRequiredEC = ze_get_item_cost(itemid)
    51.     }
    52.    
    53.     ze_set_escape_coins(id, g_iCurrentEC - g_iRequiredEC)
    54. }
3. Item:
    1. #include <zombie_escape>
    2. #include <engine>
    3. #include <fakemeta_util>
    4. #include <cstrike>
    5. #include <fun>
    6. #include <xs>
    7.  
    8. native ze_set_vip_discount(iItemid, bool:bSet, Float:flDiscount);
    9.  
    10. #define PLUGIN "[CSO] Dual Uzi"
    11. #define VERSION "1.0"
    12. #define AUTHOR "Dias Pendragon"
    13.  
    14. // Data Config
    15. #define MODEL_V "models/v_dualuzi.mdl"
    16. #define MODEL_P "models/p_dualuzi.mdl"
    17. #define MODEL_W "models/w_dualuzi.mdl"
    18. #define MODEL_W_OLD "models/w_mp5.mdl"
    19.  
    20. #define CSW_BASE CSW_MP5NAVY
    21. #define weapon_base "weapon_mp5navy"
    22.  
    23. #define SUBMODEL -1 // can -1
    24. #define WEAPON_CODE 2102015
    25. #define WEAPON_EVENT "events/mp5n.sc"
    26. #define ANIM_EXT "dualpistols"
    27.  
    28. #define ANIME_SHOOT 3
    29. #define ANIME_RELOAD 15 // can -1
    30. #define ANIME_DRAW 16 // can -1
    31. #define ANIME_IDLE random_num(0, 1) // can -1
    32.  
    33. const PRIMARY_WEAPONS_BIT_SUM = (1<<CSW_AK47)|(1<<CSW_M4A1)|(1<<CSW_FAMAS)|(1<<CSW_GALIL)|(1<<CSW_SCOUT)|(1<<CSW_AWP)|(1<<CSW_M249)|(1<<CSW_MP5NAVY)|(1<<CSW_P90)|(1<<CSW_MAC10)|(1<<CSW_TMP)|(1<<CSW_XM1014)|(1<<CSW_M3)|(1<<CSW_G3SG1)|(1<<CSW_SG550)|(1<<CSW_SG552)|(1<<CSW_AUG)|(1<<CSW_UMP45);
    34.  
    35.  
    36. new const WeaponSounds[10][] =
    37. {
    38.     "weapons/dualuzi-1.wav",
    39.     "weapons/dualuzi_draw.wav",
    40.     "weapons/dualuzi_idle2_1.wav",
    41.     "weapons/dualuzi_idle2_2.wav",
    42.     "weapons/dualuzi_clipin1.wav",
    43.     "weapons/dualuzi_clipout1.wav",
    44.     "weapons/dualuzi_off_shoulder.wav",
    45.     "weapons/dualuzi_on_shoulder.wav",
    46.     "weapons/dualuzi_on_shoulder_reload1.wav",
    47.     "weapons/dualuzi_on_shoulder_reload2.wav"
    48. }
    49.  
    50. enum
    51. {
    52.     ANIME_IDLEX = 0,
    53.     ANIME_IDLE2,
    54.     ANIME_LEFT_EMPTY,
    55.     ANIME_SHOOT_L1,
    56.     ANIME_SHOOT_L2,
    57.     ANIME_SHOOT_L3,
    58.     ANIME_SHOOT_L4,
    59.     ANIME_SHOOT_L5,
    60.     ANIME_SHOOT_LLAST,
    61.     ANIME_SHOOT_R1,
    62.     ANIME_SHOOT_R2,
    63.     ANIME_SHOOT_R3,
    64.     ANIME_SHOOT_R4,
    65.     ANIME_SHOOT_R5,
    66.     ANIME_SHOOT_RLAST,
    67.     ANIME_RELOADX,
    68.     ANIME_DRAWX,
    69.     ANIME_CHANGE_TO_B,
    70.     ANIME_B_IDLE,
    71.     ANIME_B_SHOOT_L,
    72.     ANIME_B_SHOOT_LLAST,
    73.     ANIME_B_LEFT_EMPTY,
    74.     ANIME_B_SHOOT_R,
    75.     ANIME_B_SHOOT_RLAST,
    76.     ANIME_B_RELOAD,
    77.     ANIME_CHANGE_TO_A
    78. }
    79.  
    80. // Weapon Config
    81. #define DAMAGE 26 // 52 for Zombie
    82. #define ACCURACY 70 // 0 - 100 ; -1 Default
    83. #define CLIP 80
    84. #define BPAMMO 240
    85. #define SPEED 0.05
    86. #define RECOIL 0.5
    87. #define RELOAD_TIME 3.0
    88.  
    89. // MACROS
    90. #define Get_BitVar(%1,%2) (%1 & (1 << (%2 & 31)))
    91. #define Set_BitVar(%1,%2) %1 |= (1 << (%2 & 31))
    92. #define UnSet_BitVar(%1,%2) %1 &= ~(1 << (%2 & 31))
    93.  
    94. //new g_Base
    95. new g_Had_Base, g_Clip[33], g_OldWeapon[33], Float:g_Recoil[33][3]
    96. new g_Event_Base, g_SmokePuff_SprId, g_MsgCurWeapon, g_ShellId, g_iItemID
    97.  
    98. // Safety
    99. new g_HamBot
    100. new g_IsConnected, g_IsAlive, g_PlayerWeapon[33]
    101.  
    102. public plugin_init()
    103. {
    104.     register_plugin(PLUGIN, VERSION, AUTHOR)
    105.    
    106.     // Safety
    107.     Register_SafetyFunc()
    108.    
    109.     // Event
    110.     register_event("CurWeapon", "Event_CurWeapon", "be", "1=1")
    111.    
    112.     // Forward
    113.     register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)
    114.     register_forward(FM_PlaybackEvent, "fw_PlaybackEvent")
    115.     register_forward(FM_SetModel, "fw_SetModel")    
    116.     register_forward(FM_CmdStart, "fw_CmdStart")
    117.  
    118.     // Ham
    119.     RegisterHam(Ham_Item_Deploy, weapon_base, "fw_Item_Deploy_Post", 1)
    120.     RegisterHam(Ham_Item_AddToPlayer, weapon_base, "fw_Item_AddToPlayer_Post", 1)
    121.     RegisterHam(Ham_Weapon_WeaponIdle, weapon_base, "fw_Weapon_WeaponIdle_Post", 1)
    122.     RegisterHam(Ham_Item_PostFrame, weapon_base, "fw_Item_PostFrame")  
    123.     RegisterHam(Ham_Weapon_Reload, weapon_base, "fw_Weapon_Reload")
    124.     RegisterHam(Ham_Weapon_Reload, weapon_base, "fw_Weapon_Reload_Post", 1)
    125.     RegisterHam(Ham_Weapon_PrimaryAttack, weapon_base, "fw_Weapon_PrimaryAttack")
    126.     RegisterHam(Ham_Weapon_PrimaryAttack, weapon_base, "fw_Weapon_PrimaryAttack_Post", 1)
    127.    
    128.     RegisterHam(Ham_TraceAttack, "worldspawn", "fw_TraceAttack_World")
    129.     RegisterHam(Ham_TraceAttack, "player", "fw_TraceAttack_Player")
    130.    
    131.     // Cache
    132.     g_MsgCurWeapon = get_user_msgid("CurWeapon")
    133.    
    134.     // Get
    135.     g_iItemID = ze_register_item("Dual Uzi", 0, 0)
    136.     ze_set_vip_discount(g_iItemID, true, 0.5)
    137. }
    138.  
    139. public plugin_precache()
    140. {
    141.     precache_model(MODEL_V)
    142.     precache_model(MODEL_P)
    143.     precache_model(MODEL_W)
    144.    
    145.     for(new i = 0; i < sizeof(WeaponSounds); i++)
    146.         precache_sound(WeaponSounds[i])
    147.    
    148.     g_ShellId = engfunc(EngFunc_PrecacheModel, "models/pshell.mdl")
    149.     g_SmokePuff_SprId = engfunc(EngFunc_PrecacheModel, "sprites/wall_puff1.spr")
    150.     register_forward(FM_PrecacheEvent, "fw_PrecacheEvent_Post", 1)
    151. }
    152.  
    153. public fw_PrecacheEvent_Post(type, const name[])
    154. {
    155.     if(equal(WEAPON_EVENT, name)) g_Event_Base = get_orig_retval()      
    156. }
    157.  
    158. public client_putinserver(id)
    159. {
    160.     Safety_Connected(id)
    161.    
    162.     if(!g_HamBot && is_user_bot(id))
    163.     {
    164.         g_HamBot = 1
    165.         set_task(0.1, "Register_HamBot", id)
    166.     }
    167. }
    168.  
    169. public Register_HamBot(id)
    170. {
    171.     Register_SafetyFuncBot(id)
    172.     RegisterHamFromEntity(Ham_TraceAttack, id, "fw_TraceAttack_Player")
    173. }
    174.  
    175. public client_disconnected(id)
    176. {
    177.         Safety_Disconnected(id)
    178. }
    179. /*
    180. public Mileage_WeaponGet(id, ItemID)
    181. {
    182.     if(ItemID == g_Base) Get_Base(id)
    183. }
    184.  
    185. public Mileage_WeaponRefillAmmo(id, ItemID)
    186. {
    187.     if(ItemID == g_Base) cs_set_user_bpammo(id, CSW_BASE, BPAMMO)
    188. }
    189.  
    190. public Mileage_WeaponRemove(id, ItemID)
    191. {
    192.     if(ItemID == g_Base) Remove_Base(id)
    193. }*/
    194.  
    195. public ze_select_item_pre(id, itemid)
    196. {
    197.     if (itemid != g_iItemID)
    198.         return ZE_ITEM_AVAILABLE
    199.  
    200.     if (ze_is_user_zombie(id))
    201.         return ZE_ITEM_DONT_SHOW
    202.  
    203.     return ZE_ITEM_AVAILABLE
    204. }
    205.  
    206. public ze_select_item_post(id, itemid)
    207. {
    208.     if (itemid != g_iItemID)
    209.         return
    210.  
    211.     Get_Base(id)
    212. }
    213.  
    214. public ze_user_humanized(id)
    215. {
    216.     Remove_Base(id)
    217. }
    218.  
    219. public Get_Base(id)
    220. {
    221.     drop_weapons(id, 1);
    222.     Set_BitVar(g_Had_Base, id)
    223.     give_item(id, weapon_base)
    224.    
    225.     // Clip & Ammo
    226.     static Ent; Ent = fm_get_user_weapon_entity(id, CSW_BASE)
    227.     if(!pev_valid(Ent)) return
    228.    
    229.     cs_set_weapon_ammo(Ent, CLIP)
    230.     cs_set_user_bpammo(id, CSW_BASE, BPAMMO)
    231.    
    232.     message_begin(MSG_ONE_UNRELIABLE, g_MsgCurWeapon, _, id)
    233.     write_byte(1)
    234.     write_byte(CSW_BASE)
    235.     write_byte(CLIP)
    236.     message_end()
    237.    
    238.     cs_set_weapon_silen(Ent, 0, 0)
    239. }
    240.  
    241. public Remove_Base(id)
    242. {
    243.     UnSet_BitVar(g_Had_Base, id)
    244. }
    245.  
    246. public Event_CurWeapon(id)
    247. {
    248.     static CSWID; CSWID = read_data(2)
    249.     static SubModel; SubModel = SUBMODEL
    250.    
    251.     if((CSWID == CSW_BASE && g_OldWeapon[id] != CSW_BASE) && Get_BitVar(g_Had_Base, id))
    252.     {
    253.         if(SubModel != -1) Draw_NewWeapon(id, CSWID)
    254.     } else if((CSWID == CSW_BASE && g_OldWeapon[id] == CSW_BASE) && Get_BitVar(g_Had_Base, id)) {
    255.         static Ent; Ent = fm_get_user_weapon_entity(id, CSW_BASE)
    256.         if(!pev_valid(Ent))
    257.         {
    258.             g_OldWeapon[id] = get_user_weapon(id)
    259.             return
    260.         }
    261.        
    262.         set_pdata_float(Ent, 46, SPEED, 4)
    263.         set_pdata_float(Ent, 47, SPEED, 4)
    264.     } else if(CSWID != CSW_BASE && g_OldWeapon[id] == CSW_BASE) {
    265.         if(SubModel != -1) Draw_NewWeapon(id, CSWID)
    266.     }
    267.    
    268.     g_OldWeapon[id] = get_user_weapon(id)
    269. }
    270.  
    271. public Draw_NewWeapon(id, CSW_ID)
    272. {
    273.     if(CSW_ID == CSW_BASE)
    274.     {
    275.         static ent
    276.         ent = fm_get_user_weapon_entity(id, CSW_BASE)
    277.        
    278.         if(pev_valid(ent) && Get_BitVar(g_Had_Base, id))
    279.         {
    280.             set_pev(ent, pev_effects, pev(ent, pev_effects) &~ EF_NODRAW)
    281.             engfunc(EngFunc_SetModel, ent, MODEL_P)
    282.             set_pev(ent, pev_body, SUBMODEL)
    283.         }
    284.     } else {
    285.         static ent
    286.         ent = fm_get_user_weapon_entity(id, CSW_BASE)
    287.        
    288.         if(pev_valid(ent)) set_pev(ent, pev_effects, pev(ent, pev_effects) | EF_NODRAW)            
    289.     }
    290. }
    291.  
    292. public fw_UpdateClientData_Post(id, sendweapons, cd_handle)
    293. {
    294.     if(!is_alive(id))
    295.         return FMRES_IGNORED    
    296.     if(get_user_weapon(id) == CSW_BASE && Get_BitVar(g_Had_Base, id))
    297.         set_cd(cd_handle, CD_flNextAttack, get_gametime() + 0.001)
    298.    
    299.     return FMRES_HANDLED
    300. }
    301.  
    302. public fw_PlaybackEvent(flags, invoker, eventid, Float:delay, Float:origin[3], Float:angles[3], Float:fparam1, Float:fparam2, iParam1, iParam2, bParam1, bParam2)
    303. {
    304.     if (!is_connected(invoker))
    305.         return FMRES_IGNORED    
    306.     if(get_player_weapon(invoker) != CSW_BASE || !Get_BitVar(g_Had_Base, invoker))
    307.         return FMRES_IGNORED
    308.     if(eventid != g_Event_Base)
    309.         return FMRES_IGNORED
    310.    
    311.     engfunc(EngFunc_PlaybackEvent, flags | FEV_HOSTONLY, invoker, eventid, delay, origin, angles, fparam1, fparam2, iParam1, iParam2, bParam1, bParam2)
    312.     DualAttack(invoker)
    313.    
    314.     return FMRES_SUPERCEDE
    315. }
    316. public DualAttack(id)
    317. {
    318.     static iFlags, iAnimDesired, iWeaponState, iItem, szAnimation[64]
    319.    
    320.     #define WEAPONSTATE_ELITE_LEFT (1 << 3)
    321.    
    322.     iItem = fm_get_user_weapon_entity(id, CSW_BASE)
    323.     if(!pev_valid(iItem)) return
    324.    
    325.     iFlags = pev(id, pev_flags);
    326.     iWeaponState = get_pdata_int(iItem, 74, 4)
    327.    
    328.     if(iWeaponState & WEAPONSTATE_ELITE_LEFT)
    329.     {  
    330.         iWeaponState &= ~ WEAPONSTATE_ELITE_LEFT;
    331.    
    332.         Set_WeaponAnim(id, ANIME_SHOOT_L1)
    333.         Make_Shell(id, 1)
    334.        
    335.         formatex(szAnimation, charsmax(szAnimation), iFlags & FL_DUCKING ? "crouch_shoot_%s" : "ref_shoot_%s", ANIM_EXT);
    336.     } else {
    337.         iWeaponState |= WEAPONSTATE_ELITE_LEFT;
    338.        
    339.         Set_WeaponAnim(id, ANIME_SHOOT_R1)
    340.         Make_Shell(id, 0)
    341.        
    342.         formatex(szAnimation, charsmax(szAnimation), iFlags & FL_DUCKING ? "crouch_shoot2_%s" : "ref_shoot2_%s", ANIM_EXT);
    343.     }
    344.    
    345.     if((iAnimDesired = lookup_sequence(id, szAnimation)) == -1)
    346.         iAnimDesired = 0;
    347.    
    348.     set_pev(id, pev_sequence, iAnimDesired)
    349.     set_pdata_int(iItem, 74, iWeaponState, 4)
    350.    
    351.     emit_sound(id, CHAN_WEAPON, WeaponSounds[0], 1.0, 0.4, 0, 94 + random_num(0, 15))
    352. }
    353.  
    354. public Make_Shell(id, Right)
    355. {
    356.     static Float:player_origin[3], Float:origin[3], Float:origin2[3], Float:gunorigin[3], Float:oldangles[3], Float:v_forward[3], Float:v_forward2[3], Float:v_up[3], Float:v_up2[3], Float:v_right[3], Float:v_right2[3], Float:viewoffsets[3];
    357.    
    358.     pev(id, pev_v_angle, oldangles); pev(id,pev_origin,player_origin); pev(id, pev_view_ofs, viewoffsets);
    359.  
    360.     engfunc(EngFunc_MakeVectors, oldangles)
    361.    
    362.     global_get(glb_v_forward, v_forward); global_get(glb_v_up, v_up); global_get(glb_v_right, v_right);
    363.     global_get(glb_v_forward, v_forward2); global_get(glb_v_up, v_up2); global_get(glb_v_right, v_right2);
    364.    
    365.     xs_vec_add(player_origin, viewoffsets, gunorigin);
    366.    
    367.     if(!Right)
    368.     {
    369.         xs_vec_mul_scalar(v_forward, 10.3, v_forward); xs_vec_mul_scalar(v_right, 2.0, v_right);
    370.         xs_vec_mul_scalar(v_up, -2.7, v_up);
    371.         xs_vec_mul_scalar(v_forward2, 10.0, v_forward2); xs_vec_mul_scalar(v_right2, 4.0, v_right2);
    372.         xs_vec_mul_scalar(v_up2, -3.0, v_up2);
    373.     } else {
    374.         xs_vec_mul_scalar(v_forward, 10.3, v_forward); xs_vec_mul_scalar(v_right, -4.0, v_right);
    375.         xs_vec_mul_scalar(v_up, -3.7, v_up);
    376.         xs_vec_mul_scalar(v_forward2, 10.0, v_forward2); xs_vec_mul_scalar(v_right2, 2.0, v_right2);
    377.         xs_vec_mul_scalar(v_up2, -4.0, v_up2);
    378.     }
    379.    
    380.     xs_vec_add(gunorigin, v_forward, origin);
    381.     xs_vec_add(gunorigin, v_forward2, origin2);
    382.     xs_vec_add(origin, v_right, origin);
    383.     xs_vec_add(origin2, v_right2, origin2);
    384.     xs_vec_add(origin, v_up, origin);
    385.     xs_vec_add(origin2, v_up2, origin2);
    386.  
    387.     static Float:velocity[3]
    388.     get_speed_vector(origin2, origin, random_float(140.0, 160.0), velocity)
    389.  
    390.     static angle; angle = random_num(0, 360)
    391.  
    392.     message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
    393.     write_byte(TE_MODEL)
    394.     engfunc(EngFunc_WriteCoord, origin[0])
    395.     engfunc(EngFunc_WriteCoord,origin[1])
    396.     engfunc(EngFunc_WriteCoord,origin[2])
    397.     engfunc(EngFunc_WriteCoord,velocity[0])
    398.     engfunc(EngFunc_WriteCoord,velocity[1])
    399.     engfunc(EngFunc_WriteCoord,velocity[2])
    400.     write_angle(angle)
    401.     write_short(g_ShellId)
    402.     write_byte(1)
    403.     write_byte(20)
    404.     message_end()
    405. }
    406.  
    407. public fw_SetModel(entity, model[])
    408. {
    409.     if(!pev_valid(entity))
    410.         return FMRES_IGNORED
    411.    
    412.     static Classname[32]
    413.     pev(entity, pev_classname, Classname, sizeof(Classname))
    414.    
    415.     if(!equal(Classname, "weaponbox"))
    416.         return FMRES_IGNORED
    417.    
    418.     static iOwner
    419.     iOwner = pev(entity, pev_owner)
    420.    
    421.     if(equal(model, MODEL_W_OLD))
    422.     {
    423.         static weapon; weapon = find_ent_by_owner(-1, weapon_base, entity)
    424.        
    425.         if(!pev_valid(weapon))
    426.             return FMRES_IGNORED;
    427.        
    428.         if(Get_BitVar(g_Had_Base, iOwner))
    429.         {
    430.             set_pev(weapon, pev_impulse, WEAPON_CODE)
    431.             engfunc(EngFunc_SetModel, entity, MODEL_W)
    432.             set_pev(entity, pev_body, SUBMODEL)
    433.        
    434.             Remove_Base(iOwner)
    435.            
    436.             return FMRES_SUPERCEDE
    437.         }
    438.     }
    439.  
    440.     return FMRES_IGNORED;
    441. }
    442.  
    443. public fw_CmdStart(id, uc_handle, seed)
    444. {
    445.     if (!is_alive(id))
    446.         return FMRES_IGNORED    
    447.     if(get_player_weapon(id) != CSW_BASE || !Get_BitVar(g_Had_Base, id))
    448.         return FMRES_IGNORED
    449.        
    450.     static Button; Button = get_uc(uc_handle, UC_Buttons)  
    451.    
    452.     if(Button & IN_ATTACK2)
    453.     {
    454.         static Float:Time; Time = get_pdata_float(id, 83, 5)
    455.         if(Time > 0.0) return FMRES_IGNORED
    456.        
    457.         if(cs_get_user_zoom(id) != CS_SET_AUGSG552_ZOOM) cs_set_user_zoom(id, CS_SET_AUGSG552_ZOOM, 1)
    458.         else cs_set_user_zoom(id, CS_RESET_ZOOM, 0)
    459.        
    460.         Time = 0.25
    461.         set_pdata_float(id, 83, Time, 5)
    462.     }
    463.    
    464.     return FMRES_IGNORED
    465. }
    466.  
    467. public fw_Item_Deploy_Post(Ent)
    468. {
    469.     if(pev_valid(Ent) != 2)
    470.         return
    471.     static Id; Id = get_pdata_cbase(Ent, 41, 4)
    472.     if(get_pdata_cbase(Id, 373) != Ent)
    473.         return
    474.     if(!Get_BitVar(g_Had_Base, Id))
    475.         return
    476.        
    477.     static SubModel; SubModel = SUBMODEL
    478.    
    479.     set_pev(Id, pev_viewmodel2, MODEL_V)
    480.     set_pev(Id, pev_weaponmodel2, SubModel != -1 ? "" : MODEL_P)
    481.    
    482.     static Draw; Draw = ANIME_DRAW
    483.     if(Draw != -1) Set_WeaponAnim(Id, ANIME_DRAW)
    484.    
    485.     set_pdata_string(Id, (492) * 4, ANIM_EXT, -1 , 20)
    486. }
    487.  
    488. public fw_Item_AddToPlayer_Post(Ent, id)
    489. {
    490.     if(!pev_valid(Ent))
    491.         return HAM_IGNORED
    492.        
    493.     if(pev(Ent, pev_impulse) == WEAPON_CODE)
    494.     {
    495.         Set_BitVar(g_Had_Base, id)
    496.         set_pev(Ent, pev_impulse, 0)
    497.     }
    498.    
    499.     return HAM_HANDLED  
    500. }
    501.  
    502. public fw_Item_PostFrame(ent)
    503. {
    504.     static id; id = pev(ent, pev_owner)
    505.     if(!is_user_alive(id))
    506.         return HAM_IGNORED
    507.     if(!Get_BitVar(g_Had_Base, id))
    508.         return HAM_IGNORED  
    509.    
    510.     static Float:flNextAttack; flNextAttack = get_pdata_float(id, 83, 5)
    511.     static bpammo; bpammo = cs_get_user_bpammo(id, CSW_BASE)
    512.    
    513.     static iClip; iClip = get_pdata_int(ent, 51, 4)
    514.     static fInReload; fInReload = get_pdata_int(ent, 54, 4)
    515.    
    516.     if(fInReload && flNextAttack <= 0.0)
    517.     {
    518.         static temp1
    519.         temp1 = min(CLIP - iClip, bpammo)
    520.  
    521.         set_pdata_int(ent, 51, iClip + temp1, 4)
    522.         cs_set_user_bpammo(id, CSW_BASE, bpammo - temp1)        
    523.        
    524.         set_pdata_int(ent, 54, 0, 4)
    525.        
    526.         fInReload = 0
    527.     }      
    528.    
    529.     return HAM_IGNORED
    530. }
    531.  
    532. public fw_Weapon_Reload(ent)
    533. {
    534.     static id; id = pev(ent, pev_owner)
    535.     if(!is_user_alive(id))
    536.         return HAM_IGNORED
    537.     if(!Get_BitVar(g_Had_Base, id))
    538.         return HAM_IGNORED  
    539.  
    540.     g_Clip[id] = -1
    541.        
    542.     static BPAmmo; BPAmmo = cs_get_user_bpammo(id, CSW_BASE)
    543.     static iClip; iClip = get_pdata_int(ent, 51, 4)
    544.        
    545.     if(BPAmmo <= 0)
    546.         return HAM_SUPERCEDE
    547.     if(iClip >= CLIP)
    548.         return HAM_SUPERCEDE        
    549.            
    550.     g_Clip[id] = iClip  
    551.    
    552.     return HAM_HANDLED
    553. }
    554.  
    555. public fw_Weapon_Reload_Post(ent)
    556. {
    557.     static id; id = pev(ent, pev_owner)
    558.     if(!is_user_alive(id))
    559.         return HAM_IGNORED
    560.     if(!Get_BitVar(g_Had_Base, id))
    561.         return HAM_IGNORED  
    562.    
    563.     if((get_pdata_int(ent, 54, 4) == 1))
    564.     { // Reload
    565.         if(g_Clip[id] == -1)
    566.             return HAM_IGNORED
    567.        
    568.         set_pdata_int(ent, 51, g_Clip[id], 4)
    569.        
    570.         static Reload; Reload = ANIME_RELOAD
    571.         if(Reload != -1) Set_WeaponAnim(id, ANIME_RELOAD)
    572.         Set_PlayerNextAttack(id, RELOAD_TIME)
    573.     }
    574.    
    575.     return HAM_HANDLED
    576. }
    577.  
    578. public fw_Weapon_WeaponIdle_Post( iEnt )
    579. {
    580.     if(pev_valid(iEnt) != 2)
    581.         return
    582.     static Id; Id = get_pdata_cbase(iEnt, 41, 4)
    583.     if(get_pdata_cbase(Id, 373) != iEnt)
    584.         return
    585.     if(!Get_BitVar(g_Had_Base, Id))
    586.         return
    587.        
    588.     static Idle; Idle = ANIME_IDLE
    589.    
    590.     if(Idle != -1 && get_pdata_float(iEnt, 48, 4) <= 0.25)
    591.     {
    592.         Set_WeaponAnim(Id, ANIME_IDLE)
    593.         set_pdata_float(iEnt, 48, 20.0, 4)
    594.     }  
    595. }
    596.  
    597. public fw_TraceAttack_World(Victim, Attacker, Float:Damage, Float:Direction[3], Ptr, DamageBits)
    598. {
    599.     if(!is_connected(Attacker))
    600.         return HAM_IGNORED  
    601.     if(get_player_weapon(Attacker) != CSW_BASE || !Get_BitVar(g_Had_Base, Attacker))
    602.         return HAM_IGNORED
    603.        
    604.     static Float:flEnd[3], Float:vecPlane[3]
    605.        
    606.     get_tr2(Ptr, TR_vecEndPos, flEnd)
    607.     get_tr2(Ptr, TR_vecPlaneNormal, vecPlane)      
    608.            
    609.     Make_BulletHole(Attacker, flEnd, Damage)
    610.     Make_BulletSmoke(Attacker, Ptr)
    611.  
    612.     SetHamParamFloat(3, float(DAMAGE))
    613.    
    614.     return HAM_HANDLED
    615. }
    616.  
    617. public fw_TraceAttack_Player(Victim, Attacker, Float:Damage, Float:Direction[3], Ptr, DamageBits)
    618. {
    619.     if(!is_connected(Attacker))
    620.         return HAM_IGNORED  
    621.     if(get_player_weapon(Attacker) != CSW_BASE || !Get_BitVar(g_Had_Base, Attacker))
    622.         return HAM_IGNORED
    623.  
    624.     static Float:flEnd[3]
    625.     get_tr2(Ptr, TR_vecEndPos, flEnd)  
    626.        
    627.     SetHamParamFloat(3, float(DAMAGE))
    628.    
    629.     return HAM_HANDLED
    630. }
    631.  
    632. public fw_Weapon_PrimaryAttack(Ent)
    633. {
    634.     static id; id = pev(Ent, pev_owner)
    635.     if(!is_alive(id))
    636.         return
    637.     if(!Get_BitVar(g_Had_Base, id))
    638.         return
    639.  
    640.     pev(id, pev_punchangle, g_Recoil[id])
    641. }
    642.  
    643. public fw_Weapon_PrimaryAttack_Post(Ent)
    644. {
    645.     static id; id = pev(Ent, pev_owner)
    646.     if(!is_alive(id))
    647.         return
    648.     if(!Get_BitVar(g_Had_Base, id))
    649.         return
    650.  
    651.     static Float:Push[3]
    652.     pev(id, pev_punchangle, Push)
    653.     xs_vec_sub(Push, g_Recoil[id], Push)
    654.    
    655.     xs_vec_mul_scalar(Push, RECOIL, Push)
    656.     xs_vec_add(Push, g_Recoil[id], Push)
    657.    
    658.     set_pev(id, pev_punchangle, Push)
    659.  
    660.     // Acc
    661.     static Accena; Accena = ACCURACY
    662.     if(Accena != -1)
    663.     {
    664.         static Float:Accuracy
    665.         Accuracy = (float(100 - ACCURACY) * 1.5) / 100.0
    666.  
    667.         set_pdata_float(Ent, 62, Accuracy, 4);
    668.     }
    669. }
    670.  
    671. /* ===============================
    672. ------------- SAFETY -------------
    673. =================================*/
    674. public Register_SafetyFunc()
    675. {
    676.     register_event("CurWeapon", "Safety_CurWeapon", "be", "1=1")
    677.    
    678.     RegisterHam(Ham_Spawn, "player", "fw_Safety_Spawn_Post", 1)
    679.     RegisterHam(Ham_Killed, "player", "fw_Safety_Killed_Post", 1)
    680. }
    681.  
    682. public Register_SafetyFuncBot(id)
    683. {
    684.     RegisterHamFromEntity(Ham_Spawn, id, "fw_Safety_Spawn_Post", 1)
    685.     RegisterHamFromEntity(Ham_Killed, id, "fw_Safety_Killed_Post", 1)
    686. }
    687.  
    688. public Safety_Connected(id)
    689. {
    690.     Set_BitVar(g_IsConnected, id)
    691.     UnSet_BitVar(g_IsAlive, id)
    692.    
    693.     g_PlayerWeapon[id] = 0
    694. }
    695.  
    696. public Safety_Disconnected(id)
    697. {
    698.     UnSet_BitVar(g_IsConnected, id)
    699.     UnSet_BitVar(g_IsAlive, id)
    700.    
    701.     g_PlayerWeapon[id] = 0
    702. }
    703.  
    704. public Safety_CurWeapon(id)
    705. {
    706.     if(!is_alive(id))
    707.         return
    708.        
    709.     static CSW; CSW = read_data(2)
    710.     if(g_PlayerWeapon[id] != CSW) g_PlayerWeapon[id] = CSW
    711. }
    712.  
    713. public fw_Safety_Spawn_Post(id)
    714. {
    715.     if(!is_user_alive(id))
    716.         return
    717.        
    718.     Set_BitVar(g_IsAlive, id)
    719. }
    720.  
    721. public fw_Safety_Killed_Post(id)
    722. {
    723.     UnSet_BitVar(g_IsAlive, id)
    724. }
    725.  
    726. public is_connected(id)
    727. {
    728.     if(!(1 <= id <= 32))
    729.         return 0
    730.     if(!Get_BitVar(g_IsConnected, id))
    731.         return 0
    732.  
    733.     return 1
    734. }
    735.  
    736. public is_alive(id)
    737. {
    738.     if(!is_connected(id))
    739.         return 0
    740.     if(!Get_BitVar(g_IsAlive, id))
    741.         return 0
    742.        
    743.     return 1
    744. }
    745.  
    746. public get_player_weapon(id)
    747. {
    748.     if(!is_alive(id))
    749.         return 0
    750.    
    751.     return g_PlayerWeapon[id]
    752. }
    753.  
    754. /* ===============================
    755. --------- END OF SAFETY  ---------
    756. =================================*/
    757.  
    758. stock Set_WeaponAnim(id, anim)
    759. {
    760.     set_pev(id, pev_weaponanim, anim)
    761.    
    762.     message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, {0, 0, 0}, id)
    763.     write_byte(anim)
    764.     write_byte(pev(id, pev_body))
    765.     message_end()
    766. }
    767.  
    768. stock Make_BulletHole(id, Float:Origin[3], Float:Damage)
    769. {
    770.     // Find target
    771.     static Decal; Decal = random_num(41, 45)
    772.     static LoopTime;
    773.    
    774.     if(Damage > 100.0) LoopTime = 2
    775.     else LoopTime = 1
    776.    
    777.     for(new i = 0; i < LoopTime; i++)
    778.     {
    779.         // Put decal on "world" (a wall)
    780.         message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
    781.         write_byte(TE_WORLDDECAL)
    782.         engfunc(EngFunc_WriteCoord, Origin[0])
    783.         engfunc(EngFunc_WriteCoord, Origin[1])
    784.         engfunc(EngFunc_WriteCoord, Origin[2])
    785.         write_byte(Decal)
    786.         message_end()
    787.        
    788.         // Show sparcles
    789.         message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
    790.         write_byte(TE_GUNSHOTDECAL)
    791.         engfunc(EngFunc_WriteCoord, Origin[0])
    792.         engfunc(EngFunc_WriteCoord, Origin[1])
    793.         engfunc(EngFunc_WriteCoord, Origin[2])
    794.         write_short(id)
    795.         write_byte(Decal)
    796.         message_end()
    797.     }
    798. }
    799.  
    800. stock Make_BulletSmoke(id, TrResult)
    801. {
    802.     static Float:vecSrc[3], Float:vecEnd[3], TE_FLAG
    803.    
    804.     get_weapon_attachment(id, vecSrc)
    805.     global_get(glb_v_forward, vecEnd)
    806.    
    807.     xs_vec_mul_scalar(vecEnd, 8192.0, vecEnd)
    808.     xs_vec_add(vecSrc, vecEnd, vecEnd)
    809.  
    810.     get_tr2(TrResult, TR_vecEndPos, vecSrc)
    811.     get_tr2(TrResult, TR_vecPlaneNormal, vecEnd)
    812.    
    813.     xs_vec_mul_scalar(vecEnd, 2.5, vecEnd)
    814.     xs_vec_add(vecSrc, vecEnd, vecEnd)
    815.    
    816.     TE_FLAG |= TE_EXPLFLAG_NODLIGHTS
    817.     TE_FLAG |= TE_EXPLFLAG_NOSOUND
    818.     TE_FLAG |= TE_EXPLFLAG_NOPARTICLES
    819.    
    820.     engfunc(EngFunc_MessageBegin, MSG_PAS, SVC_TEMPENTITY, vecEnd, 0)
    821.     write_byte(TE_EXPLOSION)
    822.     engfunc(EngFunc_WriteCoord, vecEnd[0])
    823.     engfunc(EngFunc_WriteCoord, vecEnd[1])
    824.     engfunc(EngFunc_WriteCoord, vecEnd[2] - 10.0)
    825.     write_short(g_SmokePuff_SprId)
    826.     write_byte(2)
    827.     write_byte(50)
    828.     write_byte(TE_FLAG)
    829.     message_end()
    830. }
    831.  
    832. stock get_weapon_attachment(id, Float:output[3], Float:fDis = 40.0)
    833. {
    834.     static Float:vfEnd[3], viEnd[3]
    835.     get_user_origin(id, viEnd, 3)  
    836.     IVecFVec(viEnd, vfEnd)
    837.    
    838.     static Float:fOrigin[3], Float:fAngle[3]
    839.    
    840.     pev(id, pev_origin, fOrigin)
    841.     pev(id, pev_view_ofs, fAngle)
    842.    
    843.     xs_vec_add(fOrigin, fAngle, fOrigin)
    844.    
    845.     static Float:fAttack[3]
    846.    
    847.     xs_vec_sub(vfEnd, fOrigin, fAttack)
    848.     xs_vec_sub(vfEnd, fOrigin, fAttack)
    849.    
    850.     static Float:fRate
    851.    
    852.     fRate = fDis / vector_length(fAttack)
    853.     xs_vec_mul_scalar(fAttack, fRate, fAttack)
    854.    
    855.     xs_vec_add(fOrigin, fAttack, output)
    856. }
    857.  
    858. stock get_position(id,Float:forw, Float:right, Float:up, Float:vStart[])
    859. {
    860.     new Float:vOrigin[3], Float:vAngle[3], Float:vForward[3], Float:vRight[3], Float:vUp[3]
    861.    
    862.     pev(id, pev_origin, vOrigin)
    863.     pev(id, pev_view_ofs,vUp) //for player
    864.     xs_vec_add(vOrigin,vUp,vOrigin)
    865.     pev(id, pev_v_angle, vAngle) // if normal entity ,use pev_angles
    866.    
    867.     angle_vector(vAngle,ANGLEVECTOR_FORWARD,vForward) //or use EngFunc_AngleVectors
    868.     angle_vector(vAngle,ANGLEVECTOR_RIGHT,vRight)
    869.     angle_vector(vAngle,ANGLEVECTOR_UP,vUp)
    870.    
    871.     vStart[0] = vOrigin[0] + vForward[0] * forw + vRight[0] * right + vUp[0] * up
    872.     vStart[1] = vOrigin[1] + vForward[1] * forw + vRight[1] * right + vUp[1] * up
    873.     vStart[2] = vOrigin[2] + vForward[2] * forw + vRight[2] * right + vUp[2] * up
    874. }
    875.  
    876. stock get_speed_vector(const Float:origin1[3],const Float:origin2[3],Float:speed, Float:new_velocity[3])
    877. {
    878.     new_velocity[0] = origin2[0] - origin1[0]
    879.     new_velocity[1] = origin2[1] - origin1[1]
    880.     new_velocity[2] = origin2[2] - origin1[2]
    881.     new Float:num = floatsqroot(speed*speed / (new_velocity[0]*new_velocity[0] + new_velocity[1]*new_velocity[1] + new_velocity[2]*new_velocity[2]))
    882.     new_velocity[0] *= num
    883.     new_velocity[1] *= num
    884.     new_velocity[2] *= num
    885.    
    886.     return 1;
    887. }
    888.  
    889. stock Set_WeaponIdleTime(id, WeaponId ,Float:TimeIdle)
    890. {
    891.     static entwpn; entwpn = fm_get_user_weapon_entity(id, WeaponId)
    892.     if(!pev_valid(entwpn))
    893.         return
    894.        
    895.     set_pdata_float(entwpn, 46, TimeIdle, 4)
    896.     set_pdata_float(entwpn, 47, TimeIdle, 4)
    897.     set_pdata_float(entwpn, 48, TimeIdle + 0.5, 4)
    898. }
    899.  
    900. stock Set_PlayerNextAttack(id, Float:nexttime)
    901. {
    902.     set_pdata_float(id, 83, nexttime, 5)
    903. }
    904.  
    905. stock Get_Position(id,Float:forw, Float:right, Float:up, Float:vStart[])
    906. {
    907.     static Float:vOrigin[3], Float:vAngle[3], Float:vForward[3], Float:vRight[3], Float:vUp[3]
    908.    
    909.     pev(id, pev_origin, vOrigin)
    910.     pev(id, pev_view_ofs,vUp) //for player
    911.     xs_vec_add(vOrigin,vUp,vOrigin)
    912.     pev(id, pev_v_angle, vAngle) // if normal entity ,use pev_angles
    913.    
    914.     angle_vector(vAngle,ANGLEVECTOR_FORWARD,vForward) //or use EngFunc_AngleVectors
    915.     angle_vector(vAngle,ANGLEVECTOR_RIGHT,vRight)
    916.     angle_vector(vAngle,ANGLEVECTOR_UP,vUp)
    917.    
    918.     vStart[0] = vOrigin[0] + vForward[0] * forw + vRight[0] * right + vUp[0] * up
    919.     vStart[1] = vOrigin[1] + vForward[1] * forw + vRight[1] * right + vUp[1] * up
    920.     vStart[2] = vOrigin[2] + vForward[2] * forw + vRight[2] * right + vUp[2] * up
    921. }
    922.  
    923. stock drop_weapons(id, dropwhat)
    924. {
    925.     static weapons[32], num, i, weaponid
    926.     num = 0
    927.     get_user_weapons(id, weapons, num)
    928.    
    929.     for (i = 0; i < num; i++)
    930.     {
    931.         weaponid = weapons[i]
    932.        
    933.         if (dropwhat == 1 && ((1<<weaponid) & PRIMARY_WEAPONS_BIT_SUM))
    934.         {
    935.             static wname[32]
    936.             get_weaponname(weaponid, wname, sizeof wname - 1)
    937.            
    938.             engclient_cmd(id, "drop", wname)
    939.         }
    940.     }
    941.    
    942. }
Last edited by Raheem on 16 Sep 2018, 02:26, edited 3 times in total.
Reason: OH, forget define native type :(
You don't know? Learn and you will know.

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

#9

Post by Mark » 2 Months Ago

Raheem wrote:
2 Months Ago
OK TRY:

1. ze_items_manager.sma
    1. #include <zombie_escape>
    2.  
    3. // Setting File
    4. new const ZE_EXTRAITEM_FILE[] = "ze_extraitems.ini"
    5.  
    6. // Defines
    7. #define MENU_PAGE_ITEMS g_iMenuData[id]
    8.  
    9. // Const
    10. const OFFSET_CSMENUCODE = 205
    11.  
    12. // Forwards
    13. enum _:TOTAL_FORWARDS
    14. {
    15.     FW_ITEM_SELECT_PRE = 0,
    16.     FW_ITEM_SELECT_POST
    17. }
    18.  
    19. new g_iForwards[TOTAL_FORWARDS],
    20.     g_iForwardReturn
    21.  
    22. // Variables
    23. new Array:g_szItemRealName,
    24.     Array:g_szItemName,  
    25.     Array:g_iItemCost,
    26.     Array:g_iItemLimit
    27.  
    28. new g_iItemCount,
    29.     g_szAdditionalMenuText[32],
    30.     g_iMenuData[33],
    31.     bool:g_bHasDiscount[MAX_EXTRA_ITEMS]
    32.  
    33. public plugin_init()
    34. {
    35.     register_plugin("[ZE] Items Manager", ZE_VERSION, AUTHORS)
    36.    
    37.     // Commands
    38.     register_clcmd("say /items", "Cmd_Items")
    39.    
    40.     // Forwards (In Pre Return Values important)
    41.     g_iForwards[FW_ITEM_SELECT_PRE] = CreateMultiForward("ze_select_item_pre", ET_CONTINUE, FP_CELL, FP_CELL, FP_CELL)
    42.     g_iForwards[FW_ITEM_SELECT_POST] = CreateMultiForward("ze_select_item_post", ET_IGNORE, FP_CELL, FP_CELL, FP_CELL)
    43. }
    44.  
    45. public plugin_natives()
    46. {
    47.     register_native("ze_register_item", "native_ze_register_item")
    48.     register_native("ze_show_items_menu", "native_ze_show_items_menu")
    49.     register_native("ze_force_buy_item", "native_ze_force_buy_item")
    50.     register_native("ze_get_item_id", "native_ze_get_item_id")
    51.     register_native("ze_get_item_cost", "native_ze_get_item_cost")
    52.     register_native("ze_add_text_to_item", "native_ze_add_text_to_item")
    53.     register_native("ze_get_item_limit", "native_ze_get_item_limit")
    54.     register_native("ze_is_valid_itemid", "native_ze_is_valid_itemid")
    55.     register_native("ze_get_item_name", "native_ze_get_item_name")
    56.     register_native("ze_set_vip_discount", "native_ze_set_vip_discount")
    57.     register_native("ze_has_vip_discount", "native_ze_has_vip_discount")
    58.    
    59.     g_szItemRealName = ArrayCreate(32, 1)
    60.     g_szItemName = ArrayCreate(32, 1)
    61.     g_iItemCost = ArrayCreate(1, 1)
    62.     g_iItemLimit = ArrayCreate(1, 1)
    63. }
    64.  
    65. public client_disconnected(id)
    66. {
    67.     MENU_PAGE_ITEMS = 0
    68. }
    69.  
    70. public Cmd_Items(id)
    71. {
    72.     if (!is_user_alive(id))
    73.         return
    74.    
    75.     Show_Items_Menu(id)
    76. }
    77.  
    78. // Items Menu
    79. Show_Items_Menu(id)
    80. {
    81.     static menu[128], name[32], cost, transkey[64]
    82.     new menuid, index, itemdata[2]
    83.    
    84.     // Title
    85.     formatex(menu, charsmax(menu), "%L:\r", id, "BUY_EXTRAITEM")
    86.     menuid = menu_create(menu, "Extra_Items_Menu")
    87.    
    88.     // Item List
    89.     for (index = 0; index < g_iItemCount; index++)
    90.     {
    91.         // Additional text to display
    92.         g_szAdditionalMenuText[0] = 0
    93.        
    94.         // Execute item select attempt forward
    95.         ExecuteForward(g_iForwards[FW_ITEM_SELECT_PRE], g_iForwardReturn, id, index, 0)
    96.        
    97.         // Show item to player?
    98.         if (g_iForwardReturn >= ZE_ITEM_DONT_SHOW)
    99.             continue;
    100.        
    101.         // Add Item Name and Cost
    102.         ArrayGetString(g_szItemName, index, name, charsmax(name))
    103.         cost = ArrayGetCell(g_iItemCost, index)
    104.        
    105.         // ML support for item name
    106.         formatex(transkey, charsmax(transkey), "ITEMNAME %s", name)
    107.         if (GetLangTransKey(transkey) != TransKey_Bad) formatex(name, charsmax(name), "%L", id, transkey)
    108.        
    109.         // Item available to player?
    110.         if (g_iForwardReturn >= ZE_ITEM_UNAVAILABLE)
    111.             formatex(menu, charsmax(menu), "\d%s %d %s", name, cost, g_szAdditionalMenuText)
    112.         else
    113.             formatex(menu, charsmax(menu), "%s \y%d \w%s", name, cost, g_szAdditionalMenuText)
    114.        
    115.         itemdata[0] = index
    116.         itemdata[1] = 0
    117.         menu_additem(menuid, menu, itemdata)
    118.     }
    119.    
    120.     // No items to display?
    121.     if (menu_items(menuid) <= 0)
    122.     {
    123.         ze_colored_print(id, "%L", id, "NO_EXTRA_ITEMS")
    124.         menu_destroy(menuid)
    125.         return;
    126.     }
    127.    
    128.     // Back - Next - Exit
    129.     formatex(menu, charsmax(menu), "%L", id, "BACK")
    130.     menu_setprop(menuid, MPROP_BACKNAME, menu)
    131.     formatex(menu, charsmax(menu), "%L", id, "NEXT")
    132.     menu_setprop(menuid, MPROP_NEXTNAME, menu)
    133.     formatex(menu, charsmax(menu), "%L", id, "EXIT")
    134.     menu_setprop(menuid, MPROP_EXITNAME, menu)
    135.    
    136.     // If remembered page is greater than number of pages, clamp down the value
    137.     MENU_PAGE_ITEMS = min(MENU_PAGE_ITEMS, menu_pages(menuid)-1)
    138.    
    139.     // Fix for AMXX custom menus
    140.     set_pdata_int(id, OFFSET_CSMENUCODE, 0)
    141.     menu_display(id, menuid, MENU_PAGE_ITEMS)
    142. }
    143.  
    144. // Items Menu
    145. public Extra_Items_Menu(id, menuid, item)
    146. {
    147.     // Menu was closed
    148.     if (item == MENU_EXIT)
    149.     {
    150.         MENU_PAGE_ITEMS = 0
    151.         menu_destroy(menuid)
    152.         return PLUGIN_HANDLED;
    153.     }
    154.    
    155.     // Remember items menu page
    156.     MENU_PAGE_ITEMS = item / 7
    157.    
    158.     // Dead players are not allowed to buy items
    159.     if (!is_user_alive(id))
    160.     {
    161.         menu_destroy(menuid)
    162.         return PLUGIN_HANDLED;
    163.     }
    164.    
    165.     // Retrieve item id
    166.     new itemdata[2], dummy, itemid
    167.     menu_item_getinfo(menuid, item, dummy, itemdata, charsmax(itemdata), _, _, dummy)
    168.     itemid = itemdata[0]
    169.    
    170.     // Attempt to buy the item
    171.     Buy_Item(id, itemid)
    172.     menu_destroy(menuid)
    173.     return PLUGIN_HANDLED;
    174. }
    175.  
    176. // Buy Item
    177. Buy_Item(id, itemid, ignorecost = 0)
    178. {
    179.     // Execute item select attempt forward
    180.     ExecuteForward(g_iForwards[FW_ITEM_SELECT_PRE], g_iForwardReturn, id, itemid, ignorecost)
    181.    
    182.     // Item available to player?
    183.     if (g_iForwardReturn >= ZE_ITEM_UNAVAILABLE)
    184.         return;
    185.    
    186.     // Execute item selected forward
    187.     ExecuteForward(g_iForwards[FW_ITEM_SELECT_POST], g_iForwardReturn, id, itemid, ignorecost)
    188. }
    189.  
    190. // Natives
    191. public native_ze_register_item(plugin_id, num_params)
    192. {
    193.     new szItem_Name[32], iItem_Cost, iItem_Limit
    194.    
    195.     // Get the Data from first Parameter in the native (Item Name)
    196.     get_string(1, szItem_Name, charsmax(szItem_Name))
    197.    
    198.     // Get the Second Parameter (Item Cost)
    199.     iItem_Cost = get_param(2)
    200.    
    201.     // Get limit third parameter
    202.     iItem_Limit = get_param(3)
    203.    
    204.     if (strlen(szItem_Name) < 1)
    205.     {
    206.         // Can't leave item name empty
    207.         log_error(AMX_ERR_NATIVE, "[ZE] Can't register item with an empty name")
    208.         return ZE_WRONG_ITEM // Same as return -1
    209.     }
    210.    
    211.     new iIndex, szItemName[32]
    212.    
    213.     // Loop from 0 to max items amount
    214.     for (iIndex = 0; iIndex < g_iItemCount; iIndex++)
    215.     {
    216.         ArrayGetString(g_szItemRealName, iIndex, szItemName, charsmax(szItemName))
    217.        
    218.         if (equali(szItem_Name, szItemName))
    219.         {
    220.             log_error(AMX_ERR_NATIVE, "[ZE] Item already registered (%s)", szItemName)
    221.             return ZE_WRONG_ITEM; // Return -1
    222.         }
    223.     }
    224.    
    225.     // Load settings from extra items file
    226.     new szItemRealName[32]
    227.     copy(szItemRealName, charsmax(szItemRealName), szItem_Name)
    228.     ArrayPushString(g_szItemRealName, szItemRealName)
    229.    
    230.     // Name
    231.     if (!amx_load_setting_string(ZE_EXTRAITEM_FILE, szItemRealName, "NAME", szItem_Name, charsmax(szItem_Name)))
    232.         amx_save_setting_string(ZE_EXTRAITEM_FILE, szItemRealName, "NAME", szItem_Name)
    233.     ArrayPushString(g_szItemName, szItem_Name)
    234.    
    235.     // Cost
    236.     if (!amx_load_setting_int(ZE_EXTRAITEM_FILE, szItemRealName, "COST", iItem_Cost))
    237.         amx_save_setting_int(ZE_EXTRAITEM_FILE, szItemRealName, "COST", iItem_Cost)
    238.     ArrayPushCell(g_iItemCost, iItem_Cost)
    239.    
    240.     // Limit
    241.     if (!amx_load_setting_int(ZE_EXTRAITEM_FILE, szItemRealName, "LIMIT", iItem_Limit))
    242.         amx_save_setting_int(ZE_EXTRAITEM_FILE, szItemRealName, "LIMIT", iItem_Limit)
    243.     ArrayPushCell(g_iItemLimit, iItem_Limit)
    244.    
    245.     g_iItemCount++
    246.     return g_iItemCount - 1
    247. }
    248.  
    249. public native_ze_show_items_menu(plugin_id, num_params)
    250. {
    251.     new id = get_param(1)
    252.    
    253.     if (!is_user_connected(id))
    254.     {
    255.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player (%d)", id)
    256.         return false;
    257.     }
    258.    
    259.     Cmd_Items(id)
    260.     return true
    261. }
    262.  
    263. public native_ze_force_buy_item(plugin_id, num_params)
    264. {
    265.     new id = get_param(1)
    266.    
    267.     if (!is_user_connected(id))
    268.     {
    269.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player (%d)", id)
    270.         return false;
    271.     }
    272.    
    273.     new item_id = get_param(2)
    274.    
    275.     if (item_id < 0 || item_id >= g_iItemCount)
    276.     {
    277.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid item id (%d)", item_id)
    278.         return false;
    279.     }
    280.    
    281.     new ignorecost = get_param(3)
    282.    
    283.     Buy_Item(id, item_id, ignorecost)
    284.     return true;
    285. }
    286.  
    287. public native_ze_get_item_id(plugin_id, num_params)
    288. {
    289.     new szRealName[32]
    290.     get_string(1, szRealName, charsmax(szRealName))
    291.  
    292.     new index, szItemName[32]
    293.    
    294.     for (index = 0; index < g_iItemCount; index++)
    295.     {
    296.         ArrayGetString(g_szItemRealName, index, szItemName, charsmax(szItemName))
    297.        
    298.         if (equali(szRealName, szItemName))
    299.             return index
    300.     }
    301.    
    302.     return ZE_WRONG_ITEM
    303. }
    304.  
    305. public native_ze_get_item_cost(plugin_id, num_params)
    306. {
    307.     new item_id = get_param(1)
    308.    
    309.     if (item_id < 0 || item_id >= g_iItemCount)
    310.     {
    311.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid item id (%d)", item_id)
    312.         return ZE_WRONG_ITEM;
    313.     }
    314.    
    315.     return ArrayGetCell(g_iItemCost, item_id);
    316. }
    317.  
    318. public native_ze_add_text_to_item(plugin_id, num_params)
    319. {
    320.     new szText[32]
    321.     get_string(1, szText, charsmax(szText))
    322.     format(g_szAdditionalMenuText, charsmax(g_szAdditionalMenuText), "%s%s", g_szAdditionalMenuText, szText)
    323. }
    324.  
    325. public native_ze_get_item_limit(plugin_id, num_params)
    326. {
    327.     new item_id = get_param(1)
    328.    
    329.     if (item_id < 0 || item_id >= g_iItemCount)
    330.     {
    331.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid item id (%d)", item_id)
    332.         return ZE_WRONG_ITEM;
    333.     }
    334.    
    335.     return ArrayGetCell(g_iItemLimit, item_id);
    336. }
    337.  
    338. public native_ze_is_valid_itemid(plugin_id, num_params)
    339. {
    340.     new item_id = get_param(1)
    341.    
    342.     if (item_id < 0 || item_id >= g_iItemCount)
    343.     {
    344.         return false;
    345.     }
    346.    
    347.     return true;
    348. }
    349.  
    350. public native_ze_get_item_name(plugin_id, num_params)
    351. {
    352.     new item_id = get_param(1)
    353.    
    354.     if (item_id < 0 || item_id >= g_iItemCount)
    355.     {
    356.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid item id (%d)", item_id)
    357.         return ZE_WRONG_ITEM;
    358.     }
    359.    
    360.     new szName[32]
    361.     ArrayGetString(g_szItemName, item_id, szName, charsmax(szName))
    362.    
    363.     new iLen = get_param(3)
    364.     set_string(2, szName, iLen)
    365.     return true;
    366. }
    367.  
    368. public native_ze_set_vip_discount(iItemid, bSet)
    369. {
    370.     g_bHasDiscount[iItemid] = bSet;
    371. }
    372.  
    373. public native_ze_has_vip_discount(iItemid)
    374. {
    375.     return g_bHasDiscount[iItemid]
    376. }
2. ze_items_escape_coins.sma
    1. #include <zombie_escape>
    2. #include <ze_vip>
    3.  
    4. native ze_has_vip_discount(iItemid)
    5.  
    6. new g_iCurrentEC,
    7.     g_iRequiredEC
    8.  
    9. public plugin_init()
    10. {
    11.     register_plugin("[ZE] Items Manager: Escape Coins", ZE_VERSION, AUTHORS)
    12. }
    13.  
    14. public ze_select_item_pre(id, itemid, ignorecost)
    15. {
    16.     if (ignorecost)
    17.         return ZE_ITEM_AVAILABLE
    18.    
    19.     g_iCurrentEC = ze_get_escape_coins(id)
    20.    
    21.     if (ze_is_user_vip(id) && ze_has_vip_discount(iItemid))
    22.     {
    23.         g_iRequiredEC = floatround(ze_get_item_cost(itemid) * 0.5) // 50 % discount
    24.     }
    25.     else
    26.     {
    27.         g_iRequiredEC = ze_get_item_cost(itemid)
    28.     }
    29.    
    30.     if (g_iCurrentEC < g_iRequiredEC)
    31.         return ZE_ITEM_UNAVAILABLE
    32.    
    33.     return ZE_ITEM_AVAILABLE
    34. }
    35.  
    36. public ze_select_item_post(id, itemid, ignorecost)
    37. {
    38.     if (ignorecost)
    39.         return
    40.    
    41.     g_iCurrentEC = ze_get_escape_coins(id)
    42.    
    43.     if (ze_is_user_vip(id) && ze_has_vip_discount(iItemid))
    44.     {
    45.         g_iRequiredEC = floatround(ze_get_item_cost(itemid) * 0.5) // 50 % discount
    46.     }
    47.     else
    48.     {
    49.         g_iRequiredEC = ze_get_item_cost(itemid)
    50.     }
    51.    
    52.     ze_set_escape_coins(id, g_iCurrentEC - g_iRequiredEC)
    53. }
3. Item:
    1. #include <zombie_escape>
    2. #include <engine>
    3. #include <fakemeta_util>
    4. #include <cstrike>
    5. #include <fun>
    6. #include <xs>
    7.  
    8. native ze_set_vip_discount(iItemid, bSet);
    9.  
    10. #define PLUGIN "[CSO] Dual Uzi"
    11. #define VERSION "1.0"
    12. #define AUTHOR "Dias Pendragon"
    13.  
    14. // Data Config
    15. #define MODEL_V "models/v_dualuzi.mdl"
    16. #define MODEL_P "models/p_dualuzi.mdl"
    17. #define MODEL_W "models/w_dualuzi.mdl"
    18. #define MODEL_W_OLD "models/w_mp5.mdl"
    19.  
    20. #define CSW_BASE CSW_MP5NAVY
    21. #define weapon_base "weapon_mp5navy"
    22.  
    23. #define SUBMODEL -1 // can -1
    24. #define WEAPON_CODE 2102015
    25. #define WEAPON_EVENT "events/mp5n.sc"
    26. #define ANIM_EXT "dualpistols"
    27.  
    28. #define ANIME_SHOOT 3
    29. #define ANIME_RELOAD 15 // can -1
    30. #define ANIME_DRAW 16 // can -1
    31. #define ANIME_IDLE random_num(0, 1) // can -1
    32.  
    33. const PRIMARY_WEAPONS_BIT_SUM = (1<<CSW_AK47)|(1<<CSW_M4A1)|(1<<CSW_FAMAS)|(1<<CSW_GALIL)|(1<<CSW_SCOUT)|(1<<CSW_AWP)|(1<<CSW_M249)|(1<<CSW_MP5NAVY)|(1<<CSW_P90)|(1<<CSW_MAC10)|(1<<CSW_TMP)|(1<<CSW_XM1014)|(1<<CSW_M3)|(1<<CSW_G3SG1)|(1<<CSW_SG550)|(1<<CSW_SG552)|(1<<CSW_AUG)|(1<<CSW_UMP45);
    34.  
    35.  
    36. new const WeaponSounds[10][] =
    37. {
    38.     "weapons/dualuzi-1.wav",
    39.     "weapons/dualuzi_draw.wav",
    40.     "weapons/dualuzi_idle2_1.wav",
    41.     "weapons/dualuzi_idle2_2.wav",
    42.     "weapons/dualuzi_clipin1.wav",
    43.     "weapons/dualuzi_clipout1.wav",
    44.     "weapons/dualuzi_off_shoulder.wav",
    45.     "weapons/dualuzi_on_shoulder.wav",
    46.     "weapons/dualuzi_on_shoulder_reload1.wav",
    47.     "weapons/dualuzi_on_shoulder_reload2.wav"
    48. }
    49.  
    50. enum
    51. {
    52.     ANIME_IDLEX = 0,
    53.     ANIME_IDLE2,
    54.     ANIME_LEFT_EMPTY,
    55.     ANIME_SHOOT_L1,
    56.     ANIME_SHOOT_L2,
    57.     ANIME_SHOOT_L3,
    58.     ANIME_SHOOT_L4,
    59.     ANIME_SHOOT_L5,
    60.     ANIME_SHOOT_LLAST,
    61.     ANIME_SHOOT_R1,
    62.     ANIME_SHOOT_R2,
    63.     ANIME_SHOOT_R3,
    64.     ANIME_SHOOT_R4,
    65.     ANIME_SHOOT_R5,
    66.     ANIME_SHOOT_RLAST,
    67.     ANIME_RELOADX,
    68.     ANIME_DRAWX,
    69.     ANIME_CHANGE_TO_B,
    70.     ANIME_B_IDLE,
    71.     ANIME_B_SHOOT_L,
    72.     ANIME_B_SHOOT_LLAST,
    73.     ANIME_B_LEFT_EMPTY,
    74.     ANIME_B_SHOOT_R,
    75.     ANIME_B_SHOOT_RLAST,
    76.     ANIME_B_RELOAD,
    77.     ANIME_CHANGE_TO_A
    78. }
    79.  
    80. // Weapon Config
    81. #define DAMAGE 26 // 52 for Zombie
    82. #define ACCURACY 70 // 0 - 100 ; -1 Default
    83. #define CLIP 80
    84. #define BPAMMO 240
    85. #define SPEED 0.05
    86. #define RECOIL 0.5
    87. #define RELOAD_TIME 3.0
    88.  
    89. // MACROS
    90. #define Get_BitVar(%1,%2) (%1 & (1 << (%2 & 31)))
    91. #define Set_BitVar(%1,%2) %1 |= (1 << (%2 & 31))
    92. #define UnSet_BitVar(%1,%2) %1 &= ~(1 << (%2 & 31))
    93.  
    94. //new g_Base
    95. new g_Had_Base, g_Clip[33], g_OldWeapon[33], Float:g_Recoil[33][3]
    96. new g_Event_Base, g_SmokePuff_SprId, g_MsgCurWeapon, g_ShellId, g_iItemID
    97.  
    98. // Safety
    99. new g_HamBot
    100. new g_IsConnected, g_IsAlive, g_PlayerWeapon[33]
    101.  
    102. public plugin_init()
    103. {
    104.     register_plugin(PLUGIN, VERSION, AUTHOR)
    105.    
    106.     // Safety
    107.     Register_SafetyFunc()
    108.    
    109.     // Event
    110.     register_event("CurWeapon", "Event_CurWeapon", "be", "1=1")
    111.    
    112.     // Forward
    113.     register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)
    114.     register_forward(FM_PlaybackEvent, "fw_PlaybackEvent")
    115.     register_forward(FM_SetModel, "fw_SetModel")    
    116.     register_forward(FM_CmdStart, "fw_CmdStart")
    117.  
    118.     // Ham
    119.     RegisterHam(Ham_Item_Deploy, weapon_base, "fw_Item_Deploy_Post", 1)
    120.     RegisterHam(Ham_Item_AddToPlayer, weapon_base, "fw_Item_AddToPlayer_Post", 1)
    121.     RegisterHam(Ham_Weapon_WeaponIdle, weapon_base, "fw_Weapon_WeaponIdle_Post", 1)
    122.     RegisterHam(Ham_Item_PostFrame, weapon_base, "fw_Item_PostFrame")  
    123.     RegisterHam(Ham_Weapon_Reload, weapon_base, "fw_Weapon_Reload")
    124.     RegisterHam(Ham_Weapon_Reload, weapon_base, "fw_Weapon_Reload_Post", 1)
    125.     RegisterHam(Ham_Weapon_PrimaryAttack, weapon_base, "fw_Weapon_PrimaryAttack")
    126.     RegisterHam(Ham_Weapon_PrimaryAttack, weapon_base, "fw_Weapon_PrimaryAttack_Post", 1)
    127.    
    128.     RegisterHam(Ham_TraceAttack, "worldspawn", "fw_TraceAttack_World")
    129.     RegisterHam(Ham_TraceAttack, "player", "fw_TraceAttack_Player")
    130.    
    131.     // Cache
    132.     g_MsgCurWeapon = get_user_msgid("CurWeapon")
    133.    
    134.     // Get
    135.     g_iItemID = ze_register_item("Dual Uzi", 0, 0)
    136.     ze_set_vip_discount(g_iItemID, true)
    137. }
    138.  
    139. public plugin_precache()
    140. {
    141.     precache_model(MODEL_V)
    142.     precache_model(MODEL_P)
    143.     precache_model(MODEL_W)
    144.    
    145.     for(new i = 0; i < sizeof(WeaponSounds); i++)
    146.         precache_sound(WeaponSounds[i])
    147.    
    148.     g_ShellId = engfunc(EngFunc_PrecacheModel, "models/pshell.mdl")
    149.     g_SmokePuff_SprId = engfunc(EngFunc_PrecacheModel, "sprites/wall_puff1.spr")
    150.     register_forward(FM_PrecacheEvent, "fw_PrecacheEvent_Post", 1)
    151. }
    152.  
    153. public fw_PrecacheEvent_Post(type, const name[])
    154. {
    155.     if(equal(WEAPON_EVENT, name)) g_Event_Base = get_orig_retval()      
    156. }
    157.  
    158. public client_putinserver(id)
    159. {
    160.     Safety_Connected(id)
    161.    
    162.     if(!g_HamBot && is_user_bot(id))
    163.     {
    164.         g_HamBot = 1
    165.         set_task(0.1, "Register_HamBot", id)
    166.     }
    167. }
    168.  
    169. public Register_HamBot(id)
    170. {
    171.     Register_SafetyFuncBot(id)
    172.     RegisterHamFromEntity(Ham_TraceAttack, id, "fw_TraceAttack_Player")
    173. }
    174.  
    175. public client_disconnected(id)
    176. {
    177.         Safety_Disconnected(id)
    178. }
    179. /*
    180. public Mileage_WeaponGet(id, ItemID)
    181. {
    182.     if(ItemID == g_Base) Get_Base(id)
    183. }
    184.  
    185. public Mileage_WeaponRefillAmmo(id, ItemID)
    186. {
    187.     if(ItemID == g_Base) cs_set_user_bpammo(id, CSW_BASE, BPAMMO)
    188. }
    189.  
    190. public Mileage_WeaponRemove(id, ItemID)
    191. {
    192.     if(ItemID == g_Base) Remove_Base(id)
    193. }*/
    194.  
    195. public ze_select_item_pre(id, itemid)
    196. {
    197.     if (itemid != g_iItemID)
    198.         return ZE_ITEM_AVAILABLE
    199.  
    200.     if (ze_is_user_zombie(id))
    201.         return ZE_ITEM_DONT_SHOW
    202.  
    203.     return ZE_ITEM_AVAILABLE
    204. }
    205.  
    206. public ze_select_item_post(id, itemid)
    207. {
    208.     if (itemid != g_iItemID)
    209.         return
    210.  
    211.     Get_Base(id)
    212. }
    213.  
    214. public ze_user_humanized(id)
    215. {
    216.     Remove_Base(id)
    217. }
    218.  
    219. public Get_Base(id)
    220. {
    221.     drop_weapons(id, 1);
    222.     Set_BitVar(g_Had_Base, id)
    223.     give_item(id, weapon_base)
    224.    
    225.     // Clip & Ammo
    226.     static Ent; Ent = fm_get_user_weapon_entity(id, CSW_BASE)
    227.     if(!pev_valid(Ent)) return
    228.    
    229.     cs_set_weapon_ammo(Ent, CLIP)
    230.     cs_set_user_bpammo(id, CSW_BASE, BPAMMO)
    231.    
    232.     message_begin(MSG_ONE_UNRELIABLE, g_MsgCurWeapon, _, id)
    233.     write_byte(1)
    234.     write_byte(CSW_BASE)
    235.     write_byte(CLIP)
    236.     message_end()
    237.    
    238.     cs_set_weapon_silen(Ent, 0, 0)
    239. }
    240.  
    241. public Remove_Base(id)
    242. {
    243.     UnSet_BitVar(g_Had_Base, id)
    244. }
    245.  
    246. public Event_CurWeapon(id)
    247. {
    248.     static CSWID; CSWID = read_data(2)
    249.     static SubModel; SubModel = SUBMODEL
    250.    
    251.     if((CSWID == CSW_BASE && g_OldWeapon[id] != CSW_BASE) && Get_BitVar(g_Had_Base, id))
    252.     {
    253.         if(SubModel != -1) Draw_NewWeapon(id, CSWID)
    254.     } else if((CSWID == CSW_BASE && g_OldWeapon[id] == CSW_BASE) && Get_BitVar(g_Had_Base, id)) {
    255.         static Ent; Ent = fm_get_user_weapon_entity(id, CSW_BASE)
    256.         if(!pev_valid(Ent))
    257.         {
    258.             g_OldWeapon[id] = get_user_weapon(id)
    259.             return
    260.         }
    261.        
    262.         set_pdata_float(Ent, 46, SPEED, 4)
    263.         set_pdata_float(Ent, 47, SPEED, 4)
    264.     } else if(CSWID != CSW_BASE && g_OldWeapon[id] == CSW_BASE) {
    265.         if(SubModel != -1) Draw_NewWeapon(id, CSWID)
    266.     }
    267.    
    268.     g_OldWeapon[id] = get_user_weapon(id)
    269. }
    270.  
    271. public Draw_NewWeapon(id, CSW_ID)
    272. {
    273.     if(CSW_ID == CSW_BASE)
    274.     {
    275.         static ent
    276.         ent = fm_get_user_weapon_entity(id, CSW_BASE)
    277.        
    278.         if(pev_valid(ent) && Get_BitVar(g_Had_Base, id))
    279.         {
    280.             set_pev(ent, pev_effects, pev(ent, pev_effects) &~ EF_NODRAW)
    281.             engfunc(EngFunc_SetModel, ent, MODEL_P)
    282.             set_pev(ent, pev_body, SUBMODEL)
    283.         }
    284.     } else {
    285.         static ent
    286.         ent = fm_get_user_weapon_entity(id, CSW_BASE)
    287.        
    288.         if(pev_valid(ent)) set_pev(ent, pev_effects, pev(ent, pev_effects) | EF_NODRAW)            
    289.     }
    290. }
    291.  
    292. public fw_UpdateClientData_Post(id, sendweapons, cd_handle)
    293. {
    294.     if(!is_alive(id))
    295.         return FMRES_IGNORED    
    296.     if(get_user_weapon(id) == CSW_BASE && Get_BitVar(g_Had_Base, id))
    297.         set_cd(cd_handle, CD_flNextAttack, get_gametime() + 0.001)
    298.    
    299.     return FMRES_HANDLED
    300. }
    301.  
    302. public fw_PlaybackEvent(flags, invoker, eventid, Float:delay, Float:origin[3], Float:angles[3], Float:fparam1, Float:fparam2, iParam1, iParam2, bParam1, bParam2)
    303. {
    304.     if (!is_connected(invoker))
    305.         return FMRES_IGNORED    
    306.     if(get_player_weapon(invoker) != CSW_BASE || !Get_BitVar(g_Had_Base, invoker))
    307.         return FMRES_IGNORED
    308.     if(eventid != g_Event_Base)
    309.         return FMRES_IGNORED
    310.    
    311.     engfunc(EngFunc_PlaybackEvent, flags | FEV_HOSTONLY, invoker, eventid, delay, origin, angles, fparam1, fparam2, iParam1, iParam2, bParam1, bParam2)
    312.     DualAttack(invoker)
    313.    
    314.     return FMRES_SUPERCEDE
    315. }
    316. public DualAttack(id)
    317. {
    318.     static iFlags, iAnimDesired, iWeaponState, iItem, szAnimation[64]
    319.    
    320.     #define WEAPONSTATE_ELITE_LEFT (1 << 3)
    321.    
    322.     iItem = fm_get_user_weapon_entity(id, CSW_BASE)
    323.     if(!pev_valid(iItem)) return
    324.    
    325.     iFlags = pev(id, pev_flags);
    326.     iWeaponState = get_pdata_int(iItem, 74, 4)
    327.    
    328.     if(iWeaponState & WEAPONSTATE_ELITE_LEFT)
    329.     {  
    330.         iWeaponState &= ~ WEAPONSTATE_ELITE_LEFT;
    331.    
    332.         Set_WeaponAnim(id, ANIME_SHOOT_L1)
    333.         Make_Shell(id, 1)
    334.        
    335.         formatex(szAnimation, charsmax(szAnimation), iFlags & FL_DUCKING ? "crouch_shoot_%s" : "ref_shoot_%s", ANIM_EXT);
    336.     } else {
    337.         iWeaponState |= WEAPONSTATE_ELITE_LEFT;
    338.        
    339.         Set_WeaponAnim(id, ANIME_SHOOT_R1)
    340.         Make_Shell(id, 0)
    341.        
    342.         formatex(szAnimation, charsmax(szAnimation), iFlags & FL_DUCKING ? "crouch_shoot2_%s" : "ref_shoot2_%s", ANIM_EXT);
    343.     }
    344.    
    345.     if((iAnimDesired = lookup_sequence(id, szAnimation)) == -1)
    346.         iAnimDesired = 0;
    347.    
    348.     set_pev(id, pev_sequence, iAnimDesired)
    349.     set_pdata_int(iItem, 74, iWeaponState, 4)
    350.    
    351.     emit_sound(id, CHAN_WEAPON, WeaponSounds[0], 1.0, 0.4, 0, 94 + random_num(0, 15))
    352. }
    353.  
    354. public Make_Shell(id, Right)
    355. {
    356.     static Float:player_origin[3], Float:origin[3], Float:origin2[3], Float:gunorigin[3], Float:oldangles[3], Float:v_forward[3], Float:v_forward2[3], Float:v_up[3], Float:v_up2[3], Float:v_right[3], Float:v_right2[3], Float:viewoffsets[3];
    357.    
    358.     pev(id, pev_v_angle, oldangles); pev(id,pev_origin,player_origin); pev(id, pev_view_ofs, viewoffsets);
    359.  
    360.     engfunc(EngFunc_MakeVectors, oldangles)
    361.    
    362.     global_get(glb_v_forward, v_forward); global_get(glb_v_up, v_up); global_get(glb_v_right, v_right);
    363.     global_get(glb_v_forward, v_forward2); global_get(glb_v_up, v_up2); global_get(glb_v_right, v_right2);
    364.    
    365.     xs_vec_add(player_origin, viewoffsets, gunorigin);
    366.    
    367.     if(!Right)
    368.     {
    369.         xs_vec_mul_scalar(v_forward, 10.3, v_forward); xs_vec_mul_scalar(v_right, 2.0, v_right);
    370.         xs_vec_mul_scalar(v_up, -2.7, v_up);
    371.         xs_vec_mul_scalar(v_forward2, 10.0, v_forward2); xs_vec_mul_scalar(v_right2, 4.0, v_right2);
    372.         xs_vec_mul_scalar(v_up2, -3.0, v_up2);
    373.     } else {
    374.         xs_vec_mul_scalar(v_forward, 10.3, v_forward); xs_vec_mul_scalar(v_right, -4.0, v_right);
    375.         xs_vec_mul_scalar(v_up, -3.7, v_up);
    376.         xs_vec_mul_scalar(v_forward2, 10.0, v_forward2); xs_vec_mul_scalar(v_right2, 2.0, v_right2);
    377.         xs_vec_mul_scalar(v_up2, -4.0, v_up2);
    378.     }
    379.    
    380.     xs_vec_add(gunorigin, v_forward, origin);
    381.     xs_vec_add(gunorigin, v_forward2, origin2);
    382.     xs_vec_add(origin, v_right, origin);
    383.     xs_vec_add(origin2, v_right2, origin2);
    384.     xs_vec_add(origin, v_up, origin);
    385.     xs_vec_add(origin2, v_up2, origin2);
    386.  
    387.     static Float:velocity[3]
    388.     get_speed_vector(origin2, origin, random_float(140.0, 160.0), velocity)
    389.  
    390.     static angle; angle = random_num(0,