AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Detect if the weapon has a bullet (https://forums.alliedmods.net/showthread.php?t=325606)

wicho 06-29-2020 03:09

Detect if the weapon has a bullet
 
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)



HamletEagle 06-29-2020 03:27

Re: Detect if the weapon has a bullet
 
https://www.amxmodx.org/api/cstrike/cs_get_weapon_ammo

wicho 06-29-2020 03:30

Re: Detect if the weapon has a bullet
 
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)



HamletEagle 06-29-2020 03:57

Re: Detect if the weapon has a bullet
 
I don't know, stop using magic numbers and name offsets properly. How can anyone understand what 373 is without searching?

wicho 06-29-2020 12:53

Re: Detect if the weapon has a bullet
 
Is this 373 = offset m_pActiveItem

HamletEagle 06-29-2020 13:00

Re: Detect if the weapon has a bullet
 
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).


All times are GMT -4. The time now is 16:56.

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