PDA

View Full Version : Feedback


dalto
07-28-2007, 12:15
Hi,

I have just finished the first version of a very simple plugin. If possible before I do anything else or put together any others I would like to get a little peer review to make sure I am going in the right direction.

Please feel free to comment on readability, naming conventions, optimizations, etc...

Thanks in advance for your asistance!

P.S. I know this plugin is not very useful on its own. It was really for my learning.


/*
LastMan.sp

Description:
Plays the lastman sound when you are the last player on your team.

Versions:
1.0
* Initial Release

*/


#include <sourcemod>
#include <sdktools>

#pragma semicolon 1

#define PLUGIN_VERSION "1.0"

// Plugin definitions
public Plugin:myinfo =
{
name = "LastMan",
author = "AMP",
description = "Last Man Sound",
version = PLUGIN_VERSION,
url = "http://www.assmonkey.org/css/"
};

new iLifeState = -1;

public OnPluginStart()
{
CreateConVar("lastman_version", PLUGIN_VERSION, "Last Man Version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FC VAR_NOTIFY);
iLifeState = FindSendPropOffs("CBasePlayer", "m_lifeState");
HookEvent("player_death", Event_PlayerDeath);
}

public OnMapStart()
{
PrecacheSound("lastman/oneandonly.wav", true);
AddFileToDownloadsTable("sound/lastman/oneandonly.wav");
}


public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
new victimId = GetEventInt(event, "userid");

new victimClient = GetClientOfUserId(victimId);

new killedTeam = GetClientTeam(victimClient);

new playersConnected = GetMaxClients();

new lastManId = 0;

for (new i = 1; i < playersConnected; i++){
if(IsClientInGame(i)){
if(killedTeam==GetClientTeam(i) && IsAlive(i)){
if( lastManId )
lastManId = -1;
else
lastManId= i;
}
}
}
if(lastManId > 0){
new String:clientname[64];
GetClientName(lastManId, clientname, sizeof(clientname));
PrintToChatAll("%s is the last man standing on his team", clientname);
ClientCommand(lastManId,"play lastman/oneandonly.wav");
}

}

// This function was stolen from ferret's teambet plugin
public bool:IsAlive(client)
{
if (iLifeState != -1 && GetEntData(client, iLifeState, 1) == 0)
return true;

return false;
}