Raised This Month: $12 Target: $400
 3% 

[INC] Overlays


Post New Thread Reply   
 
Thread Tools Display Modes
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, 772 views)
File Type: sp Get Plugin or Get Source (overlays_plugin_example.sp - 619 views - 2.5 KB)
File Type: zip overlays-test.zip (66.5 KB, 613 views)
__________________
coding & free software

Last edited by shanapu; 07-11-2018 at 16:15. Reason: small fix
shanapu is offline
Kinsi
Senior Member
Join Date: Apr 2013
Old 06-06-2017 , 16:14   Re: [INC] Overlays
Reply With Quote #2

PHP Code:
int iFlag GetCommandFlags("r_screenoverlay") & (~FCVAR_CHEAT);
SetCommandFlags("r_screenoverlay"iFlag); 
Isnt doing that unnecessary? At least for me it works without doing so (CS:GO).

Also i was wondering if its somehow possible to overlay an texture without it being streched (kinda like the scope of the AWP works).

Last edited by Kinsi; 06-06-2017 at 16:23.
Kinsi is offline
woklex
Member
Join Date: Sep 2012
Old 06-06-2017 , 16:40   Re: [INC] Overlays
Reply With Quote #3

Cool! Thank you!
woklex is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 06-06-2017 , 17:50   Re: [INC] Overlays
Reply With Quote #4

Quote:
Originally Posted by Kinsi View Post
PHP Code:
int iFlag GetCommandFlags("r_screenoverlay") & (~FCVAR_CHEAT);
SetCommandFlags("r_screenoverlay"iFlag); 
Isnt doing that unnecessary? At least for me it works without doing so (CS:GO).
This is also unnecessary on TF2.
__________________
ddhoward is offline
shanapu
Veteran Member
Join Date: Apr 2015
Location: .de
Old 06-07-2017 , 11:29   Re: [INC] Overlays
Reply With Quote #5

Quote:
Originally Posted by Kinsi View Post
PHP Code:
int iFlag GetCommandFlags("r_screenoverlay") & (~FCVAR_CHEAT);
SetCommandFlags("r_screenoverlay"iFlag); 
Isnt doing that unnecessary? At least for me it works without doing so (CS:GO).

Also i was wondering if its somehow possible to overlay an texture without it being streched (kinda like the scope of the AWP works).
Quote:
Originally Posted by ddhoward View Post
This is also unnecessary on TF2.
Can someone confirm this is also unnecessary for other sourcegames?

edit: updated with small fix. Thx good_live!

edit2: removed obsolete code. THX guys!
__________________
coding & free software

Last edited by shanapu; 06-15-2017 at 02:40.
shanapu is offline
Despirator
Senior Member
Join Date: Jun 2011
Location: Kazakhstan ->Shymkent
Old 06-08-2017 , 09:00   Re: [INC] Overlays
Reply With Quote #6

Quote:
int iFlag = GetCommandFlags("r_screenoverlay") & (~FCVAR_CHEAT);
SetCommandFlags("r_screenoverlay", iFlag);
This is unnecessary as it does on the server side only
Despirator is offline
die_man
Senior Member
Join Date: Jul 2017
Old 01-30-2020 , 15:31   Re: [INC] Overlays
Reply With Quote #7

How i can show the overlay to random player on round_start?
die_man is offline
Zahti
New Member
Join Date: Apr 2020
Location: Boise, Idaho
Old 03-10-2021 , 18:27   Re: [INC] Overlays
Reply With Quote #8

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
__________________
Zahti is offline
Reply


Thread Tools
Display Modes

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


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