Guest User

Last Man Standing | By: SyntaxQ

a guest
May 28th, 2014
1,129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 11.83 KB | None | 0 0
  1. #include <a_samp>
  2. #include <sscanf2>
  3. #include <zcmd>
  4.  
  5. #define START_TIME 30000 // Time in milliseconds
  6. #define END_TIME 30000 // Time in milliseconds
  7. #define COUNT_DOWN_SECONDS 6
  8. #define C1  "{DBED15}"
  9. #define C2  "{BABABA}"
  10. #define RED "{FF0000}"
  11. #define LMS_CHOOSE_WEAPON 9876
  12. #define function%0(%1) \
  13.         forward%0(%1); public%0(%1)
  14.  
  15. new startTimer;
  16. new initiateTimer;
  17. new cdTimer;
  18. new IsLMSactive;
  19. new IsLMSstarted;
  20. new lmsCount;
  21. new countVal;
  22. new PlayerText:rInfoTDS[MAX_PLAYERS];
  23. new playerJoined[MAX_PLAYERS];
  24. forward startLMS();
  25. forward initiateLMS();
  26. forward lmsCountDown();
  27.  
  28. public OnFilterScriptInit()
  29. {
  30.     print("\n--------------------------------------");
  31.     print(" Last Man Standing | Author: SyntaxQ");
  32.     print("--------------------------------------\n");
  33.     IsLMSactive = 0;
  34.     IsLMSstarted = 0;
  35.     lmsCount = 0;
  36.     startTimer = SetTimer("startLMS", START_TIME, false);
  37.     return 1;
  38. }
  39.  
  40.  
  41. public OnFilterScriptExit()
  42. {
  43.     return 1;
  44. }
  45.  
  46. public startLMS()
  47. {
  48.     if (IsLMSactive == 1)
  49.     {
  50.         return 0;
  51.     }
  52.     SendClientMessageToAll(-1, ""C1"[LMS] "C2"A last man standing event has started! Type "RED"/lms "C2"to join");
  53.     for (new i = 0; i < MAX_PLAYERS; i++)
  54.     {
  55.         if (IsPlayerConnected(i))
  56.         {
  57.             TD_MSG(i, 3000, "~w~A last man standing has started! Type ~h~~r~/lms ~w~to join!");
  58.         }
  59.     }
  60.     IsLMSactive = 1;
  61.     initiateTimer = SetTimer("initiateLMS", END_TIME, false);
  62.     return 1;
  63. }
  64.  
  65. public initiateLMS()
  66. {
  67.     new str[128];
  68.     KillTimer(startTimer);
  69.     if (lmsCount == 0)
  70.     {
  71.         SendClientMessageToAll(-1, ""C1"[LMS] "C2"Last Man Standing has cancelled due to lack of players! [Atleast "RED"2 "C2"players needed]");
  72.         IsLMSactive = 0;
  73.         IsLMSstarted = 0;
  74.         KillTimer(initiateTimer);
  75.         startTimer = SetTimer("startLMS", START_TIME, false);
  76.         return 1;
  77.     }
  78.     format(str, sizeof(str), ""C1"[LMS] "C2"Last Man Standing has started! [Total Players: "RED"%d"C2"]", lmsCount);
  79.     IsLMSstarted = 1;
  80.     SendClientMessageToAll(-1, str);
  81.     for (new i = 0; i < MAX_PLAYERS; i++)
  82.     {
  83.         if (IsPlayerConnected(i))
  84.         {
  85.             if (playerJoined[i] == 1)
  86.             {
  87.                 SendClientMessage(i, -1, ""C1"[LMS] "RED"The countdown begins...Get ready!");
  88.             }
  89.         }
  90.     }
  91.     cdTimer = SetTimer("lmsCountDown", 1000, false);
  92.     countVal = COUNT_DOWN_SECONDS;
  93.     return 1;
  94. }
  95.  
  96. public lmsCountDown()
  97. {
  98.     countVal--;
  99.     KillTimer(initiateTimer);
  100.     if (countVal == 0)
  101.     {
  102.         for (new i = 0; i < MAX_PLAYERS; i++)
  103.         {
  104.             if (IsPlayerConnected(i))
  105.             {
  106.                 if (playerJoined[i] == 1)
  107.                 {
  108.                     GameTextForPlayer(i, "~r~~r~FIGHT!", 1000, 4);
  109.                     TogglePlayerControllable(i, true);
  110.                     KillTimer(cdTimer);
  111.                 }
  112.             }
  113.         }
  114.     }
  115.     else
  116.     {
  117.         new c_val_str[10];
  118.         format(c_val_str, sizeof(c_val_str), "~b~~w~%d", countVal);
  119.         for (new i = 0; i < MAX_PLAYERS; i++)
  120.         {
  121.             if (IsPlayerConnected(i))
  122.             {
  123.                 if (playerJoined[i] == 1)
  124.                 {
  125.                     GameTextForPlayer(i, c_val_str, 1000, 4);
  126.                     cdTimer = SetTimer("lmsCountDown", 1000, false);
  127.                 }
  128.             }
  129.         }
  130.     }
  131.     return 1;
  132. }
  133.  
  134. CMD:lms (playerid)
  135. {
  136.     new str[128];
  137.     if (IsLMSactive == 0) return SendClientMessage(playerid, -1, ""RED"ERROR: "C2"Last Man Standing is not active.");
  138.     if (playerJoined[playerid] == 1) return SendClientMessage(playerid, -1, ""RED"ERROR: "C2"You have already joined!");
  139.     if (IsLMSstarted == 1) return SendClientMessage(playerid, -1, ""RED"ERROR: "C2"Last Man Standing has already started!");
  140.     lmsCount++;
  141.     format(str, sizeof(str), ""C1"[LMS] "C2"%s(%d) has joined the Last Man Standing event! [Total Players: "RED"%d"C2"]", GetName(playerid), playerid, lmsCount);
  142.     SendClientMessageToAll(-1, str);
  143.     new Float:RandomSpawns[][] =
  144.     {
  145.         {7.6998,36.5756,4199.5747,179.6044},
  146.         {7.9292,-10.2401,4199.5947,359.7493}
  147.  
  148.     };
  149.     new Random = random(sizeof(RandomSpawns));
  150.     SetPlayerPosEx(playerid, RandomSpawns[Random][0], RandomSpawns[Random][1], RandomSpawns[Random][2], RandomSpawns[Random][3], 0, 1);
  151.     TogglePlayerControllable(playerid, false);
  152.     TD_MSG(playerid, 3000, "~w~You have joined ~h~~r~Last Man Standing~w~!");
  153.     SetCameraBehindPlayer(playerid);
  154.     ShowPlayerDialog(playerid, LMS_CHOOSE_WEAPON, DIALOG_STYLE_LIST, ""RED"Choose a weapon for fight:", "• Deagle - M4 - Uzi - 9mm\n• Sawn-off Shotgun - MP5 - Tec9 - s9mm\n• Combat Shotgun - AK47 - Shotgun - 9mm", "Select", "");
  155.     playerJoined[playerid] = 1;
  156.     return 1;
  157. }
  158.  
  159. CMD:exitlms (playerid)
  160. {
  161.     new str[128];
  162.     if (IsLMSactive == 0) return SendClientMessage(playerid, -1, ""RED"ERROR: "C2"Last Man Standing is not active.");
  163.     if (playerJoined[playerid] == 0) return SendClientMessage(playerid, -1, ""RED"ERROR: "C2"You have not joined LMS!");
  164.     lmsCount--;
  165.     format(str, sizeof(str), ""C1"[LMS] "C2"%s(%d) has left the Last Man Standing event [Total Players: "RED"%d"C2"]", GetName(playerid), playerid, lmsCount);
  166.     SendClientMessageToAll(-1, str);
  167.     TD_MSG(playerid, 2000, "~w~You have left ~h~~r~Last Man Standing~w~!");
  168.     playerJoined[playerid] = 0;
  169.     SetPlayerPosEx(playerid, 2188.6184, 1681.6017, 11.1150, 90.3735, 0, 0);
  170.     SetCameraBehindPlayer(playerid);
  171.     TogglePlayerControllable(playerid, true);
  172.     ResetPlayerWeapons(playerid);
  173.     return 1;
  174. }
  175.  
  176. CMD:startlms (playerid)
  177. {
  178.     new str[128];
  179.     if (!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, ""RED"ERROR: "C2"You must be RCON admin to use this command!");
  180.     if (IsLMSactive == 1) return SendClientMessage(playerid, -1, ""RED"ERROR: "C2"A lms event is already active.");
  181.     format(str, sizeof(str), ""C1"[ADMIN] "RED"RCON administrator %s(%d) has manually started Last Man Standing event.", GetName(playerid), playerid);
  182.     startLMS();
  183.     SendClientMessageToAll(-1, str);
  184.     return 1;
  185. }
  186.  
  187. CMD:stoplms (playerid)
  188. {
  189.     new str[128];
  190.     if (!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, ""RED"ERROR: "C2"You must be RCON admin to use this command!");
  191.     if (IsLMSactive == 0) return SendClientMessage(playerid, -1, ""RED"ERROR: "C2"No lms events are active.");
  192.     for (new i = 0; i < MAX_PLAYERS; i++)
  193.     {
  194.         if (IsPlayerConnected(i))
  195.         {
  196.             if (playerJoined[i] == 1)
  197.             {
  198.                 SendClientMessage(i, -1, ""C1"[LMS] "RED"Last Man Standing cancelled by an Administrator.");
  199.                 TD_MSG(i, 2000, "~r~Last Man Standing ~w~cancelled!");
  200.                 SetPlayerPosEx(i, 2188.6184, 1681.6017, 11.1150, 90.3735, 0, 0);
  201.                 SetCameraBehindPlayer(i);
  202.                 TogglePlayerControllable(i, true);
  203.                 ResetPlayerWeapons(i);
  204.                 playerJoined[i] = 0;
  205.             }
  206.         }
  207.     }
  208.     format(str, sizeof(str), ""C1"[ADMIN] "RED"RCON Administrator %s(%d) has cancelled the current Last Man Standing event.", GetName(playerid), playerid);
  209.     SendClientMessageToAll(-1, str);
  210.     KillTimer(startTimer);
  211.     KillTimer(initiateTimer);
  212.     KillTimer(cdTimer);
  213.     IsLMSactive = 0;
  214.     IsLMSstarted = 0;
  215.     lmsCount = 0;
  216.     startTimer = SetTimer("startLMS", START_TIME, false);
  217.     return 1;
  218. }
  219.  
  220. public OnPlayerConnect(playerid)
  221. {
  222.     LoadPlayerTextDraws(playerid);
  223.     playerJoined[playerid] = 0;
  224.     return 1;
  225. }
  226.  
  227. public OnPlayerDeath(playerid, killerid, reason)
  228. {
  229.     new str[128];
  230.     if (playerJoined[playerid] == 1 && IsLMSactive == 1)
  231.     {
  232.         if(killerid != INVALID_PLAYER_ID)
  233.         {
  234.             lmsCount--;
  235.             if (lmsCount == 1)
  236.             {
  237.                 for (new i = 0; i < MAX_PLAYERS; i++)
  238.                 {
  239.                     if (IsPlayerConnected(i))
  240.                     {
  241.                         if (playerJoined[i] == 1)
  242.                         {
  243.                             format(str, sizeof(str), ""C1"[LMS] "C2"%s(%d) "RED"has won the Last Man Standing event! "C2"(+5 score & $50000)", GetName(i), i);
  244.                             SetPlayerScore(i, GetPlayerScore(i) + 5);
  245.                             GivePlayerMoney(i, 50000);
  246.                             IsLMSactive = 0;
  247.                             IsLMSstarted = 0;
  248.                             playerJoined[i] = 0;
  249.                             SendClientMessageToAll(-1, str);
  250.                             lmsCount = 0;
  251.                             TD_MSG(i, 3000, "~w~You have ~g~won ~w~the last man standing!");
  252.                             startTimer = SetTimer("startLMS", START_TIME, false);
  253.                             return 1;
  254.                         }
  255.                     }
  256.                 }
  257.             }
  258.             format(str, sizeof(str), ""C1"[LMS] "C2"%s(%d) has been eliminated by %s(%d)! [Total Players: "RED"%d"C2"]", GetName(playerid), playerid, GetName(killerid), killerid, lmsCount);
  259.             SendClientMessageToAll(-1, str);
  260.             SetPlayerScore(killerid, GetPlayerScore(killerid) + 1);
  261.             GivePlayerMoney(killerid, 1000);
  262.             SetPlayerPosEx(playerid, 2188.6184, 1681.6017, 11.1150, 90.3735, 0, 0);
  263.             TD_MSG(killerid, 3000, "~w~~g~+1 score & $1000!");
  264.             playerJoined[playerid] = 0;
  265.         }
  266.     }
  267.     return 1;
  268. }
  269.  
  270. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  271. {
  272.     if (dialogid == LMS_CHOOSE_WEAPON)
  273.     {
  274.         if (response)
  275.         {
  276.             switch (listitem)
  277.             {
  278.                 case 0:
  279.                 {
  280.                     GivePlayerWeapon(playerid, 24, 20);
  281.                     GivePlayerWeapon(playerid, 31, 20);
  282.                     GivePlayerWeapon(playerid, 28, 60);
  283.                     GivePlayerWeapon(playerid, 22, 100);
  284.                     TD_MSG(playerid, 2000, "~r~Weapons updated!");
  285.                 }
  286.                 case 1:
  287.                 {
  288.                     GivePlayerWeapon(playerid, 26, 20);
  289.                     GivePlayerWeapon(playerid, 29, 20);
  290.                     GivePlayerWeapon(playerid, 32, 60);
  291.                     GivePlayerWeapon(playerid, 22, 100);
  292.                     TD_MSG(playerid, 2000, "~r~Weapons updated!");
  293.                 }
  294.                 case 2:
  295.                 {
  296.                     GivePlayerWeapon(playerid, 27, 20);
  297.                     GivePlayerWeapon(playerid, 30, 20);
  298.                     GivePlayerWeapon(playerid, 32, 60);
  299.                     GivePlayerWeapon(playerid, 22, 100);
  300.                     TD_MSG(playerid, 2000, "~r~Weapons updated!");
  301.                 }
  302.             }
  303.         }
  304.     }
  305.     return 0;
  306. }
  307.  
  308. //-----------------------
  309. // Additional Functions
  310. //-----------------------
  311. // Note: Some functions are not created by me (SyntaxQ).
  312.  
  313. stock LoadPlayerTextDraws(playerid)
  314. {
  315.     rInfoTDS[ playerid ] = CreatePlayerTextDraw( playerid, 165.000000, 371.000000, " " );
  316.     PlayerTextDrawAlignment( playerid, rInfoTDS[ playerid ], 1 );
  317.     PlayerTextDrawBackgroundColor( playerid, rInfoTDS[ playerid ], 0x000000ff );
  318.     PlayerTextDrawFont( playerid, rInfoTDS[ playerid ], 1 );
  319.     PlayerTextDrawLetterSize( playerid, rInfoTDS[ playerid ], 0.299999, 1.200000 );
  320.     PlayerTextDrawColor( playerid, rInfoTDS[ playerid ], 0xffffffff );
  321.     PlayerTextDrawSetOutline( playerid, rInfoTDS[ playerid ], 1 );
  322.     PlayerTextDrawSetProportional( playerid, rInfoTDS[ playerid ], 1 );
  323.     PlayerTextDrawSetShadow( playerid, rInfoTDS[ playerid ], 1 );
  324.     PlayerTextDrawSetSelectable( playerid, rInfoTDS[ 2 ], 0 );
  325.     return 1;
  326. }
  327.  
  328. function TD_MSG_FOR_ALL( playerid, ms_time, text[] )
  329. {
  330.     if(GetPVarInt(playerid, "InfoTDshown") != -1)
  331.     {
  332.         PlayerTextDrawHide( playerid, rInfoTDS[ playerid ] );
  333.         KillTimer( GetPVarInt( playerid, "InfoTDshown" ) );
  334.     }
  335.     PlayerTextDrawSetString( playerid, rInfoTDS[ playerid ], text );
  336.     PlayerTextDrawShow( playerid, rInfoTDS[ playerid ] );
  337.     PlayerPlaySound( playerid, 1058, 0, 0, 0 );
  338.     SetPVarInt( playerid, "InfoTDshown", SetTimerEx( "InfoTD_Hide", ms_time, false, "i", playerid ) );
  339.     return ( 1 );
  340. }
  341.  
  342. function TD_MSG( playerid, ms_time, text[] )
  343. {
  344.     if(GetPVarInt(playerid, "InfoTDshown") != -1)
  345.     {
  346.         PlayerTextDrawHide( playerid, rInfoTDS[ playerid ] );
  347.         KillTimer( GetPVarInt( playerid, "InfoTDshown" ) );
  348.     }
  349.     PlayerTextDrawSetString( playerid, rInfoTDS[ playerid ], text );
  350.     PlayerTextDrawShow( playerid, rInfoTDS[ playerid ] );
  351.     PlayerPlaySound( playerid, 1058, 0, 0, 0 );
  352.     SetPVarInt( playerid, "InfoTDshown", SetTimerEx( "InfoTD_Hide", ms_time, false, "i", playerid ) );
  353.     return ( 1 );
  354. }
  355.  
  356. function InfoTD_Hide(playerid)
  357. {
  358.     SetPVarInt( playerid, "InfoTDshown", -1 );
  359.     PlayerTextDrawHide( playerid, rInfoTDS[ playerid ] );
  360. }
  361.  
  362. stock GetName(playerid)
  363. {
  364.     new pName[MAX_PLAYERS];
  365.     GetPlayerName(playerid, pName, sizeof(pName));
  366.     return pName;
  367. }
  368.  
  369. stock SetPlayerPosEx(playerid, Float:X, Float:Y, Float:Z, Float:angle, interior, world)
  370. {
  371.     SetPlayerPos(playerid, X, Y, Z);
  372.     SetPlayerFacingAngle(playerid, angle);
  373.     SetPlayerInterior(playerid, interior);
  374.     SetPlayerVirtualWorld(playerid, world);
  375.     return 1;
  376. }
Advertisement
Add Comment
Please, Sign In to add comment