Thread Rating:
  • 4 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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.
CSHARP Code
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Addon;
  5.  
  6. namespace ServerAd
  7. {
  8. public class Class1 : CPlugin
  9. {
  10. string AdText = string.Empty;
  11. int Counter = -1;
  12. float ServerAdSize = 1.6f;
  13.  
  14. public override void OnServerLoad()
  15. {
  16. ServerPrint("\n ServerAd Plugin loaded \n Author: zxz0O0 \n Thanks to Nukem, Jariz, Pozzuh and Makavel\n");
  17. 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");
  18. AdText = GetServerCFG("ServerAd", "Text", string.Empty);
  19.  
  20. if (string.IsNullOrEmpty(AdText))
  21. AdText = "Visit ^1ItsMods.com ^7for great mods.";
  22.  
  23. ServerAdSize = float.Parse(GetServerCFG("ServerAd","FontSize","1.6"), System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
  24. }
  25.  
  26. //Before we create the HudElement we wait 1second so the server is 'ready'
  27. public override void OnAddonFrame()
  28. {
  29. if (Counter >= 0)
  30. {
  31. Counter++;
  32. //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)
  33. if (Counter == (1000 / AddonFrameInterval))
  34. {
  35. CreateServerAd();
  36. Counter = -1;
  37. }
  38. }
  39. }
  40.  
  41. /*HudElements get deleted on restart*/
  42. public override void OnFastRestart()
  43. {
  44. Counter = 0;
  45. }
  46.  
  47. public override void OnMapChange()
  48. {
  49. Counter = 0;
  50. }
  51.  
  52. private void CreateServerAd()
  53. {
  54. //Create a simply 'empty' HudElement
  55. HudElem MyAd = CreateNewHudElem();
  56. //Make the HudElement Text
  57. MyAd.Type = HudElementTypes.Text;
  58. //Show the HudElement to everyone
  59. MyAd.ShowToEnt = Entity_World;
  60. //HudElement hides when player is in menu
  61. MyAd.HideInMenu = true;
  62. //Set font and fontscale, default is the best looking in my opinion
  63. MyAd.Font = HudElementFonts.Default;
  64. MyAd.FontScale = ServerAdSize;
  65. ServerPrint("New Hud: " + MyAd.HudElementNum);
  66. /* The origin is relative from this point. I did not find out yet how the point type works correctly
  67.   * Just try a bit yourself and find the perfect point
  68.   * You can also let this value 0 then the 'start point' will be right to the radar */
  69. MyAd.PointType = 82;
  70. //Set the relative origin
  71. MyAd.OriginY = 160f;
  72. MyAd.OriginX = 5f;
  73. //Set the text to the HudElement
  74. MyAd.SetString(AdText);
  75. //We just want the text to be white so we don't modify the Color struct
  76. }
  77. }
  78. }


Attached Files
.zip   ServerAd.zip (Size: 2.44 KB / Downloads: 946)
[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 1,701 07-21-2012, 01:32
Last Post: JariZ

Forum Jump:


Users browsing this thread:
2 Guest(s)

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