title. here ya go!
PHP Code:
#pragma semicolon 1
#pragma newdecls optional
#include <sourcemod>
#include <morecolors>
#define PLUGIN_VERSION "1.0"
#define IsValidClient(%1) ( 0 < %1 && %1 <= MaxClients && IsClientInGame(%1) )
public Plugin myinfo = {
name = "Hangman!",
author = "Nergal",
description = "play hangman",
version = PLUGIN_VERSION,
url = "soon my pet, soon",
};
int iWordsCorrect, WordLength, GameLives, oldCorrect;
bool letters[64] = {false,...};
bool GameInProgress = false;
char Puzzle[64];
public void OnPluginStart()
{
RegAdminCmd("sm_dohangman", Command_InitHangman, ADMFLAG_GENERIC);
RegConsoleCmd("sm_guess", Command_GuessPuzzle);
RegConsoleCmd("sm_ans", Command_PickLetter);
RegConsoleCmd("sm_letter", Command_PickLetter);
RegConsoleCmd("sm_a", Command_PickLetter);
}
public Action Command_InitHangman(int client, int args)
{
// make sure no game going
if (GameInProgress)
{
CReplyToCommand(client, "{blue}[Hangman]{green} Please wait until the current Hangman game is over.");
return Plugin_Handled;
}
GameInProgress = true;
if (args < 2)
{
CReplyToCommand(client, "{blue}[Hangman]{green} Usage: sm_dohangman <word-NoCapitalLetters> <topic/category>");
return Plugin_Handled;
}
char topic[32];
GetCmdArg(1, Puzzle, sizeof(Puzzle));
GetCmdArg(2, topic, sizeof(topic));
WordLength = strlen(Puzzle);
for (int i = 1; i <= MaxClients; i++)
{
if ( !IsValidClient(i) ) continue;
CPrintToChat(i, "{blue}[Hangman]:{green} %N started a Hangman game", client);
CPrintToChat(i, "{blue}[Hangman]:{green} word is {red}%i {green}letters, topic is {red}%s", WordLength, topic);
}
//reveal puzzle timer
//CreateTimer(300.0, Timer_RevealPuzzle); //5 minutes to answer it lol, edit: fuck it.
return Plugin_Handled;
}
public Action Command_GuessPuzzle(int client, int args)
{
if (!GameInProgress)
{
CReplyToCommand(client, "{blue}[Hangman]{green} No game in progress");
return Plugin_Handled;
}
if (args < 1)
{
CReplyToCommand(client, "{blue}[Hangman]{green} Usage: sm_guess <whole puzzle word>");
return Plugin_Handled;
}
char topic[16];
int i;
GetCmdArg(1, topic, sizeof(topic));
if (StrEqual(topic, Puzzle, false))
{
for (i = 1; i <= MaxClients; i++)
{
if ( !IsValidClient(i) ) continue;
CPrintToChat(i, "{blue}[Hangman]:{green} %N Won with his/her guess: %s", client, topic);
}
for (i = 0; i < sizeof(letters); i++)
{
if ( letters[i] ) letters[i] = false;
}
GameInProgress = false;
}
else
{
GameLives--;
CPrintToChat(client, "{blue}[Hangman]:{green} Sorry, %s is incorrect!", topic);
if (GameLives <= 0)
{
GameInProgress = false;
CPrintToChatAll(client, "{blue}[Hangman]:{green} Out of lives, Hangman died! Word was %s", Puzzle);
}
}
return Plugin_Handled;
}
public Action Command_PickLetter(int client, int args)
{
if (!GameInProgress)
{
CReplyToCommand(client, "{blue}[Hangman]{green} No game in progress");
return Plugin_Handled;
}
if (args < 1)
{
CReplyToCommand(client, "{blue}[Hangman]{green} Usage: sm_letter <letter in English-Latin alphabet>");
return Plugin_Handled;
}
char topic[4];
int i, count;
GetCmdArg(1, topic, sizeof(topic));
for (i = 0; i < WordLength; i++)
{
if (letters[i])
{
CPrintToChat(client, "{blue}[Hangman]:{green} Letter was already called, try again");
break;
}
if (topic[0] == Puzzle[i])
{
letters[i] = true;
iWordsCorrect++;
}
if (oldCorrect == iWordsCorrect)
{
GameLives--;
if (GameLives <= 0)
{
GameInProgress = false;
CPrintToChatAll(client, "{blue}[Hangman]:{green} Out of lives, Hangman died! Word was %s", Puzzle);
}
}
}
return Plugin_Handled;
}