KAKAN

VCMP rob shit.

Jul 19th, 2016
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 4.36 KB | None | 0 0
  1. /* I've left scripting in Squirrel long ago, so, it may contain bugs. It's just an example of how to do that shit efficiently. Link to original topic: http://forum.vc-mp.org/?topic=3342.0 */
  2.  
  3. //The amount of money one should get when he/she robs shit
  4. const ROB_CASH = 25000;
  5. //Everyone knows it, it's the time between the pickup's death and spawn
  6. const PICKUP_RESPAWN_TIME = 30000; //in ms
  7.  
  8. class RobSystem
  9. {
  10.     //Variables to store the data.
  11.     //The player instance.
  12.     player = null;
  13.     //His/her skills
  14.     robskill = 0;
  15.     //Database instance
  16.     db = null;
  17.  
  18.     //We'll use the variables in this function to store the data for later use.
  19.     /*
  20.     @arg player - instance
  21.     @arg db - userdata( database )
  22.     @ret integer
  23.     */
  24.     constructor( player, db ){
  25.         //Store the player instance for later use.
  26.         this.player = player;
  27.         //Store the database instance
  28.         this.db = db;
  29.         //Query the player's data.
  30.         local robs = Query( "SELECT Robskill FROM Robskills WHERE Name='%s'", player.Name );
  31.         //Check if the user exists
  32.         if( !robs ){
  33.             //THe user doesn't exist, insert him to the table.
  34.             Query( "INSET INTO Robskills( Name, Robskill ) VALUES( '%s' , 0 )", player.Name );
  35.             //Return the Robskill value.
  36.             return 0;
  37.         }
  38.         //Fetch the robskill of the user's.
  39.         local data = ::GetSQLColumnData( robs );
  40.         //Check if the data exists
  41.         if( data ) {
  42.             //Set the value.
  43.             this.robskill = data;
  44.             //Return the robskill
  45.             return data;
  46.         }
  47.         //Alright, return 0 if anything goes wrong during this process.
  48.         return 0;
  49.     }
  50.  
  51.     /*
  52.     @ret integer
  53.     */
  54.     function GetSkills(){
  55.         //Return the player's robskill
  56.         return this.robskill;
  57.     }
  58.  
  59.     /*
  60.     @arg value - integer
  61.     @ret integer
  62.     */
  63.     function IncSkills( value = 1 ){
  64.         //Increase the value.
  65.         this.robskill += value;
  66.         //Increase the cash of the player.
  67.         this.player.Cash += ::ROB_CASH*value;
  68.         //Return it.
  69.         return this.robskill;
  70.     }
  71.  
  72.     function Query( string ){
  73.         vargv.insert( 0, this );
  74.         return ::QuerySQL( this.db  format.acall( vargv ) );
  75.     }
  76.  
  77. }
  78.  
  79. //Called when the script is loaded
  80. function onScriptLoad(){
  81.     //Create an empty array
  82.     robber <- array(100);
  83.     //Connect to the database.
  84.     db <- ConnectSQL("RobSys.db");
  85.     //Finally, create the pickups
  86.     createPickups();
  87. }
  88.  
  89. //Called when a player joins.
  90. function onPlayerJoin( player )
  91. {
  92.     //Initialize our class
  93.     robber[ player.ID ] = RobSystem( player, db );
  94. }
  95.  
  96. //Called when a player types a command.
  97. function onPlayerCommand( player, cmd, args )
  98. {
  99.     if( cmd == "robskill" ){
  100.         PrivMessage( player, "Your robskills are: " + robber[ player.ID ].GetSkills() );
  101.     }
  102. }
  103.  
  104. //Called when a player picks up a pickup
  105. function onPickupPickedUp( player, pickup )
  106. {
  107.     if( pickup.Model == 408 ){
  108.         //Cache the player's postion.
  109.         local p = player.Pos;
  110.         //Message everyone that the user has robbed shits.
  111.         Message( player.Name + " has robbed: " + GetDistrictName( p.x, p.y ) );
  112.         //Increase his/her skills.
  113.         robber[ player.ID ].IncSkills();
  114.         //Announce it to the player.
  115.         Announce( "~y~You've robbed: " + ROB_CASH , player );
  116.     }
  117. }
  118.  
  119. //Create the pickups
  120. function createPickups(){
  121.     //Cache the model.
  122.     local model = 408, arr = [
  123.         Vector( 204.29, -490.98, 11.06 ),
  124.         Vector(-854.526, -631.75, 11.3756 ),
  125.         Vector(-688.706, -1262.49, 16.3473 ),
  126.         Vector(-665.025, -1484.42, 13.8016 ),
  127.         Vector(-885.324, -469.998, 13.1111 ),
  128.         Vector(-847.002, -71.6495, 11.5405 ),
  129.         Vector(-1079.64, -275.416, 12.0882 ),
  130.         Vector(-1036.4 81.2033, 11.6515 ),
  131.         Vector(-992.73, 200.392, 15.2213 ),
  132.         Vector(-830.158, 741.534, 11.2885 ),
  133.         Vector(-906.182, 799.715, 11.4546 ),
  134.         Vector(-854.047, 85 11.3846 ),
  135.         Vector(-754.53, 1342.74, 11.767 ),
  136.         Vector(472.16, 1009.2, 19.1493 ),
  137.         Vector(423.496, 1039.0 18.9648 ),
  138.         Vector(364.464, 1075.12, 19.0649 ),
  139.         Vector(470.443, 1208.18, 19.0094 )
  140.     ];
  141.     foreach( val in arr ) CreatePickup( model, val ).RespawnTime = PICKUP_RESPAWN_TIME;
  142. }
Add Comment
Please, Sign In to add comment