Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// SERVERSIDE ///
- using GTANetworkAPI;
- using System.Collections.Generic;
- using LiteDB;
- using firstresource.DataModels;
- using firstresource.Events;
- namespace firstresource.Commands
- {
- public class Job : Script
- {
- ColShape colShape = null;
- ColShape jobShape = null;
- [Command("startjob")]
- public void CMD_StartJob(Client client)
- {
- if (client.IsInVehicle && client.HasData("InColShape"))
- {
- client.SendChatMessage("~r~Get out of your vehicle.");
- return;
- }
- if (!client.HasData("InColShape"))
- return;
- if (!client.HasData("Civilian"))
- return;
- if (!client.HasData("ID"))
- {
- client.SendChatMessage("~r~Please login.");
- return;
- }
- if (client.HasData("InColShape"))
- {
- client.ResetData("InColShape");
- Vehicle veh = NAPI.Vehicle.CreateVehicle(VehicleHash.Sanchez, new Vector3(client.Position.X, client.Position.Y + 10, client.Position.Z), 0, 255, 255);
- client.SetIntoVehicle(veh, -1);
- colShape.Delete();
- colShape.ResetData("BikeJob");
- DeleteDefaultInstance(client);
- client.SendChatMessage("Started ~y~bikejob~w~. Drive to the next objective for your reward!");
- CreateJobInstance();
- CreateClientJob(client);
- }
- }
- [ServerEvent(Event.ResourceStart)]
- public void Event_ResourceStart()
- {
- DefaultJobInstance();
- }
- [ServerEvent(Event.PlayerEnterColshape)]
- public void Event_EnterJobShape(ColShape jobShape, Client client)
- {
- if (jobShape.HasData("jobShape"))
- {
- client.TriggerEvent("play_sound");
- DeleteClientJob(client);
- jobShape.Delete();
- jobShape.ResetData("jobShape");
- client.ResetData("jobstarted");
- int client_id = client.GetData("ID");
- using (var db = new LiteDatabase(@"./Database.db"))
- {
- double amount = 100;
- var col = db.GetCollection<PlayerStats>("PlayerStats");
- var stats = db.GetCollection<PlayerStats>().FindById(client_id);
- stats.AddMoney(amount);
- client.SendChatMessage($"Bikejob completed. ~g~${amount}~w~ has been added to your account.");
- col.Update(stats);
- EventTriggers.Update_Money(client);
- }
- PlaySound(client);
- DefaultJobInstance();
- DefaultClientInstance(client);
- }
- }
- [ServerEvent(Event.PlayerEnterColshape)]
- public void Event_EnterColshape(ColShape colShape, Client client)
- {
- if(!colShape.HasData("BikeJob"))
- return;
- if (!client.HasData("ID"))
- {
- client.SendChatMessage("~r~Please login.");
- return;
- }
- client.SetData("InColShape", client);
- }
- [ServerEvent(Event.PlayerExitColshape)]
- public void Event_ExitColshape(ColShape colShape, Client client)
- {
- if (client.HasData("InColShape"))
- {
- client.ResetData("InColShape");
- }
- }
- // Create default colshape
- public void DefaultJobInstance()
- {
- colShape = NAPI.ColShape.CreateCylinderColShape(new Vector3(-347.5829f, 1281.445f, 333.7606f - 1), 3, 4);
- colShape.SetData("BikeJob", colShape);
- }
- // Create job colshape once job has started
- public void CreateJobInstance()
- {
- jobShape = NAPI.ColShape.CreateCylinderColShape(new Vector3(227.1695f, 2115.825f, 106.7991f - 1), 2, 2);
- jobShape.SetData("jobShape", colShape);
- }
- // Play a sound when you complete the job
- public void PlaySound(Client client)
- {
- NAPI.ClientEvent.TriggerClientEvent(client, "PlaySound");
- }
- // Create Client-side marker/blip
- public void CreateClientJob(Client client)
- {
- NAPI.ClientEvent.TriggerClientEvent(client, "CreateMarkers");
- }
- // Delete client-side marker/blip
- public void DeleteClientJob(Client client)
- {
- NAPI.ClientEvent.TriggerClientEvent(client, "DeleteMarkers");
- }
- // Create default job marker/blip
- public void DefaultClientInstance(Client client)
- {
- NAPI.ClientEvent.TriggerClientEvent(client, "DefaultMarkers");
- }
- // Delete default job marker/blip once job has started
- public void DeleteDefaultInstance(Client client)
- {
- NAPI.ClientEvent.TriggerClientEvent(client, "DeleteDefault");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment