Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************\
- * ,-----, *
- * /----/ | ,---, ,----, *
- * | | | ,------, ,----, ,----, /---/ \ /---/ | *
- * | | | /-----/ |/----/ \/---/ | \ \ \/ / / *
- * | | | | ,__|/ | \| | | \ \ / / / *
- * | | |____ | ---,/|| \ | | \ v / / *
- * | |____/ | | ,__|/ | ^\ | | ,----, ,----, \ / / *
- * | | | | ---,/|| | \ | /----/ \/---/ | | | | *
- * |_________|/ |_____|/ |___,/ \____,/| \| | | | | | *
- * | \ | | | | | *
- * ,--------------------------, | ^\ | | |___,/ *
- * /-------------------------/ | | | \ | | *
- * |/\/\/\/\/\/\/\/\/\/\/\/\/| | |___,/ \____,/ *
- * |lenny.carlson@hotmail.com| | *
- * |/\/\/\/\/\/\/\/\/\/\/\/\/| | *
- * |_________________________,/ *
- * *
- * Information about this file: *
- * *
- * Race system written by Lenny, thread here: *
- * http://forum.sa-mp.com/showthread.php?p=1249184 *
- * *
- * Feel free to edit/republish but please give me credits :) *
- * *
- \*****************************************************************************/
- #define MAX_RACES 60 // The maximum amount of races that can be stored
- #define MAX_RACE_NAME 20 // The longest name of a race that can be allowed
- #define MAX_RACE_CHECKPOINTS 500 // The maximum amount of checkpoints in total that can be stored
- #define DIALOG_RACES 100 // The dialog for /loadrace
- #define DIALOG_RACES2 101 // The dialog for /loadrace
- #define LR_USE_VARNAMES 0 // If you don't know what it is, keep it at 0 :)
- #if LR_USE_VARNAMES == 1
- #define PlayerName[%1] PlayerInfo[%1][pName] // Here is where you define the varname if you have it!
- #else
- #define PlayerName[%1] LR_GetName(%1)
- #endif
- #define COLOR_RACE_GREY 0xAFAFAF00
- #define COLOR_RACE_GREEN 0x33AA33AA
- #define COLOR_RACE_RED 0xAA3333AA
- #define MAX_PLAYER_NAME2 MAX_PLAYER_NAME
- #undef MAX_PLAYER_NAME
- #define MAX_PLAYER_NAME 24
- forward LR_LoadRaces();
- forward LR_OnPlayerEnterRaceCheckpoint(playerid);
- forward LR_OnDialogResponse(playerid, dialogid, response, listitem);
- forward LR_RaceCountdown(playerid);
- enum RaceInfo
- {
- rID,
- rName[MAX_RACE_NAME],
- rVehicles[41],
- rFastest[MAX_PLAYER_NAME],
- rRecord
- }
- new Race[MAX_RACES][RaceInfo];
- enum RaceCheckPointInfo
- {
- rcID,
- rcRaceID,
- Float: rcX,
- Float: rcY,
- Float: rcZ,
- rcType,
- Float: rcSize
- }
- new RaceCheckPoint[MAX_RACE_CHECKPOINTS][RaceCheckPointInfo];
- public LR_LoadRaces()
- {
- print(" LoadRaces initalized...");
- new
- szString[170],
- i;
- while(i < MAX_RACES) // Resetting variables
- {
- sscanf("-1%""%""%""%0", "p<%>e<is[" #MAX_RACE_NAME "]s[41]s[" #MAX_PLAYER_NAME "]i>", Race[i]);
- i++;
- }
- i = 0;
- format(szString, sizeof(szString), "SELECT `id`,`name`,`vehicles`,`fastest`,`record` FROM `races` ORDER BY `name` ASC LIMIT %d", MAX_RACES);
- mysql_query(szString);
- mysql_store_result();
- while(mysql_fetch_row_format(szString, "%"))
- {
- sscanf(szString, "p<%>e<is[" #MAX_RACE_NAME "]s[41]s[" #MAX_PLAYER_NAME "]i>", Race[i]);
- i++;
- }
- mysql_free_result();
- i = 0;
- while(i < MAX_RACE_CHECKPOINTS) // Resetting variables
- {
- sscanf("-1%-1%-1.0%-1.0%-1.0%-1%-1.0", "p<%>e<iifffif>", RaceCheckPoint[i]);
- i++;
- }
- i = 0;
- format(szString, sizeof(szString), "SELECT `id`,`raceid`,`x`,`y`,`z`,`type`,`size` FROM `race_checkpoints` ORDER BY `id` ASC LIMIT %d", MAX_RACE_CHECKPOINTS);
- mysql_query(szString);
- mysql_store_result();
- while(mysql_fetch_row_format(szString, "|"))
- {
- sscanf(szString, "p<|>iifffif", RaceCheckPoint[i][rcID], RaceCheckPoint[i][rcRaceID], RaceCheckPoint[i][rcX], RaceCheckPoint[i][rcY], RaceCheckPoint[i][rcZ], RaceCheckPoint[i][rcType], RaceCheckPoint[i][rcSize]);
- i++;
- }
- mysql_free_result();
- }
- public LR_OnPlayerEnterRaceCheckpoint(playerid)
- {
- if(GetPlayerVehicleSeat(playerid) != 0)
- {
- SendClientMessage(playerid, COLOR_RACE_RED, "You need to be driving in order to compete in a race.");
- return 1;
- }
- new
- iRace = GetPVarInt(playerid, "Race")-1;
- if(iRace == -1)
- {
- SendClientMessage(playerid, COLOR_RACE_RED, "You're not in a race.");
- DisablePlayerRaceCheckpoint(playerid);
- return 1;
- }
- new
- a_iAllowedVehicles[10],
- iPlayerVehicleModel = GetVehicleModel(GetPlayerVehicleID(playerid)),
- bool: VehicleIsAllowed = false;
- sscanf(Race[iRace][rVehicles], "p</>A<d>(0)[10]", a_iAllowedVehicles);
- for(new i; i < 10; i++)
- {
- if(a_iAllowedVehicles[i] == iPlayerVehicleModel)
- {
- VehicleIsAllowed = true;
- break;
- }
- }
- if(!VehicleIsAllowed)
- {
- SendClientMessage(playerid, COLOR_RACE_GREY, "This vehicle isn't allowed. Type \"/racecars\" to see which vehicles are allowed for this race.");
- return 1;
- }
- new
- iRacing = GetPVarInt(playerid, "Racing");
- if(!iRacing)
- {
- SendClientMessage(playerid, COLOR_RACE_GREEN, "You can now start the race with \"/ready\".");
- return 1;
- }
- DisablePlayerRaceCheckpoint(playerid);
- PlayerPlaySound(playerid, 1139, 0, 0, 0);
- new
- iRaceID = Race[iRace][rID];
- new iCPNumber = GetPVarInt(playerid, "Checkpoint");
- new iCurrentCP;
- new iNextCP;
- if(GetPVarInt(playerid, "FinalCheckpoint"))
- {
- new
- iTime = gettime() - GetPVarInt(playerid, "RaceTimer"),
- szString[MAX_PLAYER_NAME + MAX_RACE_NAME + 9 + 40];
- format(szString, sizeof(szString), "%s finished the race \"%s\". His time was %s.", PlayerName[playerid], Race[iRace][rName], TimeToRaceTime(iTime));
- SendClientMessageToAll(COLOR_RACE_GREEN, szString);
- format(szString, sizeof(szString), "INSERT INTO `race_times` (raceid,name,time,vehicle) VALUES (%d,'%s',%d,%d)", iRaceID, PlayerName[playerid], iTime, GetVehicleModel(GetPlayerVehicleID(playerid)));
- mysql_query(szString);
- if(iTime < Race[iRace][rRecord])
- {
- format(szString, sizeof(szString), "%s beat the old record of %s!", PlayerName[playerid], TimeToRaceTime(Race[iRace][rRecord]));
- SendClientMessageToAll(COLOR_RACE_GREEN, szString);
- format(Race[iRace][rFastest], MAX_PLAYER_NAME, PlayerName[playerid]);
- Race[iRace][rRecord] = iTime;
- format(szString, sizeof(szString), "UPDATE `races` SET fastest='%s',record=%d WHERE id=%d", PlayerName[playerid], iTime, Race[iRace][rID]);
- mysql_query(szString);
- }
- DeletePVar(playerid, "Checkpoint");
- DeletePVar(playerid, "Race");
- DeletePVar(playerid, "Racing");
- DeletePVar(playerid, "RaceTimer");
- return 1;
- }
- for(new i; i < MAX_RACE_CHECKPOINTS; i++)
- {
- if(RaceCheckPoint[i][rcRaceID] == iRaceID)
- {
- if(iCPNumber == 0)
- {
- if(!iCurrentCP)
- {
- iCurrentCP = i;
- continue;
- }
- else
- {
- iNextCP = i;
- break;
- }
- }
- iCPNumber--;
- }
- }
- if(iNextCP)
- {
- SetPVarInt(playerid, "Checkpoint", GetPVarInt(playerid, "Checkpoint") + 1);
- SetPlayerRaceCheckpoint(playerid, RaceCheckPoint[iCurrentCP][rcType], RaceCheckPoint[iCurrentCP][rcX], RaceCheckPoint[iCurrentCP][rcY], RaceCheckPoint[iCurrentCP][rcZ], RaceCheckPoint[iNextCP][rcX], RaceCheckPoint[iNextCP][rcY], RaceCheckPoint[iNextCP][rcZ], RaceCheckPoint[iCurrentCP][rcSize]);
- }
- else
- {
- SetPVarInt(playerid, "FinalCheckpoint", 1);
- DeletePVar(playerid, "Checkpoint");
- if(RaceCheckPoint[iCurrentCP][rcType] < 3)
- SetPlayerRaceCheckpoint(playerid, 1, RaceCheckPoint[iCurrentCP][rcX], RaceCheckPoint[iCurrentCP][rcY], RaceCheckPoint[iCurrentCP][rcZ], 0, 0, 0, RaceCheckPoint[iCurrentCP][rcSize]);
- else
- SetPlayerRaceCheckpoint(playerid, 4, RaceCheckPoint[iCurrentCP][rcX], RaceCheckPoint[iCurrentCP][rcY], RaceCheckPoint[iCurrentCP][rcZ], 0, 0, 0, RaceCheckPoint[iCurrentCP][rcSize]);
- }
- return 1;
- }
- public LR_OnDialogResponse(playerid, dialogid, response, listitem)
- {
- if(dialogid != DIALOG_RACES && dialogid != DIALOG_RACES2)
- {
- return 1;
- }
- if(!response)
- {
- return 1;
- }
- if(dialogid == DIALOG_RACES)
- {
- foreach(Player, i)
- {
- DisablePlayerRaceCheckpoint(i);
- SetPVarInt(i, "Race", listitem+1);
- DeletePVar(i, "Racing");
- DeletePVar(i, "RaceTimer");
- DeletePVar(i, "FinalCheckpoint");
- }
- }
- else
- {
- DisablePlayerRaceCheckpoint(playerid);
- SetPVarInt(playerid, "Race", listitem+1);
- DeletePVar(playerid, "Racing");
- DeletePVar(playerid, "RaceTimer");
- DeletePVar(playerid, "FinalCheckpoint");
- }
- #define SendRaceMessage(%1); \
- if(dialogid == DIALOG_RACES) \
- SendClientMessageToAll(COLOR_RACE_GREEN, %1); \
- else \
- SendClientMessage(playerid, COLOR_RACE_GREEN, %1);
- new
- szString[128],
- a_iAllowedVehicles[10],
- szVehicleName[20];
- format(szString, sizeof(szString), "[RACE] %s loaded the race \"%s\".", PlayerName[playerid], Race[listitem][rName]);
- SendRaceMessage(szString);
- sscanf(Race[listitem][rVehicles], "p</>A<d>(0)[10]", a_iAllowedVehicles);
- for(new i; i < 10; i++)
- {
- if(!a_iAllowedVehicles[i])
- break;
- GetVehicleName(a_iAllowedVehicles[i], szVehicleName, sizeof(szVehicleName));
- if(i == 0)
- format(szString, sizeof(szString), "Allowed vehicle(s): %s", szVehicleName);
- else if(i == 5)
- {
- SendRaceMessage(szString);
- format(szString, sizeof(szString), "Additional vehicle(s): %s", szVehicleName);
- }
- else
- format(szString, sizeof(szString), "%s, %s", szString, szVehicleName);
- }
- SendRaceMessage(szString);
- format(szString, sizeof(szString), "Current recordholder and time: %s - %s", Race[listitem][rFastest], TimeToRaceTime(Race[listitem][rRecord]));
- SendRaceMessage(szString);
- SendRaceMessage("Type \"/join\" to join the race.");
- #undef SendRaceMessage
- return 1;
- }
- stock LR_GetName(playerid)
- {
- new
- szName[MAX_PLAYER_NAME];
- GetPlayerName(playerid, szName, MAX_PLAYER_NAME);
- return szName;
- }
- stock IsVehicleAllowedInRace(model, raceid)
- {
- new
- a_iAllowedVehicles[10];
- sscanf(Race[raceid][rVehicles], "p</>A<d>(0)[10]", a_iAllowedVehicles);
- for(new i; a_iAllowedVehicles[i]; i++)
- {
- if(a_iAllowedVehicles[i] == model)
- return 1;
- }
- return 0;
- }
- stock GetVehicleName(modelid,name[],namesize)
- {
- new VehicleNames[][] =
- {
- "Landstalker","Bravura","Buffalo","Linerunner","Pereniel","Sentinel","Dumper","Firetruck","Trashmaster","Stretch","Manana","Infernus","Voodoo","Pony","Mule","Cheetah","Ambulance","Leviathan","Moonbeam","Esperanto",
- "Taxi","Washington","Bobcat","Mr Whoopee","BF Injection","Hunter","Premier","Enforcer","Securicar","Banshee","Predator","Bus","Rhino","Barracks","Hotknife","Trailer","Previon","Coach","Cabbie","Stallion",
- "Rumpo","RC Bandit","Romero","Packer","Monster","Admiral","Squalo","Seasparrow","Pizzaboy","Tram","Trailer","Turismo","Speeder","Reefer","Tropic","Flatbed","Yankee","Caddy","Solair","Berkley's RC Van",
- "Skimmer","PCJ-600","Faggio","Freeway","RC Baron","RC Raider","Glendale","Oceanic","Sanchez","Sparrow","Patriot","Quad","Coastguard","Dinghy","Hermes","Sabre","Rustler","ZR3 50","Walton","Regina",
- "Comet","BMX","Burrito","Camper","Marquis","Baggage","Dozer","Maverick","News Chopper","Rancher","FBI Rancher","Virgo","Greenwood","Jetmax","Hotring","Sandking","Blista Compact","Police Maverick","Boxville","Benson",
- "Mesa","RC Goblin","Hotring Racer","Hotring Racer","Bloodring Banger","Rancher","Super GT","Elegant","Journey","Bike","Mountain Bike","Beagle","Cropdust","Stunt","Tanker","RoadTrain","Nebula","Majestic","Buccaneer","Shamal",
- "Hydra","FCR-900","NRG-500","HPV1000","Cement Truck","Tow Truck","Fortune","Cadrona","FBI Truck","Willard","Forklift","Tractor","Combine","Feltzer","Remington","Slamvan","Blade","Freight","Streak","Vortex",
- "Vincent","Bullet","Clover","Sadler","Firetruck","Hustler","Intruder","Primo","Cargobob","Tampa","Sunrise","Merit","Utility","Nevada","Yosemite","Windsor","Monster","Monster","Uranus","Jester",
- "Sultan","Stratum","Elegy","Raindance","RC Tiger","Flash","Tahoma","Savanna","Bandito","Freight","Trailer","Kart","Mower","Duneride","Sweeper","Broadway","Tornado","AT-400","DFT-30","Huntley",
- "Stafford","BF-400","Newsvan","Tug","Trailer","Emperor","Wayfarer","Euros","Hotdog","Club","Trailer","Trailer","Andromada","Dodo","RC Cam","Launch","Police Car (LSPD)","Police Car (SFPD)","Police Car (LVPD)","Police Ranger",
- "Picador","S.W.A.T. Van","Alpha","Phoenix","Glendale","Sadler","Luggage Trailer","Luggage Trailer","Stair Trailer","Boxville","Farm Plow","Utility Trailer"
- };
- if(modelid < 400 || modelid > 611) return 0;
- modelid -= 400;
- for(new i = 0, len = strlen(VehicleNames[modelid]); i < len && i < namesize; i++)
- name[i] = VehicleNames[modelid][i];
- name[min(namesize, strlen(VehicleNames[modelid]))] = '\0';
- return 1;
- }
- stock TimeToRaceTime(iTime)
- {
- new
- szTime[9],
- a_iTime[3];
- a_iTime[0] = iTime % 60; // Seconds
- iTime /= 60;
- a_iTime[1] = iTime % 60; // Minutes
- iTime /= 60;
- a_iTime[2] = iTime % 24; // Hours
- format(szTime, sizeof(szTime), "%02d:%02d:%02d", a_iTime[2], a_iTime[1], a_iTime[0]);
- return szTime;
- }
- stock Freeze(playerid, op)
- TogglePlayerControllable(playerid, 1 - op);
- stock freeze(playerid,option)
- {
- if(option)
- {
- SetPVarInt(playerid, "Frozen", GetPVarInt(playerid, "Frozen") + 1);
- Freeze(playerid, 1);
- }
- else
- SetPVarInt(playerid, "Frozen", GetPVarInt(playerid, "Frozen") - 1);
- if(GetPVarInt(playerid, "Frozen") < 1)
- {
- DeletePVar(playerid, "Frozen"); // In case of some bug that people will have minus
- Freeze(playerid, 0);
- }
- }
- public LR_RaceCountdown(playerid)
- {
- new
- iCount = GetPVarInt(playerid, "RaceCountdown");
- SetVehicleVelocity(GetPlayerVehicleID(playerid), 0.0, 0.0, 0.0);
- if(!iCount)
- {
- SetTimerEx("OnPlayerEnterRaceCheckpoint",0,0,"d",playerid);
- DeletePVar(playerid, "RaceCountdown");
- GameTextForPlayer(playerid, "~g~Go!", 2000, 3);
- freeze(playerid, false);
- SetPVarInt(playerid, "RaceTimer", gettime());
- KillTimer(GetPVarInt(playerid, "RaceCountdownID"));
- }
- else
- {
- new
- szString[5],
- Float: fPos[3];
- GetPlayerPos(playerid, fPos[0], fPos[1], fPos[2]);
- switch(iCount)
- {
- case 1:
- {
- SetCameraBehindPlayer(playerid);
- format(szString, sizeof(szString), "~r~%d", iCount);
- }
- case 2:
- {
- SetPlayerCameraPos(playerid, fPos[0], fPos[1] - 10, fPos[2] + 5);
- SetPlayerCameraLookAt(playerid, fPos[0], fPos[1] + 10, fPos[2]);
- format(szString, sizeof(szString), "~g~%d", iCount);
- }
- case 3:
- {
- SetPlayerCameraPos(playerid, fPos[0] - 10, fPos[1], fPos[2] + 5);
- SetPlayerCameraLookAt(playerid, fPos[0] + 10, fPos[1], fPos[2]);
- format(szString, sizeof(szString), "~y~%d", iCount);
- }
- case 4:
- {
- SetPlayerCameraPos(playerid, fPos[0], fPos[1], fPos[2] + 5);
- SetPlayerCameraLookAt(playerid, fPos[0], fPos[1], fPos[2] - 10);
- format(szString, sizeof(szString), "~b~%d", iCount);
- }
- default:
- {
- SetPlayerCameraLookAt(playerid, fPos[0], fPos[1], fPos[2]);
- format(szString, sizeof(szString), "~r~%d", iCount);
- }
- }
- GameTextForPlayer(playerid, szString, 2000, 3);
- SetPVarInt(playerid, "RaceCountdown", iCount-1);
- }
- }
- // COMMANDS
- stock LR_CMD_ADDRACE(playerid, params[])
- {
- new
- szRaceName[MAX_RACE_NAME],
- szString[191],
- szRaceVehicles[41],
- a_iVehicleID[10];
- if(sscanf(params, "s[" #MAX_RACE_NAME "]A<i>(-1)[10]", szRaceName, a_iVehicleID))
- {
- SendClientMessage(playerid, COLOR_RACE_GREY, "USAGE: /createrace [Racename] [Vehiclemodel ID] (Up to 9 additional Vehiclemodel IDs)");
- return 1;
- }
- if(a_iVehicleID[0] == -1)
- {
- SendClientMessage(playerid, COLOR_RACE_GREY, "You need to provide at least one vehicle ID.");
- return 1;
- }
- if(!IsValidvehicleModel(a_iVehicleID[0]))
- {
- format(szString, sizeof(szString), "%d is not a valid vehicle model.", a_iVehicleID[0]);
- SendClientMessage(playerid, COLOR_RACE_GREY, szString);
- return 1;
- }
- format(szRaceVehicles, sizeof(szRaceVehicles), "%d", a_iVehicleID[0]);
- for(new i = 1; a_iVehicleID[i] && i < 10; i++)
- {
- if(a_iVehicleID[i] == -1)
- break;
- if(!IsValidvehicleModel(a_iVehicleID[i]))
- {
- format(szString, sizeof(szString), "%d is not a valid vehicle model.", a_iVehicleID[i]);
- SendClientMessage(playerid, COLOR_RACE_GREY, szString);
- return 1;
- }
- format(szRaceVehicles, sizeof(szRaceVehicles), "%s/%d", szRaceVehicles, a_iVehicleID[i]);
- }
- mysql_real_escape_string(szRaceName, szRaceName);
- format(szString, sizeof(szString), "SELECT `id` FROM `races` WHERE `name`='%s' LIMIT 1", szRaceName);
- mysql_query(szString);
- mysql_store_result();
- if(mysql_num_rows())
- {
- mysql_free_result();
- SendClientMessage(playerid, COLOR_RACE_GREY, "This race already exists. Try a different name.");
- return 1;
- }
- mysql_free_result();
- mysql_real_escape_string(szRaceVehicles, szRaceVehicles);
- format(szString, sizeof(szString), "INSERT INTO `races` (`name`,`vehicles`,`creator`,`fastest`,`record`) VALUES ('%s','%s','%s','Noone','360000')", szRaceName, szRaceVehicles, PlayerName[playerid]);
- mysql_query(szString);
- LR_LoadRaces();
- format(szString, sizeof(szString), "You have successfully created the race \"%s\".", szRaceName);
- SendClientMessage(playerid, COLOR_RACE_GREEN, szString);
- return 1;
- }
- stock LR_CMD_ADDCHECKPOINT(playerid, params[])
- {
- new
- szRaceName[MAX_RACE_NAME],
- iRaceID,
- iCheckType,
- Float: fSize,
- szString[150],
- iCPID = 1,
- Float: fPos[3];
- if(sscanf(params, "s[" #MAX_RACE_NAME "]I(0)F(5.0)", szRaceName, iCheckType, fSize))
- {
- SendClientMessage(playerid, COLOR_RACE_GREY, "USAGE: /a(dd)c(heckpoint) [Racename] (Checkpoint type) (Size)");
- SendClientMessage(playerid, COLOR_RACE_GREY, "TYPES: 0-Normal, 1-Finish, 2-Nothing, 3-Air normal, 4-Air finish");
- return 1;
- }
- mysql_real_escape_string(szRaceName, szRaceName);
- while(iRaceID < MAX_RACES)
- {
- if(Race[iRaceID][rID] == -1)
- {
- iRaceID = MAX_RACES - 1;
- break;
- }
- if(!strcmp(szRaceName, Race[iRaceID][rName]))
- {
- break;
- }
- iRaceID++;
- }
- if(iRaceID == MAX_RACES - 1)
- {
- SendClientMessage(playerid, COLOR_RACE_GREY, "This race doesn't exist.");
- return 1;
- }
- while(iCPID < MAX_RACE_CHECKPOINTS)
- {
- if(RaceCheckPoint[iCPID][rcID] == -1)
- {
- break;
- }
- iCPID++;
- }
- if(iCPID == MAX_RACE_CHECKPOINTS)
- {
- SendClientMessage(playerid, COLOR_RACE_RED, "Maxmimum number of checkpoints allowed on the server reached. Contact a developer.");
- return 1;
- }
- GetPlayerPos(playerid, fPos[0], fPos[1], fPos[2]);
- format(szString, sizeof(szString), "INSERT INTO `race_checkpoints` (`raceid`,`x`,`y`,`z`,`type`,`size`) VALUES (%d, '%f', '%f', '%f', %d, '%f')", Race[iRaceID][rID], fPos[0], fPos[1], fPos[2], iCheckType, fSize);
- mysql_query(szString);
- format(szString, sizeof(szString), "%d>%d>%f>%f>%f>%d>%f", mysql_insert_id(), iRaceID, fPos[0], fPos[1], fPos[2], iCheckType, fSize);
- sscanf(szString, "p<>>e<iifffif>", RaceCheckPoint[iCPID]);
- sscanf("Reset, race modified%600000", "p<%>s[" #MAX_PLAYER_NAME "]i", Race[iRaceID][rFastest], Race[iRaceID][rRecord]);
- format(szString, sizeof(szString), "UPDATE `races` SET `fastest`='%s', `record`='%s' WHERE `id`='%d'", Race[iRaceID][rFastest], Race[iRaceID][rRecord], Race[iRaceID][rID]);
- mysql_query(szString);
- LR_LoadRaces();
- format(szString, sizeof(szString), "You have created a checkpoint in the race \"%s\".", szRaceName);
- SendClientMessage(playerid, COLOR_RACE_GREY, szString);
- return 1;
- }
- stock LR_CMD_LOADRACEFORALL(playerid)
- {
- new
- szDialogString[MAX_RACES*(MAX_RACE_NAME+2)];
- for(new i; i < MAX_RACES; i++)
- {
- if(Race[i][rID] == -1)
- break;
- format(szDialogString, sizeof(szDialogString), "%s\n%s", szDialogString, Race[i][rName]);
- }
- if(isnull(szDialogString))
- {
- SendClientMessage(playerid, COLOR_RACE_GREY, "There aren't any races yet.");
- return 1;
- }
- ShowPlayerDialog(playerid, DIALOG_RACES, DIALOG_STYLE_LIST, "Race list", szDialogString, "Load", "Quit");
- return 1;
- }
- stock LR_CMD_LOADRACEFORPLAYER(playerid)
- {
- new
- szDialogString[MAX_RACES*(MAX_RACE_NAME+2)];
- for(new i; i < MAX_RACES && Race[i][rID] != -1; i++)
- {
- format(szDialogString, sizeof(szDialogString), "%s\n%s", szDialogString, Race[i][rName]);
- }
- if(isnull(szDialogString))
- {
- SendClientMessage(playerid, COLOR_RACE_GREY, "There aren't any race yet.");
- return 1;
- }
- ShowPlayerDialog(playerid, DIALOG_RACES2, DIALOG_STYLE_LIST, "Races list", szDialogString, "Load", "Quit");
- return 1;
- }
- stock LR_CMD_JOINRACE(playerid)
- {
- new
- iRaceID,
- iCurrentCP = -1,
- iNextCP;
- if(!GetPVarInt(playerid, "Race"))
- {
- SendClientMessage(playerid, COLOR_RACE_GREY, "No race has been loaded.");
- return 1;
- }
- DeletePVar(playerid, "Checkpoint");
- iRaceID = Race[GetPVarInt(playerid, "Race") - 1][rID];
- while(iNextCP < MAX_RACE_CHECKPOINTS)
- {
- if(RaceCheckPoint[iNextCP][rcRaceID] == iRaceID)
- {
- if(iCurrentCP == -1)
- {
- iCurrentCP = iNextCP;
- }
- else
- {
- break;
- }
- }
- iNextCP++;
- }
- if(iNextCP == MAX_RACE_CHECKPOINTS)
- {
- SendClientMessage(playerid, COLOR_RACE_GREY, "This race doesn't have more than one checkpoint yet.");
- return 1;
- }
- new
- Float: fPos[3];
- GetPlayerPos(playerid, fPos[0], fPos[1], fPos[2]);
- if(IsPlayerInAnyVehicle(playerid))
- {
- SetVehiclePos(GetPlayerVehicleID(playerid), RaceCheckPoint[iCurrentCP][rcX], RaceCheckPoint[iCurrentCP][rcY], RaceCheckPoint[iCurrentCP][rcZ]);
- }
- else
- {
- SetPlayerPos(playerid, RaceCheckPoint[iCurrentCP][rcX], RaceCheckPoint[iCurrentCP][rcY], RaceCheckPoint[iCurrentCP][rcZ]);
- }
- SetPlayerRaceCheckpoint(playerid, RaceCheckPoint[iCurrentCP][rcType], RaceCheckPoint[iCurrentCP][rcX], RaceCheckPoint[iCurrentCP][rcY], RaceCheckPoint[iCurrentCP][rcZ], RaceCheckPoint[iNextCP][rcX], RaceCheckPoint[iNextCP][rcY], RaceCheckPoint[iNextCP][rcZ], RaceCheckPoint[iCurrentCP][rcSize]);
- return 1;
- }
- stock LR_CMD_LEAVERACE(playerid)
- {
- if(!GetPVarInt(playerid, "Racing"))
- {
- SendClientMessage(playerid, COLOR_RACE_GREY, "You are not racing.");
- return 1;
- }
- DeletePVar(playerid, "Checkpoint");
- DeletePVar(playerid, "Racing");
- DeletePVar(playerid, "RaceTimer");
- DisablePlayerRaceCheckpoint(playerid);
- SendClientMessage(playerid, COLOR_RACE_GREEN, "You have left the race.");
- return 1;
- }
- stock LR_CMD_READY(playerid)
- {
- if(!GetPVarInt(playerid, "Race"))
- {
- SendClientMessage(playerid, COLOR_RACE_GREY, "No race has been loaded.");
- return 1;
- }
- if(GetPVarInt(playerid, "Racing"))
- {
- SendClientMessage(playerid, COLOR_RACE_GREY, "You are already racing.");
- return 1;
- }
- if(!IsPlayerInRaceCheckpoint(playerid))
- {
- SendClientMessage(playerid, COLOR_RACE_GREY, "You are not inside the race checkpoint.");
- return 1;
- }
- if(!IsVehicleAllowedInRace(GetVehicleModel(GetPlayerVehicleID(playerid)), GetPVarInt(playerid, "Race") - 1))
- {
- SendClientMessage(playerid, COLOR_RACE_GREY, "This vehicle is not allowed. To show which vehicles are allowed, type \"/racecars\".");
- return 1;
- }
- SetPVarInt(playerid, "Racing", 1);
- SetPVarInt(playerid, "RaceCountdown", 5);
- SetPVarInt(playerid, "RaceCountdownID", SetTimerEx("LR_RaceCountdown", 1000, 1, "d", playerid));
- freeze(playerid, true);
- SetVehicleVelocity(GetPlayerVehicleID(playerid), 0.0, 0.0, 0.0);
- return 1;
- }
- stock LR_CMD_READYALL()
- {
- foreach(Player, i)
- {
- if(!GetPVarInt(i, "Race") || GetPVarInt(i, "Racing") || !IsPlayerInRaceCheckpoint(i) || !IsVehicleAllowedInRace(GetVehicleModel(GetPlayerVehicleID(i)), GetPVarInt(i, "Race") - 1))
- {
- continue;
- }
- SetPVarInt(i, "Racing", 1);
- SetPVarInt(i, "RaceCountdown", 5);
- SetPVarInt(i, "RaceCountdownID", SetTimerEx("LR_RaceCountdown", 1000, 1, "d", i));
- freeze(i, true);
- SetVehicleVelocity(GetPlayerVehicleID(i), 0.0, 0.0, 0.0);
- }
- return 1;
- }
- stock LR_CMD_RACECARS(playerid)
- {
- new
- iRaceID = GetPVarInt(playerid, "Race") - 1,
- a_iAllowedVehicles[10],
- szString[128],
- szVehicleName[20];
- if(iRaceID == -1)
- {
- SendClientMessage(playerid, COLOR_RACE_GREY, "No race has been loaded.");
- return 1;
- }
- sscanf(Race[iRaceID][rVehicles], "p</>A<d>(0)[10]", a_iAllowedVehicles);
- for(new i; i < 10; i++)
- {
- if(!a_iAllowedVehicles[i])
- break;
- GetVehicleName(a_iAllowedVehicles[i], szVehicleName, sizeof(szVehicleName));
- if(i == 0)
- format(szString, sizeof(szString), "Allowed vehicle(s): %s", szVehicleName);
- else if(i == 5)
- {
- SendClientMessage(playerid, COLOR_RACE_GREY, szString);
- format(szString, sizeof(szString), "Additional vehicle(s): %s", szVehicleName);
- }
- else
- format(szString, sizeof(szString), "%s, %s", szString, szVehicleName);
- }
- SendClientMessage(playerid, COLOR_RACE_GREY, szString);
- return 1;
- }
- #undef MAX_PLAYER_NAME
- #define MAX_PLAYER_NAME MAX_PLAYER_NAME2
- #undef MAX_PLAYER_NAME2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement