GM points give

Hello :slight_smile:
Plz, help me.
It not work.


function GM:EndRound(winner, nextmap)
	if self.RoundEnded then return end
	self.RoundEnded = true

	ROUNDWINNER = winner
	
    for k,v in pairs(player.GetAll()) do
        if v:Team() == TEAM_UNDEAD and v:Alive() then
        v:PS_GivePoints(100)
        end
    end

    for k,v in pairs(player.GetAll()) do
        if v:Team() == TEAM_UNDEAD and v:Alive() then
        v:PS_GivePoints(10)
        end
   end
 
	self.EndTime = CurTime()
 
	RunConsoleCommand("stopsound")
     
	timer.Simple( 21, function() RunConsoleCommand("mapvote","30") end )
end


Is EndRound already a function that exists in the gamemode or are you creating it brand new? Where is it being called?

I create


for k,v in pairs(player.GetAll()) do
        if v:Team() == TEAM_UNDEAD and v:Alive() then
        v:PS_GivePoints(100)
        end
    end

    for k,v in pairs(player.GetAll()) do
        if v:Team() == TEAM_UNDEAD and v:Alive() then
        v:PS_GivePoints(10)
        end
   end

That doesn’t answer my question. What gamemode is it? What file is that in?

It looks like Zombie Survival, but I could be wrong.

What he means is, is GM:EndRound called by any thing using hook.Call( “EndRound”, GAMEMODE, winner, nextmap ); ?? You can’t just create the function and expect it to work ( unless it is a pre-existing function which you’re overriding for your game-mode such as PlayerSpawn which already has a purpose and is called by something ).

Also, you can simplify the code / make it more readable; I’m assuming dead players get 10?


//
// Winning team points to give....
//
local WINNING_TEAM_POINTS = 100;
local WINNING_TEAM_POINTS_DEAD = 10;


//
//
//
function GM:EndRound( winner, nextmap )
	for k, _p in pairs( player.GetAll( ) ) do
		if ( !IsValid( _p ) ) then continue; end

		// Give winning team members points...
		if ( v:Team() == winner ) then
			// If the player is alive, give them them extra points. If the player is dead, give them less points.
			v:PS_GivePoints( ( v:Alive( ) && WINNING_TEAM_POINTS || WINNING_TEAM_POINTS_DEAD ) );
		end
	end

	// If nextmap is defined, change the map...
	if ( nextmap ) then
		timer.Simple( 5, function( )
			RunConsoleCommand( "changelevel", nextmap );
		end );
	end
end

Then, make sure you pass winner as the winning team…


[ERROR] gamemodes/zombiesurvival/gamemode/cl_init.lua:1364: attempt to index global 'v' (a nil value)
  1. Call - gamemodes/zombiesurvival/gamemode/cl_init.lua:1364
   2. func - gamemodes/zombiesurvival/gamemode/cl_init.lua:1676
    3. unknown - lua/includes/modules/net.lua:32


:pwn:

I changed it to _p and forgot to change the others in the loop. You could either change _p to v and any _p to v or and v to _p.


	
//
// Winning team points to give....
//
local WINNING_TEAM_POINTS = 100;
local WINNING_TEAM_POINTS_DEAD = 10;


//
//
//
function GM:EndRound( winner, nextmap )
	for k, _p in pairs( player.GetAll( ) ) do
		if ( !IsValid( _p ) ) then continue; end

		// Give winning team members points...
		if ( _p:Team() == winner ) then
			// If the player is alive, give them them extra points. If the player is dead, give them less points.
			_p:PS_GivePoints( ( _p:Alive( ) && WINNING_TEAM_POINTS || WINNING_TEAM_POINTS_DEAD ) );
		end
	end

	// If nextmap is defined, change the map...
	if ( nextmap ) then
		timer.Simple( 5, function( )
			RunConsoleCommand( "changelevel", nextmap );
		end );
	end
end


Side note: Some people intentionally post code with a typo / error in the hopes the poster knows how to debug / spot it; typically it’s something small like a variable / parenthesis missing, etc… Other times it’s a legitimate typo but it helps to know when to see if something is used / not used and how to debug.



[ERROR] gamemodes/zombiesurvival/gamemode/cl_init.lua:1368: attempt to call method 'PS_GivePoints' (a nil value)
  1. Call - gamemodes/zombiesurvival/gamemode/cl_init.lua:1368
   2. func - gamemodes/zombiesurvival/gamemode/cl_init.lua:1676
    3. unknown - lua/includes/modules/net.lua:32



CODE


local WINNING_TEAM_POINTS = 100;
local WINNING_TEAM_POINTS_DEAD = 10;

local function EndRoundGetMeleeFilter(self) return {self} end
function GM:EndRound(winner, nextmap)
	if self.RoundEnded then return end
	self.RoundEnded = true

	ROUNDWINNER = winner
 
	self.EndTime = CurTime()
 
	RunConsoleCommand("stopsound")
     
	timer.Simple( 21, function() RunConsoleCommand("mapvote","30") end )
	
		for k, _p in pairs( player.GetAll( ) ) do
		if ( !IsValid( _p ) ) then continue; end

		// Give winning team members points...
		if ( _p:Team() == winner ) then
			// If the player is alive, give them them extra points. If the player is dead, give them less points.
			_p:PS_GivePoints( ( _p:Alive( ) && WINNING_TEAM_POINTS || WINNING_TEAM_POINTS_DEAD ) );
		end
		end
		
	 
	--RunConsoleCommand("mapvote")
	 
	FindMetaTable("Player").GetMeleeFilter = EndRoundGetMeleeFilter

	self.HUDPaint = self.HUDPaintEndRound
	self.HUDPaintBackground = self.HUDPaintBackgroundEndRound

	if winner == TEAM_UNDEAD then
		hook.Add("CalcView", "EndRoundCalcView", EndRoundCalcView)
		hook.Add("ShouldDrawLocalPlayer", "EndRoundShouldDrawLocalPlayer", EndRoundShouldDrawLocalPlayer)
	end

	if winner == TEAM_UNDEAD then
		timer.Simple(0.5, function() surface_PlaySound(ALLLOSESOUND) end)
	else
		timer.Simple(0.5, function() surface_PlaySound(HUMANWINSOUND) end)
	end

	timer.Simple(5, function()
		if not (pEndBoard and pEndBoard:IsValid()) then
			MakepEndBoard(winner)
		end
	end)
end

[editline]1st March 2015[/editline]

ZombieSurv

PS_GivePoints Is a server side function. Your error suggests that you are putting the code in a client side file, which will not work. ‘gamemodes/zombiesurvival/gamemode/cl_init.lua’. Put the code in a file loaded by the server.

For more documentation on Pointshop’s functions, take a look at http://pointshop.burt0n.net/player-meta-functions/points

Oh… Thx you!

[editline]1st March 2015[/editline]

I put this script in garrysmod\lua\autorun\server, but it doesn’t work

ACT