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.
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//Startpublic 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");
}//MapStartpublic void OnMapStart(){
PrecacheDecalAnyDownload(OVERLAYPATH); //Stock for adding overlay to download table and precaching.}//Show overlay to clientpublic 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 clientspublic 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 clientpublic 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 & decalsstock 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 removestock 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 removestock 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)
Shanapu, how can I debug your plugin further? I would love to get this working since I need to display a permanent advertisement at the bottom of my CS:GO server for all clients. I posted some additional notes here since the formatting is nicer: https://github.com/shanapu/overlays.inc/issues/3