Raised This Month: $12 Target: $400
 3% 

[Snippet] Free Hangman code


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
nergal
Veteran Member
Join Date: Apr 2012
Old 09-20-2014 , 13:23   [Snippet] Free Hangman code
Reply With Quote #1

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 iWordsCorrectWordLengthGameLivesoldCorrect;
bool letters[64] = {false,...};
bool GameInProgress false;
char Puzzle[64];

public 
void OnPluginStart() 

    
RegAdminCmd("sm_dohangman"Command_InitHangmanADMFLAG_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 clientint 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(1Puzzlesizeof(Puzzle));
    
GetCmdArg(2topicsizeof(topic));

    
WordLength strlen(Puzzle); 
    for (
int i 1<= MaxClientsi++) 
    { 
        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"WordLengthtopic); 
    } 
    
//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 clientint 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(1topicsizeof(topic));
    if (
StrEqual(topicPuzzlefalse))
    {
        for (
1<= MaxClientsi++) 
        { 
            if ( !
IsValidClient(i) ) continue; 
            
CPrintToChat(i"{blue}[Hangman]:{green} %N Won with his/her guess: %s"clienttopic); 
        }
        for (
0sizeof(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 clientint 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 icount;
    
GetCmdArg(1topicsizeof(topic));

    for (
0WordLengthi++)
    {
        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;

__________________
nergal is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:05.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode