ItsMods

Full Version: For Plugin Developers
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Update Announcement

Well i was bored so i made this little code which i think will help you as well as plugin users to know if any update arrived so it will be easy for them to update as well as for you also.

CSHARP Code
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Addon;
  5. using System.Threading;
  6. using System.Net;
  7. namespace announcement
  8. {
  9. public class announcement : CPlugin
  10. {
  11. public void update()
  12. {
  13. while (true)
  14. {
  15. WebClient client = new WebClient();
  16. string current_version = "1.02";
  17. string str;
  18. str = client.DownloadString("http://www.yoursite.com/text.txt");
  19. if (str != current_version)
  20. ServerSay("your update text", false);
  21. Thread.Sleep(90000);
  22. }
  23. }
  24. public override void OnServerLoad()
  25. {
  26. new Thread(new ThreadStart(update)).Start();
  27. }
  28. }
  29. }

Well hope you guys like it. Wink
One question, why do you make a while loop? You can call the function on OnMapLoaded() without a loop.
me no make plugins but this is nice & useful.
(02-18-2012, 17:18)masterbob Wrote: [ -> ]One question, why do you make a while loop? You can call the function on OnMapLoaded() without a loop.
Well that's depend on you how to use it its just an example and well its not OnMapLoaded() its OnMapChange() and 110% chances message will not show OnMapChange(). Well i personally used it in this wayTongue
CSHARP Code
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Addon;
  5. using System.Net;
  6. namespace update
  7. {
  8. public class update : CPlugin
  9. {
  10. public override ChatType OnSay(string Message, ServerClient Client)
  11. {
  12. if (Message.StartsWith("!update"))
  13. {
  14. try
  15. {
  16. WebClient client = new WebClient();
  17. string current_version = "1.02";
  18. string version;
  19. string Msg;
  20. version = client.DownloadString("http://www.yoursite.com/version.txt");
  21. Msg = client.DownloadString("http://www.yoursite.com/text.txt");
  22. if (version != current_version)
  23. {
  24. TellClient(Client.ClientNum, "^2PM: ^3" + Msg, true);
  25. }
  26. else
  27. {
  28. TellClient(Client.ClientNum, "^2PM: ^3You have an updated version.", true);
  29. }
  30. return ChatType.ChatNone;
  31. }
  32. catch
  33. { }
  34. TellClient(Client.ClientNum, "^3PM: ^1Server is not responding try another time.", true);
  35. return ChatType.ChatNone;
  36. }
  37. return ChatType.ChatContinue;
  38. }
  39. }
  40. }


it can be operated with the addition of addon 1.414???