Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Team Counter Help

  1. #1

    Default Team Counter Help

    Hi. I need some help with a script. I'm using the Team Counter script by splatter that he pulled from the Last Man Standing mod (https://www.x-null.net/forums/thread...8663#post28663), and I am having issues. When I try to load a custom map, I get this error in my logs:

    Code:
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: sv_scriptfiles 0
    
    Cvar_Set2: sv_scriptfiles 1
    
    Cvar_Set2: sv_scriptfiles 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: sv_scriptfiles 1
    
    Cvar_Set2: sv_scriptfiles 0
    
    Cvar_Set2: sv_scriptfiles 1
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: sv_scriptfiles 0
    
    Cvar_Set2: sv_scriptfiles 1
    
    Cvar_Set2: sv_scriptfiles 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: sv_scriptfiles 1
    
    Cvar_Set2: sv_scriptfiles 0
    
    Cvar_Set2: sv_scriptfiles 1
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: sv_scriptfiles 0
    
    Cvar_Set2: sv_scriptfiles 1
    
    Cvar_Set2: sv_scriptfiles 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    Cvar_Set2: axis_amount 0
    
    Cvar_Set2: allies_amount 0
    
    SV packet 24.131.71.112:12203 : rcon
    
    Rcon from 24.131.71.112:12203:
    
    map
    
    ASSERT: [fgame/g_main.cpp:94] Command overflow.  Possible infinite loop in thread.
    
    (fyi)
    
    ASSERT: [qcommon/common.c:406] Command overflow.  Possible infinite loop in thread.
    
    (fyi)



    Here is my script for the team counter:


    Code:
    main local.attacker local.damage local.inflictor local.position local.direction local.normal local.knockback local.damageflags local.meansofdeath local.location local.player: 
    if(level.mod_run)
    end
    
    if(int(getcvar("tb_hud"))!=1)
    end
    
    level.mod_run = 1
    local.result = registerev "spawn" global/teamb.scr::spawned
    local.result = registerev "kill" global/teamb.scr::killed
    local.result = registerev "connected" global/teamb.scr::connected_p
    thread loop
    thread display
    end
    
    connected_p local.player:
     
    if(local.player == NULL)
    end
     
        /// Fixes new map spawn not working
        if(local.player.dmteam != "spectator")
        {    
            wait 0.5
            thread spawned local.player
        }
    end
    
    spawned local.player:
    //if(local.player.dmteam != "spectator" && local.player.classname == "Player")
    //{
    local.player.spawned1 = 1
    //}
    end
    
    
    killed local.attacker local.damage local.inflictor local.position local.direction local.normal local.knockback local.damageflags local.meansofdeath local.location local.player:   
    if(local.player.dmteam != "spectator" && local.player.classname == "Player")
    {
    local.player.spawned1 = 0
    }
    end
    
    loop: 
    while(1)
    {
    	level.axisCount = 0
        level.alliesCount = 0
        level.axisAliveCount = 0
        level.alliesAliveCount = 0	
    
        for (local.i = 1; local.i <= $player.size; local.i++){
            local.player = $player[local.i]
            if(local.player != NULL){    
    
    			// Counts axis
    				if (local.player.dmteam == axis){
            		level.axisCount++
    				}           
                
    			// Count allies
    				if(local.player.dmteam == allies){
    				level.alliesCount++
    				}
    			}
    			
            if(local.player != NULL && isAlive(local.player) && (local.player.spawned1 == 1)){        
                
    			// Counts axis that are alive
    				if (local.player.dmteam == axis){
            		level.axisAliveCount++
            		}
                 
                // Count allies that are alive
    				if(local.player.dmteam == allies){
    				level.alliesAliveCount++			
    				}
    			}
    		}
    	
    	if (level.mef_gametype == "obj" || level.mef_gametype == "tdm") {
    	
        huddraw_font 217 "facfont-20"
        huddraw_alpha 217 0.8
        huddraw_color 217 1 0 0
        huddraw_align 217 left bottom
        huddraw_rect 217 10 -199 100 14
        //huddraw_string 217 ("Axis: " + level.axisAliveCount + " / " + level.axisCount)
    	huddraw_string 217 ("Axis:  " + level.axisCount)	
        
        huddraw_font 220 "facfont-20"
        huddraw_alpha 220 0.8
        huddraw_color 220 0.576471 0.858824 0.439216
        huddraw_align 220 left bottom
        huddraw_rect 220 10 -182 100 14
        //huddraw_string 220 ("Allies: " + level.alliesAliveCount + " / " + level.alliesCount)
    	huddraw_string 220 ("Allies: " + level.alliesCount)
    	
    	wait 5	
    	}
    }
    waitframe
    end


    The error is coming from this script, because when it is disabled, I don't have any issues. Any reason why? Thanks.

  2. #2

    Default

    The code you have here is causing a crash with a infinite loop because the delay is not on the loop
    Is outside:

    loop:
    while(1)
    {
    level.axisCount = 0
    level.alliesCount = 0
    level.axisAliveCount = 0
    level.alliesAliveCount = 0

    for (local.i = 1; local.i <= $player.size; local.i++){
    local.player = $player[local.i]
    if(local.player != NULL){

    // Counts axis
    if (local.player.dmteam == axis){
    level.axisCount++
    }

    // Count allies
    if(local.player.dmteam == allies){
    level.alliesCount++
    }
    }

    if(local.player != NULL && isAlive(local.player) && (local.player.spawned1 == 1)){

    // Counts axis that are alive
    if (local.player.dmteam == axis){
    level.axisAliveCount++
    }

    // Count allies that are alive
    if(local.player.dmteam == allies){
    level.alliesAliveCount++
    }
    }
    }

    if (level.mef_gametype == "obj" || level.mef_gametype == "tdm") {

    huddraw_font 217 "facfont-20"
    huddraw_alpha 217 0.8
    huddraw_color 217 1 0 0
    huddraw_align 217 left bottom
    huddraw_rect 217 10 -199 100 14
    //huddraw_string 217 ("Axis: " + level.axisAliveCount + " / " + level.axisCount)
    huddraw_string 217 ("Axis: " + level.axisCount)

    huddraw_font 220 "facfont-20"
    huddraw_alpha 220 0.8
    huddraw_color 220 0.576471 0.858824 0.439216
    huddraw_align 220 left bottom
    huddraw_rect 220 10 -182 100 14
    //huddraw_string 220 ("Allies: " + level.alliesAliveCount + " / " + level.alliesCount)
    huddraw_string 220 ("Allies: " + level.alliesCount)

    wait 5
    }
    }
    waitframe //delay outside
    end

  3. #3

    Default

    Thanks DK. I moved it inside and it worked.

    Now, when I uncomment this line:

    Code:
    huddraw_string 217 ("Axis: " + level.axisAliveCount + " / " + level.axisCount)
    .. and then I comment out this line:

    Code:
    huddraw_string 217 ("Axis:  " + level.axisCount)
    ...it isn't counting my players that are alive. The first number stays at 0. Is there an error that may be causing this? I don't see an error in my server log. I'm also using Purple's event handler.

  4. #4

    Default

    Is not counting the players are just alive because you missing some logic on the code.
    You are detecting when a player die but you are not decreasing on the number of players alive.

  5. #5

    Default

    I think the logic is good enough, the alive players count gets reset every new cycle of the while loop, there is no need to decrease the count

    @win151 are you sure the spawn and kill event are working?
    it must be that local.player.spawned1 != 1 and thus the count remains as 0
    try adding some message to the events to debug it

    also I suggest moving that gametype check to the while condition, otherwise you will be running the while loop for no reason
    and change the level variables to local, unless you are using those variables in another script

    something like this

    loop:
    while (level.mef_gametype == "obj" || level.mef_gametype == "tdm") {
    local.axisCount = 0
    local.alliesCount = 0
    local.axisAliveCount = 0
    local.alliesAliveCount = 0

    for (local.i = 1; local.i <= $player.size; local.i++) {
    local.player = $player[local.i]

    // Counts axis
    if (local.player && local.player.dmteam == "axis") {
    local.axisCount++

    if (isAlive local.player && local.player.spawned1) {
    local.axisAliveCount++
    }
    }

    // Count allies
    if (local.player && local.player.dmteam == "allies") {
    local.alliesCount++

    if (isAlive local.player && local.player.spawned1) {
    local.alliesAliveCount++
    }
    }
    }

    huddraw_font 217 "facfont-20"
    huddraw_alpha 217 0.8
    huddraw_color 217 1 0 0
    huddraw_align 217 "left" "bottom"
    huddraw_rect 217 10 -199 100 14
    huddraw_string 217 ("Axis: " + local.axisAliveCount + " / " + local.axisCount)
    // huddraw_string 217 ("Axis: " + local.axisCount)

    huddraw_font 220 "facfont-20"
    huddraw_alpha 220 0.8
    huddraw_color 220 0.576471 0.858824 0.439216
    huddraw_align 220 "left" "bottom"
    huddraw_rect 220 10 -182 100 14
    huddraw_string 220 ("Allies: " + local.alliesAliveCount + " / " + local.alliesCount)
    // huddraw_string 220 ("Allies: " + local.alliesCount)

    wait 5
    }
    end

  6. #6

    Default

    you could even do it like this to make your code a bit simpler.


    loop:
    while (level.mef_gametype == "obj" || level.mef_gametype == "tdm") {
    local.totalTeamCount["axis"] = 0
    local.totalTeamCount["allies"] = 0
    local.totalTeamCount["spectator"] = 0
    local.totalAliveCount["axis"] = 0
    local.totalAliveCount["allies"] = 0
    local.totalAliveCount["spectator"] = 0

    for (local.i = 1; local.i <= $player.size; local.i++) {
    local.player = $player[local.i]

    local.totalTeamCount[local.player.dmteam]++
    local.totalAliveCount[local.player.dmteam] += isAlive local.player && local.player.spawned1
    }

    huddraw_font 217 "facfont-20"
    huddraw_alpha 217 0.8
    huddraw_color 217 1 0 0
    huddraw_align 217 "left" "bottom"
    huddraw_rect 217 10 -199 100 14
    huddraw_string 217 ("Axis: " + local.totalAliveCount["axis"] + " / " + local.totalTeamCount["axis"])

    huddraw_font 220 "facfont-20"
    huddraw_alpha 220 0.8
    huddraw_color 220 0.576471 0.858824 0.439216
    huddraw_align 220 "left" "bottom"
    huddraw_rect 220 10 -182 100 14
    huddraw_string 220 ("Allies: " + local.totalAliveCount["allies"] + " / " + local.totalTeamCount["allies"])

    wait 5
    }
    end
    Last edited by 1337Smithy; May 4th, 2022 at 12:24 PM.

  7. #7
    Senior Member Ancient Order's Avatar
    Join Date
    Aug 2015
    Location
    Paris, Fr.
    Posts
    256

    Default

    Also only huddraw_string should be set every loop. huddraw_font, huddraw_alpha, huddraw_colour, huddraw_align, huddraw_rect should be set only when a player enters the level.

  8. #8

    Default

    Quote Originally Posted by Ancient Order View Post
    Also only huddraw_string should be set every loop. huddraw_font, huddraw_alpha, huddraw_colour, huddraw_align, huddraw_rect should be set only when a player enters the level.
    It'll be more efficient true as it won't need to be broadcast to every player all the time, but the loop is only running every 5 seconds rather than on a per frame basis so there is an argument to be made for readability over efficiency in some cases. But either way I'm sure it's not that big of a deal. I wouldn't say it's an absolute rule though, but a general rule of thumb.

  9. #9

    Default

    Seems like it is not capturing the spawn event. Is there something that needs to be added to the eventhandler?

    main:


    //// 1 = ON , 0 = OFF //////////////////
    level.reg_spawn = 1
    level.reg_connected = 1
    level.reg_disconnected = 1
    level.reg_intermission = 1
    level.reg_damage = 1
    level.reg_kill = 1
    level.reg_keypress = 1
    level.reg_servercommand = 1

    /// Auto Load Feature ///
    level.auto_load = 0

    ///Wait time
    level.tagwait = 10

    /// Basic Feedback Settings
    /// Displays if the events were successfully registered , already registered , Error occured or Not Event wasnt called
    level.event_feedback = 1

    /// ^^^ Basic Feedback has to be 1 aswell ^^^ //////
    /// Displays what scripts are currently exec from each event
    level.event_advancedfeedback = 1

    end

    /*
    The Feedback looks like this in console logs

    Basic Feedback SHows what events have been registered and which ones didnt
    //////////////////////////////////////////////////////////////////////

    ~~~~~~~~~~~~~~~~~ Event Handler FeedBack ~~~~~~~~~~~~~~~~~~~~

    ~~~~Successful Registered Events~~~~

    Spawn || Connected || Disconnected || Intermission || Damage || Kill Event || Keypress ||

    ~~~~Already Registered Events~~~~

    None

    ~~~~Unsuccessful Registered Events~~~~

    None

    ~~~~Events Not Called~~~~

    Servercommand

    ~~~~~~~~~~~~~~~~~ End Handler FeedBack ~~~~~~~~~~~~~~~~~~~~
    //////////////////////////////////////////////////////////////////////////////

    Advanced Feedback includes each script which which is exec in each event

    //////////////////////////////////////////////////////////////////////////////

    ~~~~~~~~~~~~~ Advanced Event Handler FeedBack ~~~~~~~~~~~~~~~~

    ~~~~Spawn Events~~~~

    global/custom/weapons.scr::spawn ||

    ~~~~Connection Events~~~~

    None

    ~~~~Disconnected Events~~~~

    None

    ~~~~Intermission Events~~~~

    None

    ~~~~Damage Events~~~~

    None

    ~~~~Kill Events~~~~

    None

    ~~~~Keypress Events~~~~

    None

    ~~~~Servercommand Events~~~~

    None

    ~~~~Duplicates Errors ~~~~

    None

    ~~~~~~~~~~~~~ End Advanced FeedBack ~~~~~~~~~~~~~~~~

    */

  10. #10

    Default

    you are not getting your spawn script registed on this part?:

    ~~~~Spawn Events~~~~

    global/custom/weapons.scr::spawn ||

    ~~~~Connection Events~~~~

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •