Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2012
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 21.89 KB | None | 0 0
  1. /*
  2. *   Item Functions
  3. */
  4.  
  5. // Item Setup Functions
  6. ITEM_Init()
  7. {
  8.     ITEM_COST[ITEM_ANKH]        = 5000;         // Ankh of Reincarnation
  9.     ITEM_COST[ITEM_BOOTS]       = 2500;         // Boots of Speed
  10.     ITEM_COST[ITEM_CLAWS]       = 1000;         // Claws of Attack
  11.     ITEM_COST[ITEM_CLOAK]       = 800;          // Cloak of Shadows
  12.     ITEM_COST[ITEM_MASK]        = 2000;         // Mask of Death
  13.     ITEM_COST[ITEM_NECKLACE]    = 800;          // Necklace of Immunity
  14.     ITEM_COST[ITEM_FROST]       = 2000;         // Orb of Frost
  15.     ITEM_COST[ITEM_HEALTH]      = 1000;         // Periapt of Health
  16.     ITEM_COST[ITEM_TOME]        = 2000;         // Tome of Experience
  17.     ITEM_COST[ITEM_SCROLL]      = 6000;         // Scroll of Respawning
  18.     ITEM_COST[ITEM_PROTECTANT]  = 1500;         // Mole Protectant
  19.     ITEM_COST[ITEM_HELM]        = 3000;         // Helm of Excellence
  20.     ITEM_COST[ITEM_AMULET]      = 1500;         // Amulet of the Cat
  21.     ITEM_COST[ITEM_SOCK]        = 1500;         // Sock of the Feather
  22.     ITEM_COST[ITEM_GLOVES]      = 1750;         // Flaming Gloves of Warmth
  23.     ITEM_COST[ITEM_RING]        = 1000;         // Ring of Regeneration + 1
  24.     ITEM_COST[ITEM_CHAMELEON]   = 4500;         // Chameleon
  25.     ITEM_COST[ITEM_MOLE]        = 16000;        // Mole
  26.    
  27.     // Items are chargeable
  28.     g_iFlag[ITEM_NECKLACE]  |= ITEM_CHARGEABLE;
  29.     g_iFlag[ITEM_HELM]      |= ITEM_CHARGEABLE;
  30.     g_iFlag[ITEM_RING]      |= ITEM_CHARGEABLE;
  31.  
  32.     // Items should be used when bought
  33.     g_iFlag[ITEM_TOME]      |= ITEM_USEONBUY;
  34.  
  35.     // Items CAN be bought when dead
  36.     g_iFlag[ITEM_ANKH]      |= ITEM_BUYWHENDEAD;
  37.     g_iFlag[ITEM_SCROLL]    |= ITEM_BUYWHENDEAD;
  38.     g_iFlag[ITEM_MOLE]      |= ITEM_BUYWHENDEAD;
  39.     g_iFlag[ITEM_TOME]      |= ITEM_BUYWHENDEAD;
  40.  
  41.     // Items are used when the next round starts...
  42.     g_iFlag[ITEM_ANKH]      |= ITEM_NEXTROUNDUSE;
  43.     g_iFlag[ITEM_MOLE]      |= ITEM_NEXTROUNDUSE;
  44. }
  45.  
  46. // We created this to allow for different prices of items at different levels
  47. ITEM_Cost( id, iItem )
  48. {
  49.     // How much should ratio increase per level?
  50.     new Float:fInc = ( 1.0 - ITEM_COST_RATIO ) / float( MAX_LEVELS );
  51.  
  52.     // Cost * ratio (ITEM_COST_RATIO to 1.0 dependent on level)
  53.     new Float:fRatio = (float( p_data[id][P_LEVEL] ) * fInc) + ITEM_COST_RATIO;
  54.  
  55.     return ( p_data[id][P_RACE] != RACE_NONE ) ? floatround( float( ITEM_COST[iItem] ) * fRatio ) : ITEM_COST[iItem];
  56. }
  57.  
  58.  
  59. public ITEM_CanBuy( id, iItem )
  60. {
  61.     // User doesn't have the money
  62.     if ( SHARED_GetUserMoney( id ) < ITEM_Cost( id, iItem ) )
  63.     {
  64.         client_print( id, print_center, "%L", id, "INSUFFICIENT_FUNDS" );
  65.  
  66.         return false;
  67.     }
  68.    
  69.     // User already owns the item and it's not a chargeable item!
  70.     else if ( ITEM_Has( id, iItem ) > ITEM_NONE && !ITEM_CheckFlag( iItem, ITEM_CHARGEABLE ) )
  71.     {
  72.         client_print( id, print_center, "%L", id, "ALREADY_OWN_THAT_ITEM" );
  73.  
  74.         return false;
  75.     }
  76.    
  77.     // Make sure these items can be bought if the user is dead
  78.     else if ( !is_user_alive( id ) && !ITEM_CheckFlag( iItem, ITEM_BUYWHENDEAD ) )
  79.     {
  80.         client_print( id, print_center, "%L", id, "NOT_PURCHASE_WHEN_DEAD" );
  81.  
  82.         return false;
  83.     }
  84.    
  85.     // User has necklace + blink, they don't need a necklace
  86.     else if ( iItem == ITEM_NECKLACE && p_data_b[id][PB_WARDENBLINK] )
  87.     {
  88.         client_print( id, print_center, "You are already immune to ultimates through one of your skills!" );
  89.  
  90.         return false;
  91.     }
  92.  
  93.     // User doesn't need an ankh if they're going to reincarnate
  94.     else if ( iItem == ITEM_ANKH && SM_GetSkillLevel( id, SKILL_REINCARNATION ) == 3 && !p_data[id][P_CHANGERACE] && p_data[id][P_RACE] != RACE_CHAMELEON )
  95.     {
  96.         client_print( id, print_center, "You will already reincarnate your weapons through one of your skills!" );
  97.  
  98.         return false;
  99.     }
  100.    
  101.     // User has purchased the maximum allowed rings
  102.     else if ( g_iTotalRings[id] >= 5 && iItem == ITEM_RING )
  103.     {
  104.         client_print( id, print_center, "%L", id, "NOT_PURCHASE_MORE_THAN_FIVE_RINGS" );
  105.  
  106.         return false;
  107.     }
  108.  
  109.     // User has purchased gloves when they're disabled on this map
  110.     else if ( iItem == ITEM_GLOVES && g_bGlovesDisabled )
  111.     {
  112.         client_print( id, print_chat, "Gloves are disabled on this map!" );
  113.  
  114.         return false;
  115.     }
  116.  
  117.     // User is already going to reincarnate weapons because they bought an ankh earlier (probably lost it when died)
  118.     else if ( ( iItem == ITEM_ANKH && g_bPlayerBoughtAnkh[id] ) || ( iItem == ITEM_MOLE && g_bPlayerBoughtMole[id] ) )
  119.     {
  120.         client_print( id, print_center, "%L", id, "ALREADY_OWN_THAT_ITEM" );
  121.  
  122.         return false;
  123.     }
  124.  
  125.     return true;
  126. }
  127.  
  128. public ITEM_Buy( id, iItem )
  129. {
  130.  
  131.    
  132.     // If the user can buy this item...
  133.     if ( ITEM_CanBuy( id, iItem ) )
  134.     {
  135.  
  136.         // User's items are full
  137.         if ( ITEM_GetSlot( id ) == ITEM_SLOT_FULL && !ITEM_CheckFlag( iItem, ITEM_USEONBUY ) )
  138.         {
  139.  
  140.             // We only care about items being full if this item isn't a use on buy
  141.             if ( !ITEM_CheckFlag( iItem, ITEM_USEONBUY ) )
  142.             {
  143.  
  144.                 new bool:bShowReplaceMenu = false;
  145.  
  146.                 // One time use...
  147.                 if ( !ITEM_CheckFlag( iItem, ITEM_CHARGEABLE ) )
  148.                 {
  149.                     //client_print( id, print_chat, "[DEBUG] Item is not chargeable" );
  150.  
  151.                     bShowReplaceMenu = true;
  152.                 }
  153.  
  154.                 // We also need to replace it if the item is chargeable but they don't own that item
  155.                 if ( ITEM_Has( id, iItem ) == ITEM_NONE && ITEM_CheckFlag( iItem, ITEM_CHARGEABLE ) )
  156.                 {
  157.                     //client_print( id, print_chat, "[DEBUG] Doesn't have item and new item is chargeable" );
  158.  
  159.                     bShowReplaceMenu = true;
  160.                 }
  161.  
  162.                 if ( bShowReplaceMenu )
  163.                 {
  164.                     g_iFutureItem[id] = iItem;
  165.  
  166.                     MENU_ReplaceItem( id );
  167.  
  168.                     return;
  169.                 }
  170.             }
  171.         }
  172.    
  173.         // We're clear!
  174.  
  175.         // Remove user's money
  176.         new iNewMoney = SHARED_GetUserMoney( id ) - ITEM_Cost( id, iItem );
  177.         SHARED_SetUserMoney( id, iNewMoney );
  178.  
  179.         ITEM_GiveItem( id, iItem );
  180.     }
  181.  
  182.     return;
  183. }
  184.  
  185. // Item Buy Functions
  186. bool:ITEM_MenuCanBuyCheck( id )
  187. {
  188.     // Duh how can they buy if they're dead!
  189.     if ( !p_data_b[id][PB_ISCONNECTED] )
  190.     {
  191.         return false;
  192.     }
  193.  
  194.     new isPlayerAlive       = is_user_alive( id );
  195.  
  196.     if ( !get_pcvar_num( CVAR_wc3_buy_dead ) && !isPlayerAlive )
  197.     {
  198.         client_print( id, print_center, "%L", id, "NOT_BUY_ITEMS_WHEN_DEAD" );
  199.        
  200.         return false;
  201.     }
  202.    
  203.     else if ( g_MOD == GAME_CSTRIKE || g_MOD == GAME_CZERO )
  204.     {
  205.         new isPlayerInBuyZone   = cs_get_user_buyzone( id )
  206.        
  207.         if ( get_pcvar_num( CVAR_wc3_buy_time ) && !g_buyTime )
  208.         {
  209.             client_print( id, print_center, "%L", id, "SECONDS_HAVE_PASSED_CANT_BUY", ( get_cvar_float( "mp_buytime" ) * 60.0 ) );
  210.  
  211.             return false;
  212.         }
  213.        
  214.         else if ( get_pcvar_num( CVAR_wc3_buy_zone ) && !isPlayerInBuyZone && isPlayerAlive )
  215.         {
  216.             client_print( id, print_center, "%L", id, "MUST_BE_IN_BUYZONE" );
  217.            
  218.             return false;
  219.         }
  220.     }
  221.    
  222.     return true;
  223. }
  224.  
  225. // Item Preset Function
  226. ITEM_GiveItem( id, iItem )
  227. {
  228.  
  229.     // This item we should use instantly
  230.     if ( ITEM_CheckFlag( iItem, ITEM_USEONBUY ) )
  231.     {
  232.         if ( iItem == ITEM_TOME )
  233.         {
  234.             ITEM_Tome( id );
  235.  
  236.             return;
  237.         }
  238.     }
  239.  
  240.     // They are just adding some charges
  241.     else
  242.     {
  243.         // Actually set our item variable
  244.         if ( is_user_alive( id ) )
  245.         {
  246.             ITEM_Equip( id, iItem );
  247.         }
  248.  
  249.         // Display message to the user regarding the item they just purchased
  250.         ITEM_DisplayMessage( id, iItem );
  251.  
  252.         // Give bonuses
  253.         ITEM_GiveBonuses( id, iItem );
  254.  
  255.         // Play purchase sound
  256.         emit_sound( id, CHAN_STATIC, g_szSounds[SOUND_PICKUPITEM], 1.0, ATTN_NORM, 0, PITCH_NORM );
  257.     }
  258.  
  259.     WC3_ShowBar( id );
  260.  
  261.     return;
  262. }
  263.  
  264. ITEM_DisplayMessage( id, iItem )
  265. {
  266.     // Display a message regarding the item they just purchased
  267.     switch ( iItem )
  268.     {
  269.         case ITEM_ANKH:
  270.         {
  271.             (g_MOD == GAME_CSTRIKE || g_MOD == GAME_CZERO)  ? client_print( id, print_chat,"%s %L", g_MODclient, id, "INFO_SHOPMENU_1" ) : 0;
  272.         }
  273.  
  274.         case ITEM_BOOTS:
  275.         {
  276.             if ( g_MOD == GAME_CSTRIKE || g_MOD == GAME_CZERO )
  277.             {
  278.                 client_print( id, print_chat,"%s %L", g_MODclient, id, "INFO_SHOPMENU_2", ( ( get_pcvar_float( CVAR_wc3_boots ) ) * 100.00 ) );
  279.             }
  280.         }
  281.  
  282.         case ITEM_CLAWS:
  283.         {
  284.             client_print( id, print_chat,"%s %L", g_MODclient, id, "INFO_SHOPMENU_3", get_pcvar_num( CVAR_wc3_claw ) );
  285.         }
  286.  
  287.         case ITEM_CLOAK:
  288.         {
  289.             new Float:fInvis = 100.0 * ( float( get_pcvar_num( CVAR_wc3_cloak ) ) / 255.0 );
  290.             client_print(id, print_chat,"%s %L", g_MODclient, id, "INFO_SHOPMENU_4", fInvis );
  291.         }
  292.  
  293.         case ITEM_MASK:
  294.         {
  295.             new Float:fMask = ( 100.0 * get_pcvar_float( CVAR_wc3_mask ) );
  296.             client_print(id, print_chat,"%s %L", g_MODclient, id, "INFO_SHOPMENU_5", fMask );
  297.         }
  298.  
  299.         case ITEM_NECKLACE:
  300.         {
  301.             client_print( id, print_chat, "%s %L", g_MODclient, id, "INFO_SHOPMENU_6", NECKLACE_CHARGES );
  302.         }
  303.  
  304.         case ITEM_FROST:
  305.         {
  306.             new Float:fFrost = 100.0 * ( get_pcvar_float( CVAR_wc3_frost ) / 260.0 );
  307.             client_print(id, print_chat,"%s %L", g_MODclient, id, "INFO_SHOPMENU_7", fFrost );
  308.         }
  309.  
  310.         case ITEM_HEALTH:
  311.         {
  312.             client_print(id, print_chat,"%s %L", g_MODclient, id, "INFO_SHOPMENU_8", get_pcvar_num( CVAR_wc3_health ) );
  313.         }
  314.  
  315.         case ITEM_SCROLL:
  316.         {
  317.             if ( is_user_alive( id ) )
  318.             {
  319.                 client_print( id, print_chat, "%s %L", g_MODclient, id, "INFO_SHOPMENU2_1" );
  320.             }
  321.  
  322.             else
  323.             {
  324.                 client_print( id, print_chat, "%s %L", g_MODclient, id, "INFO_SHOPMENU2_1_DEAD" );
  325.             }
  326.         }
  327.  
  328.         case ITEM_PROTECTANT:
  329.         {
  330.             client_print( id, print_chat, "%s %L", g_MODclient, id, "INFO_SHOPMENU2_2" );
  331.         }
  332.  
  333.         case ITEM_HELM:
  334.         {
  335.             client_print( id, print_chat, "%s %L", g_MODclient, id, "INFO_SHOPMENU2_3", HELM_CHARGES );
  336.         }
  337.  
  338.         case ITEM_AMULET:
  339.         {
  340.             client_print( id, print_chat, "%s %L", g_MODclient, id, "INFO_SHOPMENU2_4" );
  341.         }
  342.  
  343.         case ITEM_SOCK:
  344.         {
  345.             client_print( id, print_chat, "%s %L", g_MODclient, id, "INFO_SHOPMENU2_5" );
  346.         }
  347.  
  348.         case ITEM_GLOVES:
  349.         {
  350.             client_print( id, print_chat, "%s %L", g_MODclient, id, "INFO_SHOPMENU2_6", get_pcvar_num( CVAR_wc3_glove_timer ) );
  351.         }
  352.  
  353.         case ITEM_RING:
  354.         {
  355.             client_print( id, print_chat, "%s %L", g_MODclient, id, "INFO_SHOPMENU2_7" );
  356.         }
  357.  
  358.         case ITEM_CHAMELEON:
  359.         {
  360.             client_print( id, print_chat, "%s %L", g_MODclient, id, "INFO_SHOPMENU2_8" );
  361.         }
  362.  
  363.         case ITEM_MOLE:
  364.         {
  365.             client_print( id, print_chat, "%s %L", g_MODclient, id, "INFO_SHOPMENU2_9" );
  366.         }
  367.     }
  368. }
  369.  
  370. // Give the user bonuses for their items (except charges)
  371. ITEM_GiveAllBonuses( id )
  372. {
  373.  
  374.     // Loop through all item slots
  375.     for ( new i = ITEM_SLOT_ONE; i <= ITEM_SLOT_TWO; i++ )
  376.     {
  377.        
  378.         // Do we have a valid item here?
  379.         if ( g_iShopMenuItems[id][i] != ITEM_NONE )
  380.         {
  381.  
  382.             // Don't want to give the user more charges for free do we?
  383.             //  And we don't want to give the bonuses if this is a next round use item (i.e. if we do then mole for infinity - that doesn't seem nice)
  384.             if ( !ITEM_CheckFlag( g_iShopMenuItems[id][i], ITEM_CHARGEABLE ) && !ITEM_CheckFlag( g_iShopMenuItems[id][i], ITEM_NEXTROUNDUSE ) )
  385.             {
  386.                 ITEM_GiveBonuses( id, g_iShopMenuItems[id][i] );
  387.             }
  388.         }
  389.     }
  390. }
  391.  
  392. // Give our players their bonus!
  393. ITEM_GiveBonuses( id, iItem )
  394. {
  395.    
  396.     // Display a message regarding the item they just purchased
  397.     switch ( iItem )
  398.     {
  399.         case ITEM_ANKH:
  400.         {
  401.             g_bPlayerBoughtAnkh[id] = true;
  402.         }
  403.  
  404.         case ITEM_BOOTS:
  405.         {
  406.             SHARED_SetSpeed( id );
  407.         }
  408.  
  409.         case ITEM_CLOAK:
  410.         {
  411.             SHARED_INVIS_Set( id );
  412.         }
  413.  
  414.         case ITEM_NECKLACE:
  415.         {
  416.             g_iNecklaceCharges[id] += NECKLACE_CHARGES;
  417.         }
  418.  
  419.         case ITEM_HEALTH:
  420.         {
  421.             new iHealth = get_pcvar_num( CVAR_wc3_health );
  422.             iHealth += get_user_health( id );
  423.             set_user_health( id, iHealth );
  424.         }
  425.  
  426.         case ITEM_SCROLL:
  427.         {
  428.             if ( !is_user_alive( id ) )
  429.             {
  430.                 ITEM_Scroll( id );
  431.             }
  432.         }
  433.  
  434.         case ITEM_HELM:
  435.         {
  436.             g_iHelmCharges[id] += HELM_CHARGES;
  437.         }
  438.  
  439.         case ITEM_SOCK:
  440.         {
  441.             SHARED_SetGravity( id );
  442.         }
  443.  
  444.         case ITEM_GLOVES:
  445.         {
  446.             ITEM_Gloves( id );
  447.         }
  448.  
  449.         case ITEM_RING:
  450.         {
  451.             g_iTotalRings[id] += RING_INCREMENT;
  452.  
  453.             if ( !task_exists( TASK_ITEM_RING + id ) )
  454.             {
  455.                 _ITEM_Ring( id );
  456.             }
  457.         }
  458.  
  459.         case ITEM_CHAMELEON:
  460.         {
  461.             SHARED_ChangeSkin( id, SKIN_SWITCH );
  462.         }
  463.  
  464.         case ITEM_MOLE:
  465.         {
  466.             g_bPlayerBoughtMole[id] = true;
  467.         }
  468.     }
  469. }
  470.  
  471. // Item Equip Function
  472. ITEM_Equip( id, iItem )
  473. {
  474.     new iItemSlot = ITEM_GetSlot( id );
  475.  
  476.     // Items are not full
  477.     if ( iItemSlot != ITEM_SLOT_FULL )
  478.     {
  479.  
  480.         new iOldItem = g_iShopMenuItems[id][iItemSlot];
  481.  
  482.         if ( iItem == iOldItem || ITEM_Has( id, iItem ) > ITEM_NONE )
  483.         {
  484.             // Might hit this if we added charges - we want to update the user's HUD
  485.             WC3_ShowBar( id );
  486.  
  487.             return;
  488.         }
  489.  
  490.         // Remove the user's old item if necessary
  491.         else if ( g_iShopMenuItems[id][iItemSlot] > ITEM_NONE )
  492.         {
  493.             ITEM_Remove( id, iItemSlot );
  494.         }
  495.            
  496.         // Set their new item
  497.         g_iShopMenuItems[id][iItemSlot] = iItem;
  498.     }
  499.  
  500.     WC3_ShowBar( id );
  501.  
  502.     return;
  503. }
  504.  
  505. // Item Remove Functions
  506. ITEM_RemoveID( id, iItem )
  507. {
  508.     new iItemSlot = ITEM_Has( id, iItem );
  509.  
  510.     if ( iItemSlot > ITEM_NONE )
  511.     {
  512.         ITEM_Remove( id, iItemSlot );
  513.     }
  514.  
  515.     return;
  516. }
  517.  
  518. ITEM_Remove( id, iItemSlot, bResetAnkhMole = true )
  519. {
  520.     new iItem = g_iShopMenuItems[id][iItemSlot];
  521.  
  522.     g_iShopMenuItems[id][iItemSlot] = ITEM_NONE;
  523.  
  524.     switch( iItem )
  525.     {
  526.         case ITEM_ANKH:
  527.         {
  528.             if ( bResetAnkhMole )
  529.             {
  530.                 g_bPlayerBoughtAnkh[id] = false;
  531.             }
  532.         }
  533.  
  534.         case ITEM_BOOTS:
  535.         {
  536.             SHARED_SetSpeed( id );
  537.         }
  538.  
  539.         case ITEM_CLOAK:
  540.         {
  541.             SHARED_INVIS_Set( id );
  542.         }
  543.  
  544.         case ITEM_NECKLACE:
  545.         {
  546.             g_iNecklaceCharges[id] = 0;
  547.         }
  548.  
  549.         case ITEM_HEALTH:
  550.         {
  551.             new iNewHealth = get_user_health( id ) - get_pcvar_num( CVAR_wc3_health );
  552.            
  553.             // Lets not kill the user, give them 1 health
  554.             iNewHealth = ( ( iNewHealth <= 0 ) ? 1 : iNewHealth );
  555.  
  556.             set_user_health( id, iNewHealth );
  557.         }
  558.  
  559.         case ITEM_HELM:
  560.         {
  561.             g_iHelmCharges[id] = 0;
  562.         }
  563.        
  564.         case ITEM_SOCK:
  565.         {
  566.             SHARED_SetGravity( id );
  567.         }
  568.  
  569.         case ITEM_GLOVES:
  570.         {
  571.             if ( task_exists( TASK_ITEM_GLOVES + id ) )
  572.             {
  573.                 remove_task( TASK_ITEM_GLOVES + id );
  574.             }
  575.         }
  576.  
  577.         case ITEM_RING:
  578.         {
  579.             if ( task_exists( TASK_ITEM_RING + id ) )
  580.             {
  581.                 remove_task( TASK_ITEM_RING + id );
  582.             }
  583.            
  584.             // Set the number of rings to 0
  585.             g_iTotalRings[id] = 0;
  586.         }
  587.  
  588.         case ITEM_CHAMELEON:
  589.         {
  590.             SHARED_ChangeSkin( id, SKIN_RESET );
  591.         }
  592.  
  593.         case ITEM_MOLE:
  594.         {
  595.             if ( bResetAnkhMole )
  596.             {
  597.                 g_bPlayerBoughtMole[id] = false;
  598.             }
  599.         }
  600.     }
  601.  
  602.     WC3_ShowBar( id );
  603.  
  604.     return;
  605. }
  606.  
  607. ITEM_RemoveCharge( id, iItem )
  608. {
  609.     if ( ITEM_Has( id, iItem ) > ITEM_NONE )
  610.     {
  611.         switch ( iItem )
  612.         {
  613.             case ITEM_NECKLACE:
  614.             {
  615.                 g_iNecklaceCharges[id] -= CHARGE_DISPOSE;
  616.                
  617.                 if ( g_iNecklaceCharges[id] <= 0 )
  618.                 {
  619.                     ITEM_RemoveID( id, iItem );
  620.                 }
  621.             }
  622.  
  623.             case ITEM_HELM:
  624.             {
  625.                 g_iHelmCharges[id] -= CHARGE_DISPOSE;
  626.                
  627.                 if ( g_iHelmCharges[id] <= 0 )
  628.                 {
  629.                     ITEM_RemoveID( id, iItem );
  630.                 }
  631.             }
  632.  
  633.             case ITEM_RING:
  634.             {
  635.                 g_iTotalRings[id] -= CHARGE_DISPOSE;
  636.                
  637.                 if ( g_iTotalRings[id] <= 0 )
  638.                 {
  639.                     ITEM_RemoveID( id, iItem );
  640.                 }
  641.             }
  642.         }
  643.     }
  644.  
  645.     WC3_ShowBar( id );
  646.     return;
  647. }
  648.  
  649.  
  650. // Item Get Functions
  651. ITEM_GetSlot( id )
  652. {
  653.     if ( g_iShopMenuItems[id][ITEM_SLOT_ONE] > ITEM_NONE && g_iShopMenuItems[id][ITEM_SLOT_TWO] > ITEM_NONE )
  654.         return ITEM_SLOT_FULL;
  655.  
  656.     else if ( g_iShopMenuItems[id][ITEM_SLOT_ONE] > ITEM_NONE )
  657.         return ITEM_SLOT_TWO;
  658.  
  659.     return ITEM_SLOT_ONE;
  660. }
  661.  
  662. ITEM_Has( id, iItem )
  663. {
  664.     if ( g_iShopMenuItems[id][ITEM_SLOT_ONE] == iItem )
  665.         return ITEM_SLOT_ONE;
  666.  
  667.     else if ( g_iShopMenuItems[id][ITEM_SLOT_TWO] == iItem )
  668.         return ITEM_SLOT_TWO;
  669.  
  670.     return ITEM_NONE;
  671. }
  672.  
  673. // Item Death Function
  674. ITEM_UserDied( id )
  675. {
  676.     // The user just died, remove all items
  677.     if ( g_iShopMenuItems[id][ITEM_SLOT_ONE] > ITEM_NONE )
  678.     {
  679.         ITEM_Remove( id, ITEM_SLOT_ONE, false );
  680.     }
  681.  
  682.     if ( g_iShopMenuItems[id][ITEM_SLOT_TWO] > ITEM_NONE )
  683.     {
  684.         ITEM_Remove( id, ITEM_SLOT_TWO, false );
  685.     }
  686. }
  687.  
  688. // Item Specific Functions
  689.  
  690. ITEM_Offensive( iAttacker, iVictim, iWeapon, iDamage, iHitPlace )
  691. {
  692.  
  693.     // Claws of Attack
  694.     if ( ITEM_Has( iAttacker, ITEM_CLAWS ) > ITEM_NONE )
  695.     {  
  696.         WC3_Damage( iVictim, iAttacker, get_pcvar_num( CVAR_wc3_claw ), iWeapon, iHitPlace );
  697.        
  698.         SHARED_Glow( iAttacker, (2 * get_pcvar_num( CVAR_wc3_claw ) ), 0, 0, 0 );
  699.  
  700.         Create_ScreenFade( iVictim, (1<<10), (1<<10), (1<<12), 255, 0, 0, g_GlowLevel[iVictim][0] );
  701.     }
  702.  
  703.     // Mask of Death
  704.     if ( ITEM_Has( iAttacker, ITEM_MASK ) > ITEM_NONE && p_data_b[iAttacker][PB_ISCONNECTED])
  705.     {
  706.         new iHealth = get_user_health( iAttacker );
  707.         new iBonusHealth = floatround( float( iDamage ) * get_pcvar_float( CVAR_wc3_mask ) );
  708.        
  709.         new iVampiricBonus = p_data_b[iAttacker][PB_HEXED] ? 0 : SM_GetSkillLevel( iAttacker, SKILL_VAMPIRICAURA );
  710.  
  711.         // Then the user already gets a bonus, lets lower the total amount the user is going to get
  712.         if ( iVampiricBonus > 0 )
  713.         {
  714.             iBonusHealth /= iVampiricBonus;
  715.         }
  716.        
  717.         // User needs to be set to max health
  718.         if ( iHealth + iBonusHealth > get_user_maxhealth( iAttacker ) )
  719.         {
  720.             set_user_health( iAttacker, get_user_maxhealth( iAttacker ) );
  721.         }
  722.        
  723.         // Give them bonus
  724.         else
  725.         {
  726.             set_user_health( iAttacker, iHealth + iBonusHealth );
  727.         }
  728.  
  729.         SHARED_Glow( iAttacker, 0, iBonusHealth, 0, 0 );
  730.  
  731.         Create_ScreenFade( iAttacker, (1<<10), (1<<10), (1<<12), 0, 255, 0, g_GlowLevel[iAttacker][1] );
  732.     }
  733.  
  734.     // Orb of Frost
  735.     if ( ITEM_Has( iAttacker, ITEM_FROST ) > ITEM_NONE )
  736.     {
  737.         // Only slow them if they aren't slowed/stunned already
  738.         if ( !SHARED_IsPlayerSlowed( iVictim ) )
  739.         {
  740.  
  741.             p_data_b[iVictim][PB_SLOWED]    = true;
  742.  
  743.             SHARED_SetSpeed( iVictim );
  744.  
  745.             set_task( 1.0, "SHARED_ResetMaxSpeed", TASK_RESETSPEED + iVictim );
  746.  
  747.             SHARED_Glow( iAttacker, 0, 0, 0, 100 );
  748.  
  749.             Create_ScreenFade( iVictim, (1<<10), (1<<10), (1<<12), 255, 255, 255, g_GlowLevel[iVictim][3] );
  750.         }
  751.     }
  752. }
  753.  
  754. ITEM_Tome( id )
  755. {
  756.     new iXp = get_pcvar_num( CVAR_wc3_tome ) + XP_GivenByLevel( p_data[id][P_LEVEL] );
  757.    
  758.     new iBonusXP = XP_Give( id, iXp );
  759.  
  760.     if ( iBonusXP != 0 )
  761.     {
  762.         client_print( id, print_chat, "%s %L", g_MODclient, id, "INFO_SHOPMENU_9", iBonusXP );
  763.     }
  764.  
  765.     emit_sound( id, CHAN_STATIC, "warcraft3/Tomes.wav", 1.0, ATTN_NORM, 0, PITCH_NORM );
  766.  
  767.     return;
  768. }
  769.  
  770. ITEM_Gloves( id )
  771. {
  772.     if ( !WC3_Check() )
  773.     {
  774.         return;
  775.     }
  776.  
  777.     if ( !SHARED_HasGrenade( id ) )
  778.     {
  779.         g_iGloveTimer[id] = 0;
  780.  
  781.         _ITEM_Glove_Give( id );
  782.     }
  783.  
  784.     return;
  785. }
  786.  
  787. ITEM_Glove_Begin( id )
  788. {
  789.     // Then lets start a timer to give them a grenade!
  790.     g_iGloveTimer[id] = get_pcvar_num( CVAR_wc3_glove_timer );
  791.  
  792.     WC3_StatusText( id, TXT_TIMER, "%d second(s) until your next grenade", g_iGloveTimer[id] );
  793.  
  794.     g_iGloveTimer[id]--;
  795.  
  796.     set_task( 1.0, "_ITEM_Glove_Give", TASK_ITEM_GLOVES + id );
  797. }
  798.  
  799. public _ITEM_Glove_Give( id )
  800. {
  801.     if ( !WC3_Check() )
  802.     {
  803.         return;
  804.     }
  805.  
  806.     if ( id >= TASK_ITEM_GLOVES )
  807.     {
  808.         id -= TASK_ITEM_GLOVES;
  809.     }
  810.  
  811.     if ( !p_data_b[id][PB_ISCONNECTED] || !is_user_alive( id ) )
  812.     {
  813.         return;
  814.     }
  815.  
  816.     // Only need to save once! - this is b/c I'm not sure when the loss of a grenade is updated - and I wanted SHARED_HasGrenade to work @ all times!
  817.     if ( g_iGloveTimer[id] == get_pcvar_num( CVAR_wc3_glove_timer ) - 1 )
  818.     {
  819.         SHARED_SaveWeapons( id );
  820.     }
  821.  
  822.     // If somehow they already got a grenade - stop this!
  823.     /*new bool:bHasGrenade = false;
  824.     if ( g_MOD == GAME_CSTRIKE || g_MOD == GAME_CZERO )
  825.     {
  826.         if ( cs_get_user_bpammo( id, CSW_HEGRENADE ) > 0 )
  827.         {
  828.             bHasGrenade = true;
  829.         }
  830.     }
  831.     */
  832.  
  833.     // Lets do CS/CZ only
  834.     if ( g_MOD == GAME_CSTRIKE || g_MOD == GAME_CZERO )
  835.     {
  836.         // Already have a grenade!!
  837.         if ( SHARED_HasGrenade( id ) )
  838.         {
  839.             g_iGloveTimer[id] = 0;
  840.  
  841.             return;
  842.         }
  843.     }
  844.  
  845.  
  846.     if ( g_iGloveTimer[id] > 0 )
  847.     {
  848.         WC3_StatusText( id, TXT_TIMER, "%d second(s) until your next grenade", g_iGloveTimer[id] );
  849.  
  850.         g_iGloveTimer[id]--;
  851.  
  852.         set_task( 1.0, "_ITEM_Glove_Give", TASK_ITEM_GLOVES + id );
  853.  
  854.         return;
  855.     }
  856.  
  857.     // Counter-Strike or Condition Zero grenade
  858.     if ( g_MOD == GAME_CSTRIKE || g_MOD == GAME_CZERO )
  859.     {
  860.         give_item( id, "weapon_hegrenade" );
  861.     }
  862.     // Display a message to the user
  863.     WC3_StatusText( id, TXT_TIMER, "%L", id, "ENJOY_A_GRENADE" )
  864.  
  865.     return;
  866. }      
  867.  
  868. ITEM_BuyRings( id )
  869. {
  870.  
  871.     new iItemSlot = ITEM_GetSlot( id );
  872.  
  873.     // Items are full
  874.     if ( iItemSlot == ITEM_SLOT_FULL && ITEM_Has( id, ITEM_RING ) == ITEM_NONE )
  875.     {
  876.         g_iFutureItem[id] = -3;
  877.  
  878.         MENU_ReplaceItem( id );
  879.  
  880.         return;
  881.     }
  882.  
  883.     new iMoney;
  884.     new iAdditionalRings = 0;
  885.    
  886.     while ( g_iTotalRings[id] + iAdditionalRings < 5 )
  887.     {
  888.         iMoney = SHARED_GetUserMoney( id );
  889.  
  890.         if ( iMoney < ITEM_Cost( id, ITEM_RING ) )
  891.         {
  892.             break;
  893.         }
  894.  
  895.         iAdditionalRings++;
  896.        
  897.         new iNewMoney = iMoney - ITEM_Cost( id, ITEM_RING );
  898.         SHARED_SetUserMoney( id, iNewMoney, 1 );
  899.     }
  900.  
  901.     // Then we need to give them some rings!
  902.     if ( iAdditionalRings > 0 )
  903.     {
  904.  
  905.         // Subtract 1 b/c ITEM_GiveItem will add one
  906.         g_iTotalRings[id] += ( ( iAdditionalRings * RING_INCREMENT ) - ( RING_INCREMENT ) );
  907.  
  908.         ITEM_GiveItem( id, ITEM_RING );
  909.     }
  910.  
  911.     return;
  912. }
  913.  
  914. public _ITEM_Ring( id )
  915. {
  916.     if ( !WC3_Check() )
  917.     {
  918.         return;
  919.     }
  920.  
  921.     if ( id >= TASK_ITEM_RING )
  922.     {
  923.         id -= TASK_ITEM_RING;
  924.     }
  925.  
  926.     if ( !p_data_b[id][PB_ISCONNECTED] || ITEM_Has( id, ITEM_RING ) == ITEM_NONE )
  927.     {
  928.         return;
  929.     }
  930.  
  931.     new iBonusHealth = g_iTotalRings[id];
  932.  
  933.     while ( iBonusHealth > 0 )
  934.     {
  935.         new iHealth =  get_user_health( id ) + 1;
  936.  
  937.         if ( iHealth <= get_user_maxhealth( id ) )
  938.         {
  939.             set_user_health( id, iHealth );
  940.         }
  941.  
  942.         iBonusHealth--;
  943.     }
  944.  
  945.     set_task( 2.0, "_ITEM_Ring", TASK_ITEM_RING + id );
  946.  
  947.     return;
  948. }
  949.  
  950. ITEM_Scroll( id )
  951. {
  952.     // Make sure the user isn't about to respawn when we do these checks
  953.     if ( !p_data[id][P_RESPAWNBY] )
  954.     {
  955.         p_data[id][P_RESPAWNBY] = RESPAWN_ITEM;
  956.  
  957.         set_task( SPAWN_DELAY, "_SHARED_Spawn", TASK_SPAWN + id );
  958.     }
  959. }
  960.  
  961. ITEM_CheckFlag( iItemID, iFlag )
  962. {
  963.     if ( g_iFlag[iItemID] & iFlag )
  964.     {
  965.         return true;
  966.     }
  967.  
  968.     return false;  
  969. }
  970.  
  971. // Format the item for WC3_ShowBar
  972. ITEM_Format( id, iItem, szItemString[], iLen )
  973. {
  974.     new szItemName[32];
  975.     LANG_GetItemName( iItem, id, szItemName, 31, true );
  976.  
  977.     // Special options
  978.     if ( iItem == ITEM_NECKLACE )
  979.     {
  980.         formatex( szItemString, iLen, "%s[%d]", szItemName, g_iNecklaceCharges[id] );
  981.     }
  982.  
  983.     else if ( iItem == ITEM_HELM )
  984.     {
  985.         formatex( szItemString, iLen, "%s[%d]", szItemName, g_iHelmCharges[id] );
  986.     }
  987.  
  988.     else if ( iItem == ITEM_RING )
  989.     {
  990.         formatex( szItemString, iLen, "%s[%d]", szItemName, g_iTotalRings[id] );
  991.     }
  992.    
  993.     // All other cases
  994.     else
  995.     {
  996.         copy( szItemString, iLen, szItemName );
  997.     }
  998. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement