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

Solved End round display damage done.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
deprale
Senior Member
Join Date: Oct 2018
Location: Leeds
Old 07-17-2021 , 07:54   End round display damage done.
Reply With Quote #1

https://forums.alliedmods.net/showpo...9&postcount=39

I'm trying to execute showLastRoundDamage(id) (or in my case ShowDamage(id) ) in my Ham_Spawn hook, but it always writes that I didn't take any hit, any suggestions? I also tried to do it with
https://forums.alliedmods.net/showpo...98&postcount=1 (calling CMD_ShowDamage(id) on Ham_Spawn and I guess it gets the wrong ID each time cause it displays the damage others have done(aka 0) or sometimes I kill 5 and it shows me just one line like this) '
PHP Code:
Given: ( 0 Damage 0 Hits Taken: ( 65 Damage 1 Hitsto/from "IGRACHISHKA" (-31 HP

Code(In case u don't wanna click that stuff):
PHP Code:
new hits[33][33],
    
dmgs[33][33],
    
lives[33];

public 
plugin_init(){
    
RegisterHam(Ham_Spawn"player""PlayerHasSpawned"1);
    
RegisterHamHam_TakeDamage"player""HAM_TakeDamage_Post");
}

public 
resetScores() {
    for (new 
0charsmax(hits); ++i) {
        
arrayset(hits[i], 0charsmax(hits[]));
        
dmgs[i] = hits[i];
    }
    
lives hits[0];
}

public 
HAM_TakeDamage_Post(victiminflictorattackerfloat:damagedamagebits){
    if( !
IsPlayerattacker ) ) // make sure it's not generic damage
        
return HAM_IGNORED;
    
    if (
g_GameState == 0)
        return 
HAM_SUPERCEDE;

    
hits[victim][attacker]++;
    
dmgs[victim][attacker] += floatround(damage);
    
    return 
HAM_IGNORED;
}

public 
logevent_round_start()
{
    
set_task(5.0"resetScores"___);
    
//g_FreezeTime = false;
}

public 
PlayerHasSpawned(id){
    if(
is_user_alive(id) && g_GameState == 0){ 
        
strip_user_weapons(id)
        
give_item(id"weapon_knife")
        
give_item(id"weapon_deagle")
        
give_item(id"weapon_ak47")
        
give_item(id"weapon_m4a1")
        
cs_set_user_bpammo(idCSW_AK4790)
        
cs_set_user_bpammo(idCSW_M4A190)
        
cs_set_user_bpammo(idCSW_DEAGLE35)
        
cs_set_user_armor(id100CS_ARMOR_VESTHELM)
    }
        
//This is the important part.
    
if(get_pcvar_num(cvar_AnnounceDMG) == && (g_GameState !=&& g_RoundCount >>1) )
        
ShowDamage(id); // ughhhhhh??? 

    
}

public 
ShowDamage(id) {
    new 
message[255], username[32];
    new 
bool:tookHit false;
    
    
copy(messagecharsmax(message), "Given: ( %d Damage / %d Hits ) Taken: ( %d Damage / %d Hits) to/from ^"%s^" (%d HP)");
    
    for (new 
0charsmax(hits[]); ++i) {
        if (
hits[id][i] != || hits[i][id] != 0) {
            if (
i) {
                if (
== id)
                    
copy(usernamecharsmax(username), "self");
                else
                    
get_user_name(iusernamecharsmax(username));
            } else {
                
copy(usernamecharsmax(username), "Worldspawn");
            }
            
client_print(idprint_chatmessagemin(dmgs[i][id],100), hits[i][id], min(dmgs[id][i],100), hits[id][i], usernamelives[i]);
            
tookHit true;
        }
    }
    
    if (!
tookHit)
        
client_print(idprint_chat"You didn't take any hit in the last round.");
    
    return 
PLUGIN_HANDLED_MAIN;

This is a repost from donor section since it gets like... 0 views.
__________________

Last edited by deprale; 07-19-2021 at 21:51.
deprale is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 07-17-2021 , 08:37   Re: End round display damage done.
Reply With Quote #2

Take a look here: https://forums.alliedmods.net/showpo...33&postcount=9

https://forums.alliedmods.net/showpost.php?p=2752933
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]
Shadows Adi is offline
deprale
Senior Member
Join Date: Oct 2018
Location: Leeds
Old 07-18-2021 , 03:22   Re: End round display damage done.
Reply With Quote #3


I already did research before making this topic, and indeed I stumbled across all 'posted' solutions,including the one Bugsy posted.

The problem is always the same - I get displayed only a bit of damage (Like I can do 900 dmg to 9 ppl and I'd get nothing in chat or random int number from 0 to 100 to one single person)
Sometimes I'd get the full damage I'd done to every single one.

Can it be because I'm using get_players() to iterate through everyone to display the damage they've done and I have bots on server?
__________________
deprale is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 07-18-2021 , 12:51   Re: End round display damage done.
Reply With Quote #4

Which bots sys are you using?

Show full code also.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
deprale
Senior Member
Join Date: Oct 2018
Location: Leeds
Old 07-19-2021 , 10:24   Re: End round display damage done.
Reply With Quote #5

Quote:
Originally Posted by Natsheh View Post
Which bots sys are you using?

Show full code also.
Just normal Podbots_MM

I dont think full code is necessary since g_Gamestate is just a var I'm using to increment it when I'm switching between OVERTIME and NORMAL, and g_RoundCount is just a tracker of rounds, 2 simple vars. If you meant like full code I'm using for bots or anything like that I'm not using anything with bots, I just let them join normally from the metamod plugin

PHP Code:
new g_RoundCount
new g_GameState
new cvar_AnnounceDMG
new g_tempsc[2]; 
new 
g_Team[2];
new 
g_TeamRollBack[2];
new 
hits[33][33],
    
dmgs[33][33],
    
lives[33];

public 
plugin_init(){
    
RegisterHam(Ham_Spawn"player""PlayerHasSpawned"1);
    
RegisterHamHam_TakeDamage"player""HAM_TakeDamage_Post");
    
cvar_AnnounceDMG    register_cvar"amx_announcedamage""1");
    
register_logevent"logevent_round_start"2"1=Round_Start" );
    
register_logevent"event_roundend"2"1=Round_End" );
}

public 
resetScores() {
    for (new 
0charsmax(hits); ++i) {
        
arrayset(hits[i], 0charsmax(hits[]));
        
dmgs[i] = hits[i];
    }
    
lives hits[0];
}

public 
HAM_TakeDamage_Post(victiminflictorattackerfloat:damagedamagebits){
    if( !
IsPlayerattacker ) ) // make sure it's not generic damage
        
return HAM_IGNORED;
    
    if (
g_GameState == 0)
        return 
HAM_SUPERCEDE;

    
hits[victim][attacker]++;
    
dmgs[victim][attacker] += floatround(damage);
    
    return 
HAM_IGNORED;
}

public 
logevent_round_start()
{
    
set_task(5.0"resetScores"___);
    
//g_FreezeTime = false;
}

public 
ShowDamage(id) {
    new 
message[255], username[32];
    new 
bool:tookHit false;
    
    
copy(messagecharsmax(message), "Given: ( %d Damage / %d Hits ) Taken: ( %d Damage / %d Hits) to/from ^"%s^" (%d HP)");
    
    for (new 
0charsmax(hits[]); ++i) {
        if (
hits[id][i] != || hits[i][id] != 0) {
            if (
i) {
                if (
== id)
                    
copy(usernamecharsmax(username), "self");
                else
                    
get_user_name(iusernamecharsmax(username));
            } else {
                
copy(usernamecharsmax(username), "Worldspawn");
            }
            
client_print(idprint_chatmessagemin(dmgs[i][id],100), hits[i][id], min(dmgs[id][i],100), hits[id][i], usernamelives[i]);
            
tookHit true;
        }
    }
    
    if (!
tookHit)
        
client_print(idprint_chat"You didn't take any hit in the last round.");
    
    return 
PLUGIN_HANDLED_MAIN;


public 
PlayerHasSpawned(id){
    if(
is_user_alive(id) && g_GameState == 0){ 
        
strip_user_weapons(id)
        
give_item(id"weapon_knife")
        
give_item(id"weapon_deagle")
        
give_item(id"weapon_ak47")
        
give_item(id"weapon_m4a1")
        
cs_set_user_bpammo(idCSW_AK4790)
        
cs_set_user_bpammo(idCSW_M4A190)
        
cs_set_user_bpammo(idCSW_DEAGLE35)
        
cs_set_user_armor(id100CS_ARMOR_VESTHELM)
    }
        
//This is the important part.
    
if(get_pcvar_num(cvar_AnnounceDMG) == && (g_GameState !=&& g_RoundCount >>1) )
        
ShowDamage(id); // ughhhhhh??? 

    
}
}
public 
logevent_round_start()
{
    
set_task(5.0"resetScores"___);
    
g_FreezeTime false;
}

public 
event_roundend()
{
    switch ( 
g_GameState )
    {
    case 
0:
    {
        return(
PLUGIN_HANDLED);
    }
    case 
1:
    {
        for (new 
033; ++i) {
        
lives[i] = get_user_health(i);
        }
        
RoundEndAnnouncer();
        if ( 
g_RoundCount >= 15 )
        {
            
LIVE_CFG();
            
swapteams(); /*TO-DO also have to add save frags and money and stuff. */
        
}

        if ( 
g_RoundCount >= 30 )
        {
            if ( 
g_Team[0] == g_Team[1] )
            {
                
OVERTIME_CFG();
                
g_GameState    2;
                
g_RoundCount 0;
                
swapteams();
            }
            if ( 
g_Team[0] != g_Team[1] )
            {
                
EndGame();
            }
        }
    }
    case 
2:
    {
        for (new 
033; ++i) {
        
lives[i] = get_user_health(i);
        }
        
RoundEndAnnouncer();
        if ( 
g_RoundCount >= )
        {
            if ( 
g_Team[0] == g_Team[1] )
            {
                
g_GameState    2;
                
g_RoundCount    0;
                
swapteams(); /*TO-DO */
            
}
            if ( 
g_Team[0] - g_Team[1] == || g_Team[1] - g_Team[0] == )
            {
                
EndGame();
            }
        }
    }
    case 
3:
    {
        for (new 
033; ++i) {
        
lives[i] = get_user_health(i);
        }
        
WARMUP_CFG();
        
g_GameState 0;
    }
    default: {}
    }
    return(
PLUGIN_CONTINUE);
}
public 
LIVE_CFG(){
server_cmd("various_commands INT"//This is where I execute SERVER commands like mp_freezetime etc I feel like it's irrelevant to include ( because there's like... 60 lines only of server cvars)
}
public 
WARMUP_CFG(){
server_cmd("various_commands INT"//This is where I execute SERVER commands like mp_freezetime etc I feel like it's irrelevant to include.  ( because there's like... 60 lines only of server cvars)
}
public 
swapteams()
{
    new 
iPlayers[32] , iNum Player;
    
get_playersiPlayers iNum "ah ");
    for(new 
iNum i++ ) {
        
Player iPlayers[i];

        if(!
is_user_connectedPlayer ) )
            return 
PLUGIN_CONTINUE

        
switch( cs_get_user_teamPlayer ) )
            {
                case 
CS_TEAM_CT:
                
cs_set_user_teamPlayerCS_TEAM_T );

                case 
CS_TEAM_T:
                
cs_set_user_teamPlayerCS_TEAM_CT );
            }
        }

    
g_tempsc[0] = g_Team[0]
    
g_tempsc[1] = g_Team[1]
    
g_Team[0] = g_tempsc[1]
    
g_Team[1] = g_tempsc[0]
    if(
g_RoundCount == 15){
      
g_Team[0] = g_TeamRollBack[0]
      
g_Team[1] = g_TeamRollBack[1]
    }
    
    
restart_func()
    return 
PLUGIN_HANDLED
}
public 
RoundEndAnnouncer()
{
    new 
iPlayers[32], Player;
    
get_playersiPlayersg_iMaxPlayers"ah" );
    for ( new 
0g_iMaxPlayersi++ )
    {
        
Player iPlayers[i];
        switch ( 
g_UserKills[Player] )
        {
        case 
3: {
            if ( 
get_pcvar_num(cvar_AnnounceKills) >> )
                return(
PLUGIN_CONTINUE);
            new 
PlayerName[64];
            
get_user_namePlayerPlayerName63 );
            
client_print_color0print_team_red"%L"LANG_PLAYER"TRIPLE_KILL"PlayerNameg_Tag );
        }
        case 
4: {
            if ( 
get_pcvar_num(cvar_AnnounceKills) >> )
                return(
PLUGIN_CONTINUE);
            new 
PlayerName[64];
            
get_user_namePlayerPlayerName63 );
            
client_print_color0print_team_red"%L"LANG_PLAYER"QUAD_KILL"PlayerNameg_Tag );
            
AnnouncerSound();
        }
        case 
5: {
            if ( 
get_pcvar_num(cvar_AnnounceKills) >> )
                return(
PLUGIN_CONTINUE);
            new 
PlayerName[64];
            
get_user_namePlayerPlayerName63 );
            
client_print_color0print_team_red"%L"LANG_PLAYER"ACE_KILL"PlayerNameg_Tag );
            
AnnouncerSound();
        }
        default: {}
        }
    }
    return(
PLUGIN_HANDLED);
}
public 
glhf()
{
    switch(
g_GameState){
      case 
0: for (new 0i<5i++) client_print_color(0print_team_red"%L"LANG_PLAYER"STATE_LIVE"g_Tag)
      case 
1: for (new 0i<5i++) client_print_color(0print_team_red"%L"LANG_PLAYER"STATE_LIVE"g_Tag)
      case 
2: for (new 0i<5i++) client_print_color(0print_team_red"%L"LANG_PLAYER"STATE_OVERTIME"g_Tag)
      default:{}
    }
}
/*STUPID func */
public AnnouncerSound()
{
    
client_cmd(0, ^"spk dadeda^"")
}
stock EndGame()
{
  restart_func();
  WARMUP_CFG()
  g_RoundCount = 0
  for(new i=0; i<charsmax(g_Team); i++) g_Team[i] = 0
  g_GameState = 0

I'm aware that the logic between round counting and in general the math and coding isn't perfect, which is ok because I didn't test it yet, I haven't even gotten to test it ONCE, I'll fix probably most of the bad coding in event_roundend but honestly, This is also probably more than you wanted, but here is the full code.
PHP Code:
      description      stat pend  file              vers      src  load  unlod
 
1AMX Mod X        RUN   -    amxmodx_mm.dll    v1.10.0.  ini  Start ANY
 
2POD-Bot mm       RUN   -    podbot_mm.dll     v3.0B15c  ini  Chlvl ANY
 
3CStrike          RUN   -    cstrike_amxx.dll  v1.10.0.  pl1  ANY   ANY
 
4FakeMeta         RUN   -    fakemeta_amxx.dl  v1.10.0.  pl1  ANY   ANY
 
5Fun              RUN   -    fun_amxx.dll      v1.10.0.  pl1  ANY   ANY
 
6Engine           RUN   -    engine_amxx.dll   v1.10.0.  pl1  ANY   ANY
 
7Ham Sandwich     RUN   -    hamsandwich_amxx  v1.10.0.  pl1  ANY   ANY 
EDIT: Also, on a side-note, is it because of my round end hook, is it called too early or too late?
EDIT2: Also on another side-note, I'm also testing it only with bots on the server, I think that's important to include.
__________________

Last edited by deprale; 07-19-2021 at 10:47. Reason: full code. + removing odd comments
deprale is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 07-19-2021 , 12:44   Re: End round display damage done.
Reply With Quote #6

logevent round start = when freezetime ends

you're resetting your arrays 5 seconds into the actual round
jimaway is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 07-19-2021 , 13:07   Re: End round display damage done.
Reply With Quote #7

Why do you have two public functions named logevent_round_start() you only need one.

Also this is not how you do a loop for players indexes use get_players

PHP Code:
for (new 033; ++i) {
        
lives[i] = get_user_health(i);
        } 
I suggest you to work on the code and optimize it, its very badly coded.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 07-19-2021 at 13:13.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
deprale
Senior Member
Join Date: Oct 2018
Location: Leeds
Old 07-19-2021 , 21:29   Re: End round display damage done.
Reply With Quote #8

Quote:
Originally Posted by Natsheh View Post
Why do you have two public functions named logevent_round_start() you only need one.

Also this is not how you do a loop for players indexes use get_players

PHP Code:
for (new 033; ++i) {
        
lives[i] = get_user_health(i);
        } 
I suggest you to work on the code and optimize it, its very badly coded.
Something like this?
PHP Code:
    new players[32], pnumtempid
    get_players
(playerspnum)
    
    for( new 
ii<pnumi++ ) 
    {
    
tempid players[i
    } 
I just haven't coded in a long while, the part with 2 logevent_round_end is just me being clumsy and copy pasting the same code two times (My bad), and to be fair that really wasn't my code(the for lives loop and in general the stuff I couldn't get to work.), its from somebody else who posted in the thread I linked.

I've noted your suggestions and I'll get to fix them soon.

Quote:
Originally Posted by jimaway View Post
logevent round start = when freezetime ends

you're resetting your arrays 5 seconds into the actual round
I knew I was being stupid by not doing THIS instead Thanks for the heads-up!
PHP Code:
register_event"HLTV""event_newround""a""1=0""2=0" ); 

EDIT2: Ended up using wrecked_'s method (overall better code) https://forums.alliedmods.net/showpo...98&postcount=1 , I reset my arrays in newround now instead of logevent round start(which fixed my issue of not seeing damage done/received), and I removed the !(IsPlayer) check in the fakemeta hook (Ham_TakeDamage) and now the damage is displayed properly (because I am testing with bots, but will eventually put it back when I'm done testing with bots.)

Thanks @Natsheh @jimaway!
__________________

Last edited by deprale; 07-19-2021 at 21:50. Reason: formatting and edit2
deprale is offline
Reply


Thread Tools
Display Modes

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 02:32.


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