AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugin/Gameplay Ideas and Requests (https://forums.alliedmods.net/forumdisplay.php?f=60)
-   -   Random quotes (https://forums.alliedmods.net/showthread.php?t=298164)

sipster19 06-03-2017 13:10

Random quotes
 
I'm looking for a plugin that can displays random quotes to chat. For example, I have 50 quotes in a file, and it shows one in chat every 5 minutes. Does this exist anywhere?

WatchDogs 06-03-2017 13:27

Re: Random quotes
 
Why don't you use this ?

https://forums.alliedmods.net/showthread.php?t=155705

sipster19 06-03-2017 14:15

Re: Random quotes
 
It doesn't display things randomly. It goes in order (1, 2, 3, 4). So for every map, you get the same ads over and over again.

WatchDogs 06-03-2017 15:06

Re: Random quotes
 
OK. I'm writing a plugin for you.


Almost done. Maybe finish on tomorrow

Arkarr 06-03-2017 15:46

Re: Random quotes
 
1 Attachment(s)
Faster :3

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 !");
    }



sipster19 06-03-2017 17:45

Re: Random quotes
 
Thanks, I'll give it a shot.

It seems to work fine. The only minor problem I ran into was when I changed the sm_fact_interval via the console, it didn't update the timer.

WatchDogs 06-04-2017 04:17

Re: Random quotes
 
1 Attachment(s)
OK Thank you pro :wink:


Here is fix:

PHP Code:

#include <sourcemod> 
#include <multicolors> 

#define PLUGIN_AUTHOR     "Arkarr" 
#define PLUGIN_VERSION     "1.01" 
#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."); 
    
    
HookConVarChange(CVAR_FactsIntervalCvarChange_FactsInterval);


public 
void CvarChange_FactsInterval(Handle convarchar[] oldValuechar[] newValue)
{
    
KillTimer(TMR_TimerNextFact);
    
TMR_TimerNextFact CreateTimer(GetConVarFloat(CVAR_FactsInterval) * 60TMR_PrintRandomFact_TIMER_REPEAT);
}

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 !"); 
    } 



sipster19 06-04-2017 12:37

Re: Random quotes
 
Good job guys.

sipster19 06-04-2017 21:44

Re: Random quotes
 
I played around with the plugin some. I found if you change the map, the timer continues from the previous map. I've fixed this. Also, it seems that handles are killed when the plugin is unloaded or reloaded.

https://forums.alliedmods.net/showpo...47&postcount=2
https://forums.alliedmods.net/showpo...6&postcount=12

So I removed the OnPluginEnd() method.

PHP Code:

#include <sourcemod>  
#include <multicolors>  

#define PLUGIN_AUTHOR     "Arkarr"  
#define PLUGIN_VERSION     "1.02"  
#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.");  
     
    
HookConVarChange(CVAR_FactsIntervalCvarChange_FactsInterval); 
}  

public 
void CvarChange_FactsInterval(Handle convarchar[] oldValuechar[] newValue

    
KillTimer(TMR_TimerNextFact); 
    
TMR_TimerNextFact CreateTimer(GetConVarFloat(CVAR_FactsInterval) * 60TMR_PrintRandomFact_TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE); 


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

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 !");  
    }  



WatchDogs 06-05-2017 01:06

Re: Random quotes
 
Yes right, But I think you should kill it in OnMapEnd then create it in OnConfigsExecuted.



EDIT: If you set "TIMER_FLAG_NO_MAPCHANGE" flag on the timer it doesn't need to kill it OnMapEnd & create it when map starts.


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

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