27.02.2017, 17:11
Yesterday i followed this tutorial to make a Dynamic Race: https://sampforum.blast.hk/showthread.php?tid=401252
The problem is that, i'll make a quick example: Me and another player are racing against, i'm first and the other guy is the last, he decides to leave the race by using the command /leaverace but when he uses that command and i finish the race i get the second position instead of getting the first.
Here's the script
The problem is that, i'll make a quick example: Me and another player are racing against, i'm first and the other guy is the last, he decides to leave the race by using the command /leaverace but when he uses that command and i finish the race i get the second position instead of getting the first.
Here's the script
Код:
stock LeaveRace(playerid, raceid) { RaceCheckpoint[playerid] = -1; //Race checkpoint reset InRace[playerid] = -1; //Player is put out of the race DisablePlayerRaceCheckpoint(playerid); DisableRemoteVehicleCollisions(playerid,0); //Players checkpoint is disabled. if(IsPlayerInAnyVehicle(playerid)) //If the player was in a car { new vehicleid = GetPlayerVehicleID(playerid); //We fetch the players vehicle ID SetVehicleVirtualWorld(vehicleid, 0); //We reset the vehicles virtual world to 0 SetPlayerVirtualWorld(playerid, 0); //Sets the player to virtual world 0 too PutPlayerInVehicle(playerid, vehicleid, 0); //We put the player in the vehicle just in case } else { SetPlayerVirtualWorld(playerid, 0); //If the player was on foot we just put him back to virtual //world 0. } if(RaceInfo[raceid][racerunning] == true) //If the race has actually started rather than just a player waiting for the //race to start leaving the race. { RaceInfo[raceid][racecount]--; //RaceInfo[raceid][originalcount]--;//Credo che sia questo il bug //RaceInfo[raceid][originalcount]--; BISOGNA TESTARE PIU' COSE //removes a player from the racecount. if(RaceInfo[raceid][racecount] == 0) StopRace(raceid); //If there is nobody in the race after this person leaves then we have to //stop the race from running. } return 1; }
Код:
if(InRace[playerid] != -1) //This just makes sure the player is actually in a race. You may be using //race checkpoints for something else as well as this race system. { if(RaceCheckpoint[playerid] > 0) //RaceCheckpoint[playerid] = 0 is if the player is in a race but at //the starting checkpoint rather than actually racing. We check if the //player is at a checkpoint further than CP 1. { new raceid = InRace[playerid], checkpoint = RaceCheckpoint[playerid]; //Above variables just makes it easier for us to use and understand //the code. We put the raceid that the player is in into the raceid //variable... YAY :). We also put the checkpoint id into the //checkpoint variable ;). if(checkpoint == RaceInfo[raceid][cpnum]) //If we have the same checkpoint value as the race checkpoints before //we add one to our race checkpoint variable then we have gone through //the finishing checkpoint which means we should initiate the finish //race code and stop it there with a return 1; { //Player leaves the race. new str[128], playername[24]; //creates the variables for the string we will format and the //variable to hold the players name. format(str, sizeof(str), "~w~Gara Terminata~n~~g~Posizione %d/%d - ~b~Tempo: %s", (RaceInfo[raceid][originalcount] - (RaceInfo[raceid][racecount] - 1)), RaceInfo[raceid][originalcount], ReturnTime(RaceInfo[raceid][racetime])); //Formats the string that will be sent to the player in a gametext. //(RaceInfo[raceid][originalcount] - (RaceInfo[raceid][racecount] - 1)) //Starts at the original count minus the players in the race //minus the player himself (-1). GameTextForPlayer(playerid, str, 3000, 3); //Sends the player an on screen text of that formatted text above GetPlayerName(playerid, playername, sizeof(playername)); TextDrawHideForPlayer(playerid,TDEditor_PTD[playerid]); //Gets the players name for the message that will be sent to everyone format(str, sizeof(str), "[GARA TERMINATA] %s (ID: %d) ha terminato la gara %s (ID: %d) in %s nella posizione %d/%d", playername, playerid, RaceInfo[raceid][racename], raceid, ReturnTime(RaceInfo[raceid][racetime]), (RaceInfo[raceid][originalcount] - (RaceInfo[raceid][racecount]-1)), RaceInfo[raceid][originalcount]); //Formats a message for everyone with the players race results //which include his name, id, race name, raceid, time, and //position. if(RaceInfo[raceid][originalcount] - (RaceInfo[raceid][racecount]-1) == 1) { if(IsPlayerAnyClanMember(playerid)) { new CQuery[200]; //------------------------------------------------------------------ new stringnome[256]; new nomest[128]; GetPlayerName(playerid,nomest,128); format(stringnome,sizeof(stringnome),"Grazie alla vittoria nella Gara di {00FF22}%s{00CED1} il Clan {FFFFFF}%s{00CED1} guadagna 1 Punto!",nomest,GetPlayerClan(playerid)); SendClientMessageToAll(Lightblue,stringnome); format(CQuery, 200, "UPDATE `clans` SET `clankills` = '%d' WHERE `clanname` = '%s'", GetClanKills(GetPlayerClan(playerid)) + 1, GetPlayerClan(playerid)); db_query(Database, CQuery); //------------------------------------------------------------------ } PlayerInfo[playerid][pExp]++; SendClientMessage(playerid,Lightblue,"Per essere arrivato nella prima posizione hai guadagnato 15000$ e 1 Punto Esperienza!"); GivePlayerMoney(playerid,15000); if(PlayerInfo[playerid][pExp] >= 20) { PlayerInfo[playerid][pExp] = 0; PlayerInfo[playerid][pLevel]++; new stringzul[256]; new level = PlayerInfo[playerid][pLevel]; format(stringzul, sizeof(stringzul),"[Level-UP]: {00FF22}Complimenti! Sei salito al Livello: %d", level); SendClientMessage(playerid,White,stringzul); } } SendClientMessageToAll(0xFF00AA, str); //sends everyone the formatted string. LeaveRace(playerid, InRace[playerid]); return 1; }