Advertisement
Frost12

Duel System

Sep 12th, 2015
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.12 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. /*
  4.  
  5. Script by FROST
  6. Edit line 184,185,201,202
  7.  
  8. */
  9.  
  10. #define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
  11. #define SendError(%1,%2) SendClientMessage(%1,COLOR_RED,"ERROR: " %2)
  12. #define SendUsage(%1,%2) SendClientMessage(%1,COLOR_WHITE,"USAGE: " %2)
  13.  
  14. #define COLOR_ORANGE 0xFF8040FF
  15. #define COLOR_YELLOW 0xFFFF00AA
  16. #define COLOR_RED 0xFF0000AA
  17. #define COLOR_WHITE 0xFFFFFFAA
  18.  
  19.  
  20. stock
  21. g_GotInvitedToDuel[MAX_PLAYERS],
  22. g_HasInvitedToDuel[MAX_PLAYERS],
  23. g_IsPlayerDueling[MAX_PLAYERS],
  24. g_DuelCountDown[MAX_PLAYERS],
  25. g_DuelTimer[MAX_PLAYERS],
  26. g_DuelInProgress,
  27. g_DuelingID1,
  28. g_DuelingID2;
  29.  
  30. public OnFilterScriptInit()
  31. {
  32. print("\t============================================");
  33. print("\tDuel Filterscript");
  34. print("\tBy: Frost");
  35. print("\t-");
  36. print("\tLoaded");
  37. print("\t============================================");
  38. return 1;
  39. }
  40.  
  41. public OnFilterScriptExit()
  42. {
  43. print("\t============================================");
  44. print("\tDuel Filterscript");
  45. print("\tBy: Frost");
  46. print("\t-");
  47. print("\tLoaded");
  48. print("\t============================================");
  49. return 1;
  50. }
  51.  
  52. public OnPlayerConnect(playerid)
  53. {
  54. g_GotInvitedToDuel[playerid] = 0;
  55. g_HasInvitedToDuel[playerid] = 0;
  56. g_IsPlayerDueling[playerid] = 0;
  57. return 1;
  58. }
  59.  
  60. public OnPlayerDisconnect(playerid, reason)
  61. {
  62. if(playerid == g_DuelingID1 || playerid == g_DuelingID2)
  63. {
  64. g_DuelInProgress = 0;
  65. }
  66. return 1;
  67. }
  68.  
  69. public OnPlayerCommandText(playerid, cmdtext[])
  70. {
  71. dcmd(duel,4,cmdtext);
  72. dcmd(cduel,5,cmdtext);
  73. dcmd(duelaccept,10,cmdtext);
  74. return 1;
  75. }
  76.  
  77. dcmd_cduel(playerid, params[])
  78. {
  79. #pragma unused params
  80.  
  81. if(g_HasInvitedToDuel[playerid] == 0)
  82. return SendError(playerid, "You did not invite anyone to a duel!");
  83.  
  84. SendClientMessage(playerid, COLOR_YELLOW, "You have reset your duel invite, you can now use /duel [playerid] again.");
  85. g_HasInvitedToDuel[playerid] = 0;
  86.  
  87. return 1;
  88. }
  89.  
  90. dcmd_duelaccept(playerid, params[])
  91. {
  92. if(params[0] == '\0' || !IsNumeric(params))
  93. return SendUsage(playerid, "/duelaccept [playerid]");
  94.  
  95. if(g_DuelInProgress == 1)
  96. return SendError(playerid, "Another duel is in progress at the moment, wait till that duel is finished!");
  97.  
  98. new
  99. DuelID = strvalEx(params),
  100. pName[MAX_PLAYER_NAME],
  101. zName[MAX_PLAYER_NAME],
  102. tString[128];
  103.  
  104. if(DuelID != g_GotInvitedToDuel[playerid])
  105. return SendError(playerid, "That player did not invite you to a duel!");
  106.  
  107. GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
  108. GetPlayerName(DuelID, zName, MAX_PLAYER_NAME);
  109.  
  110. format(tString, sizeof(tString), "You accepted the duel with %s (ID:%d), duel will start in 10 seconds..",zName,DuelID);
  111. SendClientMessage(playerid, COLOR_YELLOW, tString);
  112.  
  113. format(tString, sizeof(tString), "%s (ID:%d), accepted the duel with you, duel will start in 10 seconds..",pName,playerid);
  114. SendClientMessage(DuelID, COLOR_YELLOW, tString);
  115.  
  116. format(tString, sizeof(tString), "(News) Duel between %s and %s will start in 10 seconds",pName,zName);
  117. SendClientMessageToAll(COLOR_ORANGE, tString);
  118.  
  119. InitializeDuel(playerid);
  120. InitializeDuelEx( DuelID);
  121.  
  122. g_IsPlayerDueling[playerid] = 1;
  123. g_IsPlayerDueling[DuelID] = 1;
  124.  
  125. g_DuelingID1 = playerid;
  126. g_DuelingID2 = DuelID;
  127.  
  128. g_DuelInProgress = 1;
  129.  
  130. return 1;
  131. }
  132.  
  133. dcmd_duel(playerid, params[])
  134. {
  135. if(params[0] == '\0' || !IsNumeric(params))
  136. return SendUsage(playerid, "/duel [playerid]");
  137.  
  138. if(g_HasInvitedToDuel[playerid] == 1)
  139. return SendError(playerid, "You already invited someone to a duel! (Type, /cduel to reset your invite)");
  140.  
  141. new
  142. DuelID = strvalEx(params),
  143. pName[MAX_PLAYER_NAME],
  144. zName[MAX_PLAYER_NAME],
  145. tString[128];
  146.  
  147. GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
  148. GetPlayerName(DuelID, zName, MAX_PLAYER_NAME);
  149.  
  150. if (!IsPlayerConnected(DuelID))
  151. return SendError(playerid, "Player is not connected.");
  152.  
  153. if( g_HasInvitedToDuel[DuelID] == 1)
  154. return SendError(playerid, "That player is already invited to a duel!");
  155.  
  156. if( DuelID == playerid)
  157. return SendError(playerid, "You can not duel yourself!");
  158.  
  159. format(tString, sizeof(tString), "You invited %s (ID:%d) to a 1 on 1 duel, wait till %s accepts your invite.",zName, DuelID, zName);
  160. SendClientMessage(playerid, COLOR_YELLOW, tString);
  161.  
  162. format(tString, sizeof(tString), "You got invited by %s (ID:%d) to a 1 on 1 duel, type /duelaccept [playerid] to accept and start the duel. ",pName, playerid);
  163. SendClientMessage(DuelID, COLOR_YELLOW, tString);
  164.  
  165. g_GotInvitedToDuel[DuelID] = playerid;
  166. g_HasInvitedToDuel[playerid] = 1;
  167.  
  168. return 1;
  169. }
  170.  
  171. forward InitializeDuel(playerid);
  172. public InitializeDuel(playerid)
  173. {
  174. g_DuelTimer[playerid] = SetTimerEx("DuelCountDown", 1000, 1, "i", playerid);
  175.  
  176. SetPlayerHealth(playerid, 100);
  177. SetPlayerArmour(playerid, 100);
  178.  
  179. //SetPlayerPos(playerid, X, Y, Z); // da1
  180. //SetPlayerFacingAngle(playerid, A);
  181. SetCameraBehindPlayer(playerid);
  182. TogglePlayerControllable(playerid, 0);
  183. g_DuelCountDown[playerid] = 11;
  184.  
  185. return 1;
  186. }
  187.  
  188. forward InitializeDuelEx(playerid);
  189. public InitializeDuelEx(playerid)
  190. {
  191. g_DuelTimer[playerid] = SetTimerEx("DuelCountDown", 1000, 1, "i", playerid);
  192.  
  193. SetPlayerHealth(playerid, 100);
  194. SetPlayerArmour(playerid, 100);
  195.  
  196. //SetPlayerPos(playerid, X, Y, Z);
  197. //SetPlayerFacingAngle(playerid, A);
  198. SetCameraBehindPlayer(playerid);
  199. TogglePlayerControllable(playerid, 0);
  200. g_DuelCountDown[playerid] = 11;
  201.  
  202. return 1;
  203. }
  204.  
  205. forward DuelCountDown(playerid);
  206. public DuelCountDown(playerid)
  207. {
  208. new
  209. tString[128] ;
  210.  
  211. g_DuelCountDown[playerid] --;
  212.  
  213. PlayerPlaySound(playerid, 1057, 0.0, 0.0, 0.0);
  214.  
  215. format(tString, sizeof(tString), "~w~%d", g_DuelCountDown[playerid]);
  216. GameTextForPlayer(playerid, tString, 900, 3);
  217.  
  218. if(g_DuelCountDown[playerid] == 0)
  219. {
  220. KillTimer(g_DuelTimer[playerid]);
  221. TogglePlayerControllable(playerid, 1);
  222. GameTextForPlayer(playerid,"~g~GO GO GO", 900, 3);
  223. return 1;
  224. }
  225.  
  226. return 1;
  227. }
  228.  
  229. strvalEx(xxx[])
  230. {
  231. if(strlen(xxx) > 9)
  232. return 0;
  233. return strval(xxx);
  234. }
  235.  
  236. IsNumeric(const string[])
  237. {
  238. for (new i = 0, j = strlen(string); i < j; i++)
  239. {
  240. if (string[i] > '9' || string[i] < '0') return false;
  241. }
  242. return true;
  243. }
  244.  
  245. public OnPlayerDeath(playerid, killerid, reason)
  246. {
  247. new
  248. sString[128],
  249. pName[MAX_PLAYER_NAME],
  250. zName[MAX_PLAYER_NAME],
  251. Float:Health,
  252. Float:Armor;
  253.  
  254. if(g_IsPlayerDueling[playerid] == 1 && g_IsPlayerDueling[killerid] == 1)
  255. {
  256. GetPlayerHealth(killerid, Health);
  257. GetPlayerArmour(killerid, Armor);
  258.  
  259. GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
  260. GetPlayerName(killerid, zName, MAX_PLAYER_NAME);
  261.  
  262. if(Health > 90.0 && Armor > 90.0)
  263. {
  264. format(sString, sizeof(sString),"(News) %s has \"OWNED\" %s in the duel and has %.2f health and %.2f armor left!", zName,pName,Health,Armor);
  265. SendClientMessageToAll(COLOR_ORANGE, sString);
  266.  
  267. g_GotInvitedToDuel[playerid] = 0;g_HasInvitedToDuel[playerid] = 0;g_IsPlayerDueling[playerid] = 0;
  268. g_GotInvitedToDuel[killerid] = 0;g_HasInvitedToDuel[killerid] = 0;g_IsPlayerDueling[killerid] = 0;
  269. g_DuelInProgress = 0;
  270. return 1;
  271. }
  272. else
  273. {
  274. format(sString, sizeof(sString),"(News) %s has won the duel from %s and has %.2f health and %.2f armor left!", zName,pName,Health,Armor);
  275. SendClientMessageToAll(COLOR_ORANGE, sString);
  276.  
  277. g_GotInvitedToDuel[playerid] = 0;g_HasInvitedToDuel[playerid] = 0;g_IsPlayerDueling[playerid] = 0;
  278. g_GotInvitedToDuel[killerid] = 0;g_HasInvitedToDuel[killerid] = 0;g_IsPlayerDueling[killerid] = 0;
  279. g_DuelInProgress = 0;
  280. return 1;
  281. }
  282. }
  283. return 1;
  284. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement