Raised This Month: $ Target: $400
 0% 

Random quotes


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
WatchDogs
Senior Member
Join Date: Oct 2015
Location: Iran
Old 06-03-2017 , 15:06   Re: Random quotes
Reply With Quote #1

OK. I'm writing a plugin for you.


Almost done. Maybe finish on tomorrow
WatchDogs is offline
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 06-03-2017 , 15:46   Re: Random quotes
Reply With Quote #2

Faster

A config file must be created in configs folder called : facts.txt
One fact par line. And that's it !
Also, color code support :
this {green}is {red}a {orange}fact {purple}!
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <multicolors>

#define PLUGIN_AUTHOR     "Arkarr"
#define PLUGIN_VERSION     "1.00"
#define PLUGIN_TAG        "{green}[FACT]{default}"

#pragma newdecls required

Handle ARRAY_Facts;
Handle TMR_TimerNextFact;
Handle CVAR_FactsInterval;

int LastFactID;

public 
Plugin myinfo 
{
    
name "[ANY] Facts!",
    
author PLUGIN_AUTHOR,
    
description "Display a line picked up from a text file every X minutes",
    
version PLUGIN_VERSION,
    
url "http://www.sourcemod.net"
};

public 
void OnPluginStart()
{
    
CVAR_FactsInterval CreateConVar("sm_fact_interval""5""Display a fact every X minutes"_true1.0);
    
    
RegAdminCmd("sm_ffact"CMD_PrintNextFactADMFLAG_CHAT"Force to print the next fact.");
    
RegAdminCmd("sm_forcefact"CMD_PrintNextFactADMFLAG_CHAT"Force to print the next fact.");
}

public 
void OnPluginEnd()
{
    
KillTimer(TMR_TimerNextFact);
}

public 
void OnConfigsExecuted()
{
    
LoadFacts();
    
    
TMR_TimerNextFact CreateTimer(GetConVarFloat(CVAR_FactsInterval) * 60TMR_PrintRandomFact_TIMER_REPEAT);
}

public 
Action CMD_PrintNextFact(int clientint args)
{
    
PrintFact();
    
    return 
Plugin_Handled;
}

public 
Action TMR_PrintRandomFact(Handle tmr)
{
    
PrintFact();
}

public 
void PrintFact()
{
    
char fact[255];
    
    
int nextFactID GetRandomInt(0GetArraySize(ARRAY_Facts)-1);
    
    while(
nextFactID == LastFactID && GetArraySize(ARRAY_Facts)-0)
        
nextFactID GetRandomInt(0GetArraySize(ARRAY_Facts)-1);
        
    
LastFactID nextFactID;
    
GetArrayString(ARRAY_FactsnextFactIDfactsizeof(fact));
        
    
CPrintToChatAll("%s %s"PLUGIN_TAGfact);
}

public 
void LoadFacts()
{
    
char path[PLATFORM_MAX_PATH];
    
char line[255];
    
    
ARRAY_Facts CreateArray(sizeof(line));
    
    
BuildPath(Path_SMpathPLATFORM_MAX_PATH"configs/facts.txt");
    
    if(
FileExists(path))
    {
        
Handle fileHandle OpenFile(path"r");
        while(!
IsEndOfFile(fileHandle)&&ReadFileLine(fileHandlelinesizeof(line)))
            
PushArrayString(ARRAY_Factsline);
        
        
CloseHandle(fileHandle);
    }
    else
    {
        
PushArrayString(ARRAY_Facts"Config file facts.txt missing or unable to read from !");
    }

Attached Files
File Type: smx Facts.smx (14.7 KB, 54 views)
__________________
Want to check my plugins ?

Last edited by Arkarr; 06-03-2017 at 15:48.
Arkarr 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 12:28.


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