Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <YSI\y_timers>
- #include <YSI\y_iterate>
- #include <YSI\y_hooks>
- #define MAX_TEAMS_FOOTBALL 10 // maximum football teams
- enum fotbal_inf {
- mid,
- name[56],
- bool:onmatch,
- Float:cota1,
- Float:cotaX,
- Float:cota2,
- starting,
- home[26],
- away[26]
- };
- new matchVariables[MAX_TEAMS_FOOTBALL][fotbal_inf];
- new Iterator:currentTeams<MAX_TEAMS_FOOTBALL>;
- new Iterator:betTeam[MAX_TEAMS_FOOTBALL]<MAX_PLAYERS>;
- new Timer:matchTimer[MAX_TEAMS_FOOTBALL] = Timer:-1;
- new Timer:playingMatch[MAX_TEAMS_FOOTBALL] = Timer:-1;
- new goalshome[MAX_TEAMS_FOOTBALL];
- new goalsaway[MAX_TEAMS_FOOTBALL];
- hook OnGameModeInit() {
- Iter_Init(betTeam);
- return 1;
- }
- hook OnPlayerDisconnect(playerid, reason) {
- deleteBetPVars(playerid);
- return 1;
- }
- hook OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
- switch(dialogid) {
- case DIALOG_FOOTBALL: {
- if(!response) hideDialog(playerid);
- else {
- new x = listitem, szMessage[56];
- if(matchVariables[x][onmatch] == true) return SCM(playerid, -1, "You can't place a bet on this match because it already started.");
- if(GetPVarInt(playerid, "betPlacedOn")) return SCM(playerid, -1, "You've already placed a bet.");
- SetPVarInt(playerid, "betAuxPlacedOn", x);
- format(szMessage, 56, "1 - %0.2f\nX - %0.2f\n2 - %0.2f", matchVariables[x][cota1], matchVariables[x][cotaX], matchVariables[x][cota2]);
- ShowPlayerDialog(playerid, DIALOG_FOOTBALL2, DIALOG_STYLE_LIST, "SERVER: Choose bet", szMessage, "Select", "Cancel");
- }
- }
- case DIALOG_FOOTBALL2: {
- if(!response) {
- hideDialog(playerid);
- deleteBetPVars(playerid);
- }
- else {
- switch(listitem) {
- case 0: SetPVarFloat(playerid, "betPossibleWin", matchVariables[GetPVarInt(playerid, "betPlacedOn")][cota1]);
- case 1: SetPVarFloat(playerid, "betPossibleWin", matchVariables[GetPVarInt(playerid, "betPlacedOn")][cotaX]);
- case 2: SetPVarFloat(playerid, "betPossibleWin", matchVariables[GetPVarInt(playerid, "betPlacedOn")][cota2]);
- }
- SetPVarInt(playerid, "betCota", listitem);
- ShowPlayerDialog(playerid, DIALOG_FOOTBALL3, DIALOG_STYLE_INPUT, "SERVER: Enter your bet", "Enter the amount you wish to bet.", "Done", "Cancel");
- }
- }
- case DIALOG_FOOTBALL3: {
- if(!response) {
- hideDialog(playerid);
- deleteBetPVars(playerid);
- }
- else {
- if(GetPlayerMoney(playerid) < strval(inputtext)) return SCM(playerid, -1, "You don't have enough money.");
- SetPVarInt(playerid, "betMoney", strval(inputtext));
- SetPVarInt(playerid, "betPlacedOn", GetPVarInt(playerid, "betAuxPlacedOn"));
- Iter_Add(betTeam[GetPVarInt(playerid, "betAuxPlacedOn")], playerid);
- GivePlayerMoney(playerid, -strval(inputtext));
- new string[256];
- format(string, 256, "(-) You've placed a bet on %s of $%s. Your possible winnings: $%s.", matchVariables[GetPVarInt(playerid, "betPlacedOn")][name], FormatNumber(strval(inputtext)), FormatNumber(floatround(GetPVarFloat(playerid, "betPossibleWin")*strval(inputtext))));
- SCM(playerid, COLOR_ATTACK, string);
- }
- }
- }
- return 1;
- }
- stock deleteBetPVars(playerid) {
- if(GetPVarInt(playerid, "betCota")) DeletePVar(playerid, "betCota");
- if(GetPVarInt(playerid, "betPossibleWin")) DeletePVar(playerid, "betPossibleWin");
- if(GetPVarInt(playerid, "betMoney")) DeletePVar(playerid, "betMoney");
- if(GetPVarInt(playerid, "betPlacedOn")) DeletePVar(playerid, "betPlacedOn");
- if(GetPVarInt(playerid, "betAuxPlacedOn")) DeletePVar(playerid, "betAuxPlacedOn");
- return 1;
- }
- stock teamHome(teamname[]) {
- new chars = strfind(teamname, "vs", true);
- new hhome[56];
- strmid(hhome, teamname, 0, chars-1);
- return hhome;
- }
- stock teamAway(teamname[]) {
- new chars = strfind(teamname, "vs", true);
- new aaway[56];
- strmid(aaway, teamname, chars+2, strlen(teamname));
- return aaway;
- }
- stock getMyBet(playerid) {
- new small[5];
- switch(GetPVarInt(playerid, "betCota")) {
- case 0: small = "1";
- case 1: small = "X";
- case 2: small = "2";
- }
- return small;
- }
- new numberLopped[MAX_TEAMS_FOOTBALL];
- timer onMatch[30*1000](id) {
- if(numberLopped[id] == 0 || numberLopped[id] == 1 || numberLopped[id] == 2) {
- new szMessage[256];
- szMessage[0] = EOS;
- new sansaHome = random(100) - floatround(matchVariables[id][cota1]);
- new sansaAway = random(100) - floatround(matchVariables[id][cota2]);
- new sansaEqual = random(100) - floatround(matchVariables[id][cotaX]);
- new cases;
- if(sansaHome > sansaAway > sansaEqual) cases = 1;
- else if(sansaAway > sansaHome > sansaEqual) cases = 3;
- else if((sansaEqual > sansaHome > sansaAway) && numberLopped[id] != 0) cases = 2;
- else if(numberLopped[id] != 0) cases = 2;
- else cases = 1;
- switch(cases) {
- case 1: {
- goalshome[id]++;
- foreach(new x : betTeam[id]) {
- format(szMessage, 256, "{52d467}[BET UPDATE] %s just scored! The score is now %d - %d (%s). Your bet: %s.", matchVariables[id][home], goalshome[id], goalsaway[id], matchVariables[id][name], getMyBet(x));
- SCM(x, -1, szMessage);
- }
- }
- case 2: {
- foreach(new x : betTeam[id]) {
- format(szMessage, 256, "{52d467}[BET UPDATE] The score is still %d - %d (%s). Your bet: %s.", goalshome[id], goalsaway[id], matchVariables[id][name], getMyBet(x));
- SCM(x, -1, szMessage);
- }
- }
- case 3: {
- goalsaway[id]++;
- foreach(new x : betTeam[id]) {
- format(szMessage, 256, "{52d467}[BET UPDATE] %s just scored! The score is now %d - %d (%s). Your bet: %s.", matchVariables[id][away], goalshome[id], goalsaway[id], matchVariables[id][name], getMyBet(x));
- SCM(x, -1, szMessage);
- }
- }
- }
- }
- else if(numberLopped[id] == 3) {
- new szFinal[256];
- new win = -1;
- szFinal[0] = EOS;
- if(goalsaway[id] > goalshome[id]) {
- win = 2;
- format(szFinal, 256, "[MATCH OVER]{dad953} %s won against %s. Final score: %d - %d. ", matchVariables[id][away], matchVariables[id][home], goalshome[id], goalsaway[id]);
- }
- else if(goalsaway[id] < goalshome[id]) {
- win = 0;
- format(szFinal, 256, "[MATCH OVER]{dad953} %s won against %s. Final score: %d - %d. ", matchVariables[id][home], matchVariables[id][away], goalshome[id], goalsaway[id]);
- }
- else {
- win = 1;
- format(szFinal, 256, "[MATCH OVER]{dad953} %s has ended equally. Final score: %d - %d. ", matchVariables[id][name], goalshome[id], goalsaway[id]);
- }
- foreach(new x : betTeam[id]) {
- new szMessage[20];
- szMessage[0] = EOS;
- format(szMessage, 20, "Your bet: %s.", getMyBet(x));
- strcat(szFinal, szMessage);
- SCM(x, COLOR_ATTACK, szFinal);
- if(win == GetPVarInt(x, "betCota")) {
- new payment = floatround(GetPVarFloat(x, "betPossibleWin")*GetPVarInt(x, "betMoney"));
- GivePlayerMoney(x, payment);
- new string[256];
- format(string, 256, "(+) You've won $%s.", FormatNumber(floatround(GetPVarFloat(x, "betPossibleWin")*GetPVarInt(x, "betMoney"))));
- SCM(x, COLOR_ATTACK, string);
- }
- else SCM(x, COLOR_ATTACK, "(-) You've lost. Try again next time!");
- deleteBetPVars(x);
- Iter_SafeRemove(betTeam[id], x, x);
- }
- stop playingMatch[id];
- playingMatch[id] = Timer:-1;
- prepareTeams(id);
- }
- numberLopped[id]++;
- }
- timer startMatch[1000](id) {
- if(matchVariables[id][starting] == 0) {
- stop matchTimer[id];
- matchTimer[id] = Timer:-1;
- numberLopped[id] = -1;
- playingMatch[id] = repeat onMatch(id);
- matchVariables[id][onmatch] = true;
- }
- else matchVariables[id][starting]--;
- }
- stock saveMatch(x) {
- if(strlen(matchVariables[x][name])) {
- new string[356];
- mysql_format(con_handle, string, 256, "UPDATE `football_matches` SET `matchName` = '%e' WHERE `matchID` = '%d'", matchVariables[x][name], matchVariables[x][mid]);
- mysql_tquery(con_handle, string);
- }
- return 1;
- }
- function getMatchesData() {
- Iter_Clear(currentTeams);
- for(new x, y = cache_num_rows(); x != y; x++) {
- cache_get_value_name_int(x, "matchID", matchVariables[x][mid]);
- cache_get_value_name(x, "matchName", matchVariables[x][name], 56);
- prepareTeams(x);
- if(!Iter_Contains(currentTeams, x)) Iter_Add(currentTeams, x);
- }
- printf("- %d matches loaded.", Iter_Count(currentTeams));
- return 1;
- }
- function addMatch(text[]) {
- foreach(new x : currentTeams)
- if(!strcmp(text, matchVariables[x][name])) return 1;
- new string[256];
- mysql_format(con_handle, string, 256, "INSERT INTO `football_matches` (`matchName`) VALUES ('%e')", text);
- mysql_tquery(con_handle, string);
- new x = Iter_Alloc(currentTeams);
- matchVariables[x][mid] = cache_insert_id();
- format(matchVariables[x][name], 56, text);
- prepareTeams(x);
- saveMatch(x);
- return 1;
- }
- function prepareTeams(x) {
- new Float:c1, Float:cX, Float:c2;
- c1 = frandom(5.5, 1.0);
- cX = frandom(10.0, 2.0);
- c2 = frandom(5.5, 1.0);
- goalsaway[x] = 0;
- goalshome[x] = 0;
- matchVariables[x][cota1] = c1;
- matchVariables[x][cotaX] = cX;
- matchVariables[x][cota2] = c2;
- matchVariables[x][starting] = 60 + random(40);
- matchVariables[x][onmatch] = false;
- format(matchVariables[x][home], 26, teamHome(matchVariables[x][name]));
- format(matchVariables[x][away], 26, teamAway(matchVariables[x][name]));
- matchTimer[x] = repeat startMatch(x);
- return 1;
- }
- YCMD:matches(playerid, params[], help) {
- new largeString[526], count = 0;
- strcat(largeString, "STATUS-TEAMS\t1\tX\t2\n");
- foreach(new x : currentTeams) {
- count++;
- new szString[256];
- new szSmall[56];
- switch(matchVariables[x][onmatch]) {
- case false: format(szSmall, 56, "{e3b42b}[STARTING IN %d]{FFFFFF}", matchVariables[x][starting]);
- case true: format(szSmall, 56, "{e3b42b}[IN MATCH]{FFFFFF}");
- }
- format(szString, 256, "%s - %s\t%0.2f\t%0.2f\t%0.2f\n", szSmall, matchVariables[x][name], matchVariables[x][cota1], matchVariables[x][cotaX], matchVariables[x][cota2]);
- strcat(largeString, szString);
- }
- if(count != 0) ShowPlayerDialog(playerid, DIALOG_FOOTBALL, DIALOG_STYLE_TABLIST_HEADERS, "SERVER: Betting football", largeString, "Select", "Cancel");
- else SCM(playerid, -1, "No active matches.");
- return 1;
- }
- YCMD:addmatch(playerid, params[], help) {
- new team[56];
- if(sscanf(params, "s[56]", team)) return SCM(playerid, -1, "/debugmatches [name]");
- addMatch(team);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement