Raised This Month: $ Target: $400
 0% 

[INC] Overlays


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
shanapu
Veteran Member
Join Date: Apr 2015
Location: .de
Old 06-06-2017 , 01:00   [INC] Overlays
Reply With Quote #1

Quote:
Originally Posted by shanapu View Post
... 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


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!
Attached Files
File Type: inc overlays.inc (2.8 KB, 784 views)
File Type: sp Get Plugin or Get Source (overlays_plugin_example.sp - 630 views - 2.5 KB)
File Type: zip overlays-test.zip (66.5 KB, 625 views)
__________________
coding & free software

Last edited by shanapu; 07-11-2018 at 16:15. Reason: small fix
shanapu 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 17:03.


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