Raised This Month: $32 Target: $400
 8% 

[HELP] What am I doing wrong here?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GoldNux
Senior Member
Join Date: Mar 2018
Old 04-19-2018 , 15:18   [HELP] What am I doing wrong here?
Reply With Quote #1

I'm trying to write a plugin that displays the number of enemies still alive on the other team.
It does not work and I can't figure out why..

Problems:
When I test it with bots, the counter show 0.
When I test it with humans, the counter still show 0.
Counter is only visible for CTs
WARNING [46]: tag mismatch: if (get_user_team(victim) == CS_TEAM_T)
WARNING [51]: tag mismatch: if (get_user_team(victim) == CS_TEAM_CT)

Questions when problems are solved:
How do I make it so that players can enable/disable this function.
Is this code hard on the CPU, will it cause the server to lag?

Thank you very much.

Code:
#include <amxmodx> #include <amxmisc> #include <cstrike> #include <fun> #define PLUGIN "gn_enemiesleft" #define VERSION "0.1" #define AUTHOR "GoldNux" public plugin_init() {     set_hudmessage(0, 255, 0, 0.009, 0.00, 0, 6.0, 105.0, 0.3, 0.3, 1)     register_plugin(PLUGIN, VERSION, AUTHOR)     register_event("HLTV", "eventNewRound", "a", "1=0", "2=0")     register_event( "DeathMsg" , "registerDeath" , "a" ); } new playersT[32] new playersCT[32] new playerCount_T new playerCount_CT new playersAliveT new playersAliveCT public eventNewRound() {     get_players(playersCT, playerCount_CT, "e", "CT")     get_players(playersT, playerCount_T, "e", "TERRORIST")     playersAliveT = playerCount_T     playersAliveCT = playerCount_CT     new iCT     for (iCT = 0; iCT < playerCount_CT; iCT++)     show_hudmessage(playersCT[iCT], "%d", playersAliveT)     new iT     for (iT = 0; iT < playerCount_T; iT++)     show_hudmessage(playersT[iT], "%d", playersAliveCT) } public registerDeath() {     new victim = read_data(2);     if (get_user_team(victim) == CS_TEAM_T)     {         playersAliveT--         updateCT_HUD     }     if (get_user_team(victim) == CS_TEAM_CT)     {         playersAliveCT--         updateT_HUD     } } public updateCT_HUD()     {         new i         for (i = 0; i < playerCount_CT; i++)         show_hudmessage(playersCT[i], "%d", playersAliveT)     } public updateT_HUD()     {         new i         for (i = 0; i < playerCount_T; i++)         show_hudmessage(playersT[i], "%d", playersAliveCT)     }
__________________
Try my version of de_dust2, I think it's great and you should check it out!
https://gamebanana.com/mods/83731

Last edited by GoldNux; 04-19-2018 at 15:27.
GoldNux is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 04-19-2018 , 20:03   Re: [HELP] What am I doing wrong here?
Reply With Quote #2

You're totally wrong. Let me explain every single thing that you did wrong:

1. You don't need to create a global array in this situation, same as the integers. You should just create them in the function itself.
2. You're setting the hud's parameters in the init, wtf? Do it in the function, same as 1.
3. The tag mismatch, is because you're using get_user_team() native which returns numbers with CS_TEAM_T/CS_TEAM_CT. You should use 1/2 or change to cs_get_user_team().
4. You don't need to decrease the number in the death msg because get_players() has "a" flag which returns only alive players.
5. You don't need to use the loop to show the alive players.

So, the right thing to do, is simple:

PHP Code:
#include <amxmodx>

#define VERSION "1.0"

public plugin_init() 
{
    
register_plugin("Show Alive Players"VERSION"IDK")
    
    
set_task(1.0"showAlivePlayers", .flags "b")
}

public 
showAlivePlayers()
{
    new 
iPlayers[32], iNum[2]
    
get_players(iPlayersiNum[0], "ae""CT")
    
get_players(iPlayersiNum[1], "ae""TERRORIST")
    
    if((
iNum[0] + iNum[1]) <= 1)
        return
        
    
set_hudmessage(025500.0090.0006.0105.00.30.31)
    
show_hudmessage(0"CTs: %d TRs: %d"iNum[0], iNum[1])

__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx 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 22:44.


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