Advertisement
Guest User

Sandra

a guest
Mar 11th, 2009
3,271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.13 KB | None | 0 0
  1. /*===================================================================================================*\
  2. ||===================================================================================================||
  3. ||                ________    ________    ___    _    ______     ______     ________                 ||
  4. ||          \    |   _____|  |  ____  |  |   \  | |  |   _  \   |  _   \   |  ____  |    /           ||
  5. ||  ======== \   |  |_____   | |____| |  | |\ \ | |  |  | |  |  | |_|  /   | |____| |   / ========   ||
  6. ||            |  | _____  |  |  ____  |  | | \ \| |  |  | |  |  |  _  \    |  ____  |  |             ||
  7. ||  ======== /    ______| |  | |    | |  | |  \ \ |  |  |_|  |  | |  \ \   | |    | |   \ ========   ||
  8. ||          /    |________|  |_|    |_|  |_|   \__|  |______/   |_|   \_|  |_|    |_|    \           ||
  9. ||                                                                                                   ||
  10. ||===================================================================================================||
  11. ||                          Created on the 10th of March 2009 by =>Sandra<=                          ||
  12. ||                                    Do NOT remove my credits!!                                     ||
  13. \*===================================================================================================*/
  14.  
  15.  
  16. #include <a_samp>
  17.  
  18. #define MAX_CCTVS 100
  19. #define MAX_CCTVMENUS 10  //(This number should be MAX_CCTVS divided by 10  (round up))
  20.  
  21. //CameraInfo
  22. new TotalCCTVS;
  23. new CameraName[MAX_CCTVS][32];
  24. new Float:CCTVLA[MAX_PLAYERS][3];  //CCTV LookAt
  25. new Float:CCTVLAO[MAX_CCTVS][3];
  26. new Float:CCTVRadius[MAX_PLAYERS]; //CCTV Radius
  27. new Float:CCTVDegree[MAX_PLAYERS] = 0.0;
  28. new Float:CCTVCP[MAX_CCTVS][4]; //CCTV CameraPos
  29. new CurrentCCTV[MAX_PLAYERS] = -1;
  30.  
  31. //TextDraw
  32. new Text:TD;
  33.  
  34. //Menus:
  35. new Menu:CCTVMenu[MAX_CCTVMENUS];
  36. new MenuType[MAX_CCTVMENUS];
  37. new TotalMenus;
  38. new PlayerMenu[MAX_PLAYERS];
  39.  
  40. enum LP
  41. {
  42.     Float:LX,
  43.     Float:LY,
  44.     Float:LZ,
  45.     Float:LA,
  46.     LInterior
  47. }
  48. new Spawned[MAX_PLAYERS];
  49. new LastPos[MAX_PLAYERS][LP];
  50.  
  51. new KeyTimer[MAX_PLAYERS];
  52.  
  53. public OnFilterScriptInit()
  54. {
  55.  
  56.     //Put All AddCCTV-lines here below:
  57.     //======================================================
  58.     //======================================================
  59.     AddCCTV("LS Grovestreet", 2491.7839, -1666.6194, 46.3232, 0.0);
  60.     AddCCTV("LS Downtown", 1102.6440, -837.8973, 122.7000, 180.0);
  61.     AddCCTV("SF Wang Cars", -1952.4282,285.9786,57.7031, 90.0);
  62.     AddCCTV("SF Airport", -1275.8070, 52.9402, 82.9162, 0.0);
  63.     AddCCTV("SF Crossroad", -1899.0861,731.0627,65.2969, 90.0);
  64.     AddCCTV("SF Tower", -1753.6606,884.7520,305.8750, 150.0);
  65.     AddCCTV("LV The Strip 1", 2137.2390, 2143.8286, 30.6719, 270.0);
  66.     AddCCTV("LV The Strip 2", 1971.7627, 1423.9323, 82.1563, 270.0);
  67.     AddCCTV("Mount Chiliad", -2432.5852, -1620.1143, 546.8554, 270.0);
  68.     AddCCTV("Sherman Dam", -702.9260, 1848.8094, 116.0507, 0.0);
  69.     AddCCTV("Desert", 35.1291, 2245.0901, 146.6797, 310.0);
  70.     AddCCTV("Query", 588.1079,889.4715,-14.9023, 270.0);
  71.     AddCCTV("Water", 635.6223,498.1748,20.3451, 90.0);
  72.     //======================================================
  73.     //======================================================
  74.  
  75.     //Creating Textdraw
  76.     TD = TextDrawCreate(160, 400, "~y~Keys:~n~Arrow-Keys: ~w~Move The Camera~n~~y~Sprint-Key: ~w~Speed Up~n~~y~Crouch-Key: ~w~Exit Camera");
  77.     TextDrawLetterSize(TD, 0.4, 0.9);
  78.     TextDrawSetShadow(TD, 0);
  79.     TextDrawUseBox(TD,1);
  80.     TextDrawBoxColor(TD,0x00000055);
  81.     TextDrawTextSize(TD, 380, 400);
  82.  
  83.     //Creating Menu's
  84.     new Count, Left = TotalCCTVS;
  85.     for(new menu; menu<MAX_CCTVMENUS; menu++)
  86.     {
  87.         if(Left > 12)
  88.         {
  89.             CCTVMenu[menu] = CreateMenu("Choose Camera:", 1, 200, 100, 220);
  90.             TotalMenus++;
  91.             MenuType[menu] = 1;
  92.             for(new i; i<11; i++)
  93.             {
  94.                 AddMenuItem(CCTVMenu[menu], 0, CameraName[Count]);
  95.                 Count++;
  96.                 Left--;
  97.             }
  98.             AddMenuItem(CCTVMenu[menu], 0, "Next");
  99.         }
  100.         else if(Left<13 && Left > 0)
  101.         {
  102.             CCTVMenu[menu] = CreateMenu("Choose Camera:", 1, 200, 100, 220);
  103.             TotalMenus++;
  104.             MenuType[menu] = 2;
  105.             new tmp = Left;
  106.             for(new i; i<tmp; i++)
  107.             {
  108.                 AddMenuItem(CCTVMenu[menu], 0, CameraName[Count]);
  109.                 Count++;
  110.                 Left--;
  111.             }
  112.         }
  113.     }
  114.  
  115.     print("\n\n-----------------------------------------------");
  116.     print(" Remote CCTV Filterscript by =>Sandra<= Loaded!");
  117.     print("-----------------------------------------------\n\n");
  118.     return 1;
  119. }
  120.  
  121. public OnFilterScriptExit()
  122. {
  123.     TextDrawHideForAll(TD);
  124.     TextDrawDestroy(TD);
  125.     for(new i; i<TotalMenus; i++)
  126.     {
  127.         DestroyMenu(CCTVMenu[i]);
  128.     }
  129.     return 1;
  130. }
  131.  
  132. public OnPlayerConnect(playerid)
  133. {
  134.     Spawned[playerid] = 0;
  135.     CurrentCCTV[playerid] = -1;
  136.     return 1;
  137. }
  138.  
  139. public OnPlayerDisconnect(playerid, reason)
  140. {
  141.     if(CurrentCCTV[playerid] > -1)
  142.     {
  143.         KillTimer(KeyTimer[playerid]);
  144.         TextDrawHideForPlayer(playerid, TD);
  145.     }
  146.     CurrentCCTV[playerid] = -1;
  147.     return 1;
  148. }
  149.  
  150. public OnPlayerSpawn(playerid)
  151. {
  152.     Spawned[playerid] = 1;
  153.     return 1;
  154. }
  155. public OnPlayerDeath(playerid, killerid, reason)
  156. {
  157.     Spawned[playerid] = 0;
  158.     return 1;
  159. }
  160.  
  161. public OnPlayerCommandText(playerid, cmdtext[])
  162. {
  163.     if (strcmp("/cctv", cmdtext, true) == 0)
  164.     {
  165.         if(Spawned[playerid] == 1)
  166.         {
  167.             PlayerMenu[playerid] = 0;
  168.             TogglePlayerControllable(playerid, 0);
  169.             ShowMenuForPlayer(CCTVMenu[0], playerid);
  170.         }
  171.         else
  172.         {
  173.             SendClientMessage(playerid, 0xFF0000AA, "Please spawn first!");
  174.         }
  175.         return 1;
  176.     }
  177.    
  178.     if (strcmp("/exitcctv", cmdtext, true) == 0)
  179.     {
  180.         if(CurrentCCTV[playerid] > -1)
  181.         {
  182.             SetPlayerPos(playerid, LastPos[playerid][LX], LastPos[playerid][LY], LastPos[playerid][LZ]);
  183.             SetPlayerFacingAngle(playerid, LastPos[playerid][LA]);
  184.             SetPlayerInterior(playerid, LastPos[playerid][LInterior]);
  185.             TogglePlayerControllable(playerid, 1);
  186.             KillTimer(KeyTimer[playerid]);
  187.             SetCameraBehindPlayer(playerid);
  188.             TextDrawHideForPlayer(playerid, TD);
  189.             CurrentCCTV[playerid] = -1;
  190.             return 1;
  191.         }
  192.     }
  193.     return 0;
  194. }
  195.  
  196.  
  197. forward CheckKeyPress(playerid);
  198. public CheckKeyPress(playerid)
  199. {
  200.     new keys, updown, leftright;
  201.     GetPlayerKeys(playerid, keys, updown, leftright);
  202.     if(CurrentCCTV[playerid] > -1 && PlayerMenu[playerid] == -1)
  203.     {
  204.         if(leftright == KEY_RIGHT)
  205.         {
  206.             if(keys == KEY_SPRINT)
  207.             {
  208.                 CCTVDegree[playerid] = (CCTVDegree[playerid] - 2.0);
  209.             }
  210.             else
  211.             {
  212.                 CCTVDegree[playerid] = (CCTVDegree[playerid] - 0.5);
  213.             }
  214.             if(CCTVDegree[playerid] < 0)
  215.             {
  216.                 CCTVDegree[playerid] = 359;
  217.             }
  218.             MovePlayerCCTV(playerid);
  219.  
  220.         }
  221.         if(leftright == KEY_LEFT)
  222.         {
  223.             if(keys == KEY_SPRINT)
  224.             {
  225.                 CCTVDegree[playerid] = (CCTVDegree[playerid] + 2.0);
  226.             }
  227.             else
  228.             {
  229.                 CCTVDegree[playerid] = (CCTVDegree[playerid] + 0.5);
  230.             }
  231.             if(CCTVDegree[playerid] >= 360)
  232.             {
  233.                 CCTVDegree[playerid] = 0;
  234.             }
  235.             MovePlayerCCTV(playerid);
  236.  
  237.         }
  238.         if(updown == KEY_UP)
  239.         {
  240.             if(CCTVRadius[playerid] < 25)
  241.             {
  242.                 if(keys == KEY_SPRINT)
  243.                 {
  244.                     CCTVRadius[playerid] =  (CCTVRadius[playerid] + 0.5);
  245.                     MovePlayerCCTV(playerid);
  246.                 }
  247.                 else
  248.                 {
  249.                     CCTVRadius[playerid] =  (CCTVRadius[playerid] + 0.1);
  250.                     MovePlayerCCTV(playerid);
  251.                 }
  252.             }
  253.         }
  254.         if(updown == KEY_DOWN)
  255.         {
  256.             if(keys == KEY_SPRINT)
  257.             {
  258.                 if(CCTVRadius[playerid] >= 0.6)
  259.                 {
  260.                     CCTVRadius[playerid] =  (CCTVRadius[playerid] - 0.5);
  261.                     MovePlayerCCTV(playerid);
  262.                 }
  263.             }
  264.             else
  265.             {
  266.                 if(CCTVRadius[playerid] >= 0.2)
  267.                 {
  268.                     CCTVRadius[playerid] =  (CCTVRadius[playerid] - 0.1);
  269.                     MovePlayerCCTV(playerid);
  270.                 }
  271.             }
  272.         }
  273.         if(keys == KEY_CROUCH)
  274.         {
  275.             OnPlayerCommandText(playerid, "/exitcctv");
  276.         }
  277.     }
  278.     MovePlayerCCTV(playerid);
  279. }
  280.  
  281. stock MovePlayerCCTV(playerid)
  282. {
  283.     CCTVLA[playerid][0] = CCTVLAO[CurrentCCTV[playerid]][0] + (floatmul(CCTVRadius[playerid], floatsin(-CCTVDegree[playerid], degrees)));
  284.     CCTVLA[playerid][1] = CCTVLAO[CurrentCCTV[playerid]][1] + (floatmul(CCTVRadius[playerid], floatcos(-CCTVDegree[playerid], degrees)));
  285.     SetPlayerCameraLookAt(playerid, CCTVLA[playerid][0], CCTVLA[playerid][1], CCTVLA[playerid][2]);
  286. }
  287.    
  288.  
  289. stock AddCCTV(name[], Float:X, Float:Y, Float:Z, Float:Angle)
  290. {
  291.     if(TotalCCTVS >= MAX_CCTVS) return 0;
  292.     format(CameraName[TotalCCTVS], 32, "%s", name);
  293.     CCTVCP[TotalCCTVS][0] = X;
  294.     CCTVCP[TotalCCTVS][1] = Y;
  295.     CCTVCP[TotalCCTVS][2] = Z;
  296.     CCTVCP[TotalCCTVS][3] = Angle;
  297.     CCTVLAO[TotalCCTVS][0] = X;
  298.     CCTVLAO[TotalCCTVS][1] = Y;
  299.     CCTVLAO[TotalCCTVS][2] = Z-10;
  300.     TotalCCTVS++;
  301.     return TotalCCTVS-1;
  302. }
  303.  
  304. SetPlayerToCCTVCamera(playerid, CCTV)
  305. {
  306.     if(CCTV >= TotalCCTVS)
  307.     {
  308.         SendClientMessage(playerid, 0xFF0000AA, "Invald CCTV");
  309.         return 1;
  310.     }
  311.     if(CurrentCCTV[playerid] == -1)
  312.     {
  313.         GetPlayerPos(playerid, LastPos[playerid][LX], LastPos[playerid][LY], LastPos[playerid][LZ]);
  314.         GetPlayerFacingAngle(playerid, LastPos[playerid][LA]);
  315.         LastPos[playerid][LInterior] = GetPlayerInterior(playerid);
  316.     }
  317.     else
  318.     {
  319.         KillTimer(KeyTimer[playerid]);
  320.     }
  321.     CurrentCCTV[playerid] = CCTV;
  322.     TogglePlayerControllable(playerid, 0);
  323.     //SetPlayerPos(playerid, CCTVCP[CCTV][0], CCTVCP[CCTV][1], (CCTVCP[CCTV][2]-50));
  324.     SetPlayerPos(playerid, CCTVCP[CCTV][0], CCTVCP[CCTV][1], -100.0);
  325.     SetPlayerCameraPos(playerid, CCTVCP[CCTV][0], CCTVCP[CCTV][1], CCTVCP[CCTV][2]);
  326.     SetPlayerCameraLookAt(playerid, CCTVLAO[CCTV][0], (CCTVLAO[CCTV][1]+0.2), CCTVLAO[CCTV][2]);
  327.     CCTVLA[playerid][0] = CCTVLAO[CCTV][0];
  328.     CCTVLA[playerid][1] = CCTVLAO[CCTV][1]+0.2;
  329.     CCTVLA[playerid][2] = CCTVLAO[CCTV][2];
  330.     CCTVRadius[playerid] = 12.5;
  331.     CCTVDegree[playerid] = CCTVCP[CCTV][3];
  332.     MovePlayerCCTV(playerid);
  333.     KeyTimer[playerid] = SetTimerEx("CheckKeyPress", 75, 1, "i", playerid);
  334.     TextDrawShowForPlayer(playerid, TD);
  335.     return 1;
  336. }
  337.  
  338. public OnPlayerSelectedMenuRow(playerid, row)
  339. {
  340.     new Menu:Current = GetPlayerMenu(playerid);
  341.     for(new menu; menu<TotalMenus; menu++)
  342.     {
  343.        
  344.         if(Current == CCTVMenu[menu])
  345.         {
  346.             if(MenuType[PlayerMenu[playerid]] == 1)
  347.             {
  348.                 if(row == 11)
  349.                 {
  350.                     ShowMenuForPlayer(CCTVMenu[menu+1], playerid);
  351.                     TogglePlayerControllable(playerid, 0);
  352.                     PlayerMenu[playerid] = (menu+1);
  353.                 }
  354.                 else
  355.                 {
  356.                     if(PlayerMenu[playerid] == 0)
  357.                     {
  358.                         SetPlayerToCCTVCamera(playerid, row);
  359.                         PlayerMenu[playerid] = -1;
  360.                     }
  361.                     else
  362.                     {
  363.                         SetPlayerToCCTVCamera(playerid, ((PlayerMenu[playerid]*11)+row));
  364.                         PlayerMenu[playerid] = -1;
  365.                     }
  366.                 }
  367.             }
  368.             else
  369.             {
  370.                 if(PlayerMenu[playerid] == 0)
  371.                 {
  372.                     SetPlayerToCCTVCamera(playerid, row);
  373.                     PlayerMenu[playerid] = -1;
  374.                 }
  375.                 else
  376.                 {
  377.                     SetPlayerToCCTVCamera(playerid, ((PlayerMenu[playerid]*11)+row));
  378.                     PlayerMenu[playerid] = -1;
  379.                 }
  380.             }
  381.         }
  382.     }
  383.                    
  384.     return 1;
  385. }
  386.  
  387. public OnPlayerExitedMenu(playerid)
  388. {
  389.     TogglePlayerControllable(playerid, 1);
  390.     PlayerMenu[playerid] = -1;
  391.     return 1;
  392. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement