Raised This Month: $32 Target: $400
 8% 

[ANY] Random Skybox


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
painkiller
Senior Member
Join Date: Jun 2011
Old 03-15-2022 , 15:17   [ANY] Random Skybox
Reply With Quote #1

I would like to have a skybox plugin that displays a new skybox every round.
and the plugin should load all files from the materials/skybox folder.
So that you only enter the name of the skybox in the cfg and not all the files individually.

Just one question: can the skybox rotate in the game?
Would that be possible somehow?

Greeting Painkiller
painkiller is offline
iDini
Junior Member
Join Date: Jul 2020
Old 03-16-2022 , 16:58   Re: [ANY] Random Skybox
Reply With Quote #2

https://forums.alliedmods.net/showthread.php?t=285353
iDini is offline
painkiller
Senior Member
Join Date: Jun 2011
Old 03-16-2022 , 17:05   Re: [ANY] Random Skybox
Reply With Quote #3

That is not what I want.

I want a different skybox to come automatically for all clients after each mapchange.

In this plugin he writes
"Allows clients to change their skybox".
painkiller is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 03-16-2022 , 17:44   Re: [ANY] Random Skybox
Reply With Quote #4

You want something ready to use.
You should try messing a little with the plugin linked, probably with few lines can achieve what you want.
__________________
Marttt is online now
painkiller
Senior Member
Join Date: Jun 2011
Old 03-16-2022 , 18:45   Re: [ANY] Random Skybox
Reply With Quote #5

If I were a sourcemod scripter I could.
That's why I made a request here.
painkiller is offline
`666
AlliedModders Donor
Join Date: Jan 2006
Old 03-17-2022 , 07:55   Re: [ANY] Random Skybox
Reply With Quote #6

I tested only in the insurgency game. You have to add sky name for a game you want yourself. Add/remove sky names under "char ga_sSkyName[][] = {" no scripting knowledge required. You can get sky names from here https://developer.valvesoftware.com/wiki/Sky_List

Admin commands:
sm_randomskysetting - Print default & current sky setting for this map
sm_randomskyrandom - Set sky to new random
sm_randomskydefault - Set sky to default setting
Setting:
The plugin will make randomsky.cfg.
sm_randomsky - 0.0 = disable | 1.0 = on map start | 2.0 = on round start
Attached Files
File Type: sp Get Plugin or Get Source (randomsky.sp - 129 views - 3.3 KB)

Last edited by `666; 03-17-2022 at 07:56.
`666 is offline
painkiller
Senior Member
Join Date: Jun 2011
Old 03-17-2022 , 09:36   Re: [ANY] Random Skybox
Reply With Quote #7

Hello,
cool, thank you.

So just tested I have seen that in the plugin no materials / skybox for the download.
But apparently it doesn't work, the skies are all washed out.

I want to use it with these: https://gamebanana.com/mods/cats/561

Example:

Code:
# Path to the '../hl2dm/materials/skybox/' folder.
SKYBOX_PATH = GAME_PATH / 'materials' / 'skybox'

downloads = Downloadables()
# Go through all the skybox names.
for skybox in skyboxes:
    # Find all the necessary files for this skybox.
    for file in SKYBOX_PATH.files(f'{skybox}*'):
        base_name = file.basename()

        # Exclude the file if it's compressed.
        if base_name.endswith('.ztmp'):
            continue

        # Make sure the players download the file when connecting.
        downloads.add(f'materials/skybox/{base_name}')
Edit: I have since added it to my download_adder from eventscripts.

But maybe it's still possible for you that the plugin of yours can do that on its own.
Great work thank you

Last edited by painkiller; 03-17-2022 at 10:13.
painkiller is offline
`666
AlliedModders Donor
Join Date: Jan 2006
Old 03-17-2022 , 13:48   Re: [ANY] Random Skybox
Reply With Quote #8

PHP Code:
#pragma semicolon 1
#pragma newdecls required

#include <sourcemod>
#include <sdktools>

