Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <zcmd>
- #include <dini>
- #include <sscanf2>
- //=====[Internal Settings]=====
- #define MINMONEY 0 //Minimum duel bet money - Useful for A/D servers. Set to 0 for A/D
- #define MAX_DUELS 40 //Max duel maps.
- #define MAX_DUEL_WEPS 3
- #define MAX_INVITES 14
- #define MAX_ROUNDS 10
- #define INVITERESET 60000 //Total time until an invite is considered denied
- #define Money_GivePlayerMoney GivePlayerMoney //Replace with your own money functions if you have a money anticheat
- #define Money_GetPlayerMoney GetPlayerMoney
- #define DUELFILES "/Duels/%d.ini" //Set your own directory for the duel system.. Change DUEL_IDFILE too.
- #define DUEL_IDFILE "/Duels/idset.ini"
- #define SPEC_UPDATE 1000
- #define DUELDIAG 6550
- //=============================
- #define COLOR_RED 0xFF0000
- #define COLOR_DUEL 0xFFFF00FF
- //String Color
- #define G> 009900 //Green
- #define R> CC0000 //Red
- #define B> 0004B6 //Blue
- #define LB> 00EFFC //Light Blue
- #define O> FFD700 //Orange
- #define Y> FFD700 //Yellow
- #define W> FFFFFF //White
- #define BV> 8A2BE2 //Blue Violet
- new DuelTimer[MAX_PLAYERS];
- new UpdateSpecTimer[MAX_PLAYERS];
- new prounds[MAX_PLAYERS];
- forward DuelReset(player1, player2);
- forward DuelCDUpdate(playerid);
- forward UpdateSpectate(playerid);
- new dFile[70];
- new diagstr[900];
- new Text:SpecTD[MAX_PLAYERS][2];
- new diagitem[25];
- new dinvitem[MAX_PLAYERS][MAX_INVITES];
- new InDuel[MAX_PLAYERS];
- enum duels
- {
- Inviter,
- Invitee,
- BetMoney,
- Location,
- Started,
- CRounds,
- Rounds
- }
- new dInfo[MAX_DUELS][duels];
- new dWeps[MAX_DUELS][MAX_DUEL_WEPS];
- new TotalDuels; //Total duels in progress
- public OnFilterScriptInit()
- {
- SendClientMessageToAll(COLOR_DUEL, "Duel System v1.6");
- for(new x=0; x<MAX_INVITES; x++) ResetDuelInvites(x);
- return 1;
- }
- public OnFilterScriptExit()
- {
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- LoadDuelSpecTextdraw(playerid);
- ResetDuelInvites(playerid);
- SetPVarInt(playerid, "DuelDID", -1);
- InDuel[playerid] = 0;
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- new duelid = GetPVarInt(playerid, "DuelDID");
- new dueler, dueler2;
- dueler = dInfo[duelid][Inviter];
- dueler2 = dInfo[duelid][Invitee];
- if(InDuel[dueler] == 1 && InDuel[dueler2] == 1)
- {
- new sReason[15];
- switch(reason)
- {
- case 0: format(sReason, sizeof(sReason), "Timeout");
- case 1: format(sReason, sizeof(sReason), "Leaving");
- case 2: format(sReason, sizeof(sReason), "Kicked");
- }
- new gBet = dInfo[duelid][BetMoney];
- new gDuelSpot = dInfo[duelid][Location];
- new Slot[MAX_DUEL_WEPS];
- for(new i=0; i < MAX_DUEL_WEPS; i++) Slot[i] = dWeps[duelid][i];
- new winner, loser;
- if(dueler == playerid)
- {
- winner = dueler2;
- loser = dueler;
- }
- else if(dueler2 == playerid)
- {
- winner = dueler;
- loser = dueler2;
- }
- Money_GivePlayerMoney(winner, gBet);
- new wepstr[200];
- for(new x=0; x < MAX_DUEL_WEPS; x++)
- {
- if(IsValidWeapon(Slot[x])) format(wepstr, sizeof(wepstr), "%s%s ", wepstr, weaponNames(Slot[x]));
- }
- new str[150];
- format(str, sizeof(str), "Duel | %s has left the server during a duel with %s (Reason: %s)", pName(loser), pName(winner), sReason);
- SendClientMessageToAll(COLOR_DUEL, str);
- format(str, sizeof(str), "Duel | %s won the duel against %s %d - %d (Weapons %s) (Bet: $%d) (%s [ID %d])", pName(winner), pName(loser), prounds[winner], prounds[loser], wepstr, gBet, ReturnDuelNameFromID(gDuelSpot), gDuelSpot);
- SendClientMessageToAll(COLOR_DUEL, str);
- prounds[loser] = 0;
- prounds[winner] = 0;
- dInfo[duelid][Rounds] = 0;
- dInfo[duelid][CRounds] = 0;
- SetPlayerArmour(winner, 0);
- RemoveFromDuel(loser);
- RemoveFromDuel(winner);
- ResetDuelInformation(duelid);
- RemoveDuelInvite(dueler2, dueler);
- SpawnPlayer(winner);
- SetPlayerVirtualWorld(winner, 0);
- TotalDuels--;
- }
- TextDrawDestroy(SpecTD[playerid][0]);
- TextDrawDestroy(SpecTD[playerid][1]);
- InDuel[playerid] = 0;
- KillTimer(DuelTimer[playerid]);
- return 1;
- }
- public OnPlayerDeath(playerid, killerid, reason)
- {
- new duelid = GetPVarInt(killerid, "DuelDID");
- new dueler, dueler2;
- dueler = dInfo[duelid][Inviter];
- dueler2 = dInfo[duelid][Invitee];
- if(dInfo[duelid][Rounds] != dInfo[duelid][CRounds])
- {
- new winner, loser;
- if(dueler == playerid)
- {
- winner = dueler2;
- loser = dueler;
- }
- else if(dueler2 == playerid)
- {
- winner = dueler;
- loser = dueler2;
- }
- prounds[winner]++;
- dInfo[duelid][CRounds]++;
- new str[150];
- format(str, sizeof(str), "Duel | %s has smashed %s during duel in last round (%d - %d)", pName(winner), pName(loser), prounds[winner], prounds[loser]);
- SendClientMessageToAll(COLOR_RED, str);
- new Interior = dini_Int(dFile, "duelInt");
- new Float:X, Float:Y, Float:Z, Float:A;
- X = dini_Float(dFile, "duelX");
- Y = dini_Float(dFile, "duelY");
- Z = dini_Float(dFile, "duelZ");
- A = dini_Float(dFile, "duelA");
- new Float:X2, Float:Y2, Float:Z2, Float:A2;
- X2 = dini_Float(dFile, "duel2X");
- Y2 = dini_Float(dFile, "duel2Y");
- Z2 = dini_Float(dFile, "duel2Z");
- A2 = dini_Float(dFile, "duelA2");
- new Slot[3];
- Slot[0] = dWeps[duelid][0];
- Slot[1] = dWeps[duelid][1];
- Slot[2] = dWeps[duelid][2];
- new world = playerid;
- if(winner > playerid && playerid != winner) world = winner+1;
- else if(playerid > loser && playerid != loser) world = playerid+1;
- AddToDuel(loser, X2, Y2, Z2, A2, Interior, world, Slot[0], Slot[1], Slot[2]);
- AddToDuel(winner, X, Y, Z, A, Interior, world, Slot[0], Slot[1], Slot[2]);
- return 1;
- }
- if(InDuel[dueler] == 1 && InDuel[dueler2] == 1)
- {
- new gBet = dInfo[duelid][BetMoney];
- new gDuelSpot = dInfo[duelid][Location];
- new Slot[MAX_DUEL_WEPS];
- for(new i=0; i < MAX_DUEL_WEPS; i++) Slot[i] = dWeps[duelid][i];
- new winner, loser;
- if(dueler == playerid)
- {
- winner = dueler2;
- loser = dueler;
- }
- else if(dueler2 == playerid)
- {
- winner = dueler;
- loser = dueler2;
- }
- Money_GivePlayerMoney(winner, gBet);
- Money_GivePlayerMoney(loser, -gBet);
- new wepstr[200];
- for(new x=0; x < MAX_DUEL_WEPS; x++)
- {
- if(IsValidWeapon(Slot[x])) format(wepstr, sizeof(wepstr), "%s%s ", wepstr, weaponNames(Slot[x]));
- }
- new str[230], duelloc[40];
- new HPT = GetRoundedTotalHP(playerid);
- format(duelloc, sizeof(duelloc), "%s", ReturnDuelNameFromID(gDuelSpot));
- format(str, sizeof(str), "Duel | %s won the duel against %s (%d - %d) {0004B6}(HP %d) (Weapons %s) {009900}(Bet: $%d) {F8FF3D}(%s [ID %d])", pName(killerid), pName(playerid), prounds[winner], prounds[loser], HPT, wepstr, gBet, duelloc, gDuelSpot);
- SendClientMessageToAll(COLOR_RED, str);
- SetPlayerArmour(playerid, 0);
- SetPlayerArmour(killerid, 0);
- RemoveFromDuel(playerid);
- RemoveFromDuel(killerid);
- ResetDuelInformation(duelid);
- SpawnPlayer(killerid);
- TotalDuels--;
- RemoveDuelInvite(dueler2, dueler);
- }
- else if(killerid == INVALID_PLAYER_ID && InDuel[playerid] == 1)
- {
- new gBet = dInfo[duelid][BetMoney];
- new gDuelSpot = dInfo[duelid][Location];
- new Slot[MAX_DUEL_WEPS];
- for(new i=0; i < MAX_DUEL_WEPS; i++) Slot[i] = dWeps[duelid][i];
- Money_GivePlayerMoney(playerid, -gBet);
- Money_GivePlayerMoney(killerid, gBet);
- new winner, loser;
- if(dueler == playerid)
- {
- winner = dueler2;
- loser = dueler;
- }
- else if(dueler2 == playerid)
- {
- winner = dueler;
- loser = dueler2;
- }
- new wepstr[200];
- for(new x=0; x < MAX_DUEL_WEPS; x++)
- {
- if(IsValidWeapon(Slot[x])) format(wepstr, sizeof(wepstr), "%s%s ", wepstr, weaponNames(Slot[x]));
- }
- new str[220];
- format(str, sizeof(str), "Duel | %s commited suicide during a duel with %s {0004B6}(Weapons %s) {009900}(Bet: $%d) {F8FF3D}(%s [ID %d])", pName(loser), pName(winner), wepstr, gBet, ReturnDuelNameFromID(gDuelSpot), gDuelSpot);
- SendClientMessageToAll(COLOR_DUEL, str);
- SetPlayerArmour(winner, 0);
- SetPlayerArmour(loser, 0);
- RemoveDuelInvite(dueler2, dueler);
- RemoveFromDuel(winner);
- RemoveFromDuel(loser);
- ResetDuelInformation(duelid);
- SpawnPlayer(winner);
- SetPlayerVirtualWorld(winner, 0);
- TotalDuels--;
- }
- return 1;
- }
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- if(newkeys == KEY_FIRE)
- {
- new specid = GetPVarInt(playerid, "DuelSpecID");
- if(GetPVarInt(playerid, "DuelSpec") && IsPlayerInDuel(specid))
- {
- SetPlayerSpectatingDuel(playerid, GetDuelerID(specid));
- }
- }
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if(dialogid == DUELDIAG)
- {
- if(response)
- {
- switch(listitem)
- {
- case 0: //Choose player
- {
- ShowPlayerDialog(playerid, DUELDIAG+1, DIALOG_STYLE_INPUT, "Duel - Select a player", "{"#BV>"}Type in the playername or ID of the player you want\nto invite to a duel.\n\n{"#B>"}NOTE: You can enter partial names.", "Invite", "Back");
- }
- case 1: //Choose Duel location
- {
- format(diagstr, sizeof(diagstr), "ID\tDuel Name\n");
- for(new x=0; x<MAX_DUELS; x++)
- {
- format(dFile, sizeof(dFile), DUELFILES, x);
- if(strlen(dini_Get(dFile, "duelName")) > 0) format(diagstr, sizeof(diagstr), "%s%d\t%s\n", diagstr, x, dini_Get(dFile, "duelName"));
- else format(diagstr, sizeof(diagstr), "%s%d\tEmpty Slot\n", diagstr, x);
- }
- ShowPlayerDialog(playerid, DUELDIAG+2, DIALOG_STYLE_LIST, "Duel List", diagstr, "Select", "Exit");
- return 1;
- }
- case 2: //Choose weapons
- {
- ShowPlayerDialog(playerid, DUELDIAG+5, DIALOG_STYLE_LIST, "Select Weapon Slot", "Slot 1\nSlot 2\nSlot 3", "Select", "Back");
- }
- case 3: //Choose Duel Money
- {
- ShowPlayerDialog(playerid, DUELDIAG+4, DIALOG_STYLE_INPUT, "Set Bet Amount", "{"#B>"}NOTE: {"#W>"}Set the bet amount for the duel.\n\n{"#G>"}The winner takes the money and the loser\nloses this amount of money.", "Set", "Back");
- }
- case DUELDIAG+10: //Choose Rounds
- {
- ShowPlayerDialog(playerid, DUELDIAG+9, DIALOG_STYLE_INPUT, "Duel Rounds", "{"#B>"}NOTE: {"#W>"}Set the Rounds amount for the duel.\n\n{"#G>"}Max is 10.", "Select", "Back");
- }
- case 4: //Send invitation
- {
- new str[80];
- new dPID = GetPVarInt(playerid, "dPID");
- new dBet = GetPVarInt(playerid, "dBet");
- new dLoc = GetPVarInt(playerid, "dLoc");
- new rounds = GetPVarInt(playerid, "drounds");
- new dWep[3], key[7];
- for(new x=0; x<=2; x++)
- {
- format(key, sizeof(key), "dWep%d", x);
- dWep[x] = GetPVarInt(playerid, key);
- }
- format(str, sizeof(str), "invite %d %d %d %d %d %d", dPID, dBet, dLoc, dWep[0], dWep[1], dWep[2], rounds);
- return cmd_duel(playerid, str);
- }
- case 5: //Cancel invitation
- {
- return SendClientMessage(playerid, COLOR_DUEL, "Duel invite was canceled, duel settings were saved.");
- }
- }
- }
- }
- if(dialogid == DUELDIAG+1)
- {
- if(response)
- {
- new invitee;
- if(sscanf(inputtext, "u", invitee)) return ShowPlayerDialog(playerid, DUELDIAG+1, DIALOG_STYLE_INPUT, "Duel - Select a player", "{"#BV>"}Type in the playername or ID of the player you want\nto invite to a duel.\n\n{"#B>"}NOTE: You can enter partial names.", "Invite", "Back");
- if(invitee == playerid) return ShowPlayerDialog(playerid, DUELDIAG+1, DIALOG_STYLE_INPUT, "Duel - Select a player", "{"#R>"}ERROR: You cannot invite yourself to a duel!\n\n{"#BV>"}Type in the playername or ID of the player you want\nto invite to a duel.\n\n{"#B>"}NOTE: You can enter partial names.", "Invite", "Back");
- if(invitee == INVALID_PLAYER_ID || !IsPlayerConnected(invitee)) return ShowPlayerDialog(playerid, DUELDIAG+1, DIALOG_STYLE_INPUT, "Duel - Select a player", "{"#R>"}ERROR: The player specified is not connected, try again!\n\n{"#BV>"}Type in the playername or ID of the player you want\nto invite to a duel.\n\n{"#B>"}NOTE: You can enter partial names.", "Invite", "Back");
- SetPVarInt(playerid, "dPID", invitee);
- ShowDuelSettingsDialog(playerid);
- }
- else ShowDuelSettingsDialog(playerid);
- }
- if(dialogid == DUELDIAG+2)
- {
- if(response)
- {
- format(dFile, sizeof(dFile), DUELFILES, listitem-1);
- if(!dini_Exists(dFile)) return OnDialogResponse(playerid, DUELDIAG, 1, 1, "blank");
- SetPVarInt(playerid, "dLoc", listitem-1);
- ShowDuelSettingsDialog(playerid);
- }
- else ShowDuelSettingsDialog(playerid);
- }
- if(dialogid == DUELDIAG+4) //Duel money
- {
- if(response)
- {
- new amount;
- if(sscanf(inputtext, "d", amount)) return ShowPlayerDialog(playerid, DUELDIAG+4, DIALOG_STYLE_INPUT, "Set Bet Amount", "Enter the bet amount for the duel.\nThe winner takes the money and the loser\nloses this amount of money.", "Set", "Back");
- if(MINMONEY != 0 && amount < 500) return ShowPlayerDialog(playerid, DUELDIAG+4, DIALOG_STYLE_INPUT, "Set Bet Amount", "ERROR: Bet amount must be higher then $500!\nSet the bet amount for the duel.\nThe winner takes the money and the loser\nloses this amount of money.", "Set", "Back");
- SetPVarInt(playerid, "dBet", amount);
- ShowDuelSettingsDialog(playerid);
- }
- else ShowDuelSettingsDialog(playerid);
- }
- if(dialogid == DUELDIAG+5) //Weapon slots
- {
- if(response)
- {
- SetPVarInt(playerid, "dWSlot", listitem);
- ShowPlayerDialog(playerid, DUELDIAG+6, DIALOG_STYLE_LIST, "Choose a weapon", "Brass Knuckles\nGolf Club\nNite Stick\nKnife\nBaseball Bat\nShovel\nPool Cue\nKatana\nChainsaw\nDildo\nVibrator\nFlowers\nCane\nGrenade\nTeargas\nMolotov\nColt 45\nSilenced Pistol\nDeagle\nShotgun\nSawns\nSpas\nUzi\nMP5\nAK47\nM4\nTec9\nRifle\nSniper", "Select", "Back");
- }
- else ShowDuelSettingsDialog(playerid);
- }
- if(dialogid == DUELDIAG+6)
- {
- if(response)
- {
- new key[7];
- format(key, sizeof(key), "dWep%d", GetPVarInt(playerid, "dWSlot"));
- switch(listitem)
- {
- case 13..15:
- {
- ShowPlayerDialog(playerid, DUELDIAG+6, DIALOG_STYLE_LIST, "Choose a weapon", "Brass Knuckles\nGolf Club\nNite Stick\nKnife\nBaseball Bat\nShovel\nPool Cue\nKatana\nChainsaw\nDildo\nVibrator\nFlowers\nCane\nGrenade\nTeargas\nMolotov\nColt 45\nSilenced Pistol\nDeagle\nShotgun\nSawns\nSpas\nUzi\nMP5\nAK47\nM4\nTec9\nRifle\nSniper", "Select", "Back");
- return SendClientMessage(playerid, COLOR_RED, "ERROR: This weapon is disabled!");
- }
- }
- switch(listitem)
- {
- case 0: SetPVarInt(playerid, key, 1);
- case 1: SetPVarInt(playerid, key, 2);
- case 2: SetPVarInt(playerid, key, 3);
- case 3: SetPVarInt(playerid, key, 4);
- case 4: SetPVarInt(playerid, key, 5);
- case 5: SetPVarInt(playerid, key, 6);
- case 6: SetPVarInt(playerid, key, 7);
- case 7: SetPVarInt(playerid, key, 8);
- case 8: SetPVarInt(playerid, key, 9);
- case 9: SetPVarInt(playerid, key, 10);
- case 10: SetPVarInt(playerid, key, 11);
- case 11: SetPVarInt(playerid, key, 14);
- case 12: SetPVarInt(playerid, key, 15);
- case 13: SetPVarInt(playerid, key, 16);
- case 14: SetPVarInt(playerid, key, 17);
- case 15: SetPVarInt(playerid, key, 18);
- case 16: SetPVarInt(playerid, key, 22);
- case 17: SetPVarInt(playerid, key, 23);
- case 18: SetPVarInt(playerid, key, 24);
- case 19: SetPVarInt(playerid, key, 25);
- case 20: SetPVarInt(playerid, key, 26);
- case 21: SetPVarInt(playerid, key, 27);
- case 22: SetPVarInt(playerid, key, 28);
- case 23: SetPVarInt(playerid, key, 29);
- case 24: SetPVarInt(playerid, key, 30);
- case 25: SetPVarInt(playerid, key, 31);
- case 26: SetPVarInt(playerid, key, 32);
- case 27: SetPVarInt(playerid, key, 33);
- case 28: SetPVarInt(playerid, key, 34);
- }
- ShowDuelSettingsDialog(playerid);
- }
- else ShowDuelSettingsDialog(playerid);
- }
- if(dialogid == DUELDIAG+7)
- {
- if(response)
- {
- if(!IsPlayerInDuel(diagitem[listitem])) return 1;
- SetPlayerSpectatingDuel(playerid, diagitem[listitem]);
- }
- else return 1;
- }
- if(dialogid == DUELDIAG+8)
- {
- if(response)
- {
- if(listitem > MAX_INVITES) return 1;
- new dueler = dinvitem[playerid][listitem];
- if(!IsPlayerConnected(dueler)) return ShowPlayerDialog(playerid, DUELDIAG-1, DIALOG_STYLE_MSGBOX, "Duel Invites", "ERROR: This player is no longer connected!", "Ok", "");
- SetPVarInt(playerid, "DuelDID", listitem);
- AcceptDuel(playerid);
- return 1;
- }
- }
- if(dialogid == DUELDIAG+9) //Duel rounds
- {
- if(response)
- {
- new amount;
- if(sscanf(inputtext, "d", amount)) return ShowPlayerDialog(playerid, DUELDIAG+9, DIALOG_STYLE_INPUT, "Duel Rounds", "{"#B>"}NOTE: {"#W>"}Set the Rounds amount for the duel.\n\n{"#G>"}Max is 10.", "Select", "Back");
- if(amount < 0 || amount > 10) return ShowPlayerDialog(playerid, DUELDIAG+4, DIALOG_STYLE_INPUT, "Duel Rounds", "ERROR: Bet amount must be higher then 0 and less than 10!", "Set", "Back");
- SetPVarInt(playerid, "drounds", amount);
- ShowDuelSettingsDialog(playerid);
- }
- else ShowDuelSettingsDialog(playerid);
- }
- return 0;
- }
- CMD:dreset(playerid, params[])
- {
- if(!IsPlayerAdmin(playerid)) return 1;
- for(new x=0; x<MAX_PLAYERS; x++)
- {
- if(!IsPlayerConnected(x)) continue;
- if(InDuel[x] == 1)
- {
- InDuel[x] = 0;
- SpawnPlayer(x);
- }
- }
- SendClientMessageToAll(COLOR_DUEL, "The duel system has been reset!");
- return 1;
- }
- CMD:dinvites(playerid, params[])
- {
- ShowDuelInvitesDialog(playerid);
- return 1;
- }
- CMD:daccept(playerid, params[])
- {
- new listitem;
- if(sscanf(params, "d", listitem)) return SendClientMessage(playerid, COLOR_RED, "ERROR: This duel invite is not valid!");
- if(listitem > MAX_INVITES) return 1;
- new dueler = dinvitem[playerid][listitem];
- if(!IsPlayerConnected(dueler)) return ShowPlayerDialog(playerid, DUELDIAG-1, DIALOG_STYLE_MSGBOX, "Duel Invites", "ERROR: This player is no longer connected!", "Ok", "");
- SetPVarInt(playerid, "DuelDID", listitem);
- AcceptDuel(playerid);
- return 1;
- }
- CMD:duelmenu(playerid, params[])
- {
- ShowDuelSettingsDialog(playerid);
- return 1;
- }
- CMD:duels(playerid, params[])
- {
- format(diagstr, sizeof(diagstr), "");
- for(new x=0; x<MAX_PLAYERS; x++)
- {
- for(new i=0; i<sizeof(diagitem); i++) if(x == diagitem[i]) continue; //Prevent duplicate duels
- if(InDuel[x] == 1)
- {
- new dueler = GetDuelerID(x);
- format(diagstr, sizeof(diagstr), "%s%s vs %s\n", diagstr, pName(x), pName(dueler));
- diagitem[TotalDuels] = x;
- }
- }
- if(TotalDuels < 1) format(diagstr, sizeof(diagstr), "There are currently no duels.");
- ShowPlayerDialog(playerid, DUELDIAG+7, DIALOG_STYLE_LIST, "Current Duels", diagstr, "Select", "Cancel");
- return 1;
- }
- CMD:dspecoff(playerid, params[])
- {
- if(GetPVarInt(playerid, "DuelSpec") == 0) return SendClientMessage(playerid, COLOR_RED, "ERROR: You are not spectating any duels!");
- EndDuelSpectate(playerid);
- return 1;
- }
- CMD:duel(playerid, params[])
- {
- if(strfind(params, "create", true) != -1)
- {
- new third[60];
- sscanf(params[7], "s[60]", third);
- if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "You are not an admin!");
- if(GetPVarInt(playerid, "DuelEdit") == 1) return SendClientMessage(playerid, COLOR_RED, "You are already editing a duel!");
- new dName[90];
- if(unformat(third, "s[90]", dName)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /duel <create> <duelname>");
- else if(!strlen(dName)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /duel <create> <duelname>");
- else if(DuelNameExists(dName)) return SendClientMessage(playerid, COLOR_RED, "This duel name already exists");
- new getid = GetLowestDuelSlotID();
- format(dFile, sizeof(dFile), DUELFILES, getid);
- new Float:X, Float:Y, Float:Z, Float:A;
- GetPlayerPos(playerid, X, Y, Z);
- GetPlayerFacingAngle(playerid, A);
- new dInterior = GetPlayerInterior(playerid);
- dini_Create(dFile);
- dini_IntSet(dFile, "duelID", getid);
- dini_Set(dFile, "duelName", dName);
- dini_FloatSet(dFile, "duelX", X);
- dini_FloatSet(dFile, "duelY", Y);
- dini_FloatSet(dFile, "duelZ", Z);
- dini_FloatSet(dFile, "duelA", A);
- dini_IntSet(dFile, "duelInt", dInterior);
- SetPVarInt(playerid, "DuelEdit", 1);
- SetPVarInt(playerid, "DuelID", getid);
- new str[200];
- format(str, sizeof(str), "Duel \"%s\" (ID: %d) created at: %f, %f, %f (Interior: %d)", dName, getid, X, Y, Z, dInterior);
- SendClientMessage(playerid, COLOR_DUEL, str);
- SendClientMessage(playerid, COLOR_DUEL, "Now go the second duelist position and type \"/duel <save>\" to set the position.");
- return 1;
- }
- if(strfind(params, "save", true) != -1)
- {
- if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "You are not an admin!");
- if(GetPVarInt(playerid, "DuelEdit") == 0) return SendClientMessage(playerid, COLOR_RED, "You are not editing a duel.");
- new duelID = GetPVarInt(playerid, "DuelID");
- format(dFile, sizeof(dFile), DUELFILES, duelID);
- new Float:X, Float:Y, Float:Z, Float:A;
- GetPlayerPos(playerid, X, Y, Z);
- GetPlayerFacingAngle(playerid, A);
- dini_FloatSet(dFile, "duel2X", X);
- dini_FloatSet(dFile, "duel2Y", Y);
- dini_FloatSet(dFile, "duel2Z", Z);
- dini_FloatSet(dFile, "duel2A", A);
- new str[180];
- format(str, sizeof(str), "Duel \"%s\" (ID: %d) second position set at: %f, %f, %f", ReturnDuelNameFromID(duelID), duelID, X, Y, Z);
- SendClientMessage(playerid, COLOR_DUEL, str);
- SetPVarInt(playerid, "DuelEdit", 0);
- SetPVarInt(playerid, "DuelID", -1);
- return 1;
- }
- if(strfind(params, "invite", true) != -1)
- {
- new third[60];
- sscanf(params[7], "s[60]", third);
- new target, gBet, gDuelSpot[85], gWeap[85], gWeap2[85], gWeap3[85], rounds;
- sscanf(third, "uis[85]s[85]s[85]s[85]i", target, gBet, gDuelSpot, gWeap, gWeap2, gWeap3, rounds);
- if(target == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "Duel | Player not found");
- if(target == playerid) return SendClientMessage(playerid, COLOR_RED, "Duel | You can't invite yourself noob!");
- if(InDuel[playerid] == 1) return SendClientMessage(playerid, COLOR_DUEL, "Duel | You are already in a duel!");
- if(MINMONEY != 0 && gBet < 500) return SendClientMessage(playerid, COLOR_RED, "Duel | Minimum bet amount is 500");
- if(MINMONEY != 0 && Money_GetPlayerMoney(playerid) < gBet) return SendClientMessage(playerid, COLOR_RED, "Duel | You don't have that amount of money to bet");
- if(MINMONEY != 0 && Money_GetPlayerMoney(target) < gBet) return SendClientMessage(playerid, COLOR_RED, "Duel | This player does not have that amount of money!");
- if(ReturnDuelIDOrName(gDuelSpot) == -1) return SendClientMessage(playerid, COLOR_RED, "The duel id/name you entered does not exist!");
- if(ReturnWeaponIDOrName(gWeap) == -1) return SendClientMessage(playerid, COLOR_RED, "Slot 1: Invalid Weapon ID or Name");
- if(rounds < 0 || rounds > 10) return SendClientMessage(playerid, COLOR_RED, "Slot 1: rounds must be highter than 0 and less than 10");
- if(GetPlayerState(target) == 9) return SendClientMessage(playerid, COLOR_RED, "Duel | This player is in spectate mode!");
- if(!strlen(gWeap2)) format(gWeap2, sizeof(gWeap2), "48");
- if(!strlen(gWeap3)) format(gWeap3, sizeof(gWeap3), "48");
- new duelloc = ReturnDuelIDOrName(gDuelSpot);
- new duelid = GetLowestUnusedDuelID();
- dInfo[duelid][Inviter] = playerid;
- dInfo[duelid][Invitee] = target;
- dInfo[duelid][BetMoney] = gBet;
- dInfo[duelid][Rounds] = rounds;
- dInfo[duelid][CRounds] = 0;
- dInfo[duelid][Location] = duelloc;
- new Slot[3];
- Slot[0] = ReturnWeaponIDOrName(gWeap);
- Slot[1] = ReturnWeaponIDOrName(gWeap2);
- Slot[2] = ReturnWeaponIDOrName(gWeap3);
- dWeps[duelid][0] = Slot[0];
- dWeps[duelid][1] = Slot[1];
- dWeps[duelid][2] = Slot[2];
- new invid = GetLowestUnusedDuelSlot(target);
- dinvitem[target][invid] = playerid;
- SetTimerEx("DuelReset", INVITERESET, 0, "ii", playerid, target);
- new str[200];
- format(str, sizeof(str), "Duel invite from %s | (Bet: $%d) (Weapons: %s %s %s) (%s [ID %d])", pName(playerid), gBet, weaponNames(Slot[0]), weaponNames(Slot[1]), weaponNames(Slot[2]), ReturnDuelNameFromID(duelloc), duelloc);
- SendClientMessage(target, COLOR_DUEL, str);
- SendClientMessage(target, COLOR_DUEL, "You can accept the invite from the duel invites menu. (Tip: Use /dinvites or /daccept <duelid>)");
- format(str, sizeof(str), "Duel | Waiting for %s's response to your duel invite", pName(target));
- SendClientMessage(playerid, COLOR_DUEL, str);
- return 1;
- }
- if(strfind(params, "edit", true) != -1)
- {
- new third[60];
- sscanf(params[5], "s[60]", third);
- if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "You are not an admin!");
- if(GetPVarInt(playerid, "DuelEdit") == 1) return SendClientMessage(playerid, COLOR_RED, "You are already editing a duel!");
- new dName[90];
- if(unformat(third, "s[90]", dName)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /duel <edit> <duelid/name>");
- else if(!strlen(dName)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /duel <edit> <duelid/name>");
- else if(ReturnDuelIDOrName(dName) == -1) return SendClientMessage(playerid, COLOR_RED, "The duelid/name specified does not exist!");
- new getid = ReturnDuelIDOrName(dName);
- format(dFile, sizeof(dFile), DUELFILES, getid);
- new Float:X, Float:Y, Float:Z, Float:A;
- GetPlayerPos(playerid, X, Y, Z);
- GetPlayerFacingAngle(playerid, A);
- new dInterior = GetPlayerInterior(playerid);
- dini_FloatSet(dFile, "duelX", X);
- dini_FloatSet(dFile, "duelY", Y);
- dini_FloatSet(dFile, "duelZ", Z);
- dini_FloatSet(dFile, "duelA", A);
- dini_FloatSet(dFile, "duelInt", -dInterior);
- SetPVarInt(playerid, "DuelEdit", 1);
- SetPVarInt(playerid, "DuelID", getid);
- new str[200];
- format(str, sizeof(str), "Duel \"%s\" (ID %d) edited at: %f, %f, %f (Interior %d)", dName, getid, X, Y, Z, dInterior);
- SendClientMessage(playerid, COLOR_DUEL, str);
- SendClientMessage(playerid, COLOR_DUEL, "Now go the second duelist position and type \"/duel save\" to set the position.");
- return 1;
- }
- if(strfind(params, "setname", true) != -1)
- {
- new third[60];
- sscanf(params[8], "s[60]", third);
- if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "You are not an admin!");
- new dName[90], dNewName[35];
- if(unformat(third, "s[90]s[35]", dName, dNewName)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /duel <setname> <duelid/name> <newduelname>");
- else if(!strlen(dName)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /duel <setname> <duelid/name> <newduelname>");
- else if(ReturnDuelIDOrName(dName) == -1) return SendClientMessage(playerid, COLOR_RED, "The duelid/name specified does not exist!");
- else if(strlen(dNewName) > 35) return SendClientMessage(playerid, COLOR_RED, "Max duel name length is 50 characters");
- new getid = ReturnDuelIDOrName(dName);
- format(dFile, sizeof(dFile), DUELFILES, getid);
- dini_Set(dFile, "duelName", dNewName);
- new str[200];
- format(str, sizeof(str), "Duel \"%s\" (ID: %d) is now named \"%s\"", dName, getid, dNewName);
- SendClientMessage(playerid, COLOR_DUEL, str);
- return 1;
- }
- if(strfind(params, "remove", true) != -1)
- {
- new third[60];
- sscanf(params[7], "s[60]", third);
- if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "ERROR: You are not an admin!");
- new dName[90];
- if(unformat(third, "s[90]", dName)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /duel <remove> <duelid/name>");
- else if(!strlen(dName)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /duel <remove> <duelid/name>");
- else if(!DuelNameExists(dName)) return SendClientMessage(playerid, COLOR_RED, "The duel id/name specified does not exist");
- else if(ReturnDuelIDOrName(dName) == -1) return SendClientMessage(playerid, COLOR_RED, "The duel id/name specified does not exist");
- new duelID = ReturnDuelIDOrName(dName);
- format(dFile, sizeof(dFile), DUELFILES, duelID);
- dini_Remove(dFile);
- new str[100];
- format(str, sizeof(str), "Duel \"%s\" (ID: %d) has been removed!", dName, duelID);
- SendClientMessage(playerid, COLOR_DUEL, str);
- return 1;
- }
- if(strfind(params, "help", true) != -1)
- {
- ShowPlayerDialog(playerid, 0, DIALOG_STYLE_MSGBOX, "{"#Y>"}Duel Help", "{"#G>"}Invite someone to a duel:\n{"#W>"}/duel <invite> <playerid/name> <betamount> <duelspot> <wep1> <wep2> <wep3>\n\nExample: \"/duel invite Noob 500 SFBridge spas deagle\"\n{"#BV>"}You may enter partial weapon names.\nMinimum 1 weapon, max weps is 3.\n\n{"#B>"}Command '/duels' shows current duels to spectate or /duel <spec> <playerid/name>!\t\t\n\n{"#R>"}", "Ok", "");
- return 1;
- }
- if(strfind(params, "cmds", true) != -1)
- {
- if(!IsPlayerAdmin(playerid)) ShowPlayerDialog(playerid, 0, DIALOG_STYLE_MSGBOX, "{"#Y>"}Duel Commands", "{"#B>"}User Commands\t\t\t{"#W>"}Description\n\n{"#B>"}/duels\t\t\t\t\t{"#W>"}Show the duel invite dialog!\n{"#B>"}/duel <cmds>\t\t\t\t{"#W>"}Show a list of duel commands.\n{"#B>"}/duel <help>\t\t\t\t{"#W>"}Help for dueling another player.\n{"#B>"}/duel <invite> <playerid/name>\t{"#W>"}Invite a player to a duel!", "Ok", "");
- else
- {
- ShowPlayerDialog(playerid, 0, DIALOG_STYLE_MSGBOX, "{"#Y>"}Duel Commands", "{"#B>"}User Commands\t\t\t{"#W>"}Description\n\n{"#B>"}/duels\t\t\t\t\t{"#W>"}Show the duel invite dialog!\n{"#B>"}/duel <cmds>\t\t\t\t{"#W>"}Show a list of duel commands.\n{"#B>"}/duel <help>\t\t\t\t{"#W>"}Help for dueling another player.\n{"#B>"}/duel <invite> <playerid/name>\t{"#W>"}Invite a player to a duel!", "Ok", "");
- SendClientMessage(playerid, COLOR_DUEL, "DBuild: {"#G>"}/duel <create> <name> {"#W>"}Create map. Set 1st dueler position! | {"#G>"}/duel <save> {"#W>"}Save map, set 2nd dueler pos!");
- SendClientMessage(playerid, COLOR_DUEL, "{"#G>"}/duel <edit> <mapid/name> {"#W>"}Edit a map. Set 1st dueler position!");
- SendClientMessage(playerid, COLOR_DUEL, "{"#G>"}duel <remove> <mapid/name> {"#W>"}Delete a map. | {"#G>"}/duel <setname> <mapid/name> <newname> {"#W>"}Change a map name");
- }
- return 1;
- }
- if(strfind(params, "spec", true) != -1)
- {
- new third[60];
- sscanf(params[5], "s[60]", third);
- new target;
- sscanf(third, "u", target);
- if(target == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "Duel | Player not found");
- if(InDuel[target] == 0) return SendClientMessage(playerid, COLOR_DUEL, "Duel | This player is not currently in a duel!");
- new str[90];
- format(str, sizeof(str), "Duel | You are now spectating %s duel.", pName(target));
- SendClientMessage(target, COLOR_DUEL, "Duel | Type /dspecoff to exit at anytime!");
- SetPlayerSpectatingDuel(playerid, target);
- return 1;
- }
- else ShowDuelSettingsDialog(playerid);
- return 1;
- }
- public OnPlayerUpdate(playerid)
- {
- if(InDuel[playerid] == 1) SetPlayerTeam(playerid, NO_TEAM);
- return 1;
- }
- //=========[Duel Callbacks]========
- public DuelReset(player1, player2)
- {
- if(InDuel[player1] == 1) return 1;
- new str[50];
- format(str, sizeof(str), "%s didn't respond to your duel invite", pName(player2));
- SendClientMessage(player1, COLOR_DUEL, str);
- SetPlayerArmour(player1, 0);
- SetPlayerArmour(player2, 0);
- RemoveFromDuel(player1);
- RemoveFromDuel(player2);
- return 1;
- }
- public DuelCDUpdate(playerid)
- {
- SetPVarInt(playerid, "CDTick", GetPVarInt(playerid, "CDTick")+1);
- if(GetPVarInt(playerid, "CDTick") > 3)
- {
- TogglePlayerControllable(playerid, 1);
- GameTextForPlayer(playerid, "~R~Fight!", 1000, 6);
- SetPVarInt(playerid, "CDTick", 0);
- PlayerPlaySound(playerid, 1057, 0.0, 0.0, 0.0);
- KillTimer(DuelTimer[playerid]);
- }
- else
- {
- GameTextForPlayer(playerid, "~P~Starting...", 500, 6);
- PlayerPlaySound(playerid, 1056, 0.0, 0.0, 0.0);
- }
- return 1;
- }
- //=========[Duel Callbacks - END]==========
- //=========[Duel Functions]===============
- stock AddToDuel(playerid, Float:X, Float:Y, Float:Z, Float:A, interior, world, wep1, wep2, wep3)
- {
- SetPVarInt(playerid, "CDTick", 0);
- InDuel[playerid] = 1;
- SetPVarInt(playerid, "ArmourReport", 1);
- SetPlayerPosEx(playerid, X, Y, Z, A, interior, world);
- SetPlayerArmour(playerid, 100);
- SetPlayerHealth(playerid, 100);
- ResetPlayerWeapons(playerid);
- GivePlayerWeapon(playerid, wep1, 1337);
- GivePlayerWeapon(playerid, wep2, 1337);
- GivePlayerWeapon(playerid, wep3, 1337);
- TogglePlayerControllable(playerid, 0);
- SetCameraBehindPlayer(playerid);
- DuelTimer[playerid] = SetTimerEx("DuelCDUpdate", 1000, 1, "i", playerid);
- SetPlayerColor(playerid, COLOR_DUEL);
- return 1;
- }
- stock AcceptDuel(playerid)
- {
- if(InDuel[playerid] == 1) return SendClientMessage(playerid, COLOR_RED, "You are already in a duel");
- new duelid = GetPVarInt(playerid, "DuelDID");
- new gPlayer = dInfo[duelid][Inviter];
- new gBet = dInfo[duelid][BetMoney];
- if(MINMONEY != 0 && Money_GetPlayerMoney(playerid) < gBet)
- {
- SendClientMessage(playerid, COLOR_RED, "Duel | You don't have that amount of money!");
- SendClientMessage(gPlayer, COLOR_RED, "Duel | The player you invited no longer has that amount of money to bet!");
- SetPlayerArmour(playerid, 0);
- SetPlayerArmour(gPlayer, 0);
- RemoveFromDuel(playerid);
- RemoveFromDuel(gPlayer);
- return 1;
- }
- new gDuelSpot = dInfo[duelid][Location];
- format(dFile, sizeof(dFile), DUELFILES, gDuelSpot);
- new Interior = dini_Int(dFile, "duelInt");
- new Float:X, Float:Y, Float:Z, Float:A;
- X = dini_Float(dFile, "duelX");
- Y = dini_Float(dFile, "duelY");
- Z = dini_Float(dFile, "duelZ");
- A = dini_Float(dFile, "duelA");
- new Float:X2, Float:Y2, Float:Z2, Float:A2;
- X2 = dini_Float(dFile, "duel2X");
- Y2 = dini_Float(dFile, "duel2Y");
- Z2 = dini_Float(dFile, "duel2Z");
- A2 = dini_Float(dFile, "duelA2");
- new Slot[3];
- Slot[0] = dWeps[duelid][0];
- Slot[1] = dWeps[duelid][1];
- Slot[2] = dWeps[duelid][2];
- TotalDuels++;
- SetPVarInt(playerid, "DuelDID", duelid);
- SetPVarInt(gPlayer, "DuelDID", duelid);
- RemoveDuelInvite(playerid, gPlayer);
- KillTimer(DuelTimer[playerid]);
- KillTimer(DuelTimer[gPlayer]);
- new world = playerid;
- if(gPlayer > playerid) world = gPlayer+1;
- else if(playerid > gPlayer) world = playerid+1;
- AddToDuel(gPlayer, X2, Y2, Z2, A2, Interior, world, Slot[0], Slot[1], Slot[2]);
- AddToDuel(playerid, X, Y, Z, A, Interior, world, Slot[0], Slot[1], Slot[2]);
- new str[150];
- format(str, sizeof(str), "Duel | %s vs %s {0004B6}(Weapons: %s %s %s) {009900}(Bet: $%d) {F8FF3D}(Place: %s [ID %d])", pName(gPlayer), pName(playerid), weaponNames(Slot[0]), weaponNames(Slot[1]), weaponNames(Slot[2]), gBet, ReturnDuelNameFromID(gDuelSpot), gDuelSpot);
- SendClientMessageToAll(COLOR_DUEL, str);
- return 1;
- }
- stock RemoveFromDuel(playerid)
- {
- KillTimer(DuelTimer[playerid]);
- SetPlayerArmour(playerid, 0);
- SetPlayerVirtualWorld(playerid, 0);
- SetPVarInt(playerid, "ArmorReport", 0);
- InDuel[playerid] = 0;
- SetPVarInt(playerid, "DuelDID", -1);
- return 1;
- }
- stock ShowDuelSettingsDialog(playerid)
- {
- new str[255], wepstr[3][40], key[7];
- new dPID = GetPVarInt(playerid, "dPID");
- new dLoc = GetPVarInt(playerid, "dLoc");
- for(new x=0; x<=2; x++)
- {
- format(key, sizeof(key), "dWep%d", x);
- new wep = GetPVarInt(playerid, key);
- format(wepstr[x], 40, "%s", weaponNames(wep));
- }
- format(str, sizeof(str), "{009900}Player:\t\t{0004B6}%s [%d]\n{009900}Location:\t{0004B6}%s [%d]\n{009900}Weapons:\t{0004B6}%s/%s/%s\n{009900}Bet Money:{009900}\t{0004B6}$%d\n{009900}Rounds:\t{0004B6}%s\n{009900}Send Invite\n{009900}Cancel Invite", pName(dPID), dPID, ReturnDuelNameFromID(dLoc), dLoc, wepstr[0], wepstr[1], wepstr[2], GetPVarInt(playerid, "dBet"), GetPVarInt(playerid, "drounds"));
- ShowPlayerDialog(playerid, DUELDIAG, DIALOG_STYLE_LIST, "Duel Settings", str, "Select", "Cancel");
- return 1;
- }
- stock ShowDuelInvitesDialog(playerid)
- {
- new total;
- format(diagstr, sizeof(diagstr), "");
- for(new x=0; x<MAX_INVITES; x++)
- {
- new inviter = dinvitem[playerid][x];
- if(inviter == playerid || inviter == -1) continue;
- format(diagstr, sizeof(diagstr), "%s%s\n", diagstr, pName(inviter));
- total++;
- }
- if(total == 0) format(diagstr, sizeof(diagstr), "{CC0000}You have not been recently invited!");
- ShowPlayerDialog(playerid, DUELDIAG+8, DIALOG_STYLE_LIST, "Duel Invites", diagstr, "Accept", "Cancel");
- return 1;
- }
- stock RemoveDuelInvite(playerid, inviter)
- {
- for(new x=0; x<MAX_INVITES; x++)
- {
- if(dinvitem[playerid][x] == inviter) dinvitem[playerid][x] = -1;
- }
- }
- stock ResetDuelInvites(playerid)
- {
- for(new x=0; x<MAX_INVITES; x++) dinvitem[playerid][x] = -1;
- }
- stock ResetDuelInformation(duelid)
- {
- dInfo[duelid][Inviter] = -1;
- dInfo[duelid][Invitee] = -1;
- dInfo[duelid][BetMoney] = 0;
- dInfo[duelid][Rounds] = 0;
- dInfo[duelid][Location] = -1;
- dInfo[duelid][Location] = 0;
- for(new x=0; x<MAX_DUEL_WEPS; x++) dWeps[duelid][x] = 0;
- }
- stock GetDuelerID(playerid)
- {
- new duelerid = -1;
- new duelid = GetPVarInt(playerid, "DuelDID");
- if(dInfo[duelid][Inviter] == playerid) duelerid = dInfo[duelid][Invitee];
- else duelerid = dInfo[duelid][Inviter];
- return duelerid;
- }
- //=========[Duel Functions - END]===============
- //=========[Duel Spectate Functions]==========
- stock LoadDuelSpecTextdraw(playerid)
- {
- SpecTD[playerid][0] = TextDrawCreate(180.000000, 364.000000, "_");
- TextDrawBackgroundColor(SpecTD[playerid][0], 255);
- TextDrawFont(SpecTD[playerid][0], 3);
- TextDrawLetterSize(SpecTD[playerid][0], 0.469999, 1.200000);
- TextDrawColor(SpecTD[playerid][0], 52479);
- TextDrawSetOutline(SpecTD[playerid][0], 0);
- TextDrawSetProportional(SpecTD[playerid][0], 1);
- TextDrawSetShadow(SpecTD[playerid][0], 1);
- SpecTD[playerid][1] = TextDrawCreate(180.000000, 387.000000, "_");
- TextDrawBackgroundColor(SpecTD[playerid][1], 255);
- TextDrawFont(SpecTD[playerid][1], 3);
- TextDrawLetterSize(SpecTD[playerid][1], 0.469999, 1.200000);
- TextDrawColor(SpecTD[playerid][1], -1);
- TextDrawSetOutline(SpecTD[playerid][1], 0);
- TextDrawSetProportional(SpecTD[playerid][1], 1);
- TextDrawSetShadow(SpecTD[playerid][1], 1);
- TextDrawHideForAll(SpecTD[playerid][0]);
- TextDrawHideForAll(SpecTD[playerid][1]);
- }
- public UpdateSpectate(playerid)
- {
- new specid = GetPVarInt(playerid, "DuelSpecID");
- if(!IsPlayerInDuel(specid)) return EndDuelSpectate(playerid);
- else ShowDuelSpecTextdraw(playerid, specid);
- SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(specid));
- SetPlayerInterior(playerid, GetPlayerInterior(specid));
- return 1;
- }
- stock EndDuelSpectate(playerid)
- {
- KillTimer(UpdateSpecTimer[playerid]);
- SetPVarInt(playerid, "DuelSpecID", -1);
- SetPVarInt(playerid, "DuelSpec", 0);
- SendClientMessage(playerid, COLOR_DUEL, "Duel spectate ended, duel is no longer in progress.");
- TogglePlayerSpectating(playerid, 0);
- KillTimer(UpdateSpecTimer[playerid]);
- TextDrawHideForPlayer(playerid, SpecTD[playerid][0]);
- TextDrawHideForPlayer(playerid, SpecTD[playerid][1]);
- return 1;
- }
- stock SetPlayerSpectatingDuel(playerid, duelerid)
- {
- TogglePlayerSpectating(playerid, 1);
- SendClientMessage(playerid, COLOR_DUEL, "You have entered duel spectate mode!");
- SendClientMessage(playerid, COLOR_DUEL, "Press the FIRE key to switch between duelists.");
- ShowDuelSpecTextdraw(playerid, duelerid);
- KillTimer(UpdateSpecTimer[playerid]);
- UpdateSpecTimer[playerid] = SetTimerEx("UpdateSpectate", 1000, 1, "d", playerid);
- SetPVarInt(playerid, "DuelSpecID", duelerid);
- SetPVarInt(playerid, "DuelSpec", 1);
- SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(duelerid));
- SetPlayerInterior(playerid, GetPlayerInterior(duelerid));
- PlayerSpectatePlayer(playerid, duelerid, SPECTATE_MODE_NORMAL);
- }
- stock ShowDuelSpecTextdraw(playerid, duelerid)
- {
- new sstr[100], sstr2[140];
- new duelloc[40];
- new duelid, dueler;
- duelid = GetPVarInt(duelerid, "DuelDID");
- if(dInfo[duelid][Inviter] == duelerid) dueler = dInfo[duelid][Invitee];
- else dueler = dInfo[duelid][Inviter];
- new gBet = dInfo[duelid][BetMoney];
- new gDuelSpot = dInfo[duelid][Location];
- format(duelloc, sizeof(duelloc), "%s", ReturnDuelNameFromID(gDuelSpot));
- new Slot[3];
- Slot[0] = dWeps[duelid][0];
- Slot[1] = dWeps[duelid][1];
- Slot[2] = dWeps[duelid][2];
- format(sstr, sizeof(sstr), "%s vs %s~n~~R~HP ~W~%d %d", pName(duelerid), pName(dueler), GetRoundedTotalHP(duelerid), GetRoundedTotalHP(dueler));
- format(sstr2, sizeof(sstr2), "~Y~Location ~w~%s~n~~p~Weapons ~w~%s %s %s~n~~g~Bet Money ~w~$%d",
- duelloc, weaponNames(Slot[0]), weaponNames(Slot[1]), weaponNames(Slot[2]), gBet);
- TextDrawHideForPlayer(playerid, SpecTD[playerid][0]);
- TextDrawHideForPlayer(playerid, SpecTD[playerid][1]);
- TextDrawSetString(SpecTD[playerid][0], sstr);
- TextDrawSetString(SpecTD[playerid][1], sstr2);
- TextDrawShowForPlayer(playerid, SpecTD[playerid][0]);
- TextDrawShowForPlayer(playerid, SpecTD[playerid][1]);
- }
- //=======================[Spectate - END]==========================
- //======================[Internal Functions]=======================
- stock IsPlayerInDuel(playerid)
- {
- if(InDuel[playerid] == 1) return 1;
- return 0;
- }
- stock SetPlayerPosEx(playerid, Float:X, Float:Y, Float:Z, Float:angle, interior, world)
- {
- SetPlayerPos(playerid, X, Y, Z);
- SetPlayerFacingAngle(playerid, angle);
- SetPlayerInterior(playerid, interior);
- SetPlayerVirtualWorld(playerid, world);
- return 1;
- }
- stock IsValidWeapon(weaponid)
- {
- switch(weaponid)
- {
- case 0, 19, 20, 21, 35..46: return 0;
- }
- if(weaponid < 0 || weaponid > 48) return 0;
- return 1;
- }
- stock ReturnWeaponIDOrName(idname[])
- {
- if(!IsNumeric(idname))
- {
- new gWeap = GetWeaponModelIDFromName(idname);
- if(IsValidWeapon(gWeap)) return gWeap;
- }
- else if(IsNumeric(idname))
- {
- new gWeap = strval(idname);
- if(IsValidWeapon(gWeap)) return gWeap;
- }
- return -1;
- }
- stock GetRoundedTotalHP(playerid)
- {
- new Float:HP, Float:Armour, HPT;
- GetPlayerHealth(playerid, HP);
- GetPlayerArmour(playerid, Armour);
- HPT = floatround(HP) + floatround(Armour);
- return HPT;
- }
- GetWeaponModelIDFromName(wname[])
- {
- for(new i=0; i<49; i++)
- {
- if(i == 19 || i == 20 || i == 21) continue;
- if(strfind(weaponNames(i), wname, true) != -1) return i;
- }
- return -1;
- }
- stock DuelNameExists(duelname[])
- {
- for(new x=0; x<MAX_DUELS; x++)
- {
- format(dFile, sizeof(dFile), DUELFILES, x);
- if(strfind(duelname, dini_Get(dFile, "duelName"), true) != -1) return 1;
- break;
- }
- return 0;
- }
- stock ReturnDuelIDOrName(duelname[])
- {
- if(!IsNumeric(duelname))
- {
- for(new x=0; x<MAX_DUELS; x++)
- {
- new dName[128];
- new idfromname = x;
- format(dFile, sizeof(dFile), DUELFILES, x);
- format(dName, sizeof(dName), "%s", dini_Get(dFile, "duelName"));
- if(strfind(dName, duelname, true) != -1) return idfromname;
- break;
- }
- }
- else if(IsNumeric(duelname))
- {
- new dName = strval(duelname);
- format(dFile, sizeof(dFile), DUELFILES, dName);
- if(fexist(dFile)) return dName;
- }
- return -1;
- }
- stock weaponNames(weaponid)
- {
- new str[25];
- switch(weaponid)
- {
- case 0: str = "Fist";
- case 1: str = "Brass Knuckles";
- case 2: str = "Golf Club";
- case 3: str = "Night Stick";
- case 4: str = "Knife";
- case 5: str = "Baseball Bat";
- case 6: str = "Shovel";
- case 7: str = "Pool Cue";
- case 8: str = "Katana";
- case 9: str = "Chainsaw";
- case 10: str = "Purple Dildo";
- case 11: str = "Vibrator";
- case 12: str = "Vibrator";
- case 13: str = "Vibrator";
- case 14: str = "Flowers";
- case 15: str = "Cane";
- case 16: str = "Grenade";
- case 17: str = "Teargas";
- case 18: str = "Molotov";
- case 19: str = " ";
- case 20: str = " ";
- case 21: str = " ";
- case 22: str = "Colt 45";
- case 23: str = "Silenced Pistol";
- case 24: str = "Deagle";
- case 25: str = "Shotgun";
- case 26: str = "Sawns";
- case 27: str = "Spas";
- case 28: str = "Uzi";
- case 29: str = "MP5";
- case 30: str = "AK47";
- case 31: str = "M4";
- case 32: str = "Tec9";
- case 33: str = "County Rifle";
- case 34: str = "Sniper Rifle";
- case 35: str = "Rocket Launcher";
- case 36: str = "Heat-Seeker";
- case 37: str = "Flamethrower";
- case 38: str = "Minigun";
- case 39: str = "Satchel Charge";
- case 40: str = "Detonator";
- case 41: str = "Spray Can";
- case 42: str = "Fire Extinguisher";
- case 43: str = "Camera";
- case 44: str = "Night Vision Goggles";
- case 45: str = "Infrared Goggles";
- case 46: str = "Parachute";
- case 47: str = "Fake Pistol";
- case 48: str = "None"; //For duel msgs
- }
- return str;
- }
- stock ReturnDuelNameFromID(duelid)
- {
- new dName[80];
- format(dFile, sizeof(dFile), DUELFILES, duelid);
- format(dName, sizeof(dName), "%s", dini_Get(dFile, "duelName"));
- return dName;
- }
- stock pName(playerid)
- {
- new paname[MAX_PLAYER_NAME];
- GetPlayerName(playerid, paname, sizeof(paname));
- return paname;
- }
- stock IsNumeric(string[])
- {
- for(new i=0, j=strlen(string); i<j; i++)
- {
- if(string[i] > '9' || string[i] < '0') return 0;
- }
- return 1;
- }
- stock GetLowestUnusedDuelSlot(playerid)
- {
- new duelid;
- for(new x=0; x<MAX_INVITES; x++)
- {
- if(!IsPlayerConnected(dinvitem[playerid][x]))
- {
- duelid = x;
- break;
- }
- }
- return duelid;
- }
- stock GetLowestUnusedDuelID()
- {
- new duelid;
- for(new x=0; x<MAX_DUELS; x++)
- {
- if(!IsPlayerConnected(dInfo[x][Inviter]) || !IsPlayerConnected(dInfo[x][Invitee]))
- {
- duelid = x;
- break;
- }
- }
- return duelid;
- }
- stock GetLowestDuelSlotID()
- {
- for(new x=0; x<MAX_DUELS; x++)
- {
- format(dFile, sizeof(dFile), DUELFILES, x);
- if(!dini_Exists(dFile)) return x;
- }
- return 1;
- }
- //======================[Internal Functions - END]=======================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement