[FilterScript] PizzaPuntjes Website Displayer v1
#1

Welcome to my first ever filterscript release on these forums. It's nothing really special but I think it can be useful to some users that wish to learn from my code or get ideas

Features

The filterscript currently has 5 features.



Change Website Text: Here can you change your website link.
Speed: Currently it has 3 speed modes; Normal - Fast - Rapid
No Mode: A simple plain white text with no effects.
Random Letter Colors:

Flashy Colors: This will change the color of the whole link in a random color.
Text Location: Right lower corner.

Instructions

To use this filterscript you need to copy-paste the script from one of the locations below into a fresh .pwn file.
When you've gotten to this step you need to compile it into the filterscripts folder.
After you've done this, edit the server.cfg and add the filename into it after the filterscripts line.
You can also load the script from the console using 'loadfs filename' or use '/rcon loadfs filename from in-game'.

To open the dialog to edit the modes, speed or website you have to type '/website'. Please note that you need to be RCON admin to do this.

Downloads:

Pastebin:
http://pastebin.com/iZRHaK3f

PHP код:
////////////////////////////////////////////////////
////////////////////////////////////////////////////
/*
        PizzaPuntjes Website Displayer
            Please do not remove credits :)
            
*/
////////////////////////////////////////////////////
////////////////////////////////////////////////////
#include <a_samp>
////////////////////////////////////////////////////
////////////////////////////////////////////////////
forward UpdateWebsiteDraw();
////////////////////////////////////////////////////
////////////////////////////////////////////////////
#define FS_NAME                 "PizzaPuntjes Website Shower"
#define WEBSITE                 ("www.example.com") // change this to your own website or do it from in-game
#define MODE_EDIT_TEXT          (0)
#define MODE_EDIT_SPEED          (1)
#define MODE_NOTHING            (2)
#define MODE_RANDOM_COLORS         (3)
#define MODE_FLASH_COLOR        (4)
////////////////////////////////////////////////////
////////////////////////////////////////////////////
new td_colors[][] = {
    {
"~r~"}, {"~b~"}, {"~p~"}, {"~g~"}, {"~y~"}, {"~h~"}
};
new 
dr_options[][] = {
    {
"Change Website Text"}, {"Speed"}, {"No Mode"}, {"Random Letter Colors"}, {"Flashy Colors"}
};
new 
speeds[][] = {
    {
1300,  "Normal Speed"},
    {
1000,  "Regular Speed"},
    {
750,   "Rapid Speed"}
};
enum DIALOG_SHOW_OPTIONSDIALOG_CHANGE_WEBSITE };
////////////////////////////////////////////////////
////////////////////////////////////////////////////
new active_mode MODE_RANDOM_COLORSspeed_modewebsite_timer;
new 
real_site[30];
new 
Text:Website_Draw;
////////////////////////////////////////////////////
////////////////////////////////////////////////////
public OnFilterScriptInit()
{
    print(
"\n--------------------------------------");
    print(
" Website Displayer v1 by PizzaPuntjes (2015)");
    print(
"--------------------------------------\n");
    if(
active_modewebsite_timer SetTimer("UpdateWebsiteDraw"speeds[speed_mode][0], true);
    
    
Website_Draw TextDrawCreate(511.714691412.293243WEBSITE);
    
TextDrawLetterSize(Website_Draw0.2681901.523199);
    
TextDrawAlignment(Website_Draw1);
    
TextDrawColor(Website_Draw, -1);
    
TextDrawSetShadow(Website_Draw0);
    
TextDrawSetOutline(Website_Draw1);
    
TextDrawBackgroundColor(Website_Draw30);
    
TextDrawFont(Website_Draw2);
    
TextDrawSetProportional(Website_Draw1);
    
TextDrawSetShadow(Website_Draw0);
    
    
real_site WEBSITE;
    return 
1;
}
public 
OnFilterScriptExit()
{
    
TextDrawDestroy(Website_Draw);
    return 
1;
}
public 
OnPlayerConnect(playerid)
{
    
TextDrawShowForPlayer(playeridWebsite_Draw);
    return 
1;
}
public 
OnPlayerDisconnect(playeridreason)
{
    
TextDrawHideForPlayer(playeridWebsite_Draw);
    return 
1;
}
public 
UpdateWebsiteDraw()
{
    new 
td_str[60];
    static 
new_cidprev_cid;
    
    if(
strlen(real_site) > 1format(td_strsizeof(td_str), real_site); else td_str WEBSITE;
    switch(
active_mode)
    {
        case 
MODE_RANDOM_COLORS:
        {
            for(new 
strlen(td_str); 0--)
            {
                if(
== strlen(td_str)) continue;
                
repick:
                
new_cid random(sizeof(td_colors));
                if(
prev_cid == new_cid) goto repick;
                
                
prev_cid new_cid;
                
strins(td_strtd_colors[new_cid], i);
            }
            
            
repick_2:
            
new_cid random(sizeof(td_colors));
            if(
prev_cid == new_cid) goto repick_2;
            
strins(td_strtd_colors[new_cid], 0);
        }
        case 
MODE_FLASH_COLOR:
        {
            
repick_3:
            
            
new_cid random(sizeof(td_colors));
            if(
prev_cid == new_cid) goto repick_3;
            if(!
strfind(td_colors[new_cid], "~h~"false0)) goto repick_3;
            
prev_cid new_cid;
            
strins(td_strtd_colors[new_cid], 0);
        }
    }
    
    
TextDrawSetString(Website_Drawtd_str);
    return 
1;
}
public 
OnPlayerCommandText(playeridcmdtext[])
{
    if(!
strcmp(cmdtext"/website"true))
    {
        if(!
IsPlayerAdmin(playerid)) return 1;
        
        
ShowSelectionDialog(playerid);
        return 
1;
    }
    return 
0;
}
public 
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    switch(
dialogid)
    {
        case 
DIALOG_SHOW_OPTIONS:
        {
            if(!
response) return SendClientMessage(playerid0xFFC00CFF"> You have closed the dialog for changing settings.");
            switch(
listitem)
            {
                case 
0:
                {
                    
ShowDialogChangeSite(playerid0);
                }
                case 
1:
                {
                    
speed_mode ++;
                    if(
speed_mode == sizeof(speeds)) speed_mode 0;
                    if(
website_timer)
                    {
                        
KillTimer(website_timer);
                        
website_timer SetTimer("UpdateWebsiteDraw"speeds[speed_mode][0], true);
                    }
                    
ShowSelectionDialog(playerid);
                }
                case 
2:
                {
                    if(
website_timerKillTimer(website_timer);
                    
TextDrawSetString(Website_Drawreal_site);
                }
                default:
                {
                    if(
website_timer)
                    {
                        
KillTimer(website_timer);
                        
website_timer SetTimer("UpdateWebsiteDraw"speeds[speed_mode][0], true);
                    }
                    else 
website_timer SetTimer("UpdateWebsiteDraw"speeds[speed_mode][0], true);
                }
            }
            if(
listitem >= 2)
            {
                
active_mode listitem;
                
ShowSelectionDialog(playerid);
            }
            return 
1;
        }
        case 
DIALOG_CHANGE_WEBSITE:
        {
            if(!
response) return SendClientMessage(playerid0xFFC00CFF"> You have returned to the options."), ShowSelectionDialog(playerid);
            if(
strlen(inputtext) < || strlen(inputtext) > 30) return ShowDialogChangeSite(playerid1);
            
format(real_sitesizeof(real_site), inputtext);
            
UpdateWebsiteDraw();
            
ShowSelectionDialog(playerid);
            return 
1;
        }
    }
    return 
0;
}
ShowSelectionDialog(playerid)
{
    new 
dialog_str[128 2];
    for(new 
0sizeof(dr_options); ++)
    {
        
strcat(dialog_strdr_options[i]);
        
        if(
== MODE_EDIT_TEXTstrcat(dialog_str" {FF0000}||{FFFFFF} "), strcat(dialog_strreal_site);
        if(
== MODE_EDIT_SPEEDstrcat(dialog_str" {FF0000}||{FFFFFF} "), strcat(dialog_strspeeds[speed_mode][1]);
        
        if(
active_mode == istrcat(dialog_str" {FF0000}||{FFFFFF}{7cfc00} [ACTIVE]{FFFFFF}");
        if(
!= sizeof(dr_options)) strcat(dialog_str"\n");
    }
    
    
ShowPlayerDialog(playeridDIALOG_SHOW_OPTIONSDIALOG_STYLE_LIST"{FFC00C}"FS_NAME""dialog_str"Select""Exit");
    return 
1;
}
ShowDialogChangeSite(playeriderror)
{
    new 
dialog_str[128];
    
    
strcat(dialog_str"{FFFFFF}Please fill in your desired website name:\n\n");
    
    if(
errorstrcat(dialog_str"{FF0000}The length must be between 2 and 30 characters!\n");
    
    
ShowPlayerDialog(playeridDIALOG_CHANGE_WEBSITEDIALOG_STYLE_INPUT"{FFC00C}"FS_NAME""dialog_str"Change""Return");
    return 
1;

Please leave feedback if you've got any and thanks for looking at this topic
Reply
#2

nice. Is this your first work?
Reply
#3

I have made little things before, but this is my first real project/release.
Reply
#4

Looks good. A little tip straight from the SA-MP wiki: You're better off using an enum for dialogs. You will no longer have to assign an ID to them, thus avoiding dialog ID collisions. However, enums use memory to store the defines, whereas defines are processed in the 'pre-processor' (compiling) stage.

PHP код:
enum
{
    
DIALOG_SHOW_OPTIONS,
    
DIALOG_CHANGE_WEBSITE
}; 
EDIT:
I prefer the use of a switch statement to look up dialogid's under OnDialogResponse instead of all the if statements. It is more organized and easier to manage.
Reply
#5

Oh, I never knew that. Thanks for the tips I've edited the topic.
Reply
#6

very nice!
Reply
#7

Not bad. You did a good job there
Reply
#8

What I would do is extend this system to be able to do the following.

1.) Save websites
2.) Set position
3.) Create styles

Another suggestion is avoid using public OnPlayerCommandText(playerid, cmdtext[]) directly even if you have one command just use a command processor (ZCMD) it is good practice.

Overall I wouldn't say this is good but unlike a lot of new guys you actually made an effort for your script to be complete and did something that could be useful which means you've learned something here.
Reply
#9

Good job Keep it Up
Reply
#10

Quote:
Originally Posted by Pottus
Посмотреть сообщение
What I would do is extend this system to be able to do the following.

1.) Save websites
2.) Set position
3.) Create styles

Another suggestion is avoid using public OnPlayerCommandText(playerid, cmdtext[]) directly even if you have one command just use a command processor (ZCMD) it is good practice.

Overall I wouldn't say this is good but unlike a lot of new guys you actually made an effort for your script to be complete and did something that could be useful which means you've learned something here.
Thanks for the suggestions. For the ZCMD one, I didn't add it because not everyone uses it and it's pretty easy to convert it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)