I am making a few items on my own. But all of them seems to have the same problem; they all cost 2 ammo packs?
I can't change it using the cvars I created, or even hard coding it doesn't work. How come this is happening? Am I doing it wrong? Once the item is bought it work as it should.
PHP Code:
#include <amxmodx>
#include <fun>
#include <cstrike>
#include <fakemeta>
#include <hamsandwich>
#include <zp50_items>
//basic item stuff
new gItemID
new gHasItem[33]
//cvars
new pcvarTimeToAdd
new pcvarAmmoToAdd
//runs on server start/changelevel
public plugin_init()
{
//register the plugin with the server
register_plugin("[ZP] Extra: Unlimited ammo", "1.0", "Jelle")
//cvars
new pcvarCost = register_cvar("zp_unlimitedammo_cost", "10")
pcvarTimeToAdd = register_cvar("zp_unlimitedammo_timetoadd", "1")
pcvarAmmoToAdd = register_cvar("zp_unlimitedammo_ammotoadd", "5")
//make ZP register this item
gItemID = zp_items_register("Unlimited Ammo", get_pcvar_num(pcvarCost))
set_task(get_pcvar_float(pcvarTimeToAdd), "add_bullets", _, _, _, "b")
}
//after user has bought this item this runs
public zp_fw_items_select_post(id, itemid)
{
//if the item he bought is not this one do nothing
if ( gItemID != itemid ) return
//let him know this has run
client_print(id, print_chat, "[ZP] Bought unlimited ammo!")
//let plugin know he got it
gHasItem[id] = true
}
public add_bullets()
{
static players[32], playerCount, player, i
get_players(players, playerCount, "ah")
for ( i = 0; i < playerCount; i++ )
{
player = players[i]
if ( gHasItem[player] )
{
new ca
//find what weapon type the player has
switch(get_user_weapon(player))
{
case CSW_P228 : ca = 13;
case CSW_SCOUT : ca = 10;
case CSW_HEGRENADE : ca = 1;
case CSW_XM1014 : ca = 7;
case CSW_C4 : ca = 1;
case CSW_MAC10 : ca = 30;
case CSW_AUG : ca = 30;
case CSW_SMOKEGRENADE : ca = 1;
case CSW_ELITE : ca = 15;
case CSW_FIVESEVEN : ca = 20;
case CSW_UMP45 : ca = 25;
case CSW_SG550 : ca = 30;
case CSW_GALI : ca = 35;
case CSW_FAMAS : ca = 25;
case CSW_USP : ca = 12;
case CSW_GLOCK18 : ca = 20;
case CSW_AWP : ca = 10;
case CSW_MP5NAVY : ca = 30;
case CSW_M249 : ca = 100;
case CSW_M3 : ca = 8;
case CSW_M4A1 : ca = 30;
case CSW_TMP : ca = 30;
case CSW_G3SG1 : ca = 20;
case CSW_FLASHBANG : ca = 2;
case CSW_DEAGLE: ca = 7;
case CSW_SG552 : ca = 30;
case CSW_AK47 : ca = 30;
case CSW_P90 : ca = 50;
}
new currentAmmo = cs_get_weapon_ammo(get_pdata_cbase( player, 373 ))
new newAmmo = currentAmmo+get_pcvar_num(pcvarAmmoToAdd)
//This checks if ca is higher or the equal to the new ammo which will be set
if (newAmmo <= ca)
{
//Now lets set the new ammo!
cs_set_weapon_ammo(get_pdata_cbase( player, 373 ), newAmmo)
}
//what if ca = 30, and new ammo is bigger than the max? then new ammo will be 32 in a 30 max clip weapon??
else
{
//Then we just set the max bullets into the gun!
cs_set_weapon_ammo(get_pdata_cbase( player, 373 ), ca)
}
}
}
}
//runs each time someone dies
public client_death(killer, victim)
{
//now make sure no one has this if they die
gHasItem[victim] = false
}
//runs when someone joins the server
public client_connect(id)
{
//make sure new people dont have this item
gHasItem[id] = false
}
//runs when someone disconnect
public client_disconnect(id)
{
//make sure they dont have this item still
gHasItem[id] = false
}
__________________