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

Detect if the weapon has a bullet


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
wicho
Veteran Member
Join Date: Feb 2012
Location: GuateAmala
Old 06-29-2020 , 03:09   Detect if the weapon has a bullet
Reply With Quote #1

Hi everyone, well I'm doing something like a mini game of usp (pistol) that tries that when the round begins it gives everyone a usp with only one bullet ready to fire, every 5 seconds it gives a bullet, my question is how can I to detect if the player still has the bullet? What I want to do is that if the player still has the bullet, he will not get another bullet, so he will not accumulate bullets, but until he has no bullets and so on.

PHP Code:
#include <amxmodx>
#include <fun>
#include <cstrike>

#define PLUGIN "Battle Usp"
#define VERSION "1.0"
#define AUTHOR "khe"

new g_MaxPlayers

#define TASK_BULLET 655

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_event("HLTV""NewRound""a""1=0""2=0")

    
g_MaxPlayers get_maxplayers()
}

public 
NewRound() 
{    
    for (new 
id 1id <= g_MaxPlayersid++)
    {
        if (!
is_user_alive(id))
            continue

        
show_menu(id0"^n"1)        
        
strip_user_weapons(id)   
        
cs_set_weapon_ammo(give_item(id"weapon_usp"), 1)
        
set_task(5.0"Task_GiveBullet"id+TASK_BULLET__"b")
    }
}

public 
Task_GiveBullet(id)
{
    
id -= TASK_BULLET
    
    cs_set_weapon_ammo
(give_item(id"weapon_usp"), 1)

wicho is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 06-29-2020 , 03:27   Re: Detect if the weapon has a bullet
Reply With Quote #2

https://www.amxmodx.org/api/cstrike/cs_get_weapon_ammo
__________________
HamletEagle is offline
wicho
Veteran Member
Join Date: Feb 2012
Location: GuateAmala
Old 06-29-2020 , 03:30   Re: Detect if the weapon has a bullet
Reply With Quote #3

Its okay like this?

PHP Code:
public Task_GiveBullet(id)
{
    
id -= TASK_BULLET
    
    
if (cs_get_weapon_ammo(get_pdata_cbase(id373)) >= 1)
        return
    
    
cs_set_weapon_ammo(find_ent_by_owner(-1"weapon_usp"id), 1)


Last edited by wicho; 06-29-2020 at 03:31.
wicho is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 06-29-2020 , 03:57   Re: Detect if the weapon has a bullet
Reply With Quote #4

I don't know, stop using magic numbers and name offsets properly. How can anyone understand what 373 is without searching?
__________________
HamletEagle is offline
wicho
Veteran Member
Join Date: Feb 2012
Location: GuateAmala
Old 06-29-2020 , 12:53   Re: Detect if the weapon has a bullet
Reply With Quote #5

Is this 373 = offset m_pActiveItem
wicho is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 06-29-2020 , 13:00   Re: Detect if the weapon has a bullet
Reply With Quote #6

So use it like this in your code:
PHP Code:
new const m_pActiveItem 373

if (cs_get_weapon_ammo(get_pdata_cbase(idm_pActiveItem )) >= 1
This should work if players have only ups(no other items, not even knife).
PHP Code:

new activeItem get_pdata_cbase(idm_pActiveItem)
//check to see if activeItem entity is valid

if (cs_get_weapon_ammo(activeItem) >= 1)
        return
    
cs_set_weapon_ammo(activeItem1
If they can have more items, you need to check m_rgpPlayerItems[1](1 = pistol slot) offset(either directly, if they can have only USP or loop thru it using m_pNext if they can have 2 or more pistols).
__________________

Last edited by HamletEagle; 06-29-2020 at 13:01.
HamletEagle is offline
Reply


Thread Tools
Display Modes

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 09:02.


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