Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* 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 */
- //The amount of money one should get when he/she robs shit
- const ROB_CASH = 25000;
- //Everyone knows it, it's the time between the pickup's death and spawn
- const PICKUP_RESPAWN_TIME = 30000; //in ms
- class RobSystem
- {
- //Variables to store the data.
- //The player instance.
- player = null;
- //His/her skills
- robskill = 0;
- //Database instance
- db = null;
- //We'll use the variables in this function to store the data for later use.
- /*
- @arg player - instance
- @arg db - userdata( database )
- @ret integer
- */
- constructor( player, db ){
- //Store the player instance for later use.
- this.player = player;
- //Store the database instance
- this.db = db;
- //Query the player's data.
- local robs = Query( "SELECT Robskill FROM Robskills WHERE Name='%s'", player.Name );
- //Check if the user exists
- if( !robs ){
- //THe user doesn't exist, insert him to the table.
- Query( "INSET INTO Robskills( Name, Robskill ) VALUES( '%s' , 0 )", player.Name );
- //Return the Robskill value.
- return 0;
- }
- //Fetch the robskill of the user's.
- local data = ::GetSQLColumnData( robs );
- //Check if the data exists
- if( data ) {
- //Set the value.
- this.robskill = data;
- //Return the robskill
- return data;
- }
- //Alright, return 0 if anything goes wrong during this process.
- return 0;
- }
- /*
- @ret integer
- */
- function GetSkills(){
- //Return the player's robskill
- return this.robskill;
- }
- /*
- @arg value - integer
- @ret integer
- */
- function IncSkills( value = 1 ){
- //Increase the value.
- this.robskill += value;
- //Increase the cash of the player.
- this.player.Cash += ::ROB_CASH*value;
- //Return it.
- return this.robskill;
- }
- function Query( string ){
- vargv.insert( 0, this );
- return ::QuerySQL( this.db format.acall( vargv ) );
- }
- }
- //Called when the script is loaded
- function onScriptLoad(){
- //Create an empty array
- robber <- array(100);
- //Connect to the database.
- db <- ConnectSQL("RobSys.db");
- //Finally, create the pickups
- createPickups();
- }
- //Called when a player joins.
- function onPlayerJoin( player )
- {
- //Initialize our class
- robber[ player.ID ] = RobSystem( player, db );
- }
- //Called when a player types a command.
- function onPlayerCommand( player, cmd, args )
- {
- if( cmd == "robskill" ){
- PrivMessage( player, "Your robskills are: " + robber[ player.ID ].GetSkills() );
- }
- }
- //Called when a player picks up a pickup
- function onPickupPickedUp( player, pickup )
- {
- if( pickup.Model == 408 ){
- //Cache the player's postion.
- local p = player.Pos;
- //Message everyone that the user has robbed shits.
- Message( player.Name + " has robbed: " + GetDistrictName( p.x, p.y ) );
- //Increase his/her skills.
- robber[ player.ID ].IncSkills();
- //Announce it to the player.
- Announce( "~y~You've robbed: " + ROB_CASH , player );
- }
- }
- //Create the pickups
- function createPickups(){
- //Cache the model.
- local model = 408, arr = [
- Vector( 204.29, -490.98, 11.06 ),
- Vector(-854.526, -631.75, 11.3756 ),
- Vector(-688.706, -1262.49, 16.3473 ),
- Vector(-665.025, -1484.42, 13.8016 ),
- Vector(-885.324, -469.998, 13.1111 ),
- Vector(-847.002, -71.6495, 11.5405 ),
- Vector(-1079.64, -275.416, 12.0882 ),
- Vector(-1036.4 81.2033, 11.6515 ),
- Vector(-992.73, 200.392, 15.2213 ),
- Vector(-830.158, 741.534, 11.2885 ),
- Vector(-906.182, 799.715, 11.4546 ),
- Vector(-854.047, 85 11.3846 ),
- Vector(-754.53, 1342.74, 11.767 ),
- Vector(472.16, 1009.2, 19.1493 ),
- Vector(423.496, 1039.0 18.9648 ),
- Vector(364.464, 1075.12, 19.0649 ),
- Vector(470.443, 1208.18, 19.0094 )
- ];
- foreach( val in arr ) CreatePickup( model, val ).RespawnTime = PICKUP_RESPAWN_TIME;
- }
Add Comment
Please, Sign In to add comment