Raised This Month: $ Target: $400
 0% 

Need help transforming the plugin..


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
shubhamgulati12
Senior Member
Join Date: Oct 2010
Location: Inida The Holy Place!!
Old 12-30-2013 , 09:29   Need help transforming the plugin..
Reply With Quote #1

fgI have one roundsound plugin in which sounds are played after round ends based on the winning of the specific team.
I want to change it such that it runs after every xyz seconds..

Here is the code:
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <tutor>
#include <ColorChat>

#define PLUGIN "Sounds"
#define VERSION "xyz"
#define AUTHOR "xyz"

new Array:g_PathCT,
    Array:
g_PathTT,
    Array:
g_SoundNameCT,
    Array:
g_SoundNameTT;

new 
bool:g_RoundSound[33],
    
bool:g_ShowAds[33],
    
bool:g_FirstPlay,
    
bool:g_MusicPlaying;

new 
g_LastSong[96],
    
g_Prefix[64],
    
g_ShowInfo[33],
    
g_ArraySize[4],
    
g_Pcvar[4],
    
g_ValueTeam[2],
    
g_ShowType,
    
g_MaxPlayers,
    
g_PlaylistType,
    
g_RandomMusic;

new const 
g_ShowNames[][]={
    
"Brak",
    
"Tutor",
    
"Czat"
};

new const 
g_CvarName[][]={
    
"Roundsound_ads_time",
    
"Roundsound_prefix",
    
"Roundsound_random_music",
    
"Roundsound_show_type"
};

new const 
g_CvarValue[][]={
    
"120",
    
"RoundSound",
    
"0",
    
"1"
};

new const 
g_LangCmd[][]={
    
"say /sounds",    
    
"say_team /sounds"
};

new const 
g_LastLangCmd[][]={
    
"say /lastsong",
    
"say_team /lastsong"
};

enum{
    
Tutor_Msg 1,
    
Chat_Msg
};

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR);
    
    for(new 
0sizeof g_LangCmdi++){
        
register_clcmd(g_LangCmd[i], "ShowRsMenu");
    }
    for(new 
0sizeof g_LastLangCmdi++){
        
register_clcmd(g_LastLangCmd[i], "ShowLastSong");
    }
    
register_event("SendAudio""PlaySoundTT""a""2&%!MRAD_terwin");
    
register_event("SendAudio""PlaySoundCT""a""2&%!MRAD_ctwin");
    
    
register_logevent("RoundStart"2"1=Round_Start");
    
    
tutorInit();
    
    for(new 
0sizeof g_CvarNamei++){
        
g_Pcvar[i] = register_cvar(g_CvarName[i], g_CvarValue[i]);
    }
}

public 
plugin_precache(){
    
g_PathCT ArrayCreate(128);
    
g_PathTT ArrayCreate(128);
    
    
g_SoundNameCT ArrayCreate(96);
    
g_SoundNameTT ArrayCreate(96);
    
    
LoadSounds();
    
    
tutorPrecache();
}

public 
plugin_cfg(){
    
get_pcvar_string(g_Pcvar[1], g_Prefixcharsmax(g_Prefix));
    
    
g_ShowType get_pcvar_num(g_Pcvar[3]);
    
g_RandomMusic get_cvar_num(g_Pcvar[2]);
    
    
g_MaxPlayers get_maxplayers();
    
    
set_task(get_pcvar_float(g_Pcvar[0]), "ShowAds",.flags "b");
    
    
g_ValueTeam[0] = g_ValueTeam[1] = -1;
}

public 
client_authorized(id){
    
g_RoundSound[id] = true;
    
    
g_ShowAds[id]  = true;
    
    
g_ShowInfo[id] = g_ShowType;
}

public 
LoadSounds(){
    new 
g_Path[128];
    
formatex(g_Pathget_configsdir(g_Pathcharsmax(g_Path)) ], charsmax(g_Path), "/RoundSound.ini");
    
    if(
file_exists(g_Path)){
        new 
g_Line[256],
            
g_SoundPath[128],
            
g_Name[96],
            
g_Team[3],
            
g_Len;
        
        for(new 
0read_file(g_Pathig_Linecharsmax(g_Line), g_Len); i++){
            if(!
g_Len || !g_Line[0] || g_Line[0] == ';'){
                continue;
            }
            
parse(g_Lineg_SoundPathcharsmax(g_SoundPath), g_Namecharsmax(g_Name), g_Teamcharsmax(g_Team));
            
            new 
g_Value strlen(g_SoundPath) - 4;
            
            
log_amx("Path: %s | Title: %s | Team: %s | Format: %s"g_SoundPathg_Nameg_Teamg_SoundPathg_Value ]);
            
            if(
equal(g_SoundPathg_Value ], ".mp3") || equal(g_SoundPathg_Value ], ".wav")){
                if(
equal(g_SoundPathg_Value ], ".mp3")){
                    
format(g_SoundPathcharsmax(g_SoundPath), "sound/%s"g_SoundPath);
                    
precache_generic(g_SoundPath);
                }
                else{
                    
precache_sound(g_SoundPath);
                }
                
                
/*    Check team    */
                
if(equal(g_Team"CT")){
                    
ArrayPushString(g_PathCTg_SoundPath);
                    
ArrayPushString(g_SoundNameCTg_Name);
                
                }
                else if(
equal(g_Team"TT")){
                    
ArrayPushString(g_PathTTg_SoundPath);
                    
ArrayPushString(g_SoundNameTTg_Name);
                }
                
log_amx("File %s has a good format"g_SoundPath);
            }
            else{
                
log_amx("File %s has a bad format"g_SoundPath);
            }
        }
    }
    else{
        
/*        Houston, We've Got a Problem.        */
        
set_fail_state("File RoundSound.ini not exist in configs/");
    }
    
GetArraySize();
}

public 
GetArraySize(){
    
g_ArraySize[0] = ArraySize(g_PathCT);
    
g_ArraySize[1] = ArraySize(g_PathTT);
    
g_ArraySize[2] = ArraySize(g_SoundNameCT);
    
g_ArraySize[3] = ArraySize(g_SoundNameTT);
}

public 
ShowRsMenu(id){
    new 
g_FormatText[64];
    
    new 
g_Menu menu_create("\wRoundSound ustawienia""MenuChoose");
    
    
formatex(g_FormatTextcharsmax(g_FormatText), "\yRoundsound: \r[\d%s\r]"g_RoundSound[id] ? "ON" "OFF");
    
menu_additem(g_Menug_FormatText);
    
    
menu_additem(g_Menu"\rOdsluchaj utwory \yCT \d[\yPlaylista\d]");
    
menu_additem(g_Menu"\yOdsluchaj utwory \rTT \d[\rPlaylista\d]");
    
    
formatex(g_FormatTextcharsmax(g_FormatText), "\rReklamy: \y[\d%s\y]"g_ShowAds[id] ? "ON" "OFF");
    
menu_additem(g_Menug_FormatText);
    
    
formatex(g_FormatTextcharsmax(g_FormatText), "\yWyswietlanie nazwy \rutworu: \y[\d%s\y]"g_ShowNamesg_ShowInfo[id] ]);
    
menu_additem(g_Menug_FormatText);
    
    
menu_setprop(g_MenuMPROP_EXITNAME"Wyjscie");
    
menu_display(idg_Menu);
}

