Quote:
Originally Posted by shanapu
... don't ask me why - I love overlays.
|
I use this stock functions successful in many of my plugins as part of
mystocks.inc
An easy way to use overlays for plugin developers. I also added a small tut how to make your own overlays.
Used code & a example overlays from here:
https://forums.alliedmods.net/showthread.php?t=231473
Any ideas to improve this code or tutorial are welcome!
first a plugin example (overlays_plugin_example.sp):
Code:
//Includes
#include <sourcemod>
#include <sdktools> //need for adding files to download table
#include <overlays>
//Compiler Options //Optional, but please keep your code clean!
#pragma semicolon 1
#pragma newdecls required
//use a define or if needed (for cvars) a string
#define OVERLAYPATH "overlays/test" //Path to the overlay relative to materials/.. - no need for extentions like .vmt or .vft
//Start
public void OnPluginStart()
{
RegConsoleCmd("sm_testoverlay", Command_TestOverlay, "Show overlay to client");
RegConsoleCmd("sm_testoverlayall", Command_TestOverlayAll, "Show overlay to all clients for 5 seconds");
RegConsoleCmd("sm_testremoveoverlay", Command_TestRemoveOverlay, "Remove overlay of all clients");
}
//MapStart
public void OnMapStart()
{
PrecacheDecalAnyDownload(OVERLAYPATH); //Stock for adding overlay to download table and precaching.
}
//Show overlay to client
public Action Command_TestOverlay(int client, int args)
{
ShowOverlay(client, OVERLAYPATH, 0.0); //Show the overlay to the client - 0.0 as lifetime will show the overlay constant.
return Plugin_Handled;
}
//Show overlay to all clients
public Action Command_TestOverlayAll(int client, int args)
{
ShowOverlayAll(OVERLAYPATH, 5.0); //Show the overlay to the all clients - 5.0 as lifetime will delete the overlay after 5 seconds.
return Plugin_Handled;
}
//Show overlay to client
public Action Command_TestRemoveOverlay(int client, int args)
{
for (int i = 1; i <= MaxClients; i++) //Loop through all clients. Client validation in stock function
{
CreateTimer(0.0, DeleteOverlay, GetClientUserId(i)); //We use a timer to remove the overlay.
}
return Plugin_Handled;
}
the include file (overlays.inc):
Code:
// Precache & prepare download for overlays & decals
stock void PrecacheDecalAnyDownload(char[] sOverlay)
{
char sBuffer[256];
Format(sBuffer, sizeof(sBuffer), "%s.vmt", sOverlay);
PrecacheDecal(sBuffer, true);
Format(sBuffer, sizeof(sBuffer), "materials/%s.vmt", sOverlay);
AddFileToDownloadsTable(sBuffer);
Format(sBuffer, sizeof(sBuffer), "%s.vtf", sOverlay);
PrecacheDecal(sBuffer, true);
Format(sBuffer, sizeof(sBuffer), "materials/%s.vtf", sOverlay);
AddFileToDownloadsTable(sBuffer);
}
// Show overlay to a client with lifetime | 0.0 = no auto remove
stock void ShowOverlay(int client, char[] path, float lifetime)
{
if (!IsClientInGame(client) || IsFakeClient(client) || IsClientSourceTV(client) || IsClientReplay(client))
return;
ClientCommand(client, "r_screenoverlay \"%s.vtf\"", path);
if (lifetime != 0.0)
CreateTimer(lifetime, DeleteOverlay, GetClientUserId(client));
}
// Show overlay to all clients with lifetime | 0.0 = no auto remove
stock void ShowOverlayAll(char[] path, float lifetime)
{
for (int i = 1; i <= MaxClients; i++)
{
if (!IsClientInGame(i) || IsFakeClient(i) || IsClientSourceTV(i) || IsClientReplay(i))
continue;
ClientCommand(i, "r_screenoverlay \"%s.vtf\"", path);
if (lifetime != 0.0)
CreateTimer(lifetime, DeleteOverlay, GetClientUserId(i));
}
}
// Remove overlay from a client - Timer!
stock Action DeleteOverlay(Handle timer, any userid)
{
int client = GetClientOfUserId(userid);
if (client <= 0 || !IsClientInGame(client) || IsFakeClient(client) || IsClientSourceTV(client) || IsClientReplay(client))
return;
ClientCommand(client, "r_screenoverlay \"\"");
}
Tutorial:
Spoiler
In this tutorial, I try so "noob-like" as I can, to show you how to make custom overlays.
You need a windows PC, VTFEdit, an graphic editor like Photoshop or GIMP (For this tutorial I presume you know how to use a graphic software) & an text editor like SPEdit, Sublime Text or Notepad++.
- Design a new image with your graphic editor with the following size: 1820px * 1024px (optimal view at 16:9)
- Squeeze it to a 1024px * 1024px square.
- Save your image as a RGB/8bit *.png file. In this example as overlay.png
- Open VTFEdit and press the Import Button or 'Ctrl + I'
- Import your custom image from step 3
- A option windows pops up. I run good with these settings:
- Press OK & check the following settings. I run good with these:
- Save as *.vtf file. In this example as overlay.vtf
- Open your text editor and start a new file (Ctrl + N)
- Copy & Paste the following to your new text file:
Code:
MonitorScreen"
{
"$basetexture" "overlays/MyFirstOverlay/OVERLAY_PLACEHOLDER"
"$translucent" 1
}
- Edit OVERLAY_PLACEHOLDER to your filename you choose in step 8. Don't write the file extension.vft
- example with overlay.vtf:
Code:
"MonitorScreen"
{
"$basetexture" "overlays/MyFirstOverlay/overlay"
"$translucent" 1
}
- Save as *.vmt file with same name you choose in step 8. In this example as overlay.vmt
- Upload the *.vtf & *.vmt file to following folder of your server & FastDL:
Overlay: ...\csgo\materials\overlays\MyFirstOverlay
Congratulations!
Tutorial take from
here
Thanks good_live for improvement!
I hope I can help someone with it.
https://github.com/shanapu/overlays.inc
you like my work? Buy me a beer!