Raised This Month: $ Target: $400
 0% 

Solved it keep just print 1, whatever which weapon i'm handling


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
zonbarbar
Member
Join Date: Jul 2022
Old 07-25-2023 , 11:37   it keep just print 1, whatever which weapon i'm handling
Reply With Quote #1

i don't know how is this going, any another better way to make this happen?

code:
public Action CheckPlayerWeapon(Handle timer)
{

for(int client = 1; client <= MaxClients; client++)
{

if(IsSurvivor(client) && IsPlayerAlive(client) && !IsFakeClient(client))
{

int weapon = GetPlayerWeaponSlot(client, 0);
if (weapon == -1)
{
return Plugin_Continue;
}

char weaponClass[32];
GetEdictClassname(weapon, weaponClass, sizeof(weaponClass));

if(StrEqual(weaponClass, "weapon_smg_mp5")||(weaponClass, "weapon_rifle")||(weaponClass, "weapon_sniper_military"))
{
PrintToChat(client, "1");
}
else if(StrEqual(weaponClass, "weapon_rifle_desert")||(weaponClass, "weapon_sniper_awp")||(weaponClass, "weapon_shotgun_spas"))
{
PrintToChat(client, "2");
}
else if(StrEqual(weaponClass, "weapon_smg")||(weaponClass, "weapon_rifle_ak47")||(weaponClass, "weapon_shotgun_chrome"))
{
PrintToChat(client, "3");
}
else if(StrEqual(weaponClass, "weapon_autoshotgun")||(weaponClass, "weapon_sniper_scout")||(weaponClass, "weapon_rifle_sg552"))
{
PrintToChat(client, "4");
}
else if(StrEqual(weaponClass, "weapon_hunting_rifle")||(weaponClass, "weapon_smg_silenced")||(weaponClass, "weapon_pumpshotgun"))
{
PrintToChat(client, "5");
}
else
{
PrintToChat(client, "6");
}
return Plugin_Continue;
}
return Plugin_Continue;
}
return 0;
}

Last edited by zonbarbar; 07-25-2023 at 13:45.
zonbarbar is offline
zonbarbar
Member
Join Date: Jul 2022
Old 07-25-2023 , 11:51   Re: it keep just print 1, whatever which weapon i'm handling
Reply With Quote #2

and bots look like will not be check, this is timer code: CreateTimer(1.0, CheckPlayerWeapon, client, TIMER_REPEAT);
zonbarbar is offline
Red Flame
Junior Member
Join Date: Jan 2012
Old 07-25-2023 , 12:58   Re: it keep just print 1, whatever which weapon i'm handling
Reply With Quote #3

You need to check weapons like this:
Code:
if (StrEqual(weaponClass, "weapon_smg_mp5") || StrEqual(weaponClass, "weapon_rifle") || StrEqual(weaponClass, "weapon_sniper_military"))
etc...
I underlined a missing stuff.

But in every string we have "weapon_" so we don't need to check this every time, we may do it like this:
Code:
if (strcmp(weaponClass[7], "smg_mp5") == 0 || strcmp(weaponClass[7], "rifle") == 0 || strcmp(weaponClass[7], "sniper_military") == 0)
You don't need to put client index in this timer
Code:
CreateTimer(1.0, CheckPlayerWeapon, _, TIMER_REPEAT);

Last edited by Red Flame; 07-25-2023 at 13:02.
Red Flame is offline
zonbarbar
Member
Join Date: Jul 2022
Old 07-25-2023 , 13:45   Re: it keep just print 1, whatever which weapon i'm handling
Reply With Quote #4

Quote:
Originally Posted by Red Flame View Post
You need to check weapons like this:
Code:
if (StrEqual(weaponClass, "weapon_smg_mp5") || StrEqual(weaponClass, "weapon_rifle") || StrEqual(weaponClass, "weapon_sniper_military"))
etc...
I underlined a missing stuff.

But in every string we have "weapon_" so we don't need to check this every time, we may do it like this:
Code:
if (strcmp(weaponClass[7], "smg_mp5") == 0 || strcmp(weaponClass[7], "rifle") == 0 || strcmp(weaponClass[7], "sniper_military") == 0)
You don't need to put client index in this timer
Code:
CreateTimer(1.0, CheckPlayerWeapon, _, TIMER_REPEAT);
alright, i see
zonbarbar is offline
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 07-27-2023 , 03:32   Re: it keep just print 1, whatever which weapon i'm handling
Reply With Quote #5

PHP Code:
public Action CheckPlayerWeapon(Handle timer)
{
    
char wpn[24];
    for(
int i 1weapon<= MaxClientsi++)
        if(
IsSurvivor(i) && !IsFakeClient(i) && IsPlayerAlive(i) && (weapon GetPlayerWeaponSlot(i0)) != -1)
        {
            
GetEdictClassname(weaponwpnsizeof(wpn));
            if(!
strcmp(wpn[7], "smg_mp5") || !strcmp(wpn[7], "rifle") || !strcmp(wpn[7], "sniper_military"))
                
PrintToChat(i"1");
            else if(!
strcmp(wpn[7], "rifle_desert") || !strcmp(wpn[7], "sniper_awp") || !strcmp(wpn[7], "shotgun_spas"))
                
PrintToChat(i"2");
            else if(!
strcmp(wpn[7], "smg") || !strcmp(wpn[7], "rifle_ak47") || !strcmp(wpn[7], "shotgun_chrome"))
                
PrintToChat(i"3");
            else if(!
strcmp(wpn[7], "autoshotgun") || !strcmp(wpn[7], "sniper_scout") || !strcmp(wpn[7], "rifle_sg552"))
                
PrintToChat(i"4");
            else if(!
strcmp(wpn[7], "hunting_rifle") || !strcmp(wpn[7], "smg_silenced") || !strcmp(wpn[7], "pumpshotgun"))
                
PrintToChat(i"5");
            else 
PrintToChat(i"6");
        }

    return 
Plugin_Continue;

This code will send number by timer to survivors.

But maybe it's better to show the number only when the player has picked up a weapon?
PHP Code:
public void OnClientPutInServer(int client)
{
    if(!
IsFakeClient(client)) SDKHook(clientSDKHook_WeaponEquipPostHook_WeaponEvent);
}

public 
void Hook_WeaponEvent(int clientint weapon)
{
    
RequestFrame(RequestFrame_CallbackGetClientUserId(client));
}

public 
void RequestFrame_Callback(any client)
{
    static 
int weapon;
    if(!(
client GetClientOfUserId(client)) || !IsPlayerAlive(client) || (weapon GetPlayerWeaponSlot(client0)) == -1)
        return;

    
GetEdictClassname(weaponwpnsizeof(wpn));
    if(!
strcmp(wpn[7], "smg_mp5") || !strcmp(wpn[7], "rifle") || !strcmp(wpn[7], "sniper_military"))
        
PrintToChat(client"1");
    else if(!
strcmp(wpn[7], "rifle_desert") || !strcmp(wpn[7], "sniper_awp") || !strcmp(wpn[7], "shotgun_spas"))
        
PrintToChat(client"2");
    else if(!
strcmp(wpn[7], "smg") || !strcmp(wpn[7], "rifle_ak47") || !strcmp(wpn[7], "shotgun_chrome"))
        
PrintToChat(client"3");
    else if(!
strcmp(wpn[7], "autoshotgun") || !strcmp(wpn[7], "sniper_scout") || !strcmp(wpn[7], "rifle_sg552"))
        
PrintToChat(client"4");
    else if(!
strcmp(wpn[7], "hunting_rifle") || !strcmp(wpn[7], "smg_silenced") || !strcmp(wpn[7], "pumpshotgun"))
        
PrintToChat(client"5");
    else 
PrintToChat(client"6");

__________________

Last edited by Grey83; 07-27-2023 at 03:43.
Grey83 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 17:52.


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