AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   getting weapons (https://forums.alliedmods.net/showthread.php?t=54299)

Mini_Midget 04-22-2007 07:32

getting weapons
 
PHP Code:

if ( !get_pcvar_num g_switch ) )
        return 
PLUGIN_HANDLED
    
    
if ( !get_pcvar_num g_grenade ) )  
    {
        
client_printid print_chat "[AmxX] Currently unable to purchase grenades." )
    }
    
    if ( !
is_user_alive (id) || !is_user_connected (id) ) 
    {  
        
client_print (id print_chat "[AmxX] Unable to buy HE-Grenade due to your status (Dead)." )  
    }
    
    new 
money cs_get_user_money (id)
    new 
clip ammo weapon get_user_weapon id clip ammo )
    
    new 
multi get_pcvar_num g_multi )
    
    if ( 
weapon == CSW_HEGRENADE )
    {
        
client_print id print_chat "[AmxX] You already own one," )
    }
    else if ( 
money < ( multi g_he_nade ) )
    {
        
client_print id print_chat "[AmxX] You do not have enough money." )
    }
    else
    {
        
give_item (id "weapon_hegrenade" )
        
cs_set_user_money id money - ( multi g_he_nade ) )
        
client_print id print_chat ,  "[AmxX] Thank you for using Emergency Ammo!" )
    }
    
    return 
PLUGIN_HANDLED


I'm trying to check if the player has a HE or not. The problem is that get_user_weapon only works if the player is actually holding a HE in his hands.

For eg
I try to buy a HE buy with the script above (type /ammoh) and I'm holding a USP but I already have a HE. It still gives me a HE even though I'm maxed out on it. I want something to check the whole player if he has a weapon or not CARRYING it not currently HOLDING it.

regalis 04-22-2007 08:00

Re: getting weapons
 
I think you might find what you searching for here: http://www.amxmodx.org/doc/source/fu...er_weapons.htm
;)

greetz regalis

Mini_Midget 04-22-2007 08:10

Re: getting weapons
 
Oh cheers!

Never used that function before.

Can you show me how to use it with the example above?

regalis 04-22-2007 08:22

Re: getting weapons
 
I never used it too :P

But maybe something like this:
Code:

new Weapons[32]
new numWeapons, i, weapon
get_user_weapons(id, Weapons, numWeapons)
for (i=0; i<numWeapns; i++)
{
  weapon = Weapons[i]
  if ( weapon == CSW_HEGRENADE )
    {
        client_print ( id , print_chat , "[AmxX] You already own one," )
    }
    else if ( money < ( multi * g_he_nade ) )
    {
        new bool:noMoney = true
    }
    else
    {
        new bool:giveGrenade = true
    }
}
if(noMoney)    client_print(id , print_chat, "[AmxX] You do not have enough money." )

if(giveGrenade)
{
    give_item (id , "weapon_hegrenade" )
  cs_set_user_money ( id , money - ( multi * g_he_nade ) )
  client_print ( id , print_chat ,  "[AmxX] Thank you for using Emergency Ammo!" )
}
return PLUGIN_HANDLED

greetz regalis

PS: thx 4 karma :)

Mini_Midget 04-22-2007 08:59

Re: getting weapons
 
PHP Code:

public cmd_ammoh (id)
{
    if ( !
get_pcvar_num g_switch ) )
        return 
PLUGIN_HANDLED
    
    
if ( !get_pcvar_num g_grenade ) )  
    {
        
client_printid print_chat "[AmxX] Currently unable to purchase grenades." )
    }
    
    if ( !
is_user_alive (id) || !is_user_connected (id) ) 
    {  
        
client_print (id print_chat "[AmxX] Unable to buy HE-Grenade due to your status (Dead)." )  
    }
    
    new 
money cs_get_user_money (id)
    new 
multi get_pcvar_num g_multi )
    
    new 
weapons[32
    new 
numweapon
    
    get_user_weapons
(idweaponsnum)
    for(new 
0numi++)
    {
        
weapon weapons[i];
        
        if ( 
weapon == CSW_HEGRENADE )
        {
            
client_print id print_chat "[AmxX] You already own one," )
        }
    }
    if ( 
money < ( multi g_he_nade ) )
    {
        
client_print id print_chat "[AmxX] You do not have enough money." )
    }
    else
    {
        
give_item (id "weapon_hegrenade" )
        
cs_set_user_money id money - ( multi g_he_nade ) )
        
client_print id print_chat ,  "[AmxX] Thank you for using Emergency Ammo!" )
    }
    
    return 
PLUGIN_HANDLED


I'm trying to use this but it has this bug in it.

When I have a HE already. (Doesn't matter if I have it in my hands or not) and I type the command to buy. These 2 messages display.
[AmxX] You already own one!
[AmxX] Thank you for using Emergency Ammo!

AND it still charges me money even though I have one.

regalis 04-22-2007 09:08

Re: getting weapons
 
I think you should use a bool with that you can trace if the player have already a nade ;)

try this:
Code:

public cmd_ammoh (id)
{
    if ( !get_pcvar_num ( g_switch ) )
        return PLUGIN_HANDLED
   
    if ( !get_pcvar_num ( g_grenade ) ) 
    {
        client_print( id , print_chat , "[AmxX] Currently unable to purchase grenades." )
    }
   
    if ( !is_user_alive (id) || !is_user_connected (id) )
    { 
        client_print (id , print_chat , "[AmxX] Unable to buy HE-Grenade due to your status (Dead)." ) 
    }
   
    new money = cs_get_user_money (id)
    new multi = get_pcvar_num ( g_multi )
    new bool:haveOne

    new weapons[32]
    new num, weapon
   
    get_user_weapons(id, weapons, num)
    for(new i = 0; i < num; i++)
    {
        weapon = weapons[i];
       
        if ( weapon == CSW_HEGRENADE )
        {
            client_print ( id , print_chat , "[AmxX] You already own one," )
            haveOne = true
        }
    }
    if ((money < ( multi * g_he_nade )) && (!haveOne))
    {
        client_print ( id , print_chat , "[AmxX] You do not have enough money." )
    }
    else if(!haveOne)
    {
        give_item (id , "weapon_hegrenade" )
        cs_set_user_money ( id , money - ( multi * g_he_nade ) )
        client_print ( id , print_chat ,  "[AmxX] Thank you for using Emergency Ammo!" )
    }
   
    return PLUGIN_HANDLED
}


Ryu2877 04-23-2007 01:47

Re: getting weapons
 
For this case, My juvenile idea of checking user has especial weapon:
PHP Code:

stock bool:bHasWeapon(iUserIDiWeaponID)
{
    if ( 
is_user_alive(iUserID) && pev(iUserIDpev_weapons) & (1<<iWeaponID) )
        return 
true
    
return false


"iWeaponID" is "CSW_*"


All times are GMT -4. The time now is 20:54.

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