local Tunnel = module("vrp","lib/Tunnel") local Proxy = module("vrp","lib/Proxy") vRP = Proxy.getInterface("vRP") emP = Tunnel.getInterface("gh_motorista") ----------------------------------------------------------------------------------------------------------------------------------------- -- VARIAVEIS ----------------------------------------------------------------------------------------------------------------------------------------- local emservico = false local CoordenadaX = 453.48 local CoordenadaY = -607.74 local CoordenadaZ = 28.57 local timers = 0 local payment = 0 ----------------------------------------------------------------------------------------------------------------------------------------- -- GERANDO LOCAL DE ENTREGA ----------------------------------------------------------------------------------------------------------------------------------------- local entregas = { [1] = { -355.95, -835.53, 31.53 }, [2] = { -1317.21, -472.34, 33.48 }, [3] = { -487.36, -7.26, 45.15 }, [4] = { 557.5, -363.15, 43.5 }, [5] = { 789.62, -1345.47, 26.28 }, [6] = { 728.3, -2439.09, 20.01 }, [7] = { 1319.22, -1631.33, 52.15 }, [8] = { 1197.84, -465.79, 66.23 }, [9] = { 387.65, 137.91, 102.78 }, [10] = { -603.36, 270.76, 81.95 }, [11] = { -1437.29, -44.62, 52.62 }, [12] = { -2166.56, -321.98, 13.11}, [13] = { -1310.36, -889.25, 11.85 }, [14] = { -280.28, -662.64, 33.26 }, [15] = { 158.03, -337.06, 44.23 }, [16] = { -115.13, -1340.06, 29.25 }, [17] = { -540.35, -681.87, 33.21 }, [18] = { 384.69, -859.63, 29.34 }, [19] = { 482.22, -957.55, 27.42 }, [20] = { 387.93, -672.26, 29.2 }, } ----------------------------------------------------------------------------------------------------------------------------------------- -- TRABALHAR ----------------------------------------------------------------------------------------------------------------------------------------- Citizen.CreateThread(function() while true do local sleep = 500 if not emservico then local ped = PlayerPedId() if not IsPedInAnyVehicle(ped) then local x,y,z = table.unpack(GetEntityCoords(ped)) local distance = Vdist(x,y,z,CoordenadaX,CoordenadaY,CoordenadaZ) if distance <= 30.0 then sleep = 4 DrawMarker(23,CoordenadaX,CoordenadaY,CoordenadaZ-0.97,0,0,0,0,0,0,1.0,1.0,0.5,240,200,80,20,0,0,0,0) if distance <= 1.2 then sleep = 4 drawTxt("PRESSIONE ~b~E~w~ PARA INICIAR ROTA",4,0.5,0.93,0.50,255,255,255,180) if IsControlJustPressed(1,38) then emservico = true destino = 1 payment = 10 CriandoBlip(entregas,destino) TriggerEvent("Notify","sucesso","Você entrou em serviço.") end end end end end Citizen.Wait(sleep) end end) ----------------------------------------------------------------------------------------------------------------------------------------- -- GERANDO ENTREGA ----------------------------------------------------------------------------------------------------------------------------------------- Citizen.CreateThread(function() while true do local sleep = 500 if emservico then local ped = PlayerPedId() if IsPedInAnyVehicle(ped) then local x,y,z = table.unpack(GetEntityCoords(ped)) local vehicle = GetVehiclePedIsUsing(ped) local distance = Vdist(x,y,z,entregas[destino][1],entregas[destino][2],entregas[destino][3]) if distance <= 100.0 and (IsVehicleModel(vehicle,GetHashKey("bs110cn")) or IsVehicleModel(vehicle,GetHashKey("bus"))) then sleep = 4 DrawMarker(21,entregas[destino][1],entregas[destino][2],entregas[destino][3]+0.60,0,0,0,0,180.0,130.0,2.0,2.0,1.0,211,176,72,100,1,0,0,1) if distance <= 7.1 then sleep = 4 drawTxt("PRESSIONE ~b~E~w~ PARA CONTINUAR A ROTA",4,0.5,0.93,0.50,255,255,255,180) if IsControlJustPressed(1,38) then RemoveBlip(blip) if destino == 20 then emP.checkPayment(payment,350) destino = 1 payment = 10 else emP.checkPayment(payment,0) destino = destino + 1 end CriandoBlip(entregas,destino) end end end if IsEntityAVehicle(vehicle) then local vehiclespeed = GetEntitySpeed(vehicle)*2.236936 if math.ceil(vehiclespeed) >= 41 and timers <= 0 and payment > 0 then timers = 5 payment = payment - 1 end end end end Citizen.Wait(sleep) end end) ----------------------------------------------------------------------------------------------------------------------------------------- -- TIMERS ----------------------------------------------------------------------------------------------------------------------------------------- Citizen.CreateThread(function() while true do Citizen.Wait(5000) if emservico then if timers > 0 then timers = timers - 5 end end end end) ----------------------------------------------------------------------------------------------------------------------------------------- -- CANCELANDO ENTREGA ----------------------------------------------------------------------------------------------------------------------------------------- Citizen.CreateThread(function() while true do Citizen.Wait(5) if emservico then if IsControlJustPressed(0,168) then emservico = false RemoveBlip(blip) TriggerEvent("Notify","aviso","Você saiu de serviço.") end end end end) Citizen.CreateThread(function() while true do local sleep = 1000 if emservico then sleep = 5 drawTxt("~y~PRESSIONE ~r~F7 ~w~SE DESEJA FINALIZAR O EXPEDIENTE",4,0.295,0.905,0.4,255,255,255,200) drawTxt("VA ATÉ O DESTINO PARA CONTINUAR O TRANSPORTE ~g~[PASSAGEIRO]",4,0.295,0.93,0.4,255,255,255,200) end Citizen.Wait(sleep) end end) ----------------------------------------------------------------------------------------------------------------------------------------- -- FUNCOES ----------------------------------------------------------------------------------------------------------------------------------------- function drawTxt(text,font,x,y,scale,r,g,b,a) SetTextFont(font) SetTextScale(scale,scale) SetTextColour(r,g,b,a) SetTextOutline() SetTextCentre(1) SetTextEntry("STRING") AddTextComponentString(text) DrawText(x,y) end function CriandoBlip(entregas,destino) blip = AddBlipForCoord(entregas[destino][1],entregas[destino][2],entregas[destino][3]) SetBlipSprite(blip,1) SetBlipColour(blip,5) SetBlipScale(blip,0.4) SetBlipAsShortRange(blip,false) SetBlipRoute(blip,true) BeginTextCommandSetBlipName("STRING") AddTextComponentString("Rota de Motorista") EndTextCommandSetBlipName(blip) end
Write, Run & Share C Language code online using OneCompiler's C online compiler for free. It's one of the robust, feature-rich online compilers for C language, running the latest C version which is C18. Getting started with the OneCompiler's C editor is really simple and pretty fast. The editor shows sample boilerplate code when you choose language as 'C' and start coding!
OneCompiler's C online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample C program which takes name as input and print your name with hello.
#include <stdio.h>
int main()
{
char name[50];
printf("Enter name:");
scanf("%s", name);
printf("Hello %s \n" , name );
return 0;
}
C language is one of the most popular general-purpose programming language developed by Dennis Ritchie at Bell laboratories for UNIX operating system. The initial release of C Language was in the year 1972. Most of the desktop operating systems are written in C Language.
When ever you want to perform a set of operations based on a condition if-else
is used.
if(conditional-expression) {
// code
} else {
// code
}
You can also use if-else for nested Ifs and if-else-if ladder when multiple conditions are to be performed on a single variable.
Switch is an alternative to if-else-if ladder.
switch(conditional-expression) {
case value1:
// code
break; // optional
case value2:
// code
break; // optional
...
default:
// code to be executed when all the above cases are not matched;
}
For loop is used to iterate a set of statements based on a condition.
for(Initialization; Condition; Increment/decrement){
// code
}
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while(condition) {
// code
}
Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.
do {
// code
} while (condition);
Array is a collection of similar data which is stored in continuous memory addresses. Array values can be fetched using index. Index starts from 0 to size-1.
data-type array-name[size];
data-type array-name[size][size];
Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increases re-usuability and modularity.
Two types of functions are present in C
Library functions are the in-built functions which are declared in header files like printf(),scanf(),puts(),gets() etc.,
User defined functions are the ones which are written by the programmer based on the requirement.
return_type function_name(parameters);
function_name (parameters)
return_type function_name(parameters) {
//code
}