Advertisement
Guest User

pOutRun - iPLEOMAX

a guest
Jun 26th, 2011
732
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 9.18 KB | None | 0 0
  1. /*------------------------------------------------------------------------------------------------------------- */
  2. /* © iPLEOMAX's Outrun race system. Similar to NFS UG2 outrun race.                                                */
  3. /* Made from scratch. You will need zcmd & sscanf to use this.                                                  */
  4. /*------------------------------------------------------------------------------------------------------------- */
  5.  
  6. #include <a_samp>
  7. #include <zcmd>
  8. #include <sscanf2>
  9.  
  10. #define COLOR_RED 0xAA3333AA
  11. #define COLOR_LIGHTBLUE 0x33CCFFAA
  12. #define COLOR_WHITE 0xFFFFFFAA
  13. #define COLOR_BRIGHTRED 0xFF0000AA
  14. #define COLOR_LIGHTGREEN 0x24FF0AB9
  15.  
  16. new ORTimer;
  17. new Float:VVX[MAX_PLAYERS];
  18. new Float:VVY[MAX_PLAYERS];
  19. new Float:VVZ[MAX_PLAYERS];
  20. new Float:SPD[MAX_PLAYERS];
  21.  
  22. public OnFilterScriptInit()
  23. {
  24.     ORTimer = SetTimer("ORCheck",300,true);
  25.     return true;
  26. }
  27.  
  28. public OnFilterScriptExit()
  29. {
  30.     KillTimer(ORTimer);
  31.     return true;
  32. }
  33.  
  34. public OnPlayerConnect(playerid)
  35. {
  36.     SetPVarInt(playerid, "LR", -1);
  37.     SetPVarInt(playerid, "LRRequest",-1);
  38.     SetPVarInt(playerid, "bet",0);
  39.     return true;
  40. }
  41.  
  42. public OnPlayerDeath(playerid, killerid, reason)
  43. {
  44.     if(GetPVarInt(playerid, "LRRequest") != -1)
  45.     {
  46.         SendClientMessage(playerid, COLOR_BRIGHTRED, "You lost the Outrun race..");
  47.         SetPVarInt(playerid, "ORLoser", 1);
  48.     }
  49.     return true;
  50. }
  51.  
  52. public OnPlayerStateChange(playerid, newstate, oldstate)
  53. {
  54.     if(GetPVarInt(playerid, "LRRequest") != -1)
  55.     {
  56.         SendClientMessage(playerid, COLOR_BRIGHTRED, "You lost the Outrun because you exited the vehicle.");
  57.         SetPVarInt(playerid, "ORLoser", 1);
  58.     }
  59.     return true;
  60. }
  61.  
  62. public OnPlayerDisconnect(playerid, reason)
  63. {
  64.     if(GetPVarInt(playerid, "LRRequest") != -1)
  65.     {
  66.         SetPVarInt(playerid, "ORLoser", 1);
  67.     }
  68.     return true;
  69. }
  70.  
  71. forward ORCheck();
  72. public ORCheck()
  73. {
  74.     for(new i=0; i<MAX_PLAYERS; i++)
  75.     {
  76.         if(IsPlayerConnected(i) && !IsPlayerNPC(i) && GetPVarInt(i, "LR") != -1)
  77.         {
  78.             new r;
  79.             r = GetPVarInt(i,"LR");
  80.             if(GetPVarInt(r, "ORLoser") == 1) ORLoser(r);
  81.             if(GetPVarInt(i, "ORLoser") == 1) ORLoser(i);
  82.             if(IsPlayerInAnyVehicle(i))
  83.             {
  84.                 new Float:FX, Float:FY;
  85.                 GetXYInFrontOfPlayer(i, FX, FY, 13);
  86.                 new Float:X, Float:Y, Float:Z;
  87.                 GetPlayerPos(i,X,Y,Z);
  88.                 new Float:X2, Float:Y2, Float:Z2;
  89.                 GetPlayerPos(r,X2,Y2,Z2);
  90.                 new Float:VZA, Float:VZAB;
  91.                 GetVehicleZAngle(GetPlayerVehicleID(i),VZA);
  92.                 GetVehicleZAngle(GetPlayerVehicleID(r),VZAB);
  93.                 if(!IsPlayerInRangeOfPoint(r,120,X,Y,Z))
  94.                 {
  95.                     GameTextForPlayer(i,"~g~~n~~n~~n~~n~~n~~n~~n~You are far ahead...",2000,3);
  96.                     GameTextForPlayer(r,"~r~~n~~n~~n~~n~~n~~n~~n~Your Rival is far ahead!",2000,3);
  97.                 }
  98.                 if(!IsPlayerInRangeOfPoint(r,300,X,Y,Z))
  99.                 {
  100.                     ORLoser(r);
  101.                 }
  102.                 GetVehicleVelocity(GetPlayerVehicleID(i), VVX[i],VVY[i], VVZ[i]);
  103.                 GetVehicleVelocity(GetPlayerVehicleID(r), VVX[r],VVY[r], VVZ[r]);
  104.                 SPD[i] = floatsqroot(((VVX[i]*VVX[i])+(VVY[i]*VVY[i]))+(VVZ[i]*VVZ[i]))*100;
  105.                 SPD[r] = floatsqroot(((VVX[r]*VVX[r])+(VVY[r]*VVY[r]))+(VVZ[r]*VVZ[r]))*100;
  106.                 if(IsPlayerInRangeOfPoint(r,15,FX,FY,Z))
  107.                 {
  108.                     if(VZA >= VZAB-60 && VZA <= VZAB+60)
  109.                     {
  110.                         GameTextForPlayer(i,"~r~~n~~n~~n~~n~~n~~n~~n~Your Rival has the Lead!",1000,3);
  111.                         GameTextForPlayer(r,"~g~~n~~n~~n~~n~~n~~n~~n~You are leading now.",1000,3);
  112.                         SetPVarInt(r,"LR",i);
  113.                         SetPVarInt(i,"LR",-1);
  114.                     }
  115.                 }
  116.                 if(IsPlayerInRangeOfPoint(r,25,X,Y,Z))
  117.                 {
  118.                     if(SPD[i]+25 < SPD[r])
  119.                     {
  120.                         GameTextForPlayer(i,"~r~~n~~n~~n~~n~~n~~n~~n~Your Rival has the Lead!",1000,3);
  121.                         GameTextForPlayer(r,"~g~~n~~n~~n~~n~~n~~n~~n~You are leading now.",1000,3);
  122.                         SetPVarInt(r,"LR",i);
  123.                         SetPVarInt(i,"LR",-1);
  124.                     }
  125.                 }
  126.             }
  127.             return true;
  128.         }
  129.     }
  130.     return true;
  131. }
  132.  
  133. forward ORLoser(playerid);
  134. public ORLoser(playerid)
  135. {
  136.     new r;
  137.     r = GetPVarInt(playerid, "LRRequest");
  138.     GameTextForPlayer(playerid,"~r~~n~~n~~n~~n~~n~~n~You Lost the challenge...",5000,3);
  139.     GameTextForPlayer(r,"~g~~n~~n~~n~~n~~n~~n~] You Won the challenge!",5000,3);
  140.     SetPVarInt(r, "LRRequest",-1);
  141.     SetPVarInt(playerid, "LRRequest",-1);
  142.     SetPVarInt(playerid,"LR", -1);
  143.     SetPVarInt(r,"LR", -1);
  144.     SetPVarInt(playerid, "ORLoser", 0);
  145.     SetPVarInt(r, "ORLoser", 0);
  146.     new bet, msg1[10], msg2[10];
  147.     bet = GetPVarInt(playerid,"bet");
  148.     GivePlayerMoney(r, bet);
  149.     GivePlayerMoney(playerid, -bet);
  150.     format(msg2,10,"Bet Lost. %i$",-bet);
  151.     format(msg1,10,"Bet Won. +%i$",bet);
  152.     SendClientMessage(playerid,COLOR_BRIGHTRED,msg2);
  153.     SendClientMessage(r,COLOR_LIGHTGREEN,msg1);
  154.     new ORmessage[512];
  155.     format(ORmessage,sizeof(ORmessage),"* %s won an Outrun race against %s with bet %i $",GetName(r),GetName(playerid),bet);
  156.     SendClientMessageToAll(COLOR_LIGHTBLUE, ORmessage);
  157.     return true;
  158. }
  159.  
  160. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  161. {
  162.     switch(dialogid)
  163.     {
  164.         case 1337:
  165.         {
  166.             if(!response)
  167.             {
  168.                 new PID;
  169.                 PID = GetPVarInt(playerid, "LRRequest");
  170.                 TogglePlayerControllable(PID, true);
  171.                 SendClientMessage(PID,COLOR_BRIGHTRED,"Sorry, the player is not interested to race.");
  172.                 SetPVarInt(playerid, "LRRequest",-1);
  173.                 return true;
  174.             }
  175.             else
  176.             {
  177.                 new PID;
  178.                 PID = GetPVarInt(playerid, "LRRequest");
  179.                 SetPVarInt(PID,"LR",playerid);
  180.                 TogglePlayerControllable(PID, true);
  181.                 new Float:X, Float:Y, Float:Z, Float:VZ;
  182.                 GetVehiclePos(GetPlayerVehicleID(PID),X,Y,Z);
  183.                 GetXYInFrontOfPlayer(PID, X,Y,-8);
  184.                 SetVehiclePos(GetPlayerVehicleID(playerid),X,Y,Z+0.2);
  185.                 GetVehicleZAngle(GetPlayerVehicleID(PID),VZ);
  186.                 SetVehicleZAngle(GetPlayerVehicleID(playerid),VZ);
  187.                 GameTextForPlayer(PID,"~g~Race Accepted.. Run!",3000,3);
  188.                 GameTextForPlayer(playerid,"~g~Now follow him!",3000,3);
  189.             }
  190.         }
  191.     }
  192.     return true;
  193. }
  194.  
  195. CMD:outrunhelp(playerid, params[])
  196. {
  197.     SendClientMessage(playerid, COLOR_LIGHTBLUE, "[_ Outrun Race Help _]");
  198.     SendClientMessage(playerid, COLOR_WHITE, "> Use /challenge [Player ID] [Bet Amount $] to begin an outrun race.");
  199.     SendClientMessage(playerid, COLOR_WHITE, "> The race is simple, go as far as possible ahead from your rival to win the race.");
  200.     SendClientMessage(playerid, COLOR_WHITE, "> Just overtake your rival to take the lead.");
  201.     SendClientMessage(playerid, COLOR_WHITE, "© iPLEOMAX.");
  202.     return true;
  203. }
  204.  
  205. CMD:challenge(playerid, params[])
  206. {
  207.     new rplayer, bet;
  208.     if(!sscanf(params,"ui",rplayer,bet))
  209.     {
  210.         if(IsPlayerConnected(rplayer) && !IsPlayerNPC(playerid))
  211.         {
  212.         if(IsPlayerInAnyVehicle(rplayer))
  213.         {
  214.         if(IsPlayerInAnyVehicle(playerid))
  215.         {
  216.         if(bet <= 50000 && bet >= 5000)
  217.         {
  218.         if(GetPlayerMoney(playerid) >= bet)
  219.         {
  220.         if(GetPVarInt(rplayer,"LRRequest") == -1)
  221.         {
  222.         if(GetPVarInt(rplayer,"LR") == -1)
  223.         {
  224.         new Float:X,Float:Y,Float:Z;
  225.         GetPlayerPos(playerid,X,Y,Z);
  226.         if(IsPlayerInRangeOfPoint(rplayer,16,X,Y,Z))
  227.         {
  228.         new msg[24];
  229.         format(msg,24,"Bet: %i $",bet);
  230.         SendClientMessage(playerid,COLOR_LIGHTBLUE,msg);
  231.         SetPVarInt(playerid,"bet",bet);
  232.         SetPVarInt(rplayer,"bet",bet);
  233.         SetPVarInt(rplayer, "LRRequest", playerid);
  234.         SetPVarInt(playerid, "LRRequest", rplayer);
  235.         new info[160], pname[MAX_PLAYER_NAME];
  236.         GetPlayerName(playerid,pname,sizeof(pname));
  237.         format(info,160,"%s is asking you to start a challenege race\n with a bet of $%i, do you want to do this?",pname,bet);
  238.         ShowPlayerDialog(rplayer, 1337, DIALOG_STYLE_MSGBOX,"Challenge Race:",info,"Ofcouse","Nope");
  239.         TogglePlayerControllable(playerid,false);
  240.         } else SendClientMessage(playerid, COLOR_BRIGHTRED, "You should be near to that player.");
  241.         } else SendClientMessage(playerid, COLOR_BRIGHTRED, "Player is currently racing.");
  242.         } else SendClientMessage(playerid, COLOR_BRIGHTRED, "Player is already invited by someone.");
  243.         } else SendClientMessage(playerid, COLOR_BRIGHTRED, "You don't have that much money..");
  244.         } else SendClientMessage(playerid, COLOR_RED, "Min Amount: $5,000 Max Amount: $50,000");
  245.         } else SendClientMessage(playerid, COLOR_BRIGHTRED, "You need a vehicle to challenge someone.");
  246.         } else SendClientMessage(playerid, COLOR_BRIGHTRED, "The player you want to challenge doesn't have a vehicle.");
  247.         } else SendClientMessage(playerid, COLOR_RED, "Player is not connected.");
  248.     } else SendClientMessage(playerid, COLOR_RED, "Usage: /challenge [Player ID] [Bet Amount]");
  249.     return true;
  250. }
  251.  
  252. // Thanks a bunch to Y_Less for this function. =)
  253. GetXYInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
  254. {                                                 // Created by Y_Less
  255.  
  256.     new Float:a;
  257.  
  258.     GetPlayerPos(playerid, x, y, a);
  259.     GetPlayerFacingAngle(playerid, a);
  260.  
  261.     if (GetPlayerVehicleID(playerid)) {
  262.         GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
  263.     }
  264.  
  265.     x += (distance * floatsin(-a, degrees));
  266.     y += (distance * floatcos(-a, degrees));
  267. }
  268.  
  269. stock GetName(playerid)
  270. {
  271.     new playername[MAX_PLAYER_NAME];
  272.     GetPlayerName(playerid, playername,sizeof(playername));
  273.     return playername;
  274. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement