viewing paste Limao - News Board 1.2.1 | Athena

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
/* ================================================================
 ,--.   ,--.               ,--.                             ,--.  
 |  |   `--' ,---. ,--,--, |  ,---.  ,---.  ,--,--.,--.--.,-'  '-.
 |  |   ,--.| .-. ||      \|  .-.  || .-. :' ,-.  ||  .--''-.  .-'
 |  '--.|  |' '-' '|  ||  ||  | |  |\   --.\ '-'  ||  |     |  |  
 `-----'`--' `---' `--''--'`--' `--' `----' `--`--'`--'     `--'  
=========================== News Board ============================
- Current Version:
    1.2.1: - Fixed a small mistake I made on the last update;
    1.2:- Moved the configurations to the bottom of the script
         ( Line 200 to 215 );
        - Fixed a bug when posting multiple news at a time;
        - Added an option to turn broadcasts on/off;
    1.1: Optmized the script a LOT:
        - Removed many callsubs;
        - Optimized the SQL querys;
        - Corrected a mistake when deletings notices;
        - Added an option to print the news in descending order
         so you no longer need to run the SQL query to reorder the
        table;
        - Added an option to choose max number of printed news;
        - The "news" table will now be created when you
        @reloadscript or restart the server;
        - Added scape_sql so the script won't error when you use
        the string ' in your news;
 
    1.0: First, unoptimized script.
- Description:
    Easily post and read news in-game.
=================================================================== */
 
prontera,164,175,1  script  News Board  837,{
 
P_STAFF:
if ( getgmlevel() >= .gmacess ) {
    mes "[News Board]";
    mes "What would you like to do?";
    switch ( select ("Read Board:Post New Notice:Delete Post") )
    {
        case 1:
            next;
            callsub P_PLAYER;
        end;
        
        case 2: //Post new
            next;
            mes "[News Board]";
            mes "What kind of news?";
            switch ( select("Announcements:Events:Others" ) )
            {
                case 1:
                    set @type,1;
                break;
                
                case 2:
                    set @type,2;
                break;
                
                case 3:
                    set @type,3;
                break;
            }
            next;
            
            mes "[News Board]";
            mes "Enter the title:";
            input @title$;
            
            next;
            mes "[News Board]";
            mes "Enter message:";
            input @mes$[0];
                if ( select ("I'm done:Add more") == 1 ) callsub POST_END;
                
            mes "- Enter second part of notice";
            input @mes$[1];
                if ( select ("I'm done:Add third part") == 1 ) callsub POST_END;
            
            mes "- Enter third part of notice";
            input @mes$[2];
                if ( select ("I'm done:Add fourth part") == 1 ) callsub POST_END;
            
            mes "- Enter fourth part of notice";
            input @mes$[3];
                if ( select ("I'm done:Add last part") == 1 ) callsub POST_END;
            
            mes "- Enter last part of notice";
            input @mes$[4];
            
            POST_END:
                next;
                mes "[News Board]";
                mes "Here's a preview:";
                next;
                
                set .@poster$,strcharinfo(0);
                set .@dateposted$,gettimestr("%Y-%m/%d %H:%M:%S",21);
                
                mes "[^FF0000" + @title$ + "^000000]";
                mes "Posted by ^0033FF" + .@poster$ + "^000000";
                mes "On ^0033FF" + .@dateposted$ + "^000000";
                mes @mes$[0] + " " + @mes$[1] + " " + @mes$[2]+" " + @mes$[3] +" " + @mes$[4];
                next;
                
                mes "[News Board]";
                mes "Confirm?";
                    if (select("Yes:No") == 2) { next; callsub P_STAFF; }
                next;
                
                set .@ptitle$, escape_sql(@title$);
                set .@pmes$[0], escape_sql(@mes$[0]);
                set .@pmes$[1], escape_sql(@mes$[1]);
                set .@pmes$[2], escape_sql(@mes$[2]);
                set .@pmes$[3], escape_sql(@mes$[3]);
                set .@pmes$[4], escape_sql(@mes$[4]);
 
                
                query_sql("INSERT INTO `news` (`poster`,`title`,`content`,`content2`,`content3`,`content4`,`content5`,`type`,`date`) VALUES ('" + .@poster$ + "','" + .@ptitle$ + "','" + .@pmes$[0] + "','" + .@pmes$[1] + "','" + .@pmes$[2] + "','" + .@pmes$[3] + "','" + .@pmes$[4] + "','" + @type + "','" + .@dateposted$ + "')");
                
                mes "[News Board]";
                mes "New notice posted.";
                if (.broadcast) {
                    if ( @type == 1 ) announce .@poster$ + " placed a new Announcement. Check the News Board!",bc_all;
                    if ( @type == 2 ) announce .@poster$ + " placed a new Event. Check the News Board!",bc_all;
                    if ( @type == 3 ) announce .@poster$ + " placed a new Notice. Check the News Board!",bc_all;
                }
                deletearray @mes$[0],10;
        close;
        
        case 3: //Delete
            next;
            mes "[News Board]";
            mes "Input the post ID:";
            
            input @did;
            
            query_sql "SELECT `poster`,`title`,`content`,`content2`,`content3`,`content4`,`content5`,`date` FROM `news` WHERE `id`='" + @did + "'",.@dposter$,.@dtitle$,.@dcontent$,.@dcontent2$,.@dcontent3$,.@dcontent4$,.@dcontent5$,.@ddate$;
            
            next;
            if ( .@dtitle$ == "") { mes "[News Board]";  mes "This post doesn't exist!"; close; }
            
            mes "Post ID ^FF0000" + @did + "^000000 is:";
            mes "------------------------------";
            mes "[^FF0000"+.@dtitle$+"^000000]";
            mes "Posted by ^0033FF"+.@dposter$+"^000000";
            mes "Date: ^0033FF"+.@ddate$+"^000000";
            mes .@dcontent$ + " " + .@dcontent2$ + " " + .@dcontent3$ + " " + .@dcontent4$ + " " + .@dcontent5$;
            mes "------------------------------";
            
            next;
            mes "[News Board]";
            mes "Confirm?";
            
            if (select("Yes:No") == 2) { next; callsub P_STAFF; }
            
            query_sql "DELETE FROM `news` WHERE `id`='" + @did + "'";   
            
            next;
            mes "[News Board]";
            mes "Post deleted.";
        close;
    }
}
 
P_PLAYER:
mes "[News Board]";
mes "Wich news do you want to read?";
    switch ( select ("Announcements:Events:Others") )
    {
        case 1:
            set @type,1;
        break;
        
        case 2:
            set @type,2;
        break;
        
        case 3:
            set @type,3;
        break;
    }
next;
 
if ( .pdesc ) { query_sql "SELECT `id`,`poster`,`title`,`content`,`content2`,`content3`,`content4`,`content5`,`date` FROM `news` WHERE `type`='" + @type + "' ORDER BY `id` DESC LIMIT " + .nlimit,.@pid,.@pposter$,.@ptitle$,.@pcontent$,.@pcontent2$,.@pcontent3$,.@pcontent4$,.@pcontent5$,.@pdate$; }
else { query_sql "SELECT `id`,`poster`,`title`,`content`,`content2`,`content3`,`content4`,`content5`,`date` FROM `news` WHERE `type`='" + @type + "' LIMIT " + .nlimit,.@pid,.@pposter$,.@ptitle$,.@pcontent$,.@pcontent2$,.@pcontent3$,.@pcontent4$,.@pcontent5$,.@pdate$; }
 
if (!.@pid) { mes "[News Board]"; mes "This section is empty."; close; }
 
for( set .@n, 0; .@n < getarraysize( .@pid ); set .@n, .@n +1 )
{
    mes "[^FF0000" + .@ptitle$[.@n] + "^000000]";
    mes "Posted by ^0033FF" + .@pposter$[.@n] + "^000000";
    mes "Date: ^0033FF" + .@pdate$[.@n] + "^000000";
    mes .@pcontent$[.@n] + " " + .@pcontent2$[.@n] + " " + .@pcontent3$[.@n] + " " + .@pcontent4$[.@n] + " " + .@pcontent5$[.@n];
    if ( getgmlevel() >= .gmacess ) {mes "ID of this post: ^FF0000"+.@pid[.@n]+"^000000";}
    mes "==============================";
}
next;
    if ( getgmlevel() >= .gmacess ) goto P_STAFF;
    else goto P_PLAYER;
end;
 
OnInit:
 
    /* ==================== Configurations ==================== */
    // GMs with this lvl will be able to post/delete news.
    // They also will be able to see the post ID.
    set .gmacess,99;
 
    // Do you want to print the news in descending order (Newer to older)? 1 = yes, 0 = no
    set .pdesc,1;
 
    // Maximum number of news you want to display ( up to 128 )
    set .nlimit,50;
 
    // Broadcast when news are posted? 1 = yes, 0 = no
    set .broadcast,1;
    
    /* ======================================================== */
    
    query_sql("CREATE TABLE IF NOT EXISTS `news` (`id` INT(11) NOT NULL auto_increment,`poster` VARCHAR(20) NOT NULL,`title` VARCHAR(20) NOT NULL,`content` VARCHAR(100) NOT NULL,`content2` VARCHAR(100) NOT NULL,`content3` VARCHAR(100) NOT NULL,`content4` VARCHAR(100) NOT NULL,`content5` VARCHAR(100) NOT NULL,`type` INT(11) NOT NULL,`date` DATE NOT NULL, PRIMARY KEY(`id`)) ENGINE=MyISAM");
end;
}
Viewed 797 times, submitted by Guest.