Senior Member
Join Date: Jul 2007
Location: Boston,MA
|
07-27-2008
, 00:40
Re: DoD:S GunGame (Updated 07/26)
|
#28
|
with the latest version:
Code:
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#define PL_VERSION "0.2"
public Plugin:myinfo = {
name = "DoD:S GunGame",
author = "Tsunami",
description = "DoD:S GunGame for SourceMod",
version = PL_VERSION,
url = "http://www.tsunami-productions.nl"
}
new g_iAmmo[MAXPLAYERS + 1];
new g_iAmount[MAXPLAYERS + 1];
new g_iClip;
new g_iLevel[MAXPLAYERS + 1] = {1, ...};
new g_iLevels;
new g_iMaxClients;
new g_iOldLevel[MAXPLAYERS + 1] = {1, ...};
new g_iWeapon[MAXPLAYERS + 1];
new bool:g_bEnabled = true;
new Float:g_fPosition[MAXPLAYERS + 1][3];
new Handle:g_hEnabled;
new Handle:g_hHandicap;
new Handle:g_hNextMap;
new Handle:g_hSpade;
new Handle:g_hSpadePro;
new Handle:g_hTurbo;
new String:g_sPrefix[24] = "\x01[\x04GunGame\x01] ";
new String:g_sSoundJoin[PLATFORM_MAX_PATH];
new String:g_sSoundLevelUp[PLATFORM_MAX_PATH];
new String:g_sSoundLevelDown[PLATFORM_MAX_PATH];
new String:g_sSoundLevelSteal[PLATFORM_MAX_PATH];
new String:g_sSoundWin[PLATFORM_MAX_PATH];
new String:g_sWeapon[MAXPLAYERS + 1][24];
public OnPluginStart() {
CreateConVar("sm_gungame_version", PL_VERSION, "DoD:S GunGame for SourceMod", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
g_hEnabled = CreateConVar("sm_gungame_enabled", "1", "Enable/disable DoD:S GunGame.", FCVAR_PLUGIN);
g_hHandicap = CreateConVar("sm_gungame_handicap", "1", "Enable/disable Handicap mode in DoD:S GunGame.", FCVAR_PLUGIN);
g_hSpade = CreateConVar("sm_gungame_spade", "1", "Enable/disable spades in DoD:S GunGame.", FCVAR_PLUGIN);
g_hSpadePro = CreateConVar("sm_gungame_spadepro", "1", "Enable/disable Spade Pro mode in DoD:S GunGame.", FCVAR_PLUGIN);
g_hTurbo = CreateConVar("sm_gungame_turbo", "1", "Enable/disable Turbo mode in DoD:S GunGame.", FCVAR_PLUGIN);
g_hNextMap = FindConVar("sm_nextmap");
g_iClip = FindSendPropInfo("CBaseCombatWeapon", "m_iClip1");
HookConVarChange(g_hEnabled, ConVarChange_Enabled);
HookEvent("dod_round_start", Event_RoundStart);
HookEvent("player_death", Event_PlayerDeath);
HookEvent("player_spawn", Event_PlayerSpawn);
RegConsoleCmd("drop", Command_Drop, "Block weapons from being dropped in DoD:S GunGame.");
RegConsoleCmd("slot1", Command_Slot, "Switch weapon when Turbo mode is disabled in DoD:S GunGame.");
LoadTranslations("gungame.phrases");
}
public OnMapStart() {
g_iMaxClients = GetMaxClients();
LoadConfig();
}
public OnGameFrame() {
if (g_bEnabled) {
for (new i = 1, iAmmo, iAmount; i <= g_iMaxClients; i++) {
if (IsClientInGame(i) && IsPlayerAlive(i)) {
iAmmo = g_iAmmo[GetLevel(i)], iAmount = g_iAmount[i];
if (iAmmo > 0 && GetEntData(i, iAmmo) <= iAmount) {
SetEntData(i, iAmmo, iAmount * 2, _, true);
}
}
}
}
}
public OnClientPostAdminCheck(client) {
if (g_bEnabled && !StrEqual(g_sSoundJoin, "")) {
EmitSoundToClient(client, g_sSoundJoin);
}
new iClients = GetTeamClientCount(2) + GetTeamClientCount(3), iLevel = 0;
if (GetConVarBool(g_hHandicap) && iClients > 0) {
for (new i = 1; i <= g_iMaxClients; i++) {
if (IsClientInGame(i) && GetClientTeam(i) > 1) {
iLevel += GetLevel(i);
}
}
g_iLevel[client] = iLevel / iClients;
} else {
g_iLevel[client] = 1;
}
g_iWeapon[client] = 0;
}
public ConVarChange_Enabled(Handle:convar, const String:oldValue[], const String:newValue[]) {
g_bEnabled = StrEqual(newValue, "1");
for (new i = 1; i <= g_iMaxClients; i++) {
if (IsClientInGame(i) && IsPlayerAlive(i)) {
ForcePlayerSuicide(i);
}
}
}
public Action:Command_Drop(client, args) {
return g_bEnabled ? Plugin_Handled : Plugin_Continue;
}
public Action:Command_Slot(client, args) {
if (g_bEnabled && !GetConVarBool(g_hTurbo)) {
GiveWeapon(client);
return Plugin_Handled;
} else {
return Plugin_Continue;
}
}
public Action:Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast) {
if (g_bEnabled) {
decl Float:fPosition[3], String:sWeapon[24];
new iAttackerID = GetEventInt(event, "attacker"),
iClientID = GetEventInt(event, "userid"),
iAttacker = GetClientOfUserId(iAttackerID),
iClient = GetClientOfUserId(iClientID);
GetClientAbsOrigin(iClient, fPosition);
GetEventString(event, "weapon", sWeapon, sizeof(sWeapon));
if (IsValidEntity(g_iWeapon[iClient]) && g_iWeapon[iClient] > 0) {
RemoveWeapon(iClient, g_iWeapon[iClient]);
}
if (iAttacker == 0 || iAttacker == iClient) {
if (g_iLevel[iClient] > 1) {
g_iLevel[iClient]--;
PrintToChatAll("%s%t", g_sPrefix, "Suicide", 4, iClient, 1);
LogEvent("gg_leveldown", iClientID);
if (!StrEqual(g_sSoundLevelDown, "")) {
EmitSoundToClient(iClient, g_sSoundLevelDown);
}
}
} else if (GetClientTeam(iAttacker) != GetClientTeam(iClient)) {
if (fPosition[0] == g_fPosition[iClient][0] &&
fPosition[1] == g_fPosition[iClient][1]) {
PrintHintText(iAttacker, "%t", "AFK", iClient);
} else if (g_iLevel[iAttacker]++ < g_iLevels) {
if (GetConVarBool(g_hSpade) && GetConVarBool(g_hSpadePro) &&
StrEqual(sWeapon, "spade") && g_iLevel[iClient] > 1) {
g_iLevel[iClient]--;
PrintToChatAll("%s%t", g_sPrefix, "Steal", 4, iAttacker, 1, 4, iClient, 1);
LogEvent("gg_levelsteal", iAttackerID);
LogEvent("gg_leveldown", iClientID);
if (!StrEqual(g_sSoundLevelSteal, "")) {
EmitSoundToClient(iAttacker, g_sSoundLevelSteal);
}
if (!StrEqual(g_sSoundLevelDown, "")) {
EmitSoundToClient(iClient, g_sSoundLevelDown);
}
} else {
LogEvent("gg_levelup", iAttackerID);
if (!StrEqual(g_sSoundLevelUp, "")) {
EmitSoundToClient(iAttacker, g_sSoundLevelUp);
}
}
new iLeader = GetLeader(), iLevel = g_iLevel[iAttacker];
if (IsPlayerAlive(iAttacker)) {
PrintToChat(iAttacker, "%s%t", g_sPrefix, "Weapon", 4, g_sWeapon[iLevel]);
}
if (iLeader == iAttacker) {
PrintToChatAll("%s%t", g_sPrefix, "Leader", 4, iAttacker, 1, 4, iLevel, 1);
} else {
new iLead = g_iLevel[iLeader] - iLevel;
if (iLead > 0) {
PrintToChat(iAttacker, "%s%t", g_sPrefix, "Difference", 4, iLead, 1, iLead == 1 ? "" : "s");
}
}
if (GetConVarBool(g_hTurbo)) {
GiveWeapon(iAttacker);
}
} else {
decl String:sNextMap[32];
GetConVarString(g_hNextMap, sNextMap, sizeof(sNextMap));
PrintToChatAll("%s%t", g_sPrefix, "Win", 4, iAttacker, 1, 4, sNextMap);
LogEvent("gg_win", iAttackerID);
CreateTimer(4.5, Timer_EndGame);
if (!StrEqual(g_sSoundWin, "")) {
EmitSoundToAll(g_sSoundWin);
}
}
}
}
}
public Action:Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast) {
if (g_bEnabled) {
new iClient = GetClientOfUserId(GetEventInt(event, "userid"));
if (GetClientTeam(iClient) > 1) {
GetClientAbsOrigin(iClient, g_fPosition[iClient]);
CreateTimer(0.1, Timer_GiveWeapon, iClient);
}
}
}
public Action:Event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast) {
new iCaptureArea = -1;
while ((iCaptureArea = FindEntityByClassname(iCaptureArea, "dod_capture_area")) != -1) {
AcceptEntityInput(iCaptureArea, "Disable");
}
}
public Action:Timer_EndGame(Handle:timer) {
new iGameEnd = FindEntityByClassname(-1, "game_end");
if (iGameEnd == -1 && (iGameEnd = CreateEntityByName("game_end")) == -1) {
LogError("Unable to create entity \"game_end\"!");
} else {
AcceptEntityInput(iGameEnd, "EndGame");
}
}
public Action:Timer_GiveWeapon(Handle:timer, any:client) {
for (new i = 0, s; i < 5; i++) {
if ((s = GetPlayerWeaponSlot(client, i)) != -1) {
RemoveWeapon(client, s);
}
}
new iLevel = g_iLevel[client];
g_iWeapon[client] = 0;
PrintToChat(client, "%s%t", g_sPrefix, "Level", 4, iLevel, 1, 4, g_sWeapon[iLevel]);
GiveWeapon(client);
if (GetConVarBool(g_hSpade) && !StrEqual(g_sWeapon[iLevel], "amerknife")
&& !StrEqual(g_sWeapon[iLevel], "spade")) {
GivePlayerItem(client, "weapon_spade");
}
}
GetLeader() {
new iLeader = 0;
for (new i = 1; i <= g_iMaxClients; i++) {
if (IsClientInGame(i) && g_iLevel[i] > g_iLevel[iLeader]) {
iLeader = i;
}
}
return iLeader;
}
GetLevel(iClient) {
if (GetConVarBool(g_hTurbo)) {
return g_iLevel[iClient];
} else {
return g_iOldLevel[iClient];
}
}
GiveWeapon(iClient) {
if (IsPlayerAlive(iClient)) {
decl iWeapon, String:sWeapon[32];
new iLevel = g_iOldLevel[iClient] = g_iLevel[iClient];
Format(sWeapon, sizeof(sWeapon), "weapon_%s", g_sWeapon[iLevel]);
if (IsValidEntity(g_iWeapon[iClient]) && g_iWeapon[iClient] > 0) {
RemoveWeapon(iClient, g_iWeapon[iClient]);
}
if (GetConVarBool(g_hSpade) && (iWeapon = GetPlayerWeaponSlot(iClient, 2)) != -1 &&
(StrEqual(g_sWeapon[iLevel], "amerknife") || StrEqual(g_sWeapon[iLevel], "spade"))) {
RemoveWeapon(iClient, iWeapon);
}
g_iWeapon[iClient] = GivePlayerItem(iClient, sWeapon);
if ((g_iAmount[iClient] = GetEntData(g_iWeapon[iClient], g_iClip)) < 1) {
g_iAmount[iClient] = 1;
}
if (g_iAmmo[iLevel] > 0) {
SetEntData(iClient, g_iAmmo[iLevel], g_iAmount[iClient] * 2, _, true);
}
}
}
LoadConfig() {
decl String:sLevel[4], String:sPath[PLATFORM_MAX_PATH], String:sWeapon[24];
new iAmmo[MAXPLAYERS + 1] = {0, ...},
iLevel = 1,
iOffset = FindSendPropInfo("CBasePlayer", "m_iAmmo"),
iOffsets[20] = { 4, 8, 12,
16, 20, 20,
24, 28, 32,
32, 32, 36,
40, 44, 48,
48, 52, 56,
68, 72},
Handle:hConfig = CreateKeyValues("GunGame"),
String:sWeapons[20][24] = {"colt", "p38", "c96",
"garand", "k98", "k98_scoped",
"m1carbine", "spring", "thompson",
"mp40", "mp44", "bar",
"30cal", "mg42", "bazooka",
"pschreck", "frag_us", "frag_ger",
"smoke_us", "smoke_ger"};
BuildPath(Path_SM, sPath, sizeof(sPath), "configs/gungame.txt");
if (FileExists(sPath)) {
for (new i = 0; i < sizeof(g_sWeapon); i++) {
g_sWeapon[i] = "";
}
FileToKeyValues(hConfig, sPath);
KvJumpToKey(hConfig, "Levels");
KvGetString(hConfig, "1", sWeapon, sizeof(sWeapon));
while (!StrEqual(sWeapon, "")) {
g_sWeapon[iLevel] = sWeapon;
IntToString(++iLevel, sLevel, sizeof(sLevel));
KvGetString(hConfig, sLevel, sWeapon, sizeof(sWeapon));
}
KvRewind(hConfig);
KvJumpToKey(hConfig, "Sounds");
KvGetString(hConfig, "Join", g_sSoundJoin, PLATFORM_MAX_PATH);
KvGetString(hConfig, "LevelUp", g_sSoundLevelUp, PLATFORM_MAX_PATH);
KvGetString(hConfig, "LevelDown", g_sSoundLevelDown, PLATFORM_MAX_PATH);
KvGetString(hConfig, "LevelSteal", g_sSoundLevelSteal, PLATFORM_MAX_PATH);
KvGetString(hConfig, "Win", g_sSoundWin, PLATFORM_MAX_PATH);
if (!StrEqual(g_sSoundJoin, "")) {
LoadSound(g_sSoundJoin);
}
if (!StrEqual(g_sSoundLevelUp, "")) {
LoadSound(g_sSoundLevelUp);
}
if (!StrEqual(g_sSoundLevelDown, "")) {
LoadSound(g_sSoundLevelDown);
}
if (!StrEqual(g_sSoundLevelSteal, "")) {
LoadSound(g_sSoundLevelSteal);
}
if (!StrEqual(g_sSoundWin, "")) {
LoadSound(g_sSoundWin);
}
g_iAmmo = iAmmo;
g_iLevels = --iLevel;
for (new i = 1; i <= g_iLevels; i++) {
for (new j = 0; j < sizeof(sWeapons); j++) {
if (StrEqual(g_sWeapon[i], sWeapons[j])) {
g_iAmmo[i] = iOffset + iOffsets[j];
break;
}
}
}
} else {
SetFailState("File Not Found: %s", sPath);
}
}
LoadSound(String:sFile[PLATFORM_MAX_PATH]) {
decl String:sPath[PLATFORM_MAX_PATH];
Format(sPath, sizeof(sPath), "sound/%s", sFile);
PrecacheSound(sFile, true);
AddFileToDownloadsTable(sPath);
}
LogEvent(String:sName[32], iUserID) {
new iClient = GetClientOfUserId(iUserID), String:sAuth[32];
GetClientAuthString(iClient, sAuth, sizeof(sAuth));
LogToGame("\"%N<%d><%s><GunGame>\" triggered \"%s\"", iClient, iUserID, sAuth, sName);
}
RemoveWeapon(iClient, iWeapon) {
RemovePlayerItem(iClient, iWeapon);
RemoveEdict(iWeapon);
}
this is the entire code thats posted.... the game never ends after a player has won.... the game goes on until maptimelimit is reached, other than that everything seems ok suicides brought our players back a level as it should and all our players were able to join and get the correct weapons.... did notice tk's did nothing like it used to bring players back now it does nothing at all but we could just set ff to off i guess so thats not a priority but the fact that the game never announces a winner and changes maps is a major bug that we saw.
thanks for your work on this and hope their will be a fix soon.
|
|