01-03-2013, 22:49
07-23-2013, 08:25
(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:
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 } } }
Server Ad plugin loaded but not working. Plz tell me how to fix.
[attachment=2698]
[attachment=2699]
07-23-2013, 11:44
ServerAd still works on my server
08-01-2013, 20:31
this plug CSHARP Code is old?
or different
i going to compiling the code but is not working on server
or different
i going to compiling the code but is not working on server
08-01-2013, 22:41
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
the "old" code you say works, i have edited Little for my server, and that works too. nothing is wrong
08-02-2013, 00:21
(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:
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 } } }
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