public 
MenuChoose(idg_Menug_Item){
    if(
g_Item == MENU_EXIT){
        
menu_destroy(g_Menu);
        return 
PLUGIN_HANDLED;
    }
    
    switch(
g_Item){
        case 
0:{
            
g_RoundSound[id] = !g_RoundSound[id];
            
ColorChat(idTEAM_COLOR"[%s]^x04 Sound:^x03 %s"g_Prefixg_RoundSound[id] ? "switched off" "switched off");
            
            
ShowRsMenu(id);
        }
        
        case 
1..2:{
            
ShowPlaylist(idg_Item);
        }
        
        case 
3:{
            
g_ShowAds[id] = !g_ShowAds[id];
            
ColorChat(idTEAM_COLOR"[%s]^x04 Ads:^x03 %s"g_Prefixg_ShowAds[id] ? "Enabled" "Disabled");
            
            
ShowRsMenu(id);

        }
        
        case 
4:{
            if(
g_ShowInfo[id] >= 2){
                
g_ShowInfo[id] = -1;
            }
            
g_ShowInfo[id]++;
            
            
ShowRsMenu(id);
        }
    }
    
menu_destroy(g_Menu);
    return 
PLUGIN_HANDLED;
}

public 
ShowPlaylist(idg_Type){
    new 
g_FormatText[64],
        
g_Name[96];
        
    
formatex(g_FormatTextcharsmax(g_FormatText), "Playlist \d%s"g_Type == "CT" "TT");
    new 
g_Menu menu_create(g_FormatText"PlaylistChoose");
    
    switch(
g_Type){
        case 
1:{
            for(new 
g_Item 0g_Item g_ArraySize[2]; g_Item++){
                
ArrayGetString(g_SoundNameCTg_Itemg_Namecharsmax(g_Name));
                
menu_additem(g_Menug_Name);
            }
        }
        case 
2:{
            for(new 
g_Item 0g_Item g_ArraySize[3]; g_Item++){
                
ArrayGetString(g_SoundNameTTg_Itemg_Namecharsmax(g_Name));
                
menu_additem(g_Menug_Name);
            }
        }
    }
    
g_PlaylistType g_Type;
    
    
menu_setprop(g_MenuMPROP_BACKNAME"Back");
    
menu_setprop(g_MenuMPROP_NEXTNAME"Next");
    
menu_setprop(g_MenuMPROP_EXITNAME"Exit");
    
menu_setprop(g_MenuMPROP_NUMBER_COLOR"\r");
    
    
menu_display(idg_Menu);
}

public 
PlaylistChoose(idg_Menug_Item){
    if(
g_Item == MENU_EXIT){
        
menu_destroy(g_Menu);
        return 
PLUGIN_HANDLED;
    }
    
    new 
g_SoundPath[128];
    
ArrayGetString(g_PlaylistType == g_PathCT g_PathTTg_Itemg_SoundPathcharsmax(g_SoundPath));
    
    new 
g_Format strlen(g_SoundPath) - 4;
    
    if(
equal(g_SoundPathg_Format ], ".mp3")){
        
client_cmd(id"mp3 play %s"g_SoundPath);
    }
    else{
        
client_cmd(id"spk %s"g_SoundPath);
    }
    
ShowPlaylist(idg_PlaylistType);
    
    return 
PLUGIN_CONTINUE;
}

public 
ShowLastSong(id){
    if(
g_FirstPlay){
        
ColorChat(idTEAM_COLOR"[%s]^x04 The last song:^x03 %s"g_Prefixg_LastSong);
    }
    else{
        
ColorChat(idTEAM_COLOR"[%s]^x04 There was no play back^x03 song!"g_Prefix);
    }
}

public 
RoundStart(){
    
g_MusicPlaying false;
}

public 
PlaySoundTT(){
    
CheckMusic(1);
}

public 
PlaySoundCT(){
    
CheckMusic(2);
}

public 
CheckMusic(g_Type){
    if(!
g_MusicPlaying){
        
RandMusic(g_Type);
        
g_MusicPlaying true;
    }
}

public 
RandMusic(g_Type){
    if(!
g_FirstPlay){
        
g_FirstPlay true;
    }
    
    new 
g_SoundPath[128],
        
g_SoundName[128],
        
g_Name[96],
        
g_Format,
        
g_FileFormat;
        
    
    switch(
g_Type){
        case 
1:{
            if(
g_RandomMusic){
                
g_ValueTeam[0] = random(g_ArraySize[1]);
            }
            else{
                
g_ValueTeam[0]++;
                
                if(
g_ValueTeam[0] >= g_ArraySize[1]){
                    
g_ValueTeam[0] = 0;
                }
            }
            
            
ArrayGetString(g_PathTTg_ValueTeam[0], g_SoundPathcharsmax(g_SoundPath));
            
ArrayGetString(g_SoundNameTTg_ValueTeam[0], g_Namecharsmax(g_Name));
        }
        case 
2:{
            if(
g_RandomMusic){
                
g_ValueTeam[1] = random(g_ArraySize[0]);
            }
            else{
                
g_ValueTeam[1]++;
                
                if(
g_ValueTeam[1] >= g_ArraySize[0]){
                    
g_ValueTeam[1] = 0;
                }
            }
            
            
ArrayGetString(g_PathCTg_ValueTeam[1], g_SoundPathcharsmax(g_SoundPath));
            
ArrayGetString(g_SoundNameCTg_ValueTeam[1], g_Namecharsmax(g_Name));
        }
    }
    
    
/* if(equal(g_LastSoundPath, g_SoundPath)){
        RandMusic(g_Type);
        return PLUGIN_HANDLED;
    } */
    
    
copy(g_LastSongcharsmax(g_LastSong), g_Name);
    
    
g_Format strlen(g_SoundPath) - 4;
    
    if(
equal(g_SoundPathg_Format ], ".mp3")){
        
g_FileFormat 1;
    }
    else{
        
g_FileFormat 2;
    }
    
    
formatex(g_SoundNamecharsmax(g_SoundName), "Present Song: %s"g_Name);
    
    for(new 
1<= g_MaxPlayersi++){
        if(
is_user_connected(i) && g_RoundSound[i]){
            switch(
g_FileFormat){
                case 
1:{
                    
client_cmd(i"mp3 play %s"g_SoundPath);
                }
                case 
2:{
                    
client_cmd(i"spk %s"g_SoundPath);
                }
            }
            switch(
g_ShowInfo[i]){
                case 
Tutor_Msg:{
                    
tutorMake(iTUTOR_GREEN10.0g_SoundName);
                }
                case 
Chat_Msg:{
                    
ColorChat(iTEAM_COLOR"[%s]^x04 %s"g_Prefixg_SoundName);
                }
            }
        }
    }
    return 
PLUGIN_CONTINUE;
}

public 
ShowAds(){
    for(new 
1<= g_MaxPlayersi++){
        if(
is_user_connected(i) && g_ShowAds[i]){
            switch(
random(4)){
                case 
0:{
                    
ColorChat(iTEAM_COLOR"[%s]^x04 Want %s sounds enabled? Type in chat^x03 /sounds ^x04in chat^x03"g_Prefixg_RoundSound[i] ? "Disable" "Enable");
                }
                case 
1:{
                    
ColorChat(iTEAM_COLOR"[%s]^x04 Did you like the last song, and do not remember her name? Type in chat^x03 /last"g_Prefix);
                }
                case 
2:{
                    
ColorChat(iTEAM_COLOR"[%s]^x04 Do you want to listen to racetracks CT / TT? Type^ x03 /sounds ^x04in chat^x03 "g_Prefix);
                }
                case 
3:{
                    
ColorChat(iTEAM_COLOR"[%s]^x04 Do you want to disable the ads? Type^x03 /sounds ^x04in chat^x03 "g_Prefix);
                }
            }
        }
    }
}

public 
plugin_end(){
    
ArrayDestroy(g_PathCT);
    
ArrayDestroy(g_PathTT);
    
ArrayDestroy(g_SoundNameCT);
    
ArrayDestroy(g_SoundNameTT);

Thanks.
__________________

Join Free File hosting - http://db.tt/VvebKSSW
[Free 2 GB cloud storage]

Last edited by shubhamgulati12; 12-30-2013 at 09:29.
shubhamgulati12 is offline
 



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 10:12.


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