Advertisement
Guest User

Pawn GeSHi Example

a guest
Sep 12th, 2012
538
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.67 KB | None | 0 0
  1. <?php
  2. require('geshi/geshi.php');
  3.    
  4. $source = '//-------------------------------------------------
  5. //
  6. // This is an example of using the AttachCameraToObject function
  7. // to create a no-clip flying camera.
  8. //
  9. // h02 2012
  10. //
  11. // SA-MP 0.3e and above
  12. //
  13. //-------------------------------------------------
  14.  
  15. #include <a_samp>
  16.  
  17. // Players Move Speed
  18. #define MOVE_SPEED              100.0
  19. #define ACCEL_RATE              0.03
  20.  
  21. // Players Mode
  22. #define CAMERA_MODE_NONE        0
  23. #define CAMERA_MODE_FLY         1
  24.  
  25. // Key state definitions
  26. #define MOVE_FORWARD            1
  27. #define MOVE_BACK               2
  28. #define MOVE_LEFT               3
  29. #define MOVE_RIGHT              4
  30. #define MOVE_FORWARD_LEFT       5
  31. #define MOVE_FORWARD_RIGHT      6
  32. #define MOVE_BACK_LEFT          7
  33. #define MOVE_BACK_RIGHT         8
  34.  
  35. // Enumeration for storing data about the player
  36. enum noclipenum
  37. {
  38.     cameramode,
  39.     flyobject,
  40.     mode,
  41.     lrold,
  42.     udold,
  43.     lastmove,
  44.     Float:accelmul
  45. }
  46. new noclipdata[MAX_PLAYERS][noclipenum];
  47.  
  48. //--------------------------------------------------
  49.  
  50. public OnFilterScriptExit()
  51. {
  52.     // If any players are still in edit mode, boot them out before the filterscript unloads
  53.     for(new x; x<MAX_PLAYERS; x++)
  54.     {
  55.         if(noclipdata[x][cameramode] == CAMERA_MODE_FLY) CancelFlyMode(x);
  56.     }
  57.     return 1;
  58. }
  59.  
  60. //--------------------------------------------------
  61.  
  62. public OnPlayerConnect(playerid)
  63. {
  64.     // Reset the data belonging to this player slot
  65.     noclipdata[playerid][cameramode]    = CAMERA_MODE_NONE;
  66.     noclipdata[playerid][lrold]         = 0;
  67.     noclipdata[playerid][udold]         = 0;
  68.     noclipdata[playerid][mode]          = 0;
  69.     noclipdata[playerid][lastmove]      = 0;
  70.     noclipdata[playerid][accelmul]      = 0.0;
  71.     return 1;
  72. }
  73.  
  74. //--------------------------------------------------
  75.  
  76. public OnPlayerCommandText(playerid, cmdtext[])
  77. {
  78.     if(!strcmp(cmdtext, "/flymode", true))
  79.     {
  80.         // Place the player in and out of edit mode
  81.         if(GetPVarType(playerid, "FlyMode")) CancelFlyMode(playerid);
  82.         else FlyMode(playerid);
  83.         return 1;
  84.     }
  85.     return 0;
  86. }
  87.  
  88. //--------------------------------------------------
  89.  
  90. public OnPlayerUpdate(playerid)
  91. {
  92.     if(noclipdata[playerid][cameramode] == CAMERA_MODE_FLY)
  93.     {
  94.         new keys,ud,lr;
  95.         GetPlayerKeys(playerid,keys,ud,lr);
  96.  
  97.         if(noclipdata[playerid][mode] && (GetTickCount() - noclipdata[playerid][lastmove] > 100))
  98.         {
  99.             // If the last move was > 100ms ago, process moving the object the players camera is attached to
  100.             MoveCamera(playerid);
  101.         }
  102.  
  103.         // Is the players current key state different than their last keystate?
  104.         if(noclipdata[playerid][udold] != ud || noclipdata[playerid][lrold] != lr)
  105.         {
  106.             if((noclipdata[playerid][udold] != 0 || noclipdata[playerid][lrold] != 0) && ud == 0 && lr == 0)
  107.             {   // All keys have been released, stop the object the camera is attached to and reset the acceleration multiplier
  108.                 StopPlayerObject(playerid, noclipdata[playerid][flyobject]);
  109.                 noclipdata[playerid][mode]      = 0;
  110.                 noclipdata[playerid][accelmul]  = 0.0;
  111.             }
  112.             else
  113.             {   // Indicates a new key has been pressed
  114.  
  115.                 // Get the direction the player wants to move as indicated by the keys
  116.                 noclipdata[playerid][mode] = GetMoveDirectionFromKeys(ud, lr);
  117.  
  118.                 // Process moving the object the players camera is attached to
  119.                 MoveCamera(playerid);
  120.             }
  121.         }
  122.         noclipdata[playerid][udold] = ud; noclipdata[playerid][lrold] = lr; // Store current keys pressed for comparison next update
  123.         return 0;
  124.     }
  125.     return 1;
  126. }
  127.  
  128. //--------------------------------------------------
  129.  
  130. stock GetMoveDirectionFromKeys(ud, lr)
  131. {
  132.     new direction = 0;
  133.    
  134.    if(lr < 0)
  135.     {
  136.         if(ud < 0)      direction = MOVE_FORWARD_LEFT;  // Up & Left key pressed
  137.         else if(ud > 0) direction = MOVE_BACK_LEFT;     // Back & Left key pressed
  138.         else            direction = MOVE_LEFT;          // Left key pressed
  139.     }
  140.     else if(lr > 0)     // Right pressed
  141.     {
  142.         if(ud < 0)      direction = MOVE_FORWARD_RIGHT;  // Up & Right key pressed
  143.         else if(ud > 0) direction = MOVE_BACK_RIGHT;     // Back & Right key pressed
  144.         else            direction = MOVE_RIGHT;          // Right key pressed
  145.     }
  146.     else if(ud < 0)     direction = MOVE_FORWARD;   // Up key pressed
  147.     else if(ud > 0)     direction = MOVE_BACK;      // Down key pressed
  148.    
  149.     return direction;
  150. }
  151.  
  152. //--------------------------------------------------
  153.  
  154. stock MoveCamera(playerid)
  155. {
  156.     new Float:FV[3], Float:CP[3];
  157.     GetPlayerCameraPos(playerid, CP[0], CP[1], CP[2]);          //  Cameras position in space
  158.    GetPlayerCameraFrontVector(playerid, FV[0], FV[1], FV[2]);  //  Where the camera is looking at
  159.  
  160.     // Increases the acceleration multiplier the longer the key is held
  161.     if(noclipdata[playerid][accelmul] <= 1) noclipdata[playerid][accelmul] += ACCEL_RATE;
  162.  
  163.     // Determine the speed to move the camera based on the acceleration multiplier
  164.     new Float:speed = MOVE_SPEED * noclipdata[playerid][accelmul];
  165.  
  166.     // Calculate the cameras next position based on their current position and the direction their camera is facing
  167.     new Float:X, Float:Y, Float:Z;
  168.     GetNextCameraPosition(noclipdata[playerid][mode], CP, FV, X, Y, Z);
  169.     MovePlayerObject(playerid, noclipdata[playerid][flyobject], X, Y, Z, speed);
  170.  
  171.     // Store the last time the camera was moved as now
  172.     noclipdata[playerid][lastmove] = GetTickCount();
  173.     return 1;
  174. }
  175.  
  176. //--------------------------------------------------
  177.  
  178. stock GetNextCameraPosition(move_mode, Float:CP[3], Float:FV[3], &Float:X, &Float:Y, &Float:Z)
  179. {
  180.    // Calculate the cameras next position based on their current position and the direction their camera is facing
  181.    #define OFFSET_X (FV[0]*6000.0)
  182.     #define OFFSET_Y (FV[1]*6000.0)
  183.     #define OFFSET_Z (FV[2]*6000.0)
  184.     switch(move_mode)
  185.     {
  186.         case MOVE_FORWARD:
  187.         {
  188.             X = CP[0]+OFFSET_X;
  189.             Y = CP[1]+OFFSET_Y;
  190.             Z = CP[2]+OFFSET_Z;
  191.         }
  192.         case MOVE_BACK:
  193.         {
  194.             X = CP[0]-OFFSET_X;
  195.             Y = CP[1]-OFFSET_Y;
  196.             Z = CP[2]-OFFSET_Z;
  197.         }
  198.         case MOVE_LEFT:
  199.         {
  200.             X = CP[0]-OFFSET_Y;
  201.             Y = CP[1]+OFFSET_X;
  202.             Z = CP[2];
  203.         }
  204.         case MOVE_RIGHT:
  205.         {
  206.             X = CP[0]+OFFSET_Y;
  207.             Y = CP[1]-OFFSET_X;
  208.             Z = CP[2];
  209.         }
  210.         case MOVE_BACK_LEFT:
  211.         {
  212.             X = CP[0]+(-OFFSET_X - OFFSET_Y);
  213.             Y = CP[1]+(-OFFSET_Y + OFFSET_X);
  214.             Z = CP[2]-OFFSET_Z;
  215.         }
  216.         case MOVE_BACK_RIGHT:
  217.         {
  218.             X = CP[0]+(-OFFSET_X + OFFSET_Y);
  219.             Y = CP[1]+(-OFFSET_Y - OFFSET_X);
  220.             Z = CP[2]-OFFSET_Z;
  221.         }
  222.         case MOVE_FORWARD_LEFT:
  223.         {
  224.             X = CP[0]+(OFFSET_X  - OFFSET_Y);
  225.             Y = CP[1]+(OFFSET_Y  + OFFSET_X);
  226.             Z = CP[2]+OFFSET_Z;
  227.         }
  228.         case MOVE_FORWARD_RIGHT:
  229.         {
  230.             X = CP[0]+(OFFSET_X  + OFFSET_Y);
  231.             Y = CP[1]+(OFFSET_Y  - OFFSET_X);
  232.             Z = CP[2]+OFFSET_Z;
  233.         }
  234.     }
  235. }
  236. //--------------------------------------------------
  237.  
  238. stock CancelFlyMode(playerid)
  239. {
  240.     DeletePVar(playerid, "FlyMode");
  241.     CancelEdit(playerid);
  242.     TogglePlayerSpectating(playerid, false);
  243.  
  244.     DestroyPlayerObject(playerid, noclipdata[playerid][flyobject]);
  245.     noclipdata[playerid][cameramode] = CAMERA_MODE_NONE;
  246.     return 1;
  247. }
  248.  
  249. //--------------------------------------------------
  250.  
  251. stock FlyMode(playerid)
  252. {
  253.     // Create an invisible object for the players camera to be attached to
  254.     new Float:X, Float:Y, Float:Z;
  255.     GetPlayerPos(playerid, X, Y, Z);
  256.     noclipdata[playerid][flyobject] = CreatePlayerObject(playerid, 19300, X, Y, Z, 0.0, 0.0, 0.0);
  257.  
  258.     // Place the player in spectating mode so objects will be streamed based on camera location
  259.     TogglePlayerSpectating(playerid, true);
  260.     // Attach the players camera to the created object
  261.     AttachCameraToPlayerObject(playerid, noclipdata[playerid][flyobject]);
  262.  
  263.     SetPVarInt(playerid, "FlyMode", 1);
  264.     noclipdata[playerid][cameramode] = CAMERA_MODE_FLY;
  265.     return 1;
  266. }
  267.  
  268. //--------------------------------------------------';
  269.  
  270. $geshi = new GeSHi($source, 'pawn');
  271. echo $geshi->parse_code();
  272.  
  273. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement