[TUT]SISTEMA DE ABASTECER
#1

Sistema de Gasolina


Galera Eu Vo Fazer Um Sistema de Abastecer Com Textdraw emcima do radar

Vamos Comeзar


No Topo Do Seu Gm
pawn Код:
#include <a_samp>
new fuel[MAX_VEHICLES]; //fuel por o veнculo
forward timer_fuel_lower();//timer para abaixar o valor do combustнvel
forward timer_refuel(playerid); //timer para reabastecer o veнculo
new isrefuelling[MAX_PLAYERS] = 0; //bool para verific se o jogador jб estб reabastecendo
new Text:td_fuel[MAX_PLAYERS]; //textdraw com combustнvel
em public OnFilterScriptInit() Voce Coloka

pawn Код:
for(new i=0;i<MAX_VEHICLES;i++) {
        fuel[i] = 100; //sets combustнvel de cada carro a 100 em um laзo
    }
    SetTimer("timer_fuel_lower",4200,true); //sets o temporizador para deixar cair o combustнvel
se vc estiver criando em um gm

coloke em public OnGameModeInit()

pawn Код:
for(new i=0;i<MAX_VEHICLES;i++) {
        fuel[i] = 100;//sets combustнvel de cada carro a 100 em um laзo
    }
    SetTimer("timer_fuel_lower",4200,true); //sets o temporizador para deixar cair o combustнvel
agora agente vai usar uma textdraws quando um jogador spawns:
Setting-up as posiзхes/efeitos do textdraw para o jogador.


em public OnPlayerSpawn(playerid)

pawn Код:
td_fuel[playerid] = TextDrawCreate(45,324,"Fuel: 100"); //criar o textdraw na posiзгo
    TextDrawBackgroundColor(td_fuel[playerid],0x00000033); //Aki sera o BackgroundColor Do TextDraw
    TextDrawFont(td_fuel[playerid],3); O Tipo De Fonte
    TextDrawLetterSize(td_fuel[playerid],0.699999,1.700000); //O Tamanho da Fonte
    TextDrawColor(td_fuel[playerid],0x000000ff); //A Cor
    TextDrawSetShadow(td_fuel[playerid],3); //E A Sombra
}

Agora Vamos Criar Para Quanto o player entrar no veiculo aparecer e quanto sair sumir


pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if (newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
    {
        new vid = GetPlayerVehicleID(playerid);
        new string[125];format(string,sizeof string,"Gasolina:%i",fuel[vid]); //Faz A Atualizaзao Do Combustivel (assim nгo saltarб de 100 a seu valor real)
        TextDrawSetString(td_fuel[playerid],string);
        TextDrawShowForPlayer(playerid,td_fuel[playerid]);
    } else {
        TextDrawHideForPlayer(playerid,td_fuel[playerid]);
    }
    return 1;
}
Agora Vamos Criar O Comando Para Abastecer O Veiculo

Em public OnPlayerCommandText(playerid,cmdtext[]) Coloke

pawn Код:
if (!strcmp("/abastecer",cmdtext,true,7)) {
    if (!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,0xFFC800FF,"Voce nao esta em um veiculo!");  //if um jogador nгo estб em um veнculo, ele para aqui
    if (isrefuelling[playerid]) return SendClientMessage(playerid,0xFFC800FF,"Voce ja esta reabastecendo!"); //if que um jogador jб estб reabastecendo, para aqui
    if (GetPlayerMoney(playerid) - 80 <0) return SendClientMessage(playerid,0xFFC800FF,"Voce Nao Tem Dinheiro Suficiente!"); //o Player Nao Tem 80 Reias Para Pagar, Para Aqui
    GivePlayerMoney(playerid,-80); //Sets the player's cash -$80
    SetCameraBehindPlayer(playerid); //Sets a cвmera atrбs do jogador (os olhares melhoram porque o jogador serб congelado por alguns segundos)
    TogglePlayerControllable(playerid,0);
    isrefuelling[playerid] = 1;
    TextDrawSetString(td_fuel[playerid],"Reabastecimento..."); //Aki A Mensagem Q Mostra O player Reabastecimento
    SetTimerEx("timer_refuel",4500,false,"i",playerid);
pawn Код:
public timer_fuel_lower()
{
    for(new i=0;i<MAX_PLAYERS;i++) { //loop para todos os jogadores
        if (isrefuelling[i]) return 0; //Parar  quando um jogador jб reabastecer
        new vid = GetPlayerVehicleID(i); //identificaзгo do veнculo
        if (GetPlayerVehicleSeat(i) == 0) { //if o jogador й um excitador (deve somente abaixar o combustнvel quando theres um excitador!)
            fuel[vid] = fuel[vid] -1; abaixando o valor do combustнvel
            if (fuel[vid]<1) //if combustнvel estб vazio
            {
                fuel[vid] = 0; // que ajusta o combustнvel a 0 (mais o temporizador o ajustarб -1 -2 -3 etc. antes de remover o jogador)
                RemovePlayerFromVehicle(i); // remove o jogador fora do veнculo
                GameTextForPlayer(i,"~r~You are out of ~w~fuel~r~!",5000,4); //Mostra O Texto
            }
        }
        new string[125];format(string,sizeof string,"Fuel:%i",fuel[vid]); //preparando a corda com valor seguinte do combustнvel
        TextDrawSetString(td_fuel[i],string); //actualizando o textdraw
    }
    return 1;
}

public timer_refuel(playerid)
{
    new vid = GetPlayerVehicleID(playerid);
    fuel[vid] = fuel[vid] = 100; Aki E A Gasolina Em 100
    isrefuelling[playerid] = 0;//anti-Spam
    TextDrawSetString(td_fuel[playerid],"Fuel:100");//actualizaзгo pequena no textdraw
    TogglePlayerControllable(playerid,1);//unfreeze o jogador
}
By:Cobertozinho e gamer931215

Se Nao Gosto Faz Melhor E Posta Aki No Forum
Reply


Messages In This Thread
[TUT]SISTEMA DE ABASTECER - by Cobertozinho - 21.08.2010, 07:12
Re: [TUT]SISTEMA DE ABASTECER - by Gabriel_Halls - 21.08.2010, 15:17
Re: [TUT]SISTEMA DE ABASTECER - by Cobertozinho - 21.08.2010, 15:18
Re: [TUT]SISTEMA DE ABASTECER - by Cobertozinho - 21.08.2010, 15:29
Re: [TUT]SISTEMA DE ABASTECER - by frenetico - 21.08.2010, 15:49
Re: [TUT]SISTEMA DE ABASTECER - by zSuYaNw - 21.08.2010, 16:02
Re: [TUT]SISTEMA DE ABASTECER - by Ricop522 - 21.08.2010, 16:10
Re: [TUT]SISTEMA DE ABASTECER - by LeLeTe - 21.08.2010, 16:30
Re: [TUT]SISTEMA DE ABASTECER - by [Michael] - 21.08.2010, 18:19
Re: [TUT]SISTEMA DE ABASTECER - by DartakousLien - 21.08.2010, 18:37

Forum Jump:


Users browsing this thread: 1 Guest(s)