1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. GTA Network forum is now in archive mode.

A simple drive to destination script

Discussion in 'Scripts' started by Spacefrog, May 25, 2017.

  1. Spacefrog

    Spacefrog Member

    Messages:
    21
    Likes Received:
    2
    Joined:
    Sep 20, 2016
    This is my frist script for gta v, maybe it can help some beginners.
    If anyone has some tips how i could code better or what i do wrong just tell me.

    Press E to start your job.
    Press Y when on the marker.

    Know bugs:
    Destination is random, but could be the same destination when completeing your task.
    When you complete your job it will just recount from 0 so its endless.



    paintJob.cs
    Code:
    using GTANetworkServer;
    using GTANetworkShared;
    using System;
    using System.Collections.Generic;
    
    
    public class paintJob : Script
    {
        public paintJob()
        {
            API.onResourceStart += onResourceStart;
            API.onClientEventTrigger += OnClientEvent;
        }
    
        public ColShape misStartColshape;
        public ColShape misEndColshape;
    
        public Marker marker;
        public Blip desblip;
        public int taskdone;
    
        
     
        public void onResourceStart()
        {
            API.createMarker(1, new Vector3(833.1752, 1288.977, 362.5864), new Vector3(), new Vector3(), new Vector3(2, 2, 2), 255, 0, 0, 255); // marker to start the job
            Blip misBlip = API.createBlip(new Vector3(833.1752, 1288.977, 362.5864)); // blip to start job
            API.setBlipSprite(misBlip, 56);
            API.setBlipName(misBlip, "Paint Job");
            API.setBlipColor(misBlip, 5);
            misStartColshape = API.createCylinderColShape(new Vector3(833.1752, 1288.977, 362.5864), 5f, 3f); // colshap for mission start point
    
            misStartColshape.onEntityEnterColShape += (shape, entity) =>
            {
                Client player;
    
                if ((player = API.getPlayerFromHandle(entity)) != null)
                {
                    API.sendChatMessageToPlayer(player, "~b~ Press E to start the job");
                }
            };
    
        }
    
        public void OnClientEvent(Client player, string eventName, params object[] arguments) //arguments param can contain multiple params
        {
            if (eventName == "StartMission") //an eventname with no params that was triggered from the Client-side script
            {
    
                if (misStartColshape.containsEntity(player.handle))
                {
                    API.setPlayerSkin(player, PedHash.Lathandy01SMM);
                    VehicleHash taxi = API.vehicleNameToModel("Pony");
                    Vehicle myvehicle = API.createVehicle(taxi, new Vector3(833.1752, 1288.977, 362.5864), new Vector3(0, 0, 143.9855), 0, 0, 0);
                    API.setPlayerIntoVehicle(player, myvehicle, -1);
                    API.setEntityData(player, "paintJob", true);
                    API.sendChatMessageToPlayer(player, "~g~You are now a grafity remover");
                    nextDes(player);
                }
                else { API.sendChatMessageToPlayer(player, "~r~You are too far away"); }
    
            }
    
            if (eventName == "objComplete") //an eventname with no params that was triggered from the Client-side script
            {
    
                if (misEndColshape.containsEntity(player.handle))
                {
                    taskdone++;
    
                    if (taskdone == 5)
                    {
                        API.sendChatMessageToPlayer(player, "~g~ Job complete");
                        taskdone = 0;
                    }
                    else
                    {
                        API.sendChatMessageToPlayer(player, "~g~Drive to the next point " + taskdone.ToString() + "/5");
                    }
                    nextDes(player);
                }
                else { API.sendChatMessageToPlayer(player, "~r~You are too far away"); }
            }
        }
    
        public void nextDes(Client player)
        {
          
            if (misEndColshape != null)
            {
                API.deleteColShape(misEndColshape);
            }
            
            
            Random random = new Random();
    
            List<Vector3> des = new List<Vector3>();
            des.Add(new Vector3(825.7181, 1362.43, 349.3494));
            des.Add(new Vector3(800.0999, 1371.068, 346.5405));
            des.Add(new Vector3(735.2936, 1360.412, 338.0286));
            des.Add(new Vector3(653.0134, 1381.875, 323.9514));
    
          
            Vector3 despoint = des[random.Next(des.Count)];
            
            misEndColshape = API.createCylinderColShape(despoint, 5F, 3F);
    
          
           API.triggerClientEvent(player, "nextDes", despoint, despoint.X, despoint.Y,desblip,marker);
        }
      
    }
    paintJob.js
    Code:
    var desblip;
    var marker;
    
    API.onKeyDown.connect(function (sender, e) {
        if (e.KeyCode === Keys.E) {
    
            API.triggerServerEvent("StartMission");
    
        }
    
        if (e.KeyCode === Keys.Y) {
    
            API.triggerServerEvent("objComplete");
    
    
        }
    });
    
    API.onServerEventTrigger.connect(function (eventName, args) {
        if (eventName == "waypoint") {
    
            API.setWaypoint(args[0], args[1]);
          
        }
    
        if (eventName == "nextDes") {
    
            var textLabel = API.createTextLabel("Press y to complete task", args[0], 1, 1);
    
            if (desblip != null)
            {
              
                API.setBlipPosition(desblip, args[0]);
                API.deleteEntity(marker);
            }
            else
            {
                desblip = API.createBlip(args[0]);
                
            }
          
            marker = API.createMarker(1, args[0], new Vector3(), new Vector3(), new Vector3(2, 2, 2), 255, 0, 0, 255);
            API.attachEntity(textLabel, marker, "0", new Vector3(), new Vector3());
          
          API.setWaypoint(args[1], args[2]);
    
            
        }
    
    });
     

    Attached Files:

    Viper likes this.
  2. Anthony

    Anthony Member

    Messages:
    6
    Likes Received:
    1
    Joined:
    Mar 15, 2017
    Good Work! I'm sure a lot of RPG developers could use this in their driving tests.
     
  3. sammyd86

    sammyd86 New Member

    Messages:
    2
    Likes Received:
    0
    Joined:
    Aug 17, 2017
    hello,

    Can someone show me how to change the script so that you can get some fixed routes, which are then randomly selected.

    This would be a huge help.
     

Share This Page