Raised This Month: $120 Target: $400
 30% 

[TF2] ScrollingRules


Post New Thread Reply   
 
Thread Tools Display Modes
Author
Zirconium
Member
Join Date: Jul 2011
Plugin ID:
2533
Plugin Version:
1.0.0
Plugin Category:
General Purpose
Plugin Game:
Team Fortress 2
Plugin Dependencies:
    Servers with this Plugin:
    8 
    Plugin Description:
    Displays the Server Rules to users each xxx seconds or on demand to user who asked for
    Old 08-31-2011 , 17:56   [TF2] ScrollingRules
    Reply With Quote #1

    Description : Displays the Server's Rules to all players each XX seconds, or on demand for the current player when asking for them using !rules or /rules in chat command.

    CVARs :

    scrollingrules_version
    The version of this plugin, don't forget to change it in your existing cfg file when you update the plugin.

    scrollingrules_enabled
    Enables/Disable displaying the scrolling rules. (0 = disabled, 1 = enabled)
    Default 1 = enabled

    scrollingrules_howto
    Enable/Disable the display of "How To" message like "type !rules in chat to view our rules". (0 = disabled, 1 = enabled)
    Default 1 = enabled

    scrollingrules_howto_delay
    Amount of seconds before the "How To" message is shown after map has started.
    Default 20 seconds

    scrollingrules_interval
    Amount of seconds between each "group" of rules scrolling automaticaly in chat.
    Default 300 seconds

    scrollingrules_delay
    Amount of seconds between each rule line scrolling when "on demand".
    Default 0.2 seconds

    scrollingrules_autodelay
    Amount of seconds between each rule line scrolling when "auto scrolling".
    Default 0.5 seconds

    scrollingrules_file File to read the scrolling rules from, located in /translations dir.
    Default: scrollingrulesdata.phrases.txt


    The plugin, by default, reads the 'rules' from translations/scrollingrulesdata.phrases.txt, which has this format:

    Code:
            "Phrases"
            {
                "Rule01"
                {
                    "en"        "{red}This are our Server Rules !"
                }
                "Rule02"
                 {
                     "en"        "{red}Follow them {default}or you'll be {red}kicked {default}from Server"
                 }
                 ....
                 "Rule10"
                 {
                     "en"        "'=================================================="
    ...
             }


    Other language files in
    translations/de/scrollingrulesdata.phrases.txt, for german :

    Code:
            "Phrases"
            {
                "Rule01"
                {
                   "de"       "{red}Dass sind unsere Regeln !"
                }
                 "Rule02"
                 {
                     "de"        "{red}Beobachtet Sie {default}oder sie werden vom Server {red}gekickt"'
                 }
                 ....
                 "Rule10"
                 {
                     "de"        "=================================================="
    ...
             }


    or
    translations/fr/scrollingrulesdata.phrases.txt for french:

    Code:
            "Phrases"
            {
                "Rule01"
                {
                    "fr"        "{red}Voici nos Règles !"
                }
                "Rule02"
                 {
                    "fr"        "{red}Respectez les ou vous serez Kické"
                 }
                 ....
                 "Rule10"
                 {
                     "fr"        "=================================================="
    ...
             }


    or in translations/$lang/scrollingrulesdata.phrases.txt for $lang language where $lang is a language code existing in sourcemod/configs/language.cfg on your server!!!

    For more info about languages and translations look HERE

    Each language file must have the same Sections names inside.

    Keep this file structure or the plugin won't work (sections names HAVE TO CONTAIN THE WORD 'Rule', like 'Rule01' or 'Rule Line 2' etc...) .

    If you have [INC]Colors installed you can use color codes in your rules file by uncommenting the //#define USECOLORS and recompile the plugin at your own. If it's NOT installed DON'T USE COLOR TAGS or it won't give you colored text.

    WARNING
    =======

    With version 0.1.0 [INC]Colors has been be replaced by [INC]Morecolors when enabling USECOLORS you'll need to use sourcemod >= version1.5 to compile it if you start from source.

    Two versions are now included, one with USECOLORS activated and the other without it, so you don't need to compile, just choose your version and rename it to scrollingrules.smx after download.


    Installation :

    Put the scrollingrules.phrases.txt file in your %GAMEDIR%/addons/sourcemod/translations directory, this is used to have translation on "How To" message.

    Put the scrollingrulesdata.phrases.txt file in your %GAMEDIR%/addons/sourcemod/translations directory, this is used as rules KV file and for rules translation.

    Put the scrollingrules.smx file in your %GAMEDIR%/addons/sourcemod/plugins directory.

    The scrollingrules.cfg file in your %GAMEDIR%/cfg/sourcemod directory will be auto-generated because AutoExecConfig(true, "scrollingrules"); is set on plugin start, just edit this file if you want to modifiy default values to yours.


    Changelog
    :

    • 0.0.1
      • Initial version (be indulgent it's my first plugin )
    • 0.0.2
      • Changed to KV file no more rules number limit
    • 0.0.3
      • Fixed some warning coding errors
      • #define USECOLORS is not set as default in .smx version
      • scrollingrules.cfg file is 'auto-generated' if not existing at plugin start
    • 0.0.4
      • Using a translation file for getting rules translated in chat.
    • 0.0.5
      • Fixed index problem in SendToAllMsg when server is empty
    • 0.0.6
      • Fixed warning error "KillTimer" on OnMapStart
    • 0.0.7
      • Using PrintToChat and CPrintToChat translation capabilities
      • Added a scrolllingrules_howto_delay var
      • Added a "Start message" in console when plugin starts
    • 0.0.8
      • Fixed global warnings with "KillTimer"
      • translations files examples are provided without color tags inside
    • 0.0.9
      • Fixed KillTimer warning message on map change.
    • 0.1.0
      • Changed from colors.inc to morecolors.inc and updating for sourcemod 1.5.0. Two versions are now included, one with USECOLORS activated and the other without it, so you don't need to compile, just choose your version and rename it after download.
    • 0.1.1
      • updated for sourcemod 1.8.0. and fixed warning messages concerning FCVAR_PLUGIN.
    • 1.0.0
      • solved {teamcolor} issue in welcome message. Version is now fully functional.

    Screenshots
    Attached Thumbnails
    Click image for larger version

Name:	2011-09-12_00002.jpg
Views:	2221
Size:	10.8 KB
ID:	92551   Click image for larger version

Name:	2011-09-12_00003.jpg
Views:	1493
Size:	10.8 KB
ID:	92552  
    Attached Files
    File Type: txt scrollingrules.phrases.txt (262 Bytes, 994 views)
    File Type: txt scrollingrulesdata.phrases.txt (1.3 KB, 1015 views)
    File Type: smx scrollingrules_with_usecolors.smx (14.2 KB, 81 views)
    File Type: sp Get Plugin or Get Source (scrollingrules_with_usecolors.sp - 65 views - 11.6 KB)
    File Type: smx scrollingrules_without_usecolors.smx (8.2 KB, 81 views)
    File Type: sp Get Plugin or Get Source (scrollingrules_without_usecolors.sp - 254 views - 11.4 KB)

    Last edited by Zirconium; 07-04-2017 at 10:01. Reason: Version 1.0.0 released
    Zirconium is offline
    Kjaer
    Senior Member
    Join Date: Oct 2009
    Location: Canada
    Old 08-31-2011 , 18:17   Re: ScrollingRules
    Reply With Quote #2

    Might wanna up the rule max.
    __________________
    If you require server assistance add me!
    Kjaer is offline
    Antithasys
    Moderator
    Join Date: Apr 2008
    Old 08-31-2011 , 18:30   Re: ScrollingRules
    Reply With Quote #3

    The hardcoded array used to display the rules is very odd indeed. While it is necessary to know the name of the translation file, using a scheme would appear appropriate here, and it looks like you already made one.

    "RuleX" can be used. This would make the rule count almost unlimited. Since the phrases file is just a KV file, the number of sections could easily be read into a global variable and all you to append the "RuleX" string to continually get the next rule in a loop. Or something, this is just off the top of my head.
    __________________
    [my plugins]

    When you think about asking a question... consider what have you tried?
    Antithasys is offline
    desynced
    Member
    Join Date: Feb 2010
    Old 09-01-2011 , 00:15   Re: ScrollingRules
    Reply With Quote #4

    Plugin failed to compile! Please try contacting the author.
    desynced is offline
    Zirconium
    Member
    Join Date: Jul 2011
    Old 09-01-2011 , 07:18   Re: ScrollingRules
    Reply With Quote #5

    to desynced which errors did you get ??

    try to comment out the #define USECOLORS maybe you don't have colors.inc in your inc files list.


    to Antithasys :
    Quote:
    Originally Posted by Antithasys View Post
    The hardcoded array used to display the rules is very odd indeed. While it is necessary to know the name of the translation file, using a scheme would appear appropriate here, and it looks like you already made one.
    ermmm sorry m8, but i don't know yet how to use KV file with translations , but i'm working "hard" to learn it .

    Quote:
    Originally Posted by Antithasys View Post
    "RuleX" can be used. This would make the rule count almost unlimited. Since the phrases file is just a KV file, the number of sections could easily be read into a global variable and all you to append the "RuleX" string to continually get the next rule in a loop. Or something, this is just off the top of my head.
    When i solved first point i'll try to do it like you proposed , the point is, the same file is used to "auto scroll" rules and when !rules (sm_rules) is asked by a player !!

    Last edited by Zirconium; 09-01-2011 at 09:49.
    Zirconium is offline
    Antithasys
    Moderator
    Join Date: Apr 2008
    Old 09-01-2011 , 16:38   Re: ScrollingRules
    Reply With Quote #6

    Some suggestions:

    Create a global to get the total number of rules.
    PHP Code:
    //total amount of rules in file.
    //get this from counting kv sections in some function
    new g_iTotalRules 0
    Then when you need to load the rules into the message que, or whatever.
    PHP Code:
    for (new 1<= g_iTotalRulesi++)
    {
        
    decl String:sBuffer[256];
        
    Format(sBuffersizeof(sBuffer), "Rule%i"i);
        
    Format(sBuffersizeof(sBuffer), "%T"sBuffer);
        
    AddMsgToAllQueue(clientsBuffer);

    What the above loop does is append the word 'Rule' with a number that increases... like 1, 2, 3, 4, etc... It then gets the translation for that new string and stores it. Then adds it to the queue. This way you don't need to know the literal translation phrase or the total amount of rules.

    *While I didn't solve all your problems, this should get you going in the right direction.
    __________________
    [my plugins]

    When you think about asking a question... consider what have you tried?
    Antithasys is offline
    Zirconium
    Member
    Join Date: Jul 2011
    Old 09-05-2011 , 18:21   Re: [TF2]ScrollingRules
    Reply With Quote #7

    to Antithasys :

    If you could have a look at what i did and tell me if it's ok or not it would be great.

    Not sure i did well

    Thanks for your help.
    Zirconium is offline
    Zirconium
    Member
    Join Date: Jul 2011
    Old 09-06-2011 , 10:15   Re: [TF2]ScrollingRules
    Reply With Quote #8

    I'll try it with KV file like this, hope it 'll work (a scrollingrulesdata.phrases.txt file from translations dir will be loaded and used to translate and also as KV file)

    PHP Code:
    ...
    LoadTranslations("myplugin.phrases");
    ...
        
    BuildPath(Path_SMsPathsizeof(sPath), "translations/%s"sFile);
        if (
    FileExists(sPath)) {
            
    FileToKeyValues(g_hRulessPath);
            
    // Moves to the FIRST SubKey level before reading
            
    KvGotoFirstSubKey(g_hRules);
            
    // Loop for reading all rules
    ...
            do
            {
                
    // Get the Section's Name to use it for getting translations 
                
    KvGetSectionName(kvsSectionNamesizeof(sSectionName));
                
    // Send the rule text to client's message queue using translations
                
    if (StrContains(sSectionName"Rule"true) != -) {
                    new 
    String:sMsg[255];
                    
    // Formating the message string with translation file
                    
    Format(sMsgsizeof(sMsg), "%t" sSectionNameclient);
                    
    AddMsgToQueue(clientsMsg);
                } 
            } while (
    KvGotoNextKey(kv));
            
    ...

    stock bool:AddMsgToQueue(iClient, const String:szMessage[], any:...) {
        if (!
    IsClientInGame(iClient)) {
            return 
    false;
        }
        new 
    String:szFormattedMsg[64];
        
    VFormat(szFormattedMsgsizeof(szFormattedMsg), szMessage3);
        
    PushArrayCell(g_hUserIdQueueGetClientUserId(iClient));
        
    PushArrayString(g_hMsgQueueszFormattedMsg);
        
        if (
    g_hMsgTimer == INVALID_HANDLE) {
            
    g_hMsgTimer CreateTimer(GetConVarFloat(g_hDelay) * 1.0Timer_SendMsg_TIMER_REPEAT);
        }
        return 
    true;
    }
    ...
    public 
    Action:Timer_SendMsg(Handle:timer) {
        if (!
    GetArraySize(g_hMsgQueue)) {
            
    g_hMsgTimer INVALID_HANDLE;
            return 
    Plugin_Stop;
        }
        new 
    String:szMessage[64];
        
    GetArrayString(g_hMsgQueue0szMessagesizeof(szMessage));
        new 
    iClient GetClientOfUserId(GetArrayCell(g_hUserIdQueue0));
        if (
    IsPlaying(iClient)) {
            
    #if defined USECOLORS
                
    CPrintToChat(iClientszMessage);
            
    #else
                
    PrintToChat(iClientszMessage);
            
    #endif        
        
    }
        
    RemoveFromArray(g_hMsgQueue0);
        
    RemoveFromArray(g_hUserIdQueue0);
        return 
    Plugin_Handled;
    }  

    ... 
    This is working not too bad, my only problem now is i can't get the first rule section printed because it seems it's not detected correctly.
    I hope i'll reach to solve this last point, if someone has an idea ?

    Ok problem is solved, was an encoding problem with my phrases.txt file, switched to UTF8 without BOM, put the files in different translations subdir for each corresponding language and now all is working

    Last edited by Zirconium; 09-05-2013 at 03:27.
    Zirconium is offline
    Zirconium
    Member
    Join Date: Jul 2011
    Old 09-08-2011 , 18:06   Re: [TF2]ScrollingRules
    Reply With Quote #9

    Plugin is working good since a couple of days, hope someone will look at it and why not approve it if it's ok for it.
    __________________

    Last edited by Zirconium; 09-08-2011 at 18:14.
    Zirconium is offline
    Spunkie
    Junior Member
    Join Date: Aug 2011
    Old 09-11-2011 , 04:27   Re: [TF2]ScrollingRules
    Reply With Quote #10

    Would love to get a couple of screenshots or a demo video in your original post. ^_^
    Spunkie is offline
    Reply


    Thread Tools
    Display Modes

    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:34.


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