Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <zcmd>
- #include <foreach>
- #include <sscanf>
- #define MAX_GAMES 500 // infinite, aka 500 as we'll never play this many games
- // Player Information
- enum player_data
- {
- pLogged,
- pReg,
- pTeam, // 0 America, 1 Canada
- // ^ Temps
- pMoney,
- pKills,
- pDeaths,
- pFlagCaps,
- pFlagReturns
- }
- new p_data[MAX_PLAYERS][player_data];
- // Game Information
- enum game_data
- {
- gStatus, // 0 Stopped, 1 Prep, 2 Started
- gRound,
- gTimeLeft
- }
- new g_data[MAX_GAMES][game_data];
- // Team Information (1 - USA) (2 - Canada)
- static usa = 1;
- static can = 2;
- enum team_data
- {
- tName[24],
- tFlagScore,
- tFlag,
- tFlagCarrier, // Equal to the ID of the player who has the flag
- tFlagState // 0 At base, 1 taken
- }
- new t_data[3][team_data];
- // Team Vars
- new usa_guns[5][] = {2, 3, 4, 5, 6};
- new can_guns[5][] = {7, 10, 4, 5, 15};
- new usa_skins[5][] = {207, 135, 241, 182, 36};
- new can_skins[5][] = {138, 146, 251, 154, 140};
- #define FLAG 2993
- // Dialog Information
- #define REG_DIA 1
- #define LOG_DIA 2
- #define TEAM_SELECT_DIA 3
- //SQL Information
- new DB:ctfDB;
- main() print("Script Started");
- public OnGameModeInit()
- {
- ctfDB = db_open("ctf.db");
- SetGameModeText("CTF:Pro");
- AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
- TeamSetup();
- return 1;
- }
- public OnGameModeExit()
- {
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- if(existingUser(playerid) == 1) ShowPlayerDialog(playerid,LOG_DIA,DIALOG_STYLE_INPUT,"Login","Enter your password below:","Login","Quit");
- else ShowPlayerDialog(playerid,REG_DIA,DIALOG_STYLE_INPUT,"Register","Enter your password below:","Register","Quit");
- return 1;
- }
- public OnPlayerRequestSpawn(playerid)
- {
- if(p_data[playerid][pLogged] != 1) return 0;
- if(p_data[playerid][pTeam] == 0) return ShowPlayerDialog(playerid, TEAM_SELECT_DIA, DIALOG_STYLE_LIST, "Team Select", "United States of America\nCanada", "Select", "Quit");
- return 1;
- }
- public OnPlayerSpawn(playerid)
- {
- if(p_data[playerid][pTeam] == can)
- {
- PlayerTeamSetup(playerid, can , 1928.8804,1273.2756,10.6719);
- }
- if(p_data[playerid][pTeam] == usa)
- {
- PlayerTeamSetup(playerid, usa , 2039.3749,1273.2112,10.6797);
- }
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- switch(dialogid)
- {
- case REG_DIA:
- {
- if(!response) return Kick(playerid);
- else
- {
- new tmp[150], DBResult:result;
- format(tmp, sizeof(tmp), "INSERT INTO accounts (username, password) VALUES ('%s', '%s')", name(playerid), DB_Escape(inputtext));
- result = db_query(ctfDB, tmp);
- db_free_result(result);
- SendClientMessage(playerid, -1, "Account registered!");
- ShowPlayerDialog(playerid, TEAM_SELECT_DIA, DIALOG_STYLE_LIST, "Team Select", "United States of America\nCanada", "Select", "Quit");
- }
- }
- case LOG_DIA:
- {
- if(!response) return Kick(playerid);
- else
- {
- new tmp[150], DBResult:result;
- format(tmp, sizeof(tmp), "SELECT * FROM accounts WHERE username = '%s' AND password = '%s'", name(playerid), inputtext);
- result = db_query(ctfDB, tmp);
- if(db_num_rows(result) > 0)
- {
- SendClientMessage(playerid, -1, "Login Success!");
- p_data[playerid][pLogged] = 1;
- }
- else
- {
- SendClientMessage(playerid, -1, "Login failure! [ Kicked ]");
- Kick(playerid);
- }
- db_free_result(result);
- ShowPlayerDialog(playerid, TEAM_SELECT_DIA, DIALOG_STYLE_LIST, "Team Select", "United States of America\nCanada", "Select", "Quit");
- }
- }
- case TEAM_SELECT_DIA:
- {
- if(!response) return Kick(playerid);
- else
- {
- switch(listitem)
- {
- case 0:
- {
- SendClientMessage(playerid, -1, "You've chosen USA!");
- p_data[playerid][pTeam] = usa;
- PlayerTeamSetup(playerid, usa , 2039.3749,1273.2112,10.6797);
- SpawnPlayer(playerid);
- }
- case 1:
- {
- SendClientMessage(playerid, -1, "You've chosen Canada!");
- p_data[playerid][pTeam] = can;
- PlayerTeamSetup(playerid, can , 1928.8804,1273.2756,10.6719);
- SpawnPlayer(playerid);
- }
- }
- }
- }
- }
- return 1;
- }
- public OnPlayerPickUpPickup(playerid, pickupid)
- {
- new tmp[128];
- if(pickupid == t_data[usa][tFlag]) // USA
- {
- if(p_data[playerid][pTeam] == usa && t_data[usa][tFlagState] == 0) return SendClientMessage(playerid, -1, "You can't steal your team flag!");
- if(p_data[playerid][pTeam] == usa && t_data[usa][tFlagState] == 1)
- {
- format(tmp, sizeof(tmp), "%s has returned his team flag!", name(playerid));
- GameTextForAll(tmp, 3000, 6);
- DestroyPickup(t_data[usa][tFlag]);
- t_data[usa][tFlag] = CreatePickup(FLAG, 23, 2034.6960,1273.2317,10.6719, 0);
- t_data[usa][tFlagState] = 0;
- }
- if(p_data[playerid][pTeam] == can && t_data[usa][tFlagState] == 0)
- {
- format(tmp, sizeof(tmp), "~r~%s ~g~has stolen team %s's flag!", name(playerid), t_data[usa][tName]);
- GameTextForAll(tmp, 3000, 6);
- t_data[usa][tFlagCarrier] = playerid;
- t_data[usa][tFlagState] = 1;
- DestroyPickup(t_data[usa][tFlag]);
- }
- }
- if(pickupid == t_data[can][tFlag]) // CANADA
- {
- if(p_data[playerid][pTeam] == can && t_data[can][tFlagState] == 0) return SendClientMessage(playerid, -1, "You can't steal your team flag!");
- if(p_data[playerid][pTeam] == can && t_data[can][tFlagState] == 1)
- {
- format(tmp, sizeof(tmp), "%s has returned his team flag!", name(playerid));
- GameTextForAll(tmp, 3000, 6);
- DestroyPickup(t_data[can][tFlag]);
- t_data[can][tFlag] = CreatePickup(FLAG, 23, 1934.6691,1273.2633,10.6719, 0);
- t_data[can][tFlagState] = 0;
- }
- if(p_data[playerid][pTeam] == usa && t_data[can][tFlagState] == 0)
- {
- format(tmp, sizeof(tmp), "~r~%s ~g~has stolen team %s's flag!", name(playerid), t_data[can][tName]);
- GameTextForAll(tmp, 3000, 6);
- t_data[can][tFlagCarrier] = playerid;
- t_data[can][tFlagState] = 1;
- DestroyPickup(t_data[can][tFlag]);
- }
- }
- return 1;
- }
- public OnPlayerDeath(playerid, killerid, reason)
- {
- new Float:x, Float:y, Float:z;
- GetPlayerPos(playerid, x, y, z);
- for(new team = 0; team < 3; team++)
- {
- if(t_data[team][tFlagCarrier] == playerid)
- {
- t_data[team][tFlag] = CreatePickup(FLAG, 23, x, y, z, 0);
- t_data[team][tFlagState] = 1;
- t_data[team][tFlagCarrier] = -1;
- }
- }
- return 1;
- }
- stock TeamSetup()
- {
- format(t_data[usa][tName], 24, "USA");
- t_data[usa][tFlag] = CreatePickup(FLAG, 23, 2034.6960,1273.2317,10.6719, 0);
- t_data[usa][tFlagState] = 0;
- t_data[usa][tFlagCarrier] = -1;
- t_data[usa][tFlagScore] = 0;
- format(t_data[can][tName], 24, "Canada");
- t_data[can][tFlag] = CreatePickup(FLAG, 23, 1934.6691,1273.2633,10.6719, 0);
- t_data[can][tFlagState] = 0;
- t_data[can][tFlagCarrier] = -1;
- t_data[can][tFlagScore] = 0;
- }
- stock existingUser(playerid) //Returns 1 if the user exists
- {
- new tmp[150], DBResult:result;
- format(tmp, sizeof(tmp), "SELECT * FROM accounts WHERE username = '%s'", name(playerid));
- result = db_query(ctfDB, tmp);
- if(db_num_rows(result) > 0)
- {
- db_free_result(result);
- return 1;
- }
- else
- {
- db_free_result(result);
- return 0;
- }
- }
- stock name(playerid)
- {
- new temp[MAX_PLAYER_NAME];
- GetPlayerName(playerid, temp, sizeof(temp));
- return temp;
- }
- stock PlayerTeamSetup(playerid, teamid, Float:x, Float:y, Float:z)
- {
- new ran = random(5);
- p_data[playerid][pTeam] = teamid;
- SetPlayerPos(playerid, x, y, z);
- if(teamid == usa) // Usa
- {
- GivePlayerWeapon(playerid, usa_guns[ran][0], 1);
- SetPlayerSkin(playerid, usa_skins[ran][0]);
- }
- if(teamid == can) // Canada
- {
- GivePlayerWeapon(playerid, can_guns[ran][0], 1);
- SetPlayerSkin(playerid, can_skins[ran][0]);
- }
- printf("[DEBUG] ran number: %d", ran);
- }
- //DB Escape function (Y_LESS)
- #define MAX_INI_ENTRY_TEXT 80
- stock DB_Escape(text[])
- {
- new
- ret[MAX_INI_ENTRY_TEXT * 2],
- ch,
- i,
- j;
- while ((ch = text[i++]) && j < sizeof (ret))
- {
- if (ch == '\'')
- {
- if (j < sizeof (ret) - 2)
- {
- ret[j++] = '\'';
- ret[j++] = '\'';
- }
- }
- else if (j < sizeof (ret))
- {
- ret[j++] = ch;
- }
- else
- {
- j++;
- }
- }
- ret[sizeof (ret) - 1] = '\0';
- return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement