Guest User

Untitled

a guest
Mar 28th, 2019
117
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// SERVERSIDE ///
  2. using GTANetworkAPI;
  3. using System.Collections.Generic;
  4. using LiteDB;
  5. using firstresource.DataModels;
  6. using firstresource.Events;
  7.  
  8. namespace firstresource.Commands
  9. {
  10.     public class Job : Script
  11.     {
  12.         ColShape colShape = null;
  13.  
  14.         ColShape jobShape = null;
  15.  
  16.         [Command("startjob")]
  17.         public void CMD_StartJob(Client client)
  18.         {
  19.             if (client.IsInVehicle && client.HasData("InColShape"))
  20.             {
  21.                 client.SendChatMessage("~r~Get out of your vehicle.");
  22.                 return;
  23.             }
  24.  
  25.             if (!client.HasData("InColShape"))
  26.                 return;
  27.  
  28.             if (!client.HasData("Civilian"))
  29.                 return;
  30.  
  31.             if (!client.HasData("ID"))
  32.             {
  33.                 client.SendChatMessage("~r~Please login.");
  34.                 return;
  35.             }
  36.  
  37.             if (client.HasData("InColShape"))
  38.             {
  39.                 client.ResetData("InColShape");
  40.  
  41.                 Vehicle veh = NAPI.Vehicle.CreateVehicle(VehicleHash.Sanchez, new Vector3(client.Position.X, client.Position.Y + 10, client.Position.Z), 0, 255, 255);
  42.                 client.SetIntoVehicle(veh, -1);
  43.  
  44.                 colShape.Delete();
  45.                 colShape.ResetData("BikeJob");
  46.                 DeleteDefaultInstance(client);
  47.                 client.SendChatMessage("Started ~y~bikejob~w~. Drive to the next objective for your reward!");
  48.  
  49.                 CreateJobInstance();
  50.                 CreateClientJob(client);
  51.             }
  52.         }
  53.  
  54.         [ServerEvent(Event.ResourceStart)]
  55.         public void Event_ResourceStart()
  56.         {
  57.             DefaultJobInstance();
  58.         }
  59.  
  60.  
  61.         [ServerEvent(Event.PlayerEnterColshape)]
  62.         public void Event_EnterJobShape(ColShape jobShape, Client client)
  63.         {
  64.            
  65.             if (jobShape.HasData("jobShape"))
  66.             {
  67.                
  68.                 client.TriggerEvent("play_sound");
  69.                 DeleteClientJob(client);
  70.                 jobShape.Delete();
  71.                 jobShape.ResetData("jobShape");
  72.                 client.ResetData("jobstarted");
  73.  
  74.                 int client_id = client.GetData("ID");
  75.  
  76.                 using (var db = new LiteDatabase(@"./Database.db"))
  77.                 {
  78.                     double amount = 100;
  79.  
  80.                     var col = db.GetCollection<PlayerStats>("PlayerStats");
  81.                     var stats = db.GetCollection<PlayerStats>().FindById(client_id);
  82.  
  83.                     stats.AddMoney(amount);
  84.                     client.SendChatMessage($"Bikejob completed. ~g~${amount}~w~ has been added to your account.");
  85.                     col.Update(stats);
  86.                     EventTriggers.Update_Money(client);
  87.  
  88.                 }
  89.  
  90.                 PlaySound(client);
  91.                 DefaultJobInstance();
  92.                 DefaultClientInstance(client);
  93.             }
  94.         }
  95.  
  96.         [ServerEvent(Event.PlayerEnterColshape)]
  97.         public void Event_EnterColshape(ColShape colShape, Client client)
  98.         {
  99.  
  100.             if(!colShape.HasData("BikeJob"))
  101.                 return;
  102.  
  103.             if (!client.HasData("ID"))
  104.             {
  105.                 client.SendChatMessage("~r~Please login.");
  106.                 return;
  107.             }
  108.  
  109.             client.SetData("InColShape", client);
  110.         }
  111.  
  112.         [ServerEvent(Event.PlayerExitColshape)]
  113.         public void Event_ExitColshape(ColShape colShape, Client client)
  114.         {
  115.  
  116.             if (client.HasData("InColShape"))
  117.             {
  118.             client.ResetData("InColShape");
  119.             }
  120.         }
  121.  
  122.         // Create default colshape
  123.         public void DefaultJobInstance()
  124.         {
  125.                 colShape = NAPI.ColShape.CreateCylinderColShape(new Vector3(-347.5829f, 1281.445f, 333.7606f - 1), 3, 4);
  126.                 colShape.SetData("BikeJob", colShape);
  127.         }
  128.  
  129.         // Create job colshape once job has started
  130.         public void CreateJobInstance()
  131.         {
  132.             jobShape = NAPI.ColShape.CreateCylinderColShape(new Vector3(227.1695f, 2115.825f, 106.7991f - 1), 2, 2);
  133.             jobShape.SetData("jobShape", colShape);
  134.         }
  135.  
  136.         // Play a sound when you complete the job
  137.         public void PlaySound(Client client)
  138.         {
  139.             NAPI.ClientEvent.TriggerClientEvent(client, "PlaySound");
  140.         }
  141.  
  142.         // Create Client-side marker/blip
  143.         public void CreateClientJob(Client client)
  144.         {
  145.                 NAPI.ClientEvent.TriggerClientEvent(client, "CreateMarkers");
  146.         }
  147.  
  148.         // Delete client-side marker/blip
  149.         public void DeleteClientJob(Client client)
  150.         {
  151.                 NAPI.ClientEvent.TriggerClientEvent(client, "DeleteMarkers");
  152.         }
  153.  
  154.         // Create default job marker/blip
  155.         public void DefaultClientInstance(Client client)
  156.         {
  157.                 NAPI.ClientEvent.TriggerClientEvent(client, "DefaultMarkers");
  158.         }
  159.  
  160.  
  161.         // Delete default job marker/blip once job has started
  162.         public void DeleteDefaultInstance(Client client)
  163.         {
  164.             NAPI.ClientEvent.TriggerClientEvent(client, "DeleteDefault");
  165.         }
  166.  
  167.     }
  168. }
RAW Paste Data