• Why is the Team.AddScore() function broken?
    8 replies, posted
I was making a new gamemode and I decided to copy the base gamemode and just change some functions around while still deriving from the base. Everything was going ok and working like normal until I tried to use the Team.AddScore function. Whenever I try to use the function and then print its response it says its score is 1 but it never changes from 0. Code: [lua] --[[--------------------------------------------------------- Name: gamemode:PlayerDeath( ) Desc: Called when a player dies. -----------------------------------------------------------]] function GM:PlayerDeath( ply, inflictor, attacker ) -------------------------------------------------------------------------------------------------------------------------------Start My Code //Add points to team for tdm if attacker:Team() != ply:Team() and GetConVarNumber( "esp_pointsperkill") == 1 then team.AddScore( attacker:Team(), 1 ) print("Attacker Score: "..team.GetScore(attacker:Team())) end //Auto Assign code if math.abs( #team.GetPlayers(1) - #team.GetPlayers(2) ) >= 2 then ply:SetTeam( team.BestAutoJoinTeam() ) end --Test Spectate code //ply:Spectate(OBS_MODE_CHASE) -------------------------------------------------------------------------------------------------------------------------------End My Code -- Don't spawn for at least 2 seconds ply.NextSpawnTime = CurTime() + 2 ply.DeathTime = CurTime() if ( IsValid( attacker ) && attacker:GetClass() == "trigger_hurt" ) then attacker = ply end if ( IsValid( attacker ) && attacker:IsVehicle() && IsValid( attacker:GetDriver() ) ) then attacker = attacker:GetDriver() end if ( !IsValid( inflictor ) && IsValid( attacker ) ) then inflictor = attacker end -- Convert the inflictor to the weapon that they're holding if we can. -- This can be right or wrong with NPCs since combine can be holding a -- pistol but kill you by hitting you with their arm. if ( IsValid( inflictor ) && inflictor == attacker && ( inflictor:IsPlayer() || inflictor:IsNPC() ) ) then inflictor = inflictor:GetActiveWeapon() if ( !IsValid( inflictor ) ) then inflictor = attacker end end if ( attacker == ply ) then net.Start( "PlayerKilledSelf" ) net.WriteEntity( ply ) net.Broadcast() MsgAll( attacker:Nick() .. " suicided!\n" ) return end if ( attacker:IsPlayer() ) then net.Start( "PlayerKilledByPlayer" ) net.WriteEntity( ply ) net.WriteString( inflictor:GetClass() ) net.WriteEntity( attacker ) net.Broadcast() MsgAll( attacker:Nick() .. " killed " .. ply:Nick() .. " using " .. inflictor:GetClass() .. "\n" ) return end net.Start( "PlayerKilled" ) net.WriteEntity( ply ) net.WriteString( inflictor:GetClass() ) net.WriteString( attacker:GetClass() ) net.Broadcast() MsgAll( ply:Nick() .. " was killed by " .. attacker:GetClass() .. "\n" ) end [/lua] I have tried moving the PlayerDeath function to the init.lua file instead of it being inside of the player.lua file and it didn't work. I have tried getting the score and adding one to it before setting it. I have tried changing how the game-mode was derived from. I have tried messing with the team.setup functions. Nothing appears to be working. Does anyone know what is going on? Thank you in advance, I know its gonna be something stupidly retardly simple that was staring me int he face but I can't get it.
It seems to be noted as a shared function in the wiki which could mean it isn't networked by itself but the wiki has been wrong on other occasions... The team library is missing a few functions by default and can be odd to mess around with. Make sure you set up the teams in a SHARED file in GM:CreateTeams( ) because if it is networked, if the client doesn't have the team in the table then they won't be able to see the change since the key doesn't exist... Edit: It seems to be networked just fine; the only thing I see myself doing differently is setting the teams up using GM:CreateTeams( ) ( or in a shared environment ).... Server: [code]Dropped Acecool from server (Disconnect by user.) lua_run team.AddScore( 1, 1 ) > team.AddScore( 1, 1 )... lua_run team.AddScore( 1, 1 ) > team.AddScore( 1, 1 )... lua_run team.AddScore( 1, 1 ) > team.AddScore( 1, 1 )... lua_run print( team.GetScore( 1 ) ) > print( team.GetScore( 1 ) )... 3 [AcecoolDev] Bans-Bot: [ "Acecool" STEAM_0:1:4173055 ] Client "Acecool" connected (10.0.0.2:27006). [ Debugging AcecoolDev ] DatabasePlayerInfo: Account Exists: Acecool STEAM_0: 1:4173055 sv_cheats 1 [AcecoolDev]- _p PlayerSpawn Player [1][Acecool][STEAM_0:1:4173055] has fully connected. ( 8847.455078125 ) [ Debugging AcecoolDev ] DatabasePlayerInfo: Account Loaded: [1] lua_run team.AddScore( 1, 1 ) > team.AddScore( 1, 1 )... lua_run team.AddScore( 1, 1 ) > team.AddScore( 1, 1 )... lua_run print( team.GetScore( 1 ) ) > print( team.GetScore( 1 ) )... 5 [/code] Client: [code]Characters Count: 0 ] lua_run_cl print( team.GetScore( 1 ) ) 3 ] lua_run_cl print( team.GetScore( 1 ) ) 5 [/code] Where 1 is a valid team, TEAM_CIVILIAN... I disconnected, set it to 3, reconnected output as 3, added 2 more to ensure networking and it printed 5 on both client and server... Edit 2: I just tested with an UNKNOWN team 99999 and it still worked just fine... Make sure you're running a LOCAL SRCDS for dev work; make sure maxplayers is > 1 otherwise you'll be in singleplayer. If you're testing using singleplayer or the gmod client as the server, you'll get bad results on an actual server.. Make a local SRCDS if you haven't already, it's easy: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/server_srcds_steamcmd/setting_up_a_server_with_steamcmd.lua.html[/url]
[QUOTE=Acecool;47072573]It seems to be noted as a shared function in the wiki which could mean it isn't networked by itself but the wiki has been wrong on other occasions... The team library is missing a few functions by default and can be odd to mess around with. Make sure you set up the teams in a SHARED file in GM:CreateTeams( ) because if it is networked, if the client doesn't have the team in the table then they won't be able to see the change since the key doesn't exist... Edit: It seems to be networked just fine; the only thing I see myself doing differently is setting the teams up using GM:CreateTeams( ) ( or in a shared environment ).... Server: [code]Dropped Acecool from server (Disconnect by user.) lua_run team.AddScore( 1, 1 ) > team.AddScore( 1, 1 )... lua_run team.AddScore( 1, 1 ) > team.AddScore( 1, 1 )... lua_run team.AddScore( 1, 1 ) > team.AddScore( 1, 1 )... lua_run print( team.GetScore( 1 ) ) > print( team.GetScore( 1 ) )... 3 [AcecoolDev] Bans-Bot: [ "Acecool" STEAM_0:1:4173055 ] Client "Acecool" connected (10.0.0.2:27006). [ Debugging AcecoolDev ] DatabasePlayerInfo: Account Exists: Acecool STEAM_0: 1:4173055 sv_cheats 1 [AcecoolDev]- _p PlayerSpawn Player [1][Acecool][STEAM_0:1:4173055] has fully connected. ( 8847.455078125 ) [ Debugging AcecoolDev ] DatabasePlayerInfo: Account Loaded: [1] lua_run team.AddScore( 1, 1 ) > team.AddScore( 1, 1 )... lua_run team.AddScore( 1, 1 ) > team.AddScore( 1, 1 )... lua_run print( team.GetScore( 1 ) ) > print( team.GetScore( 1 ) )... 5 [/code] Client: [code]Characters Count: 0 ] lua_run_cl print( team.GetScore( 1 ) ) 3 ] lua_run_cl print( team.GetScore( 1 ) ) 5 [/code] Where 1 is a valid team, TEAM_CIVILIAN... I disconnected, set it to 3, reconnected output as 3, added 2 more to ensure networking and it printed 5 on both client and server... Edit 2: I just tested with an UNKNOWN team 99999 and it still worked just fine... Make sure you're running a LOCAL SRCDS for dev work; make sure maxplayers is > 1 otherwise you'll be in singleplayer. If you're testing using singleplayer or the gmod client as the server, you'll get bad results on an actual server.. Make a local SRCDS if you haven't already, it's easy: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/server_srcds_steamcmd/setting_up_a_server_with_steamcmd.lua.html[/url][/QUOTE] Thanks for the response. I did setupt he teams in the shared.lua file like this: [lua] --[[--------------------------------------------------------- Name: gamemode:CreateTeams() Desc: Note - HAS to be shared. -----------------------------------------------------------]] function GM:CreateTeams() -- Don't do this if not teambased. But if it is teambased we -- create a few teams here as an example. If you're making a teambased -- gamemode you should override this function in your gamemode --[[ Good guys MI6 (UNITED KINGDOM) CIA (UNITED STATES) CSIS (CANADA) MAD (GERMANY) Bad guys SVR (RUSSIA) SSD (NORTH KOREA) MSS (CHINA) MOIS (IRAN) --]] --[[ CSS MODELS Good "models/player/arctic.mdl", "models/player/phoenix.mdl", "models/player/guerilla.mdl", "models/player/leet.mdl" Bad "models/player/urban.mdl", "models/player/swat.mdl", "models/player/gasmask.mdl", "models/player/riot.mdl" --]] --The first part is the team name, the second part is the models used for that team gteams = { { "MI6", ""}, { "CIA", "" }, { "CSIS", "" }, { "MAD", "" }, } bteams = { { "SVR", "" }, { "SSD", "" }, { "MSS", "" }, { "MOIS", "" }, } if ( !GAMEMODE.TeamBased ) then return end local gvar = GetConVarNumber("esp_goodteam" ) local bvar = GetConVarNumber("esp_badteam" ) TEAM_GOOD = 1 //team.SetUp( TEAM_GOOD , "Team 1", Color( 0, 0, 255 ) ) team.SetUp( 1 , "TEAM_GOOD", Color( 0, 0, 255), true ) //team.SetSpawnPoint( TEAM_GOOD , "ai_hint" ) -- <-- This would be info_terrorist or some entity that is in your map team.SetSpawnPoint( 1 , "info_player_counterterrorist" ) -- <-- This would be info_terrorist or some entity that is in your map TEAM_BAD = 2 //team.SetUp( TEAM_BAD, "Team 2", Color( 255, 0, 0 ) ) team.SetUp( 2, "TEAM_BAD", Color( 255, 0, 0), true ) //team.SetSpawnPoint( TEAM_BAD, "sky_camera" ) -- <-- This would be info_terrorist or some entity that is in your map team.SetSpawnPoint( 2, "info_player_terrorist" ) -- <-- This would be info_terrorist or some entity that is in your map team.SetSpawnPoint( TEAM_SPECTATOR, "worldspawn" ) end [/lua]
All of that looks good but the "TEAM_GOOD" isn't a good "name".., the commented out versions are good: TEAM_SPECTATORS = 1001; team.SetUp( TEAM_SPECTATORS, "Spectators", color_white ); or so... because team.GetName( TEAM_SPECTATORS ); would then return Spectators. although what you've named them won't hurt... Where are you trying to output the information? If it is on the score-board or vgui panel, you'd need to manually update them. If it is on the HUD you should have no problem. Can you show where you're retrieving the score?
[QUOTE=Acecool;47073249]All of that looks good but the "TEAM_GOOD" isn't a good "name".., the commented out versions are good: TEAM_SPECTATORS = 1001; team.SetUp( TEAM_SPECTATORS, "Spectators", color_white ); or so... because team.GetName( TEAM_SPECTATORS ); would then return Spectators. although what you've named them won't hurt... Where are you trying to output the information? If it is on the score-board or vgui panel, you'd need to manually update them. If it is on the HUD you should have no problem. Can you show where you're retrieving the score?[/QUOTE] The name didn't matter cause I was making the name change visually for different maps, also I tried to see the score from both the console on the server side and the client by using the hud. [lua] --[[--------------------------------------------------------- Name: gamemode:HUDPaint( ) Desc: Use this section to paint your HUD -----------------------------------------------------------]] function GM:HUDPaint() draw.DrawText( gteams[GetConVarNumber("esp_goodteam" )][1]..": "..team.GetScore(1) , "TargetID", ScrW() * 0.5 - 200, 50, Color( 255, 255, 255, 255 ), TEXT_ALIGN_CENTER ) draw.DrawText( bteams[GetConVarNumber("esp_badteam" )][1]..": "..team.GetScore(2) , "TargetID", ScrW() * 0.5 + 200, 50, Color( 255, 255, 255, 255 ), TEXT_ALIGN_CENTER ) hook.Run( "HUDDrawTargetID" ) hook.Run( "HUDDrawPickupHistory" ) hook.Run( "DrawDeathNotice", 0.85, 0.04 ) //hook.Run( "DrawDeathNotice", 0.12, 0.45 ) end [/lua]
Ok I just redid the game-mode and its still not working. I am starting to feel like a addon is breaking this or something, because nothing I have done has worked. I have even tried verifying my game cache.
I found where team.AddScore sets the data. It uses Global Vars to set data; my networking system overwrites a lot of those systems and puts the data into my flag system so it may be interfering with the results I posted above.. [code]dev_getdata 0 [concommand][04.Feb.2015 21:09:44]: RCON called dev_getdata with arguments: 0 [ 0 :"NULL": :"NULL": :"NULL"] [default] [day_night_brush] = 433 [elevators] [1] [id] = 1054 [property] = Skyscraper [env_skypaint] = 1053 [env_sun] = 399 [light_environment] = 402 [lists] [globalvars] [Team.1001.Score] = 10 [/code] You won't have that but GlobalVars are supposed to network the data... You could try: [url]http://wiki.garrysmod.com/page/Global/GetGlobalInt[/url] enable sv_cheats on the server then in the server try: lua_run team.AddScore( 1, 10 ); On the client try: lua_run_cl print( team.GetScore( 1 ) ) lua_run_cl print( GetGlobalInt( "Team.1.Score", 0 ) ) and see what comes of it. I'll re-verify that it works without my networking system and update this post or respond in a bit.
[QUOTE=Acecool;47077365]I found where team.AddScore sets the data. It uses Global Vars to set data; my networking system overwrites a lot of those systems and puts the data into my flag system so it may be interfering with the results I posted above.. [code]dev_getdata 0 [concommand][04.Feb.2015 21:09:44]: RCON called dev_getdata with arguments: 0 [ 0 :"NULL": :"NULL": :"NULL"] [default] [day_night_brush] = 433 [elevators] [1] [id] = 1054 [property] = Skyscraper [env_skypaint] = 1053 [env_sun] = 399 [light_environment] = 402 [lists] [globalvars] [Team.1001.Score] = 10 [/code] You won't have that but GlobalVars are supposed to network the data... You could try: [url]http://wiki.garrysmod.com/page/Global/GetGlobalInt[/url] enable sv_cheats on the server then in the server try: lua_run team.AddScore( 1, 10 ); On the client try: lua_run_cl print( team.GetScore( 1 ) ) lua_run_cl print( GetGlobalInt( "Team.1.Score", 0 ) ) and see what comes of it. I'll re-verify that it works without my networking system and update this post or respond in a bit.[/QUOTE] I am gonna try that after I get done deleting this: [IMG]http://i.gyazo.com/312182e0109d98e1e4631761d2b26833.png[/IMG] Edit---------------------------------- Ok I fixed it. It was something in that 32 gigs worth of stuff I had in my garrys mod. The goodness also is my gmod takes like 1 nanosecond to load.
I'd suggest renaming the addons folder of the server temporarily... Feel free to add me on Steam if you like.
Sorry, you need to Log In to post a reply to this thread.