Raised This Month: $ Target: $400
 0% 

Check and give weapons inaccuracy...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Unkolix
Veteran Member
Join Date: Sep 2012
Old 04-16-2013 , 15:10   Check and give weapons inaccuracy...
Reply With Quote #1

So I have this code below:
PHP Code:
public Pressedrod(idmenuitem)
{
    if( 
item == MENU_EXIT //Checks if player clicks menu exit (0)
    
{
        
menu_destroy(menu); //If so the menu will be destroyed
        
return PLUGIN_HANDLED;
    }
    new 
iFlashes cs_get_user_bpammoidCSW_FLASHBANG );
    new 
HasC4[33], HasHE[33], HasSG[33];
    
HasC4[id] = (user_has_weapon(idCSW_C4))
    
HasHE[id] = (user_has_weapon(idCSW_HEGRENADE))
    
HasSG[id] = (user_has_weapon(idCSW_SMOKEGRENADE))
    new 
data[6], szName[64];
    new 
accesscallback;
    
menu_item_getinfo(menuitemaccessdata,charsmax(data), szName,charsmax(szName), callback);
    new 
key str_to_num(data);
    if(
is_user_alive(id) && !g_bRoundEnd)
    {
        
strip_user_weaponsid );
        switch(
key)
        {
        case 
1: {                                  
                
give_item(id,"weapon_m4a1"//Gives M4A1
                
cs_set_user_bpammo(idCSW_M4A190); //Sets M4A1 back pack ammo to 90
                
client_printidprint_center"%L"id"CHOSE_M4A1" ); //Shows a message that's set in vipplugin.txt as CHOSE_M4A1
            
}
        case 
2: {     
                
give_item(id,"weapon_ak47"//Gives AK47
                
cs_set_user_bpammo(idCSW_AK4790); //Sets AK47 back pack ammo to 90
                
client_printidprint_center"%L"id"CHOSE_AK47" ); //Shows a message that's set in vipplugin.txt as CHOSE_AK47
            
}
        case 
3: { 
                
give_item(id,"weapon_awp"//Gives AWP
                
cs_set_user_bpammo(idCSW_AWP30); //Sets AWP back pack ammo to 30
                
client_printidprint_center"%L"id"CHOSE_AWP" ); //Shows a message that's set in vipplugin.txt as CHOSE_AWP
            
}
        }
        if (
HasC4[id])
        {
            
give_item(id"weapon_c4");
            
cs_set_user_plantid );
            
set_pev(idpev_body1);
        }
        if (
HasHE[id])
        {
            
give_item(id"weapon_hegrenade")
        }
        if (
HasSG[id])
        {
            
give_item(id"weapon_smokegrenade");
        }
        if( 
iFlashes 
        { 
            
give_itemid"weapon_flashbang" ); 
            
cs_set_user_bpammoidCSW_FLASHBANGiFlashes ); 
        } 
        
give_item(id,"weapon_knife"//Gives knife
        
give_item(id,"weapon_deagle"//Gives deagle
        
cs_set_user_bpammo(idCSW_DEAGLE35); //Sets deagle back pack ammo to 35
        
if(g_bHasBombSite && cs_get_user_team(id) == CS_TEAM_CT//Checks if current map has bombsite
        
{
            
give_item(id"item_thighpack"); //Gives defuse kit
        
}
        
gMenuUsed[id]++ //Makes sure that VIP really made a choice
    
}
    
menu_destroy(menu); //Destroys menu
    
return PLUGIN_CONTINUE

After I throw a grenade and really fast choose any of the cases I still get the grenade back... That's the inaccuracy, you actually don't have the grenade, but you still get it... Is it possible to fix this somehow?
Unkolix is offline
Leon M.
Senior Member
Join Date: Apr 2009
Location: Germany
Old 04-16-2013 , 17:00   Re: Check and give weapons inaccuracy...
Reply With Quote #2

I assume you use the menu very fast? If so then you should notice this behavior for all grenade types.

Take a look below. I'm using this code to check for grenades on players death accordingly so take it just as an idea.

PHP Code:
            new iAmmo cs_get_user_bpammo(idCSW_HEGRENADE)

            
// = 1 pullpin (animation is played if you press +attack)
            // = 2 thrown (animation is played if you release +attack) 
            // get_user_weapon (active weapon) and user_has_weapon  (including non-active weapons) will return true because the grenade is  still in your hand.
            
new iAnimation pev(idpev_weaponanim)
            if (
get_user_weapon(id) == CSW_HEGRENADE && (iAnimation == || iAnimation == 2iAmmo--
            if (
iAmmo 0client_print(0print_chat"Player has still a grenade"
__________________
  • ZapTic - Paintball (Version 7.1.3 b1303)
  • Your #1 CS Paintball Server since 2008
  • 85.131.163.101:27015

Last edited by Leon M.; 04-17-2013 at 03:53.
Leon M. is offline
Unkolix
Veteran Member
Join Date: Sep 2012
Old 04-17-2013 , 00:29   Re: Check and give weapons inaccuracy...
Reply With Quote #3

That's something that I am looking for, but shouldn't player not have the grenade after grenade very recently thrown?
Unkolix is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-17-2013 , 02:50   Re: Check and give weapons inaccuracy...
Reply With Quote #4

I think pev->weapons (check by user_has_weapon) is updated right after, so check bpammo in combination.
Also, when you are checking more than 1 weapon, prefer pev_weapons rather than user_has_weapon, but it's not a big deal if you prefer to stick with user_has_weapon, would be different if code would be called often as in PreThink for example.

PHP Code:
    new weapons pev(idpev_weapons)
    
HasC4[id] = ( weapons 1<<CSW_C4 )
    
HasHE[id] = ( weapons 1<<CSW_HEGRENADE ) && cs_get_user_bpammo(idCCSW_HEGRENADE)
    
HasSG[id] = ( weapons 1<<CSW_SMOKEGRENADE ) && cs_get_user_bpammo(idCCSW_SMOKEGRENADE
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 04-17-2013 at 02:51.
ConnorMcLeod is offline
Leon M.
Senior Member
Join Date: Apr 2009
Location: Germany
Old 04-17-2013 , 03:25   Re: Check and give weapons inaccuracy...
Reply With Quote #5

Quote:
Originally Posted by Unkolix View Post
That's something that I am looking for, but shouldn't player not have the grenade after grenade very recently thrown?
For some reasons which I don't know, user_has_weapon returns still true very recently. I'm using it to drop nades on players death accordingly. Sometimes a grenade got dropped although the grenade explode. As you noticed it is a small time window but it happens too often to ignore it. I don't have any issues after I've used suggested check.

Not sure about pev_weapons as Connor suggested, never tested with pev_weapons


EDIT: LOL I just realized I could check the animation, what there happens
iAnimation == 1: Sequence name is "pullpin"
iAnimation == 2: Sequence name is "thrown"

The player has still the grenade in his hands, the grenade is not flying. user_has_weapon (for non- and active weapons) must return true like get_user_weapon (for active weapon only). According to this, pev_weapons should ... must also return true. So you will need to check for active weapon and those animations.

But you can abort the pullpin if you change to another weapon, not sure if you are able to switch to another weapon if you are throwing the nade right in this moment. Maybe you want to check only for animation 2 then. Trial and error ;)
__________________
  • ZapTic - Paintball (Version 7.1.3 b1303)
  • Your #1 CS Paintball Server since 2008
  • 85.131.163.101:27015

Last edited by Leon M.; 04-17-2013 at 03:40.
Leon M. is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-17-2013 , 13:07   Re: Check and give weapons inaccuracy...
Reply With Quote #6

pev_weapons returns the same as user_has_weapon, was just a little optimization to 3 user_has_weapon calls.
bpammo check in combination with user_has_weapon or pev_weapons should solve problem (animation is not reliable because player can have few nades from the same type, flashbang by default, other nades with specific plugins).
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Unkolix
Veteran Member
Join Date: Sep 2012
Old 04-17-2013 , 13:39   Re: Check and give weapons inaccuracy...
Reply With Quote #7

Quote:
Originally Posted by ConnorMcLeod View Post
pev_weapons returns the same as user_has_weapon, was just a little optimization to 3 user_has_weapon calls.
bpammo check in combination with user_has_weapon or pev_weapons should solve problem (animation is not reliable because player can have few nades from the same type, flashbang by default, other nades with specific plugins).
Yeah, yur code works perfectly, thanks.
Unkolix 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 10:56.


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