Release ServerAd
#1
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:
Code:
[ServerAd] //Text to be displayed Text=Visit ^1ItsMods.com ^7for great mods. //FontScale FontSize=1.6

Example how it will look like:
[Image: 56D9DDDAA20C9F14557CD920B33C4CAF7542D86A]

I have added comments to the source code so it's easier to understand. If you still have any questions feel free to ask.
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(" 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 } } }


Attached Files
.zip   ServerAd.zip (Size: 2.44 KB / Downloads: 990)
[Image: azuw.jpg]
Reply

#2
It should be named: ServerSpam
Reply

#3
nice 1, i like it.
[Image: b_560_95_1.png]


[Image: b_560_95_1.png]

Reply

#4
(07-13-2012, 09:49)Yamato Wrote: It should be named: ServerSpam

Huh It's just some textline like the gametype string between the round time and killfeed.
[Image: azuw.jpg]
Reply

#5
how long does the text stay? or is it permanent?
Had a life, Got a modem..
Reply

#6
(07-13-2012, 10:48)pieter Wrote: how long does the text stay? or is it permanent?

looks like it's perm
[Image: b_560_95_1.png]


[Image: b_560_95_1.png]

Reply

#7
(07-13-2012, 10:48)pieter Wrote: how long does the text stay? or is it permanent?

Line #29. Ugly fix to make it permanent.
Reply

#8
(07-13-2012, 14:25)SuperNovaAO Wrote:
(07-13-2012, 10:48)pieter Wrote: how long does the text stay? or is it permanent?

Line #29. Ugly fix to make it permanent.

Fail. Just read the comments. This whole OnAddonFrame stuff is just because I need to wait a bit until the server is fully loaded because if you make the hudelement just in OnMapChange/OnFastRestart it will get deleted again.

A HudElement is always permanent until you delete it (or the game).
[Image: azuw.jpg]
Reply

#9
(07-13-2012, 14:30)zxz0O0 Wrote:
(07-13-2012, 14:25)SuperNovaAO Wrote:
(07-13-2012, 10:48)pieter Wrote: how long does the text stay? or is it permanent?

Line #29. Ugly fix to make it permanent.

Fail. Just read the comments. This whole OnAddonFrame stuff is just because I need to wait a bit until the server is fully loaded because if you make the hudelement just in OnMapChange/OnFastRestart it will get deleted again.

A HudElement is always permanent until you delete it (or the game).

[img][Image: spam.jpg] [/img]

config_ini copy the code in the dll and copy the plugin folder ...
but I worked ...
why??
Reply

#10
No.

Get out.
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  ServerAd kpoviv 1 2,482 07-21-2012, 01:32
Last Post: JariZ

Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum Powered By MyBB, Theme by © 2002-2026 Melroy van den Berg.