AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HELP] get_user_weapons (https://forums.alliedmods.net/showthread.php?t=306978)

GoldNux 04-21-2018 12:39

[HELP] get_user_weapons
 
I'm trying to print primary, secondary, grenades and kit to chat.
And I'm testing get_user_weapons using this code, but its not working.

Can someone tell me why?

Code:
const WEAPONS_TO_LOOK_FOR = ( 1 << CSW_USP ) | ( 1 << CSW_M4A1 ); public plugin_init() {     register_clcmd("say test", "testFunction") }     public testFunction(id) {     static iWeapons[32], iNum, i;     iNum = 0;     get_user_weapons(id, iWeapons, iNum);     for(i = 0; i < iNum; i++)     if((1 << iWeapons[i]) & WEAPONS_TO_LOOK_FOR)     {         client_cmd(id, "%d %d", iWeapons[0], iWeapons[1])     } }

Natsheh 04-21-2018 13:13

Re: [HELP] get_user_weapons
 
if(get_user_weapons(id,....) & ((1<<CSW_M4A1)|(1<<CSW_USP)))
User has m4a1 and usp

GoldNux 04-21-2018 13:22

Re: [HELP] get_user_weapons
 
Quote:

Originally Posted by Natsheh (Post 2588735)
if(get_user_weapons(id,....) & ((1<<CSW_M4A1)|(1<<CSW_USP)))
User has m4a1 and usp

Do you mean it only prints if the player has both?
I have tried triggering this while carrying both usp and M4A1.

Nothing happens.

Bugsy 04-21-2018 13:44

Re: [HELP] get_user_weapons
 
@GoldNux: Are you trying to print a players primary, secondary, grenades and kit to chat? Or only if they have those 2 weapons?

Quote:

Originally Posted by Natsheh (Post 2588735)
if(get_user_weapons(id,....) & ((1<<CSW_M4A1)|(1<<CSW_USP)))
User has m4a1 and usp

That will only check if he has one of the two or both weapons, not guaranteed to have both.

Any time you want to check for both, you will need to check that both flags are in the result.
PHP Code:

if ( ( get_user_weaponsid iWeapons iNum ) & ( ( 1<<CSW_M4A1 ) | ( 1<<CSW_USP ) ) ) == ( ( 1<<CSW_M4A1 ) | ( 1<<CSW_USP ) ) )
{
    
//Player has M4A1 and USP



GoldNux 04-21-2018 13:54

Re: [HELP] get_user_weapons
 
Quote:

Originally Posted by Bugsy (Post 2588741)
@GoldNux: Are you trying to print a players primary, secondary, grenades and kit to chat? Or only if they have those 2 weapons?



That will only check if he has one of the two or both weapons, not guaranteed to have both.

Any time you want to check for both, you will need to check that both flags are in the result.
PHP Code:

if ( ( get_user_weaponsid iWeapons iNum ) & ( ( 1<<CSW_M4A1 ) | ( 1<<CSW_USP ) ) ) == ( ( 1<<CSW_M4A1 ) | ( 1<<CSW_USP ) ) )
{
    
//Player has M4A1 and USP



I'm trying to check for: guns (both prim and sec), grenades and kit.
I would like to store these in a variable each and print it in chat.

I'm a beginner, have not done much coding at all.
This is what my plugin looks like:

Code:
#include <amxmodx> #include <amxmisc> #include <cstrike> #include <cromchat> #include <fun> #define PLUGIN "gn_showmoney" #define VERSION "0.3" #define AUTHOR "GoldNuX" public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_event("HLTV", "eventNewRound", "a", "1=0", "2=0")     register_cvar("gn_showmoney", "0")     register_concmd("gn_setmoney","setMoney", ADMIN_KICK, "<amount>") } public setMoney(id, level, cid) {     if (!cmd_access(id, level, cid, 1))     {         return PLUGIN_HANDLED     }     if (is_user_alive(id) && cs_get_user_team(id) != CS_TEAM_SPECTATOR && !is_user_hltv(id))     {         new arg1[6]         read_argv(1, arg1, charsmax(arg1))         new amount = str_to_num(arg1)         cs_set_user_money(id, amount)     }     return PLUGIN_CONTINUE } public eventNewRound() {     if (!get_cvar_num("gn_showmoney"))     return PLUGIN_CONTINUE;     new players[32];     new playercount, i;     get_players(players, playercount);     for (i=0; i<playercount; i++)     set_task(0.0,"printColorText",players[i]);     return PLUGIN_CONTINUE; } public printColorText(id) {     new primaryWeapon[7]     new secondaryWeapon[6]     new smokeGrenade[4]     new flashGrenade[4]     new heGrenade[4]     new kit[4]     new armor[4]         new name[32]     get_user_name(id, name, charsmax(name))     new money = cs_get_user_money(id)     if (!is_user_hltv(id) && cs_get_user_team(id) != CS_TEAM_SPECTATOR && user_has_weapon(id, CSW_AK47 || CSW_M4A1 || CSW_GALIL || CSW_FAMAS || CSW_AWP || CSW_SCOUT || CSW_G3SG1 || CSW_SG550 || CSW_SG552 || CSW_MP5NAVY || CSW_AUG))     {         if (user_has_weapon(id, CSW_AK47))             primaryWeapon = "AK-47"         else if (user_has_weapon(id, CSW_M4A1))             primaryWeapon = "M4A1"         else if (user_has_weapon(id, CSW_GALIL))             primaryWeapon = "GALIL"         else if (user_has_weapon(id, CSW_FAMAS))             primaryWeapon = "FAMAS"         else if (user_has_weapon(id, CSW_AWP))             primaryWeapon = "AWP"         else if (user_has_weapon(id, CSW_SCOUT))             primaryWeapon = "SCOUT"         else if (user_has_weapon(id, CSW_G3SG1))             primaryWeapon = "CG3SG1"         else if (user_has_weapon(id, CSW_SG550))             primaryWeapon = "SG550"         else if (user_has_weapon(id, CSW_SG552))             primaryWeapon = "SG552"         else if (user_has_weapon(id, CSW_MP5NAVY))             primaryWeapon = "MP5N"         else if (user_has_weapon(id, CSW_AUG))             primaryWeapon = "AUG"     }     if (!is_user_hltv(id) && cs_get_user_team(id) != CS_TEAM_SPECTATOR && user_has_weapon(id, CSW_DEAGLE || CSW_USP || CSW_GLOCK18))     {         if (user_has_weapon(id, CSW_DEAGLE))             secondaryWeapon = "DGL"         else if (user_has_weapon(id, CSW_USP))             secondaryWeapon = "USP"         else if (user_has_weapon(id, CSW_GLOCK18))             secondaryWeapon = "GLOCK"     }     if (!is_user_hltv(id) && cs_get_user_team(id) != CS_TEAM_SPECTATOR && user_has_weapon(id, CSW_SMOKEGRENADE || CSW_FLASHBANG || CSW_HEGRENADE))     {         if (user_has_weapon(id, CSW_SMOKEGRENADE))             smokeGrenade = "〇"         else if (user_has_weapon(id, CSW_FLASHBANG))             flashGrenade = "〙"         else if (user_has_weapon(id, CSW_HEGRENADE))             heGrenade = "※"     }     if (!is_user_hltv(id) && cs_get_user_team(id) != CS_TEAM_SPECTATOR && user_has_weapon(id, CSW_VESTHELM))     {         armor = "웃"     }     if (!is_user_hltv(id) && cs_get_user_team(id) != CS_TEAM_SPECTATOR && user_has_weapon(id, CSW_VEST))     {         armor = "回"     }     if (!is_user_hltv(id) && cs_get_user_team(id) != CS_TEAM_SPECTATOR && cs_get_user_defuse(id) == 1)     {         kit = "•"     }     if (cs_get_user_team(id) == CS_TEAM_T && !is_user_hltv(id) && cs_get_user_team(id) != CS_TEAM_SPECTATOR)     {         if (money < 3000)             CC_GroupMessage("ae", "TERRORIST", "%s:&x05 $ %d %d %d %d %d %d %d %d", name, money, primaryWeapon, secondaryWeapon, smokeGrenade, flashGrenade, heGrenade, kit, armor)         else if (money > 3000 && money < 3500)             CC_GroupMessage("ae", "TERRORIST", "%s:&x07 $ %d %d %d %d %d %d %d %d", name, money, primaryWeapon, secondaryWeapon, smokeGrenade, flashGrenade, heGrenade, kit, armor)         else if (money > 3500 && money < 10000)             CC_GroupMessage("ae", "TERRORIST", "%s:&x04 $ %d %d %d %d %d %d %d %d", name, money, primaryWeapon, secondaryWeapon, smokeGrenade, flashGrenade, heGrenade, kit, armor)         else if (money > 10000)             CC_GroupMessage("ae", "TERRORIST", "%s:&x06 $ %d %d %d %d %d %d %d %d", name, money, primaryWeapon, secondaryWeapon, smokeGrenade, flashGrenade, heGrenade, kit, armor)     }     else if (cs_get_user_team(id) == CS_TEAM_CT && !is_user_hltv(id) && cs_get_user_team(id) != CS_TEAM_SPECTATOR)     {         if (money < 3250)             CC_GroupMessage("ae", "CT", "%s:&x05 $ %d %d %d %d %d %d %d %d", name, money, primaryWeapon, secondaryWeapon, smokeGrenade, flashGrenade, heGrenade, kit, armor)         else if (money > 3250 && money < 4100)             CC_GroupMessage("ae", "CT", "%s:&x07 $ %d %d %d %d %d %d %d %d", name, money, primaryWeapon, secondaryWeapon, smokeGrenade, flashGrenade, heGrenade, kit, armor)         else if (money > 4100 && money < 10000)             CC_GroupMessage("ae", "CT", "%s:&x04 $ %d %d %d %d %d %d %d %d", name, money, primaryWeapon, secondaryWeapon, smokeGrenade, flashGrenade, heGrenade, kit, armor)         else if (money > 10000)             CC_GroupMessage("ae", "CT", "%s:&x06 $ %d %d %d %d %d %d %d %d", name, money, primaryWeapon, secondaryWeapon, smokeGrenade, flashGrenade, heGrenade, kit, armor)     } }

Bugsy 04-21-2018 21:07

Re: [HELP] get_user_weapons
 
Not sure what the intent is with this. Since your delay is 0.0 seconds then you should call printColorText() directly without using set_task().
Code:
public eventNewRound() {     if (!get_cvar_num("gn_showmoney"))     return PLUGIN_CONTINUE;     new players[32];     new playercount, i;     get_players(players, playercount);     for (i=0; i<playercount; i++)     set_task(0.0,"printColorText",players[i]);     return PLUGIN_CONTINUE; }
Here's some help with getting the player data
PHP Code:

new const m_rgpPlayerItems_CBasePlayer[6] = { 367 368 , ... };  

public 
ShowInfoid )
{
    new 
iSlotItem szItemList128 ] , iPos szName32 ] , szWeapon20 ] , CsArmorType:csaType iWeaponBits;
    
    
get_user_nameid szName charsmaxszName ) );
    
