This is a plugin to display some advertisement in your server and also intended to provide an example on how to use the HudElem type.
Requires @Nukem's Server Addon 1.410+
sv_config.ini entries:
Example how it will look like:
I have added comments to the source code so it's easier to understand. If you still have any questions feel free to ask.
Requires @Nukem's Server Addon 1.410+
sv_config.ini entries:
Code:
[ServerAd]
//Text to be displayed
Text=Visit ^1ItsMods.com ^7for great mods.
//FontScale
FontSize=1.6
Example how it will look like:
I have added comments to the source code so it's easier to understand. If you still have any questions feel free to ask.
CSHARP Code
- using System;
- using System.Collections.Generic;
- using System.Text;
- using Addon;
-
- namespace ServerAd
- {
- public class Class1 : CPlugin
- {
- string AdText = string.Empty;
- int Counter = -1;
- float ServerAdSize = 1.6f;
-
- public override void OnServerLoad()
- {
- ServerPrint("\n ServerAd Plugin loaded \n Author: zxz0O0 \n Thanks to Nukem, Jariz, Pozzuh and Makavel\n");
- ServerPrint(" <a href="http://www.youtube.com/zxz0O0" target="_blank" rel="noopener" class="mycode_url">www.youtube.com/zxz0O0</a> \n <a href="http://www.itsmods.com" target="_blank" rel="noopener" class="mycode_url">www.itsmods.com</a>\n");
- AdText = GetServerCFG("ServerAd", "Text", string.Empty);
-
- if (string.IsNullOrEmpty(AdText))
- AdText = "Visit ^1ItsMods.com ^7for great mods.";
-
- ServerAdSize = float.Parse(GetServerCFG("ServerAd","FontSize","1.6"), System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
- }
-
- //Before we create the HudElement we wait 1second so the server is 'ready'
- public override void OnAddonFrame()
- {
- if (Counter >= 0)
- {
- Counter++;
- //Calculation: AddonFrameInterval holds the interval of the thread in milliseconds (currently 250ms) so we do 1000ms/current interval and we get the number of frames per second (currently 4)
- if (Counter == (1000 / AddonFrameInterval))
- {
- CreateServerAd();
- Counter = -1;
- }
- }
- }
-
- /*HudElements get deleted on restart*/
- public override void OnFastRestart()
- {
- Counter = 0;
- }
-
- public override void OnMapChange()
- {
- Counter = 0;
- }
-
- private void CreateServerAd()
- {
- //Create a simply 'empty' HudElement
- HudElem MyAd = CreateNewHudElem();
- //Make the HudElement Text
- MyAd.Type = HudElementTypes.Text;
- //Show the HudElement to everyone
- MyAd.ShowToEnt = Entity_World;
- //HudElement hides when player is in menu
- MyAd.HideInMenu = true;
- //Set font and fontscale, default is the best looking in my opinion
- MyAd.Font = HudElementFonts.Default;
- MyAd.FontScale = ServerAdSize;
- ServerPrint("New Hud: " + MyAd.HudElementNum);
- /* The origin is relative from this point. I did not find out yet how the point type works correctly
- * Just try a bit yourself and find the perfect point
- * You can also let this value 0 then the 'start point' will be right to the radar */
- MyAd.PointType = 82;
- //Set the relative origin
- MyAd.OriginY = 160f;
- MyAd.OriginX = 5f;
- //Set the text to the HudElement
- MyAd.SetString(AdText);
- //We just want the text to be white so we don't modify the Color struct
- }
- }
- }