//custom skies from https://gamebanana.com/mods/cats/561
char ga_sSkyName[][] = {
    
"mr_58",            //https://gamebanana.com/mods/334824
    
"sky_universe",        //https://gamebanana.com/mods/350042
    
"doom",                //https://gamebanana.com/mods/323263
    
"mr_22b"            //https://gamebanana.com/mods/218297
};

bool    g_bEventHooked false;
char    g_sDefaultSky[32];
ConVar    g_cvWhenToSet;

public 
Plugin myinfo = {
    
name        "randomsky",
    
author        "Nullifidian & idea by painkiller",
    
description    "set random sky",
    
version        "1.1",
    
url            ""
};

public 
void OnPluginStart() {
    
RegAdminCmd("sm_randomskysetting"cmd_CheckSkyADMFLAG_RCON"Print default & current sky setting for this map");
    
RegAdminCmd("sm_randomskyrandom"cmd_RandomSkyADMFLAG_RCON"Set sky to new random");
    
RegAdminCmd("sm_randomskydefault"cmd_DefaultSkyADMFLAG_RCON"Set sky to default setting");

    
g_cvWhenToSet CreateConVar("sm_randomsky""1.0""0.0 = disable | 1.0 = on map start | 2.0 = on round start"_true0.0true2.0);
    
AutoExecConfig(true"randomsky");
    
HookConVarChange(g_cvWhenToSetConVarChanged);
}

public 
void OnMapStart() {
    
DownloadFiles();
    
CreateTimer(1.0Timer_CheckSetting);
}

public 
Action Event_RoundStart(Event event, const char[] namebool dontBroadcast) {
    
SetRandomSky();
}

void SetRandomSky() {
    
ServerCommand("sv_skyname %s"ga_sSkyName[GetRandomInt(0, ((sizeof(ga_sSkyName)) - 1))]);
}

Action Timer_CheckSetting(Handle timer) {
    
GetConVarString(FindConVar("sv_skyname"), g_sDefaultSkysizeof(g_sDefaultSky));
    switch (
g_cvWhenToSet.FloatValue) {
        case 
0.0: {
            if (
g_bEventHooked) {
                
SetupHookEvent(false);
            }
        }
        case 
1.0: {
            if (
g_bEventHooked) {
                
SetupHookEvent(false);
            }
            
SetRandomSky();
        }
        case 
2.0: {
            if (!
g_bEventHooked) {
                
SetupHookEvent();
            }
        }
    }
}

void SetupHookEvent(bool bHook true) {
    if (
bHook) {
        
HookEvent("round_start"Event_RoundStartEventHookMode_PostNoCopy);
        
g_bEventHooked true;
    } else {
        
UnhookEvent("round_start"Event_RoundStartEventHookMode_PostNoCopy);
        
g_bEventHooked false;
    }
}

public 
Action cmd_CheckSky(int clientint args) {
    
char sBuffer[32];
    
GetConVarString(FindConVar("sv_skyname"), sBuffersizeof(sBuffer));
    
ReplyToCommand(client"sv_skyname = %s | default = %s"sBufferg_sDefaultSky);
    return 
Plugin_Handled;
}

public 
Action cmd_RandomSky(int clientint args) {
    
SetRandomSky();
    
ReplyToCommand(client"Done!");
    return 
Plugin_Handled;
}

public 
Action cmd_DefaultSky(int clientint args) {
    
ServerCommand("sv_skyname %s"g_sDefaultSky);
    
ReplyToCommand(client"Set sky to default: %s"g_sDefaultSky);
    return 
Plugin_Handled;
}

void ConVarChanged(ConVar convar, const char[] oldValue, const char[] newValue) {
    if (
StringToFloat(newValue) == 2.0) {
        if (!
g_bEventHooked) {
            
SetupHookEvent();
        }
    }
    else if (
g_bEventHooked) {
        
SetupHookEvent(false);
    }
}

void DownloadFiles() {
    
char sBuffer[PLATFORM_MAX_PATH];

    
char sLower[][] = {
        
"bk",
        
"dn",
        
"ft",
        
"lf",
        
"rt",
        
"up"
    
};

    
char sUpper[][] = {
        
"BK",
        
"DN",
        
"FT",
        
"LF",
        
"RT",
        
"UP"
    
};

    for (
int i 0sizeof(ga_sSkyName); i++) {
        for (
int j 06j++) {
            
FormatEx(sBuffersizeof(sBuffer), "materials/skybox/%s%s.vmt"ga_sSkyName[i], sLower[j]);
            if (
FileExists(sBufferfalse)) {
                
AddFileToDownloadsTable(sBuffer);
            } else {
                
FormatEx(sBuffersizeof(sBuffer), "materials/skybox/%s%s.vmt"ga_sSkyName[i], sUpper[j]);
                if (
FileExists(sBufferfalse)) {
                    
AddFileToDownloadsTable(sBuffer);
                } else {
                    
LogError("Can't find: %s"sBuffer);
                }
            }

            
FormatEx(sBuffersizeof(sBuffer), "materials/skybox/%s%s.vtf"ga_sSkyName[i], sLower[j]);
            if (
FileExists(sBufferfalse)) {
                
AddFileToDownloadsTable(sBuffer);
            } else {
                
FormatEx(sBuffersizeof(sBuffer), "materials/skybox/%s%s.vtf"ga_sSkyName[i], sUpper[j]);
                if (
FileExists(sBufferfalse)) {
                    
AddFileToDownloadsTable(sBuffer);
                } else {
                    
LogError("Can't find: %s"sBuffer);
                }
            }
        }
    }


Last edited by `666; 03-17-2022 at 14:17.
`666 is offline
painkiller
Senior Member
Join Date: Jun 2011
Old 03-17-2022 , 14:27   Re: [ANY] Random Skybox
Reply With Quote #9

Quote:
Originally Posted by `666 View Post
PHP Code:
#pragma semicolon 1
#pragma newdecls required

#include <sourcemod>
#include <sdktools>

//custom skies from https://gamebanana.com/mods/cats/561
char ga_sSkyName[][] = {
    
"mr_58",            //https://gamebanana.com/mods/334824
    
"sky_universe",        //https://gamebanana.com/mods/350042
    
"doom",                //https://gamebanana.com/mods/323263
    
"mr_22b"            //https://gamebanana.com/mods/218297
};

bool    g_bEventHooked false;
char    g_sDefaultSky[32];
ConVar    g_cvWhenToSet;

public 
Plugin myinfo = {
    
name        "randomsky",
    
author        "Nullifidian & idea by painkiller",
    
description    "set random sky",
    
version        "1.1",
    
url            ""
};

public 
void OnPluginStart() {
    
RegAdminCmd("sm_randomskysetting"cmd_CheckSkyADMFLAG_RCON"Print default & current sky setting for this map");
    
RegAdminCmd("sm_randomskyrandom"cmd_RandomSkyADMFLAG_RCON"Set sky to new random");
    
RegAdminCmd("sm_randomskydefault"cmd_DefaultSkyADMFLAG_RCON"Set sky to default setting");

    
g_cvWhenToSet CreateConVar("sm_randomsky""1.0""0.0 = disable | 1.0 = on map start | 2.0 = on round start"_true0.0true2.0);
    
AutoExecConfig(true"randomsky");
    
HookConVarChange(g_cvWhenToSetConVarChanged);
}

public 
void OnMapStart() {
    
DownloadFiles();
    
CreateTimer(1.0Timer_CheckSetting);
}

public 
Action Event_RoundStart(Event event, const char[] namebool dontBroadcast) {
    
SetRandomSky();
}

void SetRandomSky() {
    
ServerCommand("sv_skyname %s"ga_sSkyName[GetRandomInt(0, ((sizeof(ga_sSkyName)) - 1))]);
}

Action Timer_CheckSetting(Handle timer) {
    
GetConVarString(FindConVar("sv_skyname"), g_sDefaultSkysizeof(g_sDefaultSky));
    switch (
g_cvWhenToSet.FloatValue) {
        case 
0.0: {
            if (
g_bEventHooked) {
                
SetupHookEvent(false);
            }
        }
        case 
1.0: {
            if (
g_bEventHooked) {
                
SetupHookEvent(false);
            }
            
SetRandomSky();
        }
        case 
2.0: {
            if (!
g_bEventHooked) {
                
SetupHookEvent();
            }
        }
    }
}

void SetupHookEvent(bool bHook true) {
    if (
bHook) {
        
HookEvent("round_start"Event_RoundStartEventHookMode_PostNoCopy);
        
g_bEventHooked true;
    } else {
        
UnhookEvent("round_start"Event_RoundStartEventHookMode_PostNoCopy);
        
g_bEventHooked false;
    }
}

public 
Action cmd_CheckSky(int clientint args) {
    
char sBuffer[32];
    
GetConVarString(FindConVar("sv_skyname"), sBuffersizeof(sBuffer));
    
ReplyToCommand(client"sv_skyname = %s | default = %s"sBufferg_sDefaultSky);
    return 
Plugin_Handled;
}

public 
Action cmd_RandomSky(int clientint args) {
    
SetRandomSky();
    
ReplyToCommand(client"Done!");
    return 
Plugin_Handled;
}

public 
Action cmd_DefaultSky(int clientint args) {
    
ServerCommand("sv_skyname %s"g_sDefaultSky);
    
ReplyToCommand(client"Set sky to default: %s"g_sDefaultSky);
    return 
Plugin_Handled;
}

void ConVarChanged(ConVar convar, const char[] oldValue, const char[] newValue) {
    if (
StringToFloat(newValue) == 2.0) {
        if (!
g_bEventHooked) {
            
SetupHookEvent();
        }
    }
    else if (
g_bEventHooked) {
        
SetupHookEvent(false);
    }
}

void DownloadFiles() {
    
char sBuffer[PLATFORM_MAX_PATH];

    
char sLower[][] = {
        
"bk",
        
"dn",
        
"ft",
        
"lf",
        
"rt",
        
"up"
    
};

    
char sUpper[][] = {
        
"BK",
        
"DN",
        
"FT",
        
"LF",
        
"RT",
        
"UP"
    
};

    for (
int i 0sizeof(ga_sSkyName); i++) {
        for (
int j 06j++) {
            
FormatEx(sBuffersizeof(sBuffer), "materials/skybox/%s%s.vmt"ga_sSkyName[i], sLower[j]);
            if (
FileExists(sBufferfalse)) {
                
AddFileToDownloadsTable(sBuffer);
            } else {
                
FormatEx(sBuffersizeof(sBuffer), "materials/skybox/%s%s.vmt"ga_sSkyName[i], sUpper[j]);
                if (
FileExists(sBufferfalse)) {
                    
AddFileToDownloadsTable(sBuffer);
                } else {
                    
LogError("Can't find: %s"sBuffer);
                }
            }

            
FormatEx(sBuffersizeof(sBuffer), "materials/skybox/%s%s.vtf"ga_sSkyName[i], sLower[j]);
            if (
FileExists(sBufferfalse)) {
                
AddFileToDownloadsTable(sBuffer);
            } else {
                
FormatEx(sBuffersizeof(sBuffer), "materials/skybox/%s%s.vtf"ga_sSkyName[i], sUpper[j]);
                if (
FileExists(sBufferfalse)) {
                    
AddFileToDownloadsTable(sBuffer);
                } else {
                    
LogError("Can't find: %s"sBuffer);
                }
            }
        }
    }

That's great, thank you very much, it works perfectly.

Is there a possibility that you could make another plugin I don't know how far your skills go.
But I think it would not be that easy.
Unfortunately, we can't write to you privately.

Last edited by painkiller; 03-17-2022 at 14:28.
painkiller is offline
`666
AlliedModders Donor
Join Date: Jan 2006
Old 03-17-2022 , 14:32   Re: [ANY] Random Skybox
Reply With Quote #10

Just make new thread, I'm sure others want to help too.
`666 is offline
Reply



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 23:09.


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