Raised This Month: $ Target: $400
 0% 

Random quotes


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
WatchDogs
Senior Member
Join Date: Oct 2015
Location: Iran
Old 06-06-2017 , 10:05   Re: Random quotes
Reply With Quote #13

Here is my version if you like you can use.

Thank a lot to Arkarr

PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <multicolors>


#pragma newdecls required

Handle h_qInterval;
Handle h_Timer;
Handle h_qMode;
Handle h_Tag;

Handle ARRAY_Quotes;

int lastqID;

public 
Plugin myinfo 
{
    
name "Random Message Printer",
    
author "[W]atch [D]ogs",
    
description "Prints random messages every X minutes from a config file",
    
version "1.0"
};

public 
void OnPluginStart()
{
    
h_qMode CreateConVar("sm_quotes_mode""0""Print message mode\n\n0 = Chat\n1 = Hint\n2 = Center"_true0.0true2.0);
    
h_qInterval CreateConVar("sm_quotes_interval""5""The time between printing quotes (Every X minutes)");
    
h_Tag CreateConVar("sm_quotes_tag""{green}[Quotes]{default}""The tag before quotes (Set empty for disable)");
    
h_Timer CreateTimer(GetConVarFloat(h_qInterval) * 60Timer_Print_TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
    
    
RegAdminCmd("sm_nextq"CMD_NextQADMFLAG_CHAT"Force print next quote");
    
    
LoadQuotes();
    
    
HookConVarChange(h_qIntervalqInterval_Changed);
    
    
AutoExecConfig(true);
}

public 
Action CMD_NextQ(int clientint args)
{
    
PrintQuote();
}

public 
void qInterval_Changed(Handle convarchar[] oldValuechar[] newValue)
{
    
KillTimer(h_Timer);
    
h_Timer CreateTimer(GetConVarFloat(convar) * 60Timer_Print_TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}

public 
void OnConfigsExecuted()
{
    
LoadQuotes();
}

public 
void LoadQuotes()
{
    
char path[PLATFORM_MAX_PATH], sLine[255];
    
    
ARRAY_Quotes CreateArray(sizeof(sLine));
    
BuildPath(Path_SMpathPLATFORM_MAX_PATH"configs/quotes.txt");
    
    if(
FileExists(path))
    {
        
Handle hFile OpenFile(path"r");
        while(!
IsEndOfFile(hFile) && ReadFileLine(hFilesLinesizeof(sLine)))
            
PushArrayString(ARRAY_QuotessLine);
            
        
CloseHandle(hFile);
    }
    else
    {
        
PushArrayString(ARRAY_Quotes"Quotes config file missing.");
    }
}

public 
Action Timer_Print(Handle timer)
{
    
PrintQuote();
}

public 
void PrintQuote()
{
    
char sQuote[255], sTag[255];
    
int qMode GetConVarInt(h_qMode);
    
int nextqID;
    
nextqID GetRandomInt(0GetArraySize(ARRAY_Quotes) - 1);
    
    while(
nextqID == lastqID) {
        
nextqID GetRandomInt(0GetArraySize(ARRAY_Quotes) - 1);
    }
    
    
GetArrayString(ARRAY_QuotesnextqIDsQuotesizeof(sQuote));
    
GetConVarString(h_TagsTagsizeof(sTag));
    
lastqID nextqID;
    
    if(
qMode == 0)
    {
        if(
StrEqual(sTag"")) {
            
CPrintToChatAll("%s"sQuote);
        } else {
            
CPrintToChatAll("%s %s"sTagsQuote);
        }
    } 
    else if(
qMode == 1)
    {
        if(
StrEqual(sTag"")) {
            
PrintHintTextToAll("%s"sQuote);
        } else {
            
PrintHintTextToAll("%s %s"sTagsQuote);
        }
    } 
    else
    {
        if(
StrEqual(sTag"")) {
            
PrintCenterTextAll("%s"sQuote);
        } else {
            
PrintCenterTextAll("%s %s"sTagsQuote);
        }
    }

Attached Files
File Type: sp Get Plugin or Get Source (RandomQuotes.sp - 44 views - 2.8 KB)
File Type: smx RandomQuotes.smx (15.3 KB, 57 views)
WatchDogs is offline
 



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 12:20.


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