AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [INC] Overlays (https://forums.alliedmods.net/showthread.php?t=298248)

shanapu 06-06-2017 01:00

[INC] Overlays
 
3 Attachment(s)
Quote:

Originally Posted by shanapu (Post 2456153)
... 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! https://www.paypalobjects.com/websta...aypal-26px.png

Kinsi 06-06-2017 16:14

Re: [INC] Overlays
 
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).

woklex 06-06-2017 16:40

Re: [INC] Overlays
 
Cool! Thank you!

ddhoward 06-06-2017 17:50

Re: [INC] Overlays
 
Quote:

Originally Posted by Kinsi (Post 2526667)
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.

shanapu 06-07-2017 11:29

Re: [INC] Overlays
 
Quote:

Originally Posted by Kinsi (Post 2526667)
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 (Post 2526683)
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!

Despirator 06-08-2017 09:00

Re: [INC] Overlays
 
Quote:

int iFlag = GetCommandFlags("r_screenoverlay") & (~FCVAR_CHEAT);
SetCommandFlags("r_screenoverlay", iFlag);
This is unnecessary as it does on the server side only

die_man 01-30-2020 15:31

Re: [INC] Overlays
 
How i can show the overlay to random player on round_start?

Zahti 03-10-2021 18:27

Re: [INC] Overlays
 
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


All times are GMT -4. The time now is 21:12.

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