iPos += formatexszItemListiPos ] , charsmaxszItemList ) - iPos "%s, $%d, " szName cs_get_user_moneyid ) );
    
    for ( new 
iSlot iSlot iSlot++ )
    {
        
iSlotItem WeaponInSlotid iSlot );
        
        if ( 
iSlotItem > -)
        {
            
get_weaponnameiSlotItem szWeapon charsmaxszWeapon ) );
            
iPos += formatexszItemListiPos ] , charsmaxszItemList ) - iPos "%s, " szWeapon] );
        }
    }
    
    
iWeaponBits pevid pev_weapons );
    
    if ( 
iWeaponBits & ( << CSW_HEGRENADE ) )
    {
        
iPos += formatexszItemListiPos ] , charsmaxszItemList ) - iPos "hegrenade, " );
    }

    if ( ( 
iWeaponBits & ( << CSW_FLASHBANG ) ) )
    {
        
iPos += formatexszItemListiPos ] , charsmaxszItemList ) - iPos "flash, " );
    }
    
    if ( ( 
iWeaponBits & ( << CSW_SMOKEGRENADE ) ) )
    {
        
iPos += formatexszItemListiPos ] , charsmaxszItemList ) - iPos "smoke, " );
    }
    
    if ( 
cs_get_user_armorid csaType ) )
    {
        
iPos += formatexszItemListiPos ] , charsmaxszItemList ) - iPos csaType == CS_ARMOR_KEVLAR "V, " "VH, " );
    }
    
    if ( 
cs_get_user_defuseid ) )
    {
        
iPos += formatexszItemListiPos ] , charsmaxszItemList ) - iPos "D, " );
    }
    
    
