Dynamic MOTD?
#7

Hi.
i will explain the code with comment in the script.


pawn Код:
#include <YSI\y_ini>
//>Including y_ini from YSI Library

#include <zcmd>
//> i'll use ZCMD to make command

#include <sscanf2>
//>For command

#define ServerFile "Server/Info.ini" //>Definind .ini file address in > scriptfiles/Server/"Ini file"
//>You have to create "Server" Folder in scriptfile folder in your server files.

enum sInfo //>Creating enum for variables that i want to load my ini file data into it!
{
 LoginMSG[128] //> String
}
new ServerInfo[sInfo]; //>My Variable(s)

//>Creating a callback that i will use to load my ini file into variables With "INI_ParseFile" function.
forward LoadServerInfo(name[], value[]);
public LoadServerInfo(name[], value[])
{
    INI_String("LoginMSG",ServerInfo[LoginMSG],128); //> i use "INI_String" to load a string into "ServerInfo[LoginMSG]" Variable
    return 1;
}

public OnGameModeInit() //>Load Data from file when server start
{
  INI_ParseFile(ServerFile, "LoadServerInfo", .bExtra = false, .extra = 0); //>Load "ServerFile" path with "LoadServerInfo" Function that i created.
  return 1;
}

public OnPlayerConnect(playerid) //>Sending ServerMSG with formating "ServerInfo[LoginMSG]" Variable...
{
//>My Server Message Loaded in "ServerInfo[LoginMSG]" Variable with "LoadServerInfo" Callback
 new string[128];
 format(string,sizeof(string),"%s",ServerInfo[LoginMSG]);
 SendClientMessage(playerid,-1,string);
 return 1;
}

//>Creatind command for creating or updating "Info.ini" File !!
CMD:servermsg(playerid, params[])
{
  new servermsg[128];
  if(sscanf(params,"s[128]",servermsg)) return SendClientMessage(playerid,-1,"Usage: /servermsg [Your Login Message]");
  new INI:File = INI_Open("Server/Info.ini"); //>Open Or Create Info.ini File in /scriptfiles/Server/Info.ini
  INI_SetTag(File,"sdata"); //>Set "[sdata]" tag in ini file for assortment data
  INI_WriteString(File,"LoginMSG",servermsg); //>wreite "servermsg" that i used in sscanf (my msg)
  INI_Close(File); //>Closing File that i opened for writing
  SendClientMessage(playerid,-1,"Your Srver Message Successfully Created."); //> :D :D
  return 1;
}
hope i helped...

Good Luck.
Reply


Messages In This Thread
Dynamic MOTD? - by rangerxxll - 26.11.2014, 22:22
Re: Dynamic MOTD? - by Write - 26.11.2014, 23:14
Re: Dynamic MOTD? - by rangerxxll - 26.11.2014, 23:15
Re: Dynamic MOTD? - by Abagail - 26.11.2014, 23:27
Re: Dynamic MOTD? - by Write - 26.11.2014, 23:34
Re: Dynamic MOTD? - by rangerxxll - 29.11.2014, 21:38
Re: Dynamic MOTD? - by M4D - 30.11.2014, 07:27

Forum Jump:


Users browsing this thread: 1 Guest(s)