Death of a class as a win trigger

I’m new to LUA and I’m working on making a custom gamemode.

It’s called FBI. Basically a team of agents against a team of gangsters where the win trigger is the death of the ganglord which is a seperate class, but on the same team as the gangsters. I just can’t figure out how to define the death of the ganglord as a win trigger.

It’s based on the Fretta gamemode. I have everything else in place… But I can’t figure this out. This would give me a good starting point to learning LUA, so I would appreciate any help.

On SERVER hook, PlayerDeath, if victim:GetTeam / GetRole / GetCustomClass, then the gang-lord has died, call the FBI win hook and network it.

How would that look in code? I’m still trying to get an idea of how the lua scripting is setup lol

It depends how the GangLord is defined.

team.SetUp( GANGLORD_TEAM, “GangLord”, Color( 255, 0, 0, 255 ) )

hook.Add( “PlayerDeath”, “MyGangLordDontYouDie”, function( _v, _w, _k ) // victim, weapon, killer
// This is where it depends on how it’s set up…

// If the gang lord is a team:
if ( _v:Team( ) == GANGLORD_TEAM ) then
	// Trigger the win / loss

end );[/lua]

What custom functions do you have defined? You’ll have to use them to check.

Thank you. I figured it out based on what you posted. I’m starting to understand classes more and more.

Also, how can I make it so that players spawn randomly as the ganglord?

Depending how you have it set up, at the beginning of the round, pick a player on a team randomly to be the “VIP/GangLord”

That can be done by doing a table.Random( players.GetAll( ) ) or, just grabbing players from one team and doing the same thing.

hook.Add( "PlayerDeath", "GanglordDies", function( _v, _w, _k )
	if ( _v:Team( ) == TEAM_GANGLORD ) then
		GM.RoundEndWithResult(1, team.GetName(1) .. " wins!")
end );

The current script gives me coding errors. What is wrong with this?

[editline]30th September 2013[/editline]

The error is “[ERROR] gamemodes/gangland/gamemode/init.lua:700: attempt to index global ‘GM’ (a nil value)”

I believe GM is a local reference to the global GameMode.

What would be the fix for this?

I’m trying to figure out how to make the round end after the ‘then’ tag. I can’t seem to figure out the proper syntax… :confused:

Instead of using GM. use GAMEMODE.

It works now. Thank you.

What is the useage of the local GM vs the global GAMEMODE?

Some examples would be awesome.

GM is used when the game-mode is initializing or being refreshed such as function GM:…( ) but when the game-mode is loaded you use GAMEMODE.