Raised This Month: $51 Target: $400
 12% 

API Scripting Help Problem with cost of items


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Jelle
[b]MOAR CANDY[/b]
Join Date: Aug 2009
Location: Denmark
Old 06-25-2012 , 12:10   Problem with cost of items
Reply With Quote #1

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(iditemid)
{
    
//if the item he bought is not this one do nothing
    
if ( gItemID != itemid ) return
    
    
//let him know this has run
    
client_print(idprint_chat"[ZP] Bought unlimited ammo!")
    
//let plugin know he got it
    
gHasItem[id] = true
}

public 
add_bullets()
{
    static 
players[32], playerCountplayeri
    get_players
(playersplayerCount"ah")

    for ( 
0playerCounti++ )
    {
        
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_DEAGLEca 7;
            case 
CSW_SG552 ca 30;
            case 
CSW_AK47 ca 30;
            case 
CSW_P90 ca 50;
            }
            
            new 
currentAmmo cs_get_weapon_ammo(get_pdata_cbaseplayer373 ))
            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_cbaseplayer373 ), 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_cbaseplayer373 ), ca)
            }
        }
    }
}

//runs each time someone dies
public client_death(killervictim)
{
    
//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

__________________
No idea what to write here...
Jelle is offline
Send a message via MSN to Jelle
H.RED.ZONE
Veteran Member
Join Date: Sep 2011
Location: Serbia, Belgrade
Old 06-25-2012 , 18:40   Re: Problem with cost of items
Reply With Quote #2

Try.
PHP Code:
#include <amxmodx>
#include <cstrike>
#include <hamsandwich>

#include <zp50_items> // extra items
#include <zp50_class_nemesis> // nemesis
#include <zp50_class_survivor> // survivor 

#define _PLUGIN   "[ZP] Extra: Unlimited ammo"
#define _VERSION           "1.0"
#define _AUTHOR           "Jelle"

#define _MarkPlayerHasItem(%0)  _bitIsHasItem |= (1 << (%0 & 31))
#define _ClearPlayerHasItem(%0) _bitIsHasItem &= ~(1 << (%0 & 31))
#define _IsHasItem(%0)          _bitIsHasItem & (1 << (%0 & 31))

new _bitIsHasItem

new gItemID

new pcvarTimeToAdd
    
,pcvarAmmoToAdd
    
,pcvarCost

new _pcvar_enable
    
,_pcvar_allow_survivor
    
,_pcvar_enable_human    
    
public plugin_init() {
    
register_plugin(_PLUGIN_VERSION_AUTHOR)
    
gItemID zp_items_register("Unlimited Ammo"get_pcvar_num(pcvarCost))
    
    
// Cvars
    
_pcvar_enable register_cvar("zp_unlimitedammo_enabled""1")
    
_pcvar_allow_survivor register_cvar("zp_unlimitedammo_survivor""0")
    
_pcvar_enable_human register_cvar("zp_unlimitedammo_human""1")
    
    
pcvarCost register_cvar("zp_unlimitedammo_cost""10")
    
pcvarTimeToAdd register_cvar("zp_unlimitedammo_timetoadd""1")
    
pcvarAmmoToAdd register_cvar("zp_unlimitedammo_ammotoadd""5")
    
    
set_task(get_pcvar_float(pcvarTimeToAdd), "add_bullets"___"b")    
}

public 
zp_fw_items_select_post(iditemid) {
    if (
itemid == gItemID) {
        
client_print(idprint_chat"[ZP] Bought unlimited ammo!")
        
_MarkPlayerHasItem(id)
    }
}

public 
zp_fw_items_select_pre(iditemid)
{
    if (
itemid == gItemID)
    {
        if (
get_pcvar_num(_pcvar_enable) == 0)
            return 
ZP_ITEM_DONT_SHOW;
            
        if (
get_pcvar_num(_pcvar_enable_human) == && !zp_core_is_zombie(id))
            return 
ZP_ITEM_DONT_SHOW;
        
        if (
zp_core_is_zombie(id))
            return 
ZP_ITEM_DONT_SHOW;    
            
        if (
get_pcvar_num(_pcvar_allow_survivor) == && zp_class_survivor_get(id))
            return 
ZP_ITEM_DONT_SHOW;
            
        if (
zp_class_nemesis_get(id))
            return 
ZP_ITEM_DONT_SHOW;
        
        return 
ZP_ITEM_AVAILABLE;
    }
    return 
ZP_ITEM_AVAILABLE;
}

public 
add_bullets() {
    static 
players[32], playerCountplayeri
    get_players
(playersplayerCount"ah")

    for ( 
0playerCounti++ ) {
        
player players[i]

        if ( 
_IsHasItem(player) ) {
            
            new 
ca
            
            
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_DEAGLEca 7;
                case 
CSW_SG552 ca 30;
                case 
CSW_AK47 ca 30;
                case 
CSW_P90 ca 50;
            }
            
            new 
currentAmmo cs_get_weapon_ammo(get_pdata_cbaseplayer373 ))
            new 
newAmmo currentAmmo+get_pcvar_num(pcvarAmmoToAdd)
            
            if (
newAmmo <= ca) {
                
                
cs_set_weapon_ammo(get_pdata_cbaseplayer373 ), newAmmo)
            }
            else {
                
cs_set_weapon_ammo(get_pdata_cbaseplayer373 ), ca)
            }
        }
    }
}

public 
client_death(killervictim) {
    
_ClearPlayerHasItem(victim)
}

public 
client_connect(id) {
    
_ClearPlayerHasItem(id)
}

public 
client_disconnect(id) {
    
_ClearPlayerHasItem(id)

__________________
H.RED.ZONE is offline
Jelle
[b]MOAR CANDY[/b]
Join Date: Aug 2009
Location: Denmark
Old 06-26-2012 , 17:46   Re: Problem with cost of items
Reply With Quote #3

Thank you.

I will try this. It is kind off hard when there is not much for zp 5.0 to look at, and I don't really know the natives and forwards yet.

Although it seems to be much more complicated than with 4.3. One include file, one main plugin. Way easier to keep track of.
__________________
No idea what to write here...
Jelle is offline
Send a message via MSN to Jelle
Y060N
BANNED
Join Date: Dec 2011
Location: www.equilibriumcs.com
Old 07-01-2012 , 16:59   Re: Problem with cost of items
Reply With Quote #4

Terrible idea to do infinite tasks in plugin init. You declare the cvar as a new variable in init, just do as follows:

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 pcvarAmmoToAdd
new pcvarCost

//runs on server start/changelevel
public plugin_init()
{
    
//register the plugin with the server
    
register_plugin("[ZP] Extra: Unlimited ammo""1.0""Jelle")
    
    
//cvars
    
pcvarCost register_cvar("zp_unlimitedammo_cost""10")
    
pcvarAmmoToAdd register_cvar("zp_unlimitedammo_ammotoadd""5")
    
    
//make ZP register this item
    
gItemID zp_items_register("Unlimited Ammo"get_pcvar_num(pcvarCost))
}

//after user has bought this item this runs
public zp_fw_items_select_post(iditemid)
{
    
//if the item he bought is not this one do nothing
    
if ( gItemID != itemid ) return
    
    
//let him know this has run
    
client_print(idprint_chat"[ZP] Bought unlimited ammo!")
    
//let plugin know he got it
    
gHasItem[id] = true
}

public 
add_bullets()
{
    static 
players[32], playerCountplayeri
    get_players
(playersplayerCount"ah")

    for ( 
0playerCounti++ )
    {
        
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_DEAGLEca 7;
            case 
CSW_SG552 ca 30;
            case 
CSW_AK47 ca 30;
            case 
CSW_P90 ca 50;
            }
            
            new 
currentAmmo cs_get_weapon_ammo(get_pdata_cbaseplayer373 ))
            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_cbaseplayer373 ), 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_cbaseplayer373 ), ca)
            }
        }
    }
}

//runs each time someone dies
public client_death(killervictim)
{
    
//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

If you want to add it after the gamemode has started or something let me know and I will help you out.

Last edited by Y060N; 07-01-2012 at 17:07.
Y060N is offline
H.RED.ZONE
Veteran Member
Join Date: Sep 2011
Location: Serbia, Belgrade
Old 07-01-2012 , 22:16   Re: Problem with cost of items
Reply With Quote #5

Look at the unlimited ammo plugin in zp 5.0 that would be the best way as i know...
__________________
H.RED.ZONE is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:57.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode