• 4 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Release] ServerAd
#21
Yes
  Reply
#22
(07-13-2012, 09:32)zxz0O0 Wrote: 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. }

Server Ad plugin loaded but not working. Plz tell me how to fix.

   

   
  Reply
#23
ServerAd still works on my server
  Reply
#24
this plug CSHARP Code is old?

or different

i going to compiling the code but is not working on server
  Reply
#25
the plugin works withour errors or crashes.
the "old" code you say works, i have edited Little for my server, and that works too. nothing is wrong
  Reply
#26
(07-23-2013, 08:25)sylvester123 Wrote:
(07-13-2012, 09:32)zxz0O0 Wrote: 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. }

Server Ad plugin loaded but not working. Plz tell me how to fix.

It wont work for older versions of addon like 1.204. Use latest one

Sent from my E16i using Tapatalk 2
  Reply


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

Forum Jump:


Users browsing this thread: 1 Guest(s)