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(" www.youtube.com/zxz0O0 \n www.itsmods.com\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
}
}
}