szItemListiPos ] = EOS;
    
    
client_printid print_chat szItemList );
}

WeaponInSlotid iSlot

    new 
iEntity get_pdata_cbaseid m_rgpPlayerItems_CBasePlayeriSlot ] ); 
    
    return ( 
iEntity > -cs_get_weapon_idiEntity ) : -);



GoldNux 04-22-2018 09:10

Re: [HELP] get_user_weapons
 
Quote:

Originally Posted by Bugsy (Post 2588806)
Here's some help with getting the player data...

Wow impressive! Thanks for this.
It is working great!

I can't use the colorchat because for some reason it prints to both teams even when I use the team flag. So I will be using "say_team" instead.

I tried to remove the name in the print, but I ended up messing up the code.
Could you please do me this last favor and properly remove the name?

You rock! Thanks again.

Bugsy 04-22-2018 10:59

Re: [HELP] get_user_weapons
 
Name removed
PHP Code:

public ShowInfoid )
{
    new 
iSlotItem szItemList128 ] , iPos szWeapon20 ] , CsArmorType:csaType iWeaponBits;
    
    
iPos formatexszItemListiPos ] , charsmaxszItemList ) - iPos "$%d, " cs_get_user_moneyid ) ); 



All times are GMT -4. The time now is 04:36.

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