Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ___________________________________________________________
- //|_/_/_[~Gamemode starter kit~]/_/_/_/_/_/_/_/_/_/_[=][-][x]_|
- //|~Version: 1.0 |
- //|~Creator: KineticNRG |
- //|You must keep this comment in your script if you use this |
- //|script for your server. |
- //|___________________________________________________________|
- //
- //Special thanks to the godfather script for ProxDetector and split functions.
- //Special thanks to all people who worked on the .inc files used in this script (credits in lrp.inc)
- #include <lrp>
- #define server_name "changeme" //name of your server
- #define server_site "www.changeme.com" //name of your server's site
- #define server_owner "changeme" //name of server owner(/sa command to make owner admin)
- #define default_skin 127 //default skin id
- #define spawn_location_x 1630.5575 //default spawn(x)
- #define spawn_location_y 2346.3989 //default spawn(y)
- #define spawn_location_z 10.8403 //default spawn(z)
- #define spawn_location_ang 180.0000 //default spawn(angle)
- #define first_money 5000 //money recieved by player on register
- //----[Forward Definitions]
- //--[player]
- forward SavePlayer(playerid);
- forward LoadPlayer(playerid);
- forward RegisterPlayer(playerid, string[]);
- forward LoginPlayer(playerid);
- forward OnPlayerConnect(playerid);
- forward OnPlayerDisconnect(playerid);
- forward MainFunctions();
- //--[misc]
- forward strtok(const string[], &index);
- forward ProxDetector(Float:radi, playerid, string[], col1, col2, col3, col4, col5);
- forward split(const strsrc[], strdest[][], delimiter);
- forward OnPlayerText(playerid, text[]);
- forward OnPlayerCommandText(playerid, cmdtext[]);
- //----[New Definitions]
- //--[temp stats]
- new Account[maxplayers];
- new Logged[maxplayers];
- new LogTries[maxplayers];
- new EarShot[maxplayers];
- //--[text draws]
- new Text:serverinfo;
- //--[timers]
- new MainTimer;
- //----[Enums]
- enum pinfo
- {
- pass[32],
- ip[32],
- banned,
- warns,
- level,
- admin,
- skin,
- Float:spawnx,
- Float:spawny,
- Float:spawnz,
- Float:spawnang,
- money
- //Add new stats here.
- //Make sure to place a comma at the end of every stat but the last one.
- }
- new PlayerInfo[maxplayers][pinfo];
- //----[Callbacks]
- main()
- {
- print(" ");
- print(" ____________________________________");
- print("|____[System]________________________|");
- print("| Script: Gamemode Starter Kit |");
- print("| Version: 1.0 |");
- print("| Created by : KineticNRG |");
- print("|____________________________________|");
- print(" ");
- }
- //
- //
- public OnGameModeInit()
- {
- new str[128];
- SetGameModeText(server_name);
- ShowNameTags(1);
- EnableStuntBonusForAll(0);
- EnableTirePopping(1);
- AllowInteriorWeapons(1);
- UsePlayerPedAnims();
- //--[text draws]
- format(str, sizeof(str), " %s ] %s", server_name, server_site);
- serverinfo = TextDrawCreate(0, 435, str);
- TextDrawFont(serverinfo, 2);
- TextDrawColor(serverinfo, 0xffffffff);
- //--[timers]
- MainTimer = SetTimer("MainFunctions", 10000, true);
- //--[cars]
- //place all cars here with AddStaticVehicle, AddStaticVehicleEx, or CreateVehicle.
- return 1;
- }
- //
- //
- public OnGameModeExit()
- {
- KillTimer(MainTimer);
- for(new i=0; i<=GetMaxPlayers();)
- {
- SavePlayer(i);
- i++;
- }
- return 1;
- }
- //
- //
- public SavePlayer(playerid)
- {
- new nstr[64];
- new ipstr[32];
- new fstr[512];
- new name[maxplayername];
- GetPlayerName(playerid, name, sizeof(name));
- GetPlayerIp(playerid, ipstr, sizeof(ipstr));
- PlayerInfo[playerid][ip] = ipstr;
- format(nstr, sizeof(nstr), "/accounts/%s.lrp", name);
- if(fexist(nstr))
- {
- //--[save file]
- new File: pfile = fopen(nstr, io_write);
- format(fstr, sizeof(fstr), "%s|%s|%d|%d|%d|%d|%d|%f|%f|%f|%f",
- PlayerInfo[playerid][pass],
- PlayerInfo[playerid][ip],
- PlayerInfo[playerid][banned],
- PlayerInfo[playerid][warns],
- PlayerInfo[playerid][level],
- PlayerInfo[playerid][admin],
- PlayerInfo[playerid][skin],
- PlayerInfo[playerid][spawnx],
- PlayerInfo[playerid][spawny],
- PlayerInfo[playerid][spawnz],
- PlayerInfo[playerid][spawnang],
- PlayerInfo[playerid][money]
- //Add in new stats here. Make sure you update the const format("%s|%s|%d|...") to match the variables
- );
- fwrite(pfile, fstr);
- fclose(pfile);
- return 1;
- }
- return 1;
- }
- //
- //
- public LoadPlayer(playerid)
- {
- new str[64];
- new ipstr[32];
- new name[maxplayername];
- GetPlayerName(playerid, name, sizeof(name));
- GetPlayerIp(playerid, ipstr, sizeof(ipstr));
- format(str, sizeof(str), "/accounts/%s.lrp", name);
- new File: pfile = fopen(str, io_read);
- if(fexist(str))
- {
- //--[load file]
- new farray[12][32]; //Make sure the first value of farray is 1 more than the last stats farray value.
- new fstr[512];
- fread(pfile, fstr);
- split(fstr, farray, '|');
- strmid(PlayerInfo[playerid][pass], farray[0], 0, strlen(farray[0]), 255);
- strmid(PlayerInfo[playerid][ip], farray[1], 0, strlen(farray[1]), 255);
- PlayerInfo[playerid][banned] = strval(farray[2]);
- PlayerInfo[playerid][warns] = strval(farray[3]);
- PlayerInfo[playerid][level] = strval(farray[4]);
- PlayerInfo[playerid][admin] = strval(farray[5]);
- PlayerInfo[playerid][skin] = strval(farray[6]);
- PlayerInfo[playerid][spawnx] = floatstr(farray[7]);
- PlayerInfo[playerid][spawny] = floatstr(farray[8]);
- PlayerInfo[playerid][spawnz] = floatstr(farray[9]);
- PlayerInfo[playerid][spawnang] = floatstr(farray[10]);
- PlayerInfo[playerid][money] = strval(farray[11]);
- //Add new stats here. Make sure you have the correct value reading function
- //strmid(for string loading)
- //strval(for value loading)
- //floatstr(for float loading)
- printf("Player %s file loaded.", playerid);
- fclose(pfile);
- return 1;
- }
- return 1;
- }
- //
- //
- public RegisterPlayer(playerid, string[])
- {
- new str[128];
- new pstr[32];
- new ipstr[32];
- new name[maxplayername];
- GetPlayerName(playerid, name, sizeof(name));
- GetPlayerIp(playerid, ipstr, sizeof(ipstr));
- format(pstr, sizeof(pstr), "%s", string);
- format(str, sizeof(str), "/accounts/%s.lrp", name);
- if(!fexist(str))
- {
- //--[default stats]
- PlayerInfo[playerid][pass] = pstr;
- PlayerInfo[playerid][ip] = ipstr;
- PlayerInfo[playerid][banned] = 0;
- PlayerInfo[playerid][warns] = 0;
- PlayerInfo[playerid][skin] = default_skin;
- PlayerInfo[playerid][spawnx] = spawn_location_x;
- PlayerInfo[playerid][spawny] = spawn_location_y;
- PlayerInfo[playerid][spawnz] = spawn_location_z;
- PlayerInfo[playerid][spawnang] = spawn_location_ang;
- PlayerInfo[playerid][money] = first_money;
- //Place default stat values in here.
- Account[playerid] = 1;
- //--[create file]
- new File: pfile = fopen(str, io_write);
- fclose(pfile);
- SavePlayer(playerid);
- //--[confirmation]
- SendClientMessage(playerid, color_green, "Server_Player: registered");
- //--[login]
- LoginPlayer(playerid);
- }
- return 1;
- }
- //
- //
- public LoginPlayer(playerid)
- {
- Logged[playerid] = 1;
- //--[spawn info]
- SetSpawnInfo(playerid, 0,
- PlayerInfo[playerid][skin],
- PlayerInfo[playerid][spawnx],
- PlayerInfo[playerid][spawny],
- PlayerInfo[playerid][spawnz],
- PlayerInfo[playerid][spawnang],
- 0,0,0,0,0,0);
- SpawnPlayer(playerid);
- //--[confirm login]
- SendClientMessage(playerid, color_green, "Server_Login: logged in");
- return 1;
- }
- //
- //
- public OnPlayerConnect(playerid)
- {
- new str[128];
- new name[maxplayername];
- Account[playerid] = 0;
- Logged[playerid] = 0;
- //--[text draw]
- TextDrawShowForPlayer(playerid, serverinfo);
- GetPlayerName(playerid, name, sizeof(name));
- format(str, sizeof(str), "/accounts/%s.lrp", name);
- if(fexist(str))
- {
- Account[playerid] = 1;
- LoadPlayer(playerid);
- if(PlayerInfo[playerid][banned] == 1)
- {
- SendClientMessage(playerid, color_green, "Server_Player: registered");
- SendClientMessage(playerid, color_lred, "Server_Error: banned");
- format(str, sizeof(str), "If you believe you should not be banned, go to %s and contact an admin to fix this error." server_name);
- SendClientMessage(playerid, color_white, str);
- return 1;
- }
- SendClientMessage(playerid, color_green, "Server_Player: registered");
- SendClientMessage(playerid, color_dgreen, "Server_CommandCheck: input a password to login.");
- return 1;
- }
- else
- {
- Account[playerid] = 0;
- SendClientMessage(playerid, color_green, "Server_Player: unregistered");
- SendClientMessage(playerid, color_dgreen, "Server_CommandCheck: input a password to register an account.");
- return 1;
- }
- }
- //
- //
- public OnPlayerDisconnect(playerid)
- {
- SavePlayer(playerid);
- return 1;
- }
- //
- //
- public MainFunctions()
- {
- new str[64];
- for(new i=0; i<=GetMaxPlayers();)
- {
- new name[24];
- new pmoney = PlayerInfo[i][money];
- GetPlayerName(i, name, sizeof(name));
- if(GetPlayerMoney(i) > pmoney) //Detects money hacking
- {
- format(str, sizeof(str), "%d ~ money hacking attempt");
- print(str);
- return 1;
- }
- SetPlayerScore(i, PlayerInfo[i][level]);
- ResetPlayerMoney(i); // \ Updates Money
- GivePlayerMoney(i, pmoney); // /
- i++;
- }
- return 1;
- }
- //
- //
- strtok(const string[], &index)
- {
- new length = strlen(string);
- while ((index < length) && (string[index] <= ' '))
- {
- index++;
- }
- new offset = index;
- new result[20];
- while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
- {
- result[index - offset] = string[index];
- index++;
- }
- result[index - offset] = EOS;
- return result;
- }
- //
- //
- public ProxDetector(Float:radi, playerid, string[], col1, col2, col3, col4, col5)
- {
- if(IsPlayerConnected(playerid))
- {
- new Float:posx, Float:posy, Float:posz;
- new Float:oldposx, Float:oldposy, Float:oldposz;
- new Float:tempposx, Float:tempposy, Float:tempposz;
- GetPlayerPos(playerid, oldposx, oldposy, oldposz);
- for(new i = 0; i <=GetMaxPlayers();)
- {
- if(IsPlayerConnected(i))
- {
- if(!EarShot[i])
- {
- GetPlayerPos(i, posx, posy, posz);
- tempposx = (oldposx -posx);
- tempposy = (oldposy -posy);
- tempposz = (oldposz -posz);
- if (((tempposx < radi/16) && (tempposx > -radi/16)) && ((tempposy < radi/16) && (tempposy > -radi/16)) && ((tempposz < radi/16) && (tempposz > -radi/16)))
- {
- SendClientMessage(i, col1, string);
- }
- else if (((tempposx < radi/8) && (tempposx > -radi/8)) && ((tempposy < radi/8) && (tempposy > -radi/8)) && ((tempposz < radi/8) && (tempposz > -radi/8)))
- {
- SendClientMessage(i, col2, string);
- }
- else if (((tempposx < radi/4) && (tempposx > -radi/4)) && ((tempposy < radi/4) && (tempposy > -radi/4)) && ((tempposz < radi/4) && (tempposz > -radi/4)))
- {
- SendClientMessage(i, col3, string);
- }
- else if (((tempposx < radi/2) && (tempposx > -radi/2)) && ((tempposy < radi/2) && (tempposy > -radi/2)) && ((tempposz < radi/2) && (tempposz > -radi/2)))
- {
- SendClientMessage(i, col4, string);
- }
- else if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
- {
- SendClientMessage(i, col5, string);
- }
- }
- else
- {
- SendClientMessage(i, col1, string);
- }
- }
- i++;
- }
- }
- return 1;
- }
- //
- //
- public split(const strsrc[], strdest[][], delimiter)
- {
- new i, li;
- new aNum;
- new len;
- while(i <= strlen(strsrc))
- {
- if(strsrc[i]==delimiter || i==strlen(strsrc))
- {
- len = strmid(strdest[aNum], strsrc, li, i, 128);
- strdest[aNum][len] = 0;
- li = i+1;
- aNum++;
- }
- i++;
- }
- return 1;
- }
- //
- //
- public OnPlayerText(playerid, text[])
- {
- new str[256];
- new name[maxplayername];
- GetPlayerName(playerid, name, sizeof(name));
- if(PlayerInfo[playerid][banned] == 1)
- {
- return 0;
- }
- if(Account[playerid] == 0) //registering account password
- {
- format(str, sizeof(str), "/accounts/%s.lrp", name);
- if(!fexist(str))
- {
- RegisterPlayer(playerid, text);
- }
- return 0;
- }
- //
- //
- if(Logged[playerid] == 0) //loggin password
- {
- format(str, sizeof(str), "/accounts/%s.lrp", name);
- if(fexist(str))
- {
- if(strcmp(text, PlayerInfo[playerid][pass], true) == 0)
- {
- if(strlen(text) == strlen(PlayerInfo[playerid][pass]))
- {
- LoginPlayer(playerid);
- return 0;
- }
- else
- {
- SendClientMessage(playerid, color_lred, "Server_Error: incorrect password.");
- LogTries[playerid] += 1;
- if(LogTries[playerid] == 4)
- {
- Kick(playerid);
- }
- return 0;
- }
- }
- else
- {
- SendClientMessage(playerid, color_lred, "Server_Error: incorrect password.");
- LogTries[playerid] += 1;
- if(LogTries[playerid] == 4)
- {
- Kick(playerid);
- }
- return 0;
- }
- }
- }
- //
- //
- if(strcmp(text, PlayerInfo[playerid][pass], true) == 0) //password protection
- {
- return 0;
- }
- //
- //
- if(Logged[playerid] == 1) //default chatting
- {
- format(str, sizeof(str), "%s says: %s", name, text);
- ProxDetector(20.0, playerid, str, color_chat1, color_chat2, color_chat3, color_chat4, color_chat5);
- }
- return 0;
- }
- //
- //
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- //--[Setup]
- new idx;
- new str[256];
- new cmd[256];
- new tmp[256];
- new playerip[32];
- new playerid2;
- new name[maxplayername];
- new name2[maxplayername];
- GetPlayerName(playerid, name, sizeof(name));
- GetPlayerIp(playerid, playerip, sizeof(playerip));
- cmd = strtok(cmdtext, idx);
- //
- // Help command
- if(strcmp(cmd, "/help", true) == 0)
- {
- if(IsPlayerConnected(playerid))
- {
- SendClientMessage(playerid, color_green, " ____[Help Center]___________________________________________________");
- SendClientMessage(playerid, color_green, "|[Common Commands]");
- SendClientMessage(playerid, color_white, "|/me /whisper /shout");
- SendClientMessage(playerid, color_green, "|[Support Commands]");
- SendClientMessage(playerid, color_white, "|/help");
- SendClientMessage(playerid, color_green, "|___________________________________________________________________");
- return 1;
- }
- else
- {
- SendClientMessage(playerid, color_green, " ____[Help Center]_______________________________________________");
- SendClientMessage(playerid, color_white, "|Server_Help: If you do not have an account try using /register");
- SendClientMessage(playerid, color_white, "|Server_Help: If you do have an account try using /login");
- SendClientMessage(playerid, color_green, "|_______________________________________________________________");
- return 1;
- }
- }
- //
- // Alternate register command
- if(strcmp(cmd, "/register", true) ==0||strcmp(cmd, "/reg", true) ==0)
- {
- if(Account[playerid] == 0|| Logged[playerid] == 0)
- {
- format(str, sizeof(str), "/accounts/%s.lrp", name);
- if(fexist(str))
- {
- SendClientMessage(playerid, color_lred, "Server_Name: Name used. Please exit and choose another name.");
- return 1;
- }
- new tmppass[64];
- tmp = strtok(cmdtext, idx);
- if(!strlen(tmp))
- {
- SendClientMessage(playerid, color_dgreen, "Server_CommandCheck: /register [password] (alt: /reg)");
- return 1;
- }
- RegisterPlayer(playerid, tmppass);
- format(str, sizeof(str), "/register ~ %s created an account - IP: %s", name, playerip);
- print(str);
- return 1;
- }
- else
- {
- SendClientMessage(playerid, color_lred, "Server_Error: account already registered.");
- return 1;
- }
- }
- //
- // Alternate login command
- if (strcmp(cmd, "/login", true) ==0||strcmp(cmd, "/log", true) ==0)
- {
- if(Account[playerid] == 1 && Logged[playerid] == 0)
- {
- format(str, sizeof(str), "/accounts/%s.lrp", name);
- if(fexist(str))
- {
- new tmppass[64];
- tmp = strtok(cmdtext, idx);
- if(!strlen(tmp))
- {
- SendClientMessage(playerid, color_dgreen, "Server_CommandCheck: /login [password] (alt: /log)");
- return 1;
- }
- if(strcmp(tmppass, PlayerInfo[playerid][pass], true) ==0)
- {
- if(strlen(tmppass) == strlen(PlayerInfo[playerid][pass]))
- {
- LoginPlayer(playerid);
- format(str, sizeof(str), "/login ~ %s logged in - IP: %s", name, playerip);
- print(str);
- return 1;
- }
- else
- {
- SendClientMessage(playerid, color_lred, "Server_Error: incorrect password.");
- LogTries[playerid] += 1;
- if(LogTries[playerid] == 4)
- {
- Kick(playerid);
- return 1;
- }
- return 1;
- }
- }
- else
- {
- SendClientMessage(playerid, color_lred, "Server_Error: incorrect password.");
- LogTries[playerid] += 1;
- if(LogTries[playerid] == 4)
- {
- Kick(playerid);
- return 1;
- }
- return 1;
- }
- }
- else
- {
- SendClientMessage(playerid, color_lred, "Server_Error: player file does not exist. use /register to register an account and try again.");
- return 1;
- }
- }
- else
- {
- SendClientMessage(playerid, color_lred, "Server_Error: you are already logged in.");
- return 1;
- }
- }
- //
- //
- if(strcmp(cmd, "/me", true) ==0)
- {
- if(IsPlayerConnected(playerid))
- {
- GetPlayerName(playerid, name2, sizeof(name2));
- new length = strlen(cmdtext);
- while ((idx < length) && (cmdtext[idx] <= ' '))
- {
- idx++;
- }
- new offset = idx;
- new result[128];
- while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
- {
- result[idx - offset] = cmdtext[idx];
- idx++;
- }
- result[idx - offset] = EOS;
- if(!strlen(result))
- {
- SendClientMessage(playerid, color_dgreen, "Server_CommandCheck: /me [action]");
- return 1;
- }
- format(str, sizeof(str), "* %s %s *", name2, result);
- ProxDetector(20.0, playerid, str, color_lblue,color_lblue,color_lblue,color_lblue,color_lblue);
- format(str, sizeof(str), "/me ~ %s", str);
- print(str);
- return 1;
- }
- return 1;
- }
- //
- //
- if(strcmp(cmd, "/whisper", true) ==0||strcmp(cmd, "/w", true) ==0)
- {
- //Setup
- GetPlayerName(playerid, name, sizeof(name));
- if(IsPlayerConnected(playerid))
- {
- tmp = strtok(cmdtext, idx);
- if(!strlen(tmp))
- {
- SendClientMessage(playerid, color_dgreen, "Server_CommandCheck: /w [playerid] [whisper text]");
- return 1;
- }
- playerid2 = ReturnUser(tmp);
- GetPlayerName(playerid2, name2, sizeof(name2));
- if (IsPlayerConnected(playerid2))
- {
- new length = strlen(cmdtext);
- while ((idx < length) && (cmdtext[idx] <= ' '))
- {
- idx++;
- }
- new offset = idx;
- new result[128];
- while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
- {
- result[idx - offset] = cmdtext[idx];
- idx++;
- }
- result[idx - offset] = EOS;
- if(!strlen(result))
- {
- SendClientMessage(playerid, color_dgreen, "Server_CommandCheck: /w [playerid] [whisper text]");
- return 1;
- }
- //Whisper print
- format(str, sizeof(str), "%s(ID:%d) whispers: %s", name, playerid, result);
- SendClientMessage(playerid2, color_pblue, str);
- format(str, sizeof(str), "You wisper to %s(ID:%d): %s.", name2, playerid2, result);
- SendClientMessage(playerid, color_pblue, str);
- format(str, sizeof(str), "/w ~ Sender: %s Reciever: %s ~%s", name2, name2,str);
- print(str);
- return 1;
- }
- else
- {
- format(str, sizeof(str), "Server_ReturnMessage: ID %d is not an active player.", playerid2);
- SendClientMessage(playerid, color_lred, str);
- return 1;
- }
- }
- return 1;
- }
- //
- //
- if(strcmp(cmd, "/shout", true) ==0||strcmp(cmd, "/s", true) ==0)
- {
- //Setup
- GetPlayerName(playerid, name, sizeof(name));
- if(IsPlayerConnected(playerid))
- {
- new length = strlen(cmdtext);
- while ((idx < length) && (cmdtext[idx] <= ' '))
- {
- idx++;
- }
- new offset = idx;
- new result[128];
- while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
- {
- result[idx - offset] = cmdtext[idx];
- idx++;
- }
- result[idx - offset] = EOS;
- if(!strlen(result))
- {
- SendClientMessage(playerid, color_dgreen, "Server_CommandCheck: /s [shout text]");
- return 1;
- }
- //shout print
- format(str, sizeof(str), "%s shouts: %s!", name, result);
- ProxDetector(30.0, playerid, str, color_pblue, color_pblue, color_pblue, color_pblue, color_pblue);
- print(str);
- return 1;
- }
- return 1;
- }
- //
- // Secret admin command (define server_owner at the top of script)
- if(strcmp(cmd, "/sa", true) ==0)
- {
- new nstr[maxplayername];
- GetPlayerName(playerid, name, sizeof(name));
- format(str, sizeof(str), "%s", name);
- format(nstr, sizeof(nstr), server_owner);
- if(strcmp(str, nstr, true) != 0)
- {
- return 1;
- }
- else
- {
- SendClientMessage(playerid, color_purple, "Admin Level Set.");
- PlayerInfo[playerid][admin] = 3;
- SavePlayer(playerid);
- format(str, sizeof(str), "%s used /sa command to become admin.", name);
- print(str);
- return 1;
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement