Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *
- * Caminhoneiro / Truck Driver Script
- * Lucas Gomes ( Dry ) Version: 1.0
- *
- */
- /*
- Commands:
- CMD:newtruck (RCON) » Usado para iniciar o processo de CRIAÇÃO de caminhões no jogo;
- CMD:deltruck (RCON) » Usado para iniciar o processo de REMOÇÃO de caminhões no jogo;
- CMD:setmaincp(RCON) » Usado para criar o checkpoint principal;
- CMD:newcp(RCON) » Usado para criar um checkpoint de entregas;
- */
- /*
- Developer Functions:
- - addTruck(Float: X, Float: Y, Float: Z); » Adiciona um novo caminhão de entregas ao servidor.
- - removeTruck(TruckID); » Remove um caminhão de entrega do servidor.
- - loadTrucks(); » Fazer a atualização dos caminhões.
- - unLoadTrucks(); » Usado para retirar os caminhões do servidor(unload);
- - startCreation(playerid); » Inicia o processo de criação de caminhões no jogo;
- - checkTruckInfo(playerid); » Função final para o processo de criação de caminhões;
- - deleteTruck(playerid); » Remover o caminhão do jogo ( permanentemente );
- - setMPoint(playerid); » Cria o checkpoint principal;
- - LoadMainPoint(); » Carrega as vars do checkpoint principal;
- - StartJobForPlayer(playerid); » Inicia o processo de entregas para o jogador;
- - SetNewCheckpoint(playerid); » Sega um novo checkpoint para fazer entregas;
- - SetPlayerLocal(playerid); » Escolhe de forma randomica um checkpoint para o jogador fazer as entregas;
- */
- #include <a_samp>
- #include <zcmd>
- #include <dof2>
- #define cPadrao 0xFF8080FF
- #define cAzul 0x0080C0FF
- #define cBranco -1
- #define MAX_PAY 10000
- #define MIN_PAY 1000
- #define MAX_TRUCKS 50 // default: 50 (recomendado);
- #define MAX_CP 50 // Max Checkpoints;
- #define Truck_ID 515 // ID do veículo: caminhão;
- #define Trailer_ID 435 // ID da carga;
- #define PRESSED(%0) \
- (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
- #define truckConfig "TruckDriver/%d.ini"
- #define main_point "TruckDriver/main_point.ini"
- #define local_cp "TruckDriver/CP/%d.ini"
- enum tInfo
- {
- bool:created,
- id,
- Float:posX,
- Float:posY,
- Float:posZ,
- Float:posA,
- };
- enum i_player
- {
- bool:working,
- bool:building,
- veh,
- step,
- Float: pX,
- Float: pY,
- Float: pZ,
- trailer
- };
- enum m_point
- {
- Float: cX,
- Float: cY,
- Float: cZ,
- bool:created
- };
- new mPoint[m_point];
- new pInfo[MAX_PLAYERS][i_player];
- new TruckInfo[MAX_TRUCKS][tInfo];
- addTruck(Float: X, Float: Y, Float: Z, Float: A)
- {
- for ( new i = 0; i < MAX_TRUCKS; i++)
- {
- if ( i > MAX_TRUCKS )
- {
- printf("Limite de caminhôes atingido. (%d)", MAX_TRUCKS);
- break;
- }
- new Str[500];
- format ( Str, sizeof Str, truckConfig, i);
- if ( !DOF2::FileExists(Str))
- {
- DOF2::CreateFile(Str);
- if (!DOF2::FileExists(Str))
- {
- print("Erro ao adicionar um novo caminhão.");
- print("Certifique-se de criar as pastas necessárias.");
- return 1;
- }
- DOF2::SetFloat(Str, "PosX", X);
- DOF2::SetFloat(Str, "PosY", Y);
- DOF2::SetFloat(Str, "PosZ", Z);
- DOF2::SetFloat(Str, "Angle", A);
- DOF2::SaveFile();
- LoadTrucks();
- printf("Caminhão %d adicionado", i);
- break;
- }
- }
- return 1;
- }
- LoadTrucks()
- {
- new Str[500];
- for ( new i = 0; i < MAX_TRUCKS; i++)
- {
- format ( Str, sizeof Str, truckConfig, i);
- if ( TruckInfo[i][created] == false && DOF2::FileExists(Str))
- {
- TruckInfo[i][created] = true;
- TruckInfo[i][posX] = DOF2::GetFloat(Str, "PosX");
- TruckInfo[i][posY] = DOF2::GetFloat(Str, "PosY");
- TruckInfo[i][posZ] = DOF2::GetFloat(Str, "PosZ");
- TruckInfo[i][posA] = DOF2::GetFloat(Str, "Angle");
- TruckInfo[i][id] = CreateVehicle(Truck_ID, TruckInfo[i][posX],TruckInfo[i][posY],TruckInfo[i][posZ],TruckInfo[i][posA], 0, 0, -1);
- printf("Caminhão %d carregado!", i);
- }
- }
- return 1;
- }
- unLoadTrucks()
- {
- for ( new i = 0; i < MAX_TRUCKS; i++)
- {
- if ( TruckInfo[i][created] == true )
- {
- TruckInfo[i][created] = false;
- DestroyVehicle(TruckInfo[i][id]);
- printf("Encerrando script (%d)",i);
- }
- }
- for ( new i = 0; i < GetMaxPlayers(); i++)
- {
- DestroyVehicle(pInfo[i][trailer]);
- }
- return 1;
- }
- startCreation(playerid)
- {
- if ( pInfo[playerid][building] == true ) SendClientMessage(playerid, cPadrao, "Você já está criando um caminhão!");
- if ( IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, cPadrao, "Saia do seu veículo atual!");
- new Float: X, Float: Y, Float: Z, Float: A;
- GetPlayerPos(playerid, X, Y, Z);
- GetPlayerFacingAngle(playerid, A);
- pInfo[playerid][veh] = CreateVehicle(Truck_ID, X, Y, Z, A, 0, 0, -1);
- PutPlayerInVehicle(playerid, pInfo[playerid][veh], 0);
- pInfo[playerid][building] = true;
- SendClientMessage(playerid, cPadrao, "Vamos criar um novo caminhão?");
- SendClientMessage(playerid, cPadrao, "Você foi setado para dentro de um deles!");
- SendClientMessage(playerid, cPadrao, "Quando estiver pronto para cria-lo pressione: 'Y'");
- return 1;
- }
- checkTruckInfo(playerid)
- {
- if ( IsPlayerInAnyVehicle(playerid) && pInfo[playerid][building] == true )
- {
- new Float: X, Float: Y, Float: Z, Float: A, v;
- v = GetPlayerVehicleID(playerid);
- GetVehiclePos(v, X, Y, Z);
- GetVehicleZAngle(v, A);
- DestroyVehicle(GetPlayerVehicleID(playerid));
- addTruck(X, Y, Z, A);
- GetPlayerPos(playerid, X, Y, Z);
- SetPlayerPos(playerid, X, Y, Z+3);
- pInfo[playerid][building] = false;
- SendClientMessage(playerid, cPadrao, "Veículo adicionado!");
- return 1;
- }
- else
- {
- SendClientMessage(playerid, cPadrao, "Algo de errado aconteceu!");
- SendClientMessage(playerid, cPadrao, "Erro: 1A");
- return 1;
- }
- }
- deleteTruck(playerid)
- {
- if ( !IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, cPadrao, "Entre em um veículo!");
- for ( new i = 0; i < MAX_TRUCKS; i++)
- {
- if ( IsPlayerInVehicle(playerid, TruckInfo[i][id]))
- {
- new Str[500];
- format ( Str, sizeof Str, truckConfig, i);
- if(!DOF2::FileExists(Str)) return SendClientMessage(playerid, cPadrao, "Caminhão não encontrado!");
- TruckInfo[i][created] = false;
- DestroyVehicle(TruckInfo[i][id]);
- DOF2::RemoveFile(Str);
- if(!DOF2::FileExists(Str)) SendClientMessage(playerid, cPadrao, "Caminhão removido com sucesso!");
- break;
- }
- }
- return 1;
- }
- setMPoint(playerid)
- {
- new Str[500], Float: X, Float: Y, Float: Z;
- GetPlayerPos(playerid, X, Y, Z);
- format ( Str, sizeof Str, main_point);
- if (!DOF2::FileExists(Str))
- {
- DOF2::CreateFile(Str);
- if ( !DOF2::FileExists(Str))
- {
- print("Erro ao criar CheckPoint principal!");
- SendClientMessage(playerid, cPadrao, "Erro ao criar CheckPoint principal");
- return 1;
- }
- }
- if ( DOF2::FileExists(Str))
- {
- mPoint[created] = true;
- DOF2::SetFloat(Str, "cX", X);
- DOF2::SetFloat(Str, "cY", Y);
- DOF2::SetFloat(Str, "cZ", Z);
- DOF2::SaveFile();
- SendClientMessage(playerid, cPadrao, "Check Point principal criado!");
- LoadMainPoint();
- return 1;
- }
- return 1;
- }
- LoadMainPoint()
- {
- new Str[500];
- format ( Str, sizeof Str, main_point);
- if ( !DOF2::FileExists(Str))
- {
- print("Crie o check point principal!");
- mPoint[created] = false;
- return 1;
- }
- mPoint[cX] = DOF2::GetFloat(Str, "cX");
- mPoint[cY] = DOF2::GetFloat(Str, "cY");
- mPoint[cZ] = DOF2::GetFloat(Str, "cZ");
- mPoint[created] = true;
- print("Ponto principal carregado!");
- return 1;
- }
- StartJobForPlayer(playerid)
- {
- if ( pInfo[playerid][building] == true ) return SendClientMessage(playerid, cPadrao, "Ops! Você está criando um veículo!");
- if ( pInfo[playerid][working] == true ) return SendClientMessage(playerid, cPadrao, "Você já está fazendo uma entrega!");
- if ( mPoint[created] == false) return SendClientMessage(playerid, cPadrao, "Ponto de carga não definido!");
- if ( pInfo[playerid][step] == 0)
- {
- SetPlayerCheckpoint(playerid, mPoint[cX], mPoint[cY], mPoint[cZ], 5.0);
- SendClientMessage(playerid, cPadrao, "Siga o checkpoint para iniciar a entrega!");
- pInfo[playerid][step]++;
- pInfo[playerid][working] = true;
- return 1;
- }
- return 1;
- }
- SetNewCheckpoint(playerid)
- {
- new Str[500];
- for ( new i = 0; i < MAX_PLAYERS; i++)
- {
- format ( Str, sizeof Str, local_cp, i);
- if ( !DOF2::FileExists(Str))
- {
- DOF2::CreateFile(Str);
- if ( !DOF2::FileExists(Str))
- {
- printf("Checkpoint %d não criado.", i);
- SendClientMessage(playerid, cPadrao, "Erro ao criar novo checkpoint!");
- break;
- }
- new Float: X, Float: Y, Float: Z;
- GetPlayerPos(playerid, X, Y, Z);
- DOF2::SetFloat(Str, "pX", X);
- DOF2::SetFloat(Str, "pY", Y);
- DOF2::SetFloat(Str, "pZ", Z);
- DOF2::SaveFile();
- printf("Checkpoint %d criado!", i);
- SendClientMessage(playerid, cPadrao, "Checkpoint criado!");
- break;
- }
- }
- return 1;
- }
- SetPlayerLocal(playerid)
- {
- new xmax;
- new Str[500];
- for ( new i = 0; i < MAX_CP; i++)
- {
- format ( Str, sizeof Str, local_cp, i );
- if ( DOF2::FileExists(Str))
- {
- xmax++;
- }
- }
- if ( xmax == 0)
- {
- SendClientMessage(playerid, cPadrao, "Nenhum ponto de entrega definido!");
- DisablePlayerCheckpoint(playerid);
- return 1;
- }
- new target = random(xmax);
- format ( Str, sizeof Str, local_cp, target);
- new Float: X, Float: Y, Float: Z;
- X = DOF2::GetFloat(Str, "pX");
- Y = DOF2::GetFloat(Str, "pY");
- Z = DOF2::GetFloat(Str, "pZ");
- SetPlayerCheckpoint(playerid, X, Y, Z, 5.0);
- GetPlayerPos(playerid, X, Y, Z);
- pInfo[playerid][trailer] = CreateVehicle(Trailer_ID, X, Y, Z-10, 0, 1, 1, -1);
- SetTimerEx("attach", 1000, false, "i", playerid);
- pInfo[playerid][step]++;
- return 1;
- }
- forward attach(playerid);
- public attach(playerid)
- {
- AttachTrailerToVehicle(pInfo[playerid][trailer], GetPlayerVehicleID(playerid));
- if ( IsTrailerAttachedToVehicle(GetPlayerVehicleID(playerid)))
- {
- pInfo[playerid][step] = 2;
- SendClientMessage(playerid, cPadrao, "Siga o checkpoint para entregar a carga!");
- SendClientMessage(playerid, cPadrao, "Se sair do caminhão a entrega é cancelada!");
- SendClientMessage(playerid, cPadrao, "Boa sorte!");
- }
- return 1;
- }
- CMD:newtruck(playerid)
- {
- if ( IsPlayerAdmin(playerid)) startCreation(playerid);
- return 1;
- }
- CMD:deltruck(playerid)
- {
- if ( !IsPlayerAdmin(playerid)) return SendClientMessage(playerid, cPadrao, "Error.");
- deleteTruck(playerid);
- return 1;
- }
- CMD:setmaincp(playerid)
- {
- if (!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, cPadrao, "Você é admin?");
- setMPoint(playerid);
- return 1;
- }
- CMD:newcp(playerid)
- {
- if ( IsPlayerAdmin(playerid)) SetNewCheckpoint(playerid);
- return 1;
- }
- public OnFilterScriptInit()
- {
- LoadMainPoint();
- LoadTrucks();
- return 1;
- }
- public OnFilterScriptExit()
- {
- unLoadTrucks();
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- pInfo[playerid][building] = false;
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- if ( IsPlayerAdmin(playerid) && pInfo[playerid][building] == true && pInfo[playerid][step] == 1)
- {
- pInfo[playerid][building] = false;
- DestroyVehicle(pInfo[playerid][veh]);
- DestroyVehicle(pInfo[playerid][trailer]);
- }
- if ( pInfo[playerid][working] == true ) pInfo[playerid][working] = false;
- return 1;
- }
- public OnPlayerStateChange(playerid, newstate, oldstate)
- {
- if(newstate == PLAYER_STATE_DRIVER && pInfo[playerid][building] == false && pInfo[playerid][working] == false)
- {
- for ( new i = 0; i < MAX_TRUCKS; i++)
- {
- if ( IsPlayerInVehicle(playerid, TruckInfo[i][id]))
- {
- SendClientMessage(playerid, cPadrao, "Bem vindo caminhoneiro!");
- SendClientMessage(playerid, cPadrao, "Pressione: 'Y' para iniciar uma entrega!");
- break;
- }
- }
- }
- if(oldstate == PLAYER_STATE_DRIVER && pInfo[playerid][building] == true)
- {
- pInfo[playerid][building] = false;
- DestroyVehicle(pInfo[playerid][veh]);
- SendClientMessage(playerid, cPadrao, "Você saiu do veículo, e o processo foi cancelado.");
- }
- if(oldstate == PLAYER_STATE_DRIVER && pInfo[playerid][working] == true)
- {
- pInfo[playerid][working] = false;
- pInfo[playerid][step] = 0;
- DisablePlayerCheckpoint(playerid);
- DestroyVehicle(pInfo[playerid][trailer]);
- SendClientMessage(playerid, cPadrao, "Você saiu do caminhão no meio de uma entrega!");
- SendClientMessage(playerid, cPadrao, "Ganhos: $0");
- }
- return 1;
- }
- public OnPlayerEnterCheckpoint(playerid)
- {
- if ( pInfo[playerid][step] == 1 && pInfo[playerid][working] == true)
- {
- SetPlayerLocal(playerid);
- return 1;
- }
- if ( pInfo[playerid][step] == 2 && pInfo[playerid][working] == true)
- {
- if ( IsTrailerAttachedToVehicle(GetPlayerVehicleID(playerid)))
- {
- new Money = random(MAX_PAY);
- if ( Money < MIN_PAY) Money = MIN_PAY;
- GivePlayerMoney(playerid, Money);
- DisablePlayerCheckpoint(playerid);
- DestroyVehicle(pInfo[playerid][trailer]);
- pInfo[playerid][working] = false;
- pInfo[playerid][step] = 0;
- new Str[128];
- format ( Str, sizeof Str, "Você recebeu: {FFFFFF}$%d", Money);
- SendClientMessage(playerid, cPadrao, Str);
- return 1;
- }
- return 1;
- }
- return 1;
- }
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- if (PRESSED(KEY_YES))
- {
- if ( IsPlayerAdmin(playerid) && pInfo[playerid][building] == true) return checkTruckInfo(playerid);
- if ( pInfo[playerid][working] == false && pInfo[playerid][building] == false )
- {
- for ( new i = 0; i < MAX_TRUCKS; i++)
- {
- if ( IsPlayerInVehicle(playerid, TruckInfo[i][id])) StartJobForPlayer(playerid);
- break;
- }
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement