How to add fuel per second?
#1

Ok, I have a fuel system, and I want to edit it for instead of typing /fill and getting 100 fuel, I want it to /fill, and add 1 Fuel every 1 second, can anyone help me? Some tutorials or anything? Links? Or just PWN/CODE quotes?

Reply please.
Reply
#2

Give us the code - there somewhere is one timer witch gives 1 fuel per time ..
Reply
#3

Quote:
Originally Posted by GaGlets®
Give us the code - there somewhere is one timer witch gives 1 fuel per time ..
It's about 300 lines long
pawn Код:
/*
*
*  Fuel System by RyDeR
*  DracoBlue for DCMD
*  Someone for the Gas Station Coцrdinates
*
*/

#include <a_samp>

#define dcmd(%1,%2,%3)          if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1 // Credits go to DracoBlue

#define COLOR_GREY              0xAFAFAFAA
#define COLOR_GREEN             0x33FF33AA
#define COLOR_YELLOW            0xFFFF00AA
#define COLOR_WHITE             0xFFFFFFAA
#define COLOR_BRIGHTRED         0xE60000FF
#define COLOR_BLUE              0x0000FFAA
#define COLOR_PURPLE            0x9900FFAA
#define COLOR_BROWN             0x993300AA
#define COLOR_ORANGE            0xFF9933AA
#define COLOR_CYAN              0x99FFFFAA
#define COLOR_TAN               0xFFFFCCAA
#define COLOR_PINK              0xFF66FFAA
#define COLOR_KHAKI             0x999900AA
#define COLOR_LIME              0x99FF00AA
#define COLOR_BLACK             0x000000AA
#define COLOR_TURQ              0x00A3C0AA
#define COLOR_LIGHTBLUE         0x33CCFFAA
#define COLOR_DARKRED           0xAA993333
#define COLOR_VIOLET            0x9955DEEE
#define COLOR_RED               0xFB0000FF

#define DIVBY          1.300

new
    Benzin[MAX_VEHICLES],
    bool:PortableFuel[MAX_PLAYERS],
    FuelTimer;

new
    Text: Fuel[MAX_PLAYERS],
    Text: BlackBox,
    Text: Moving[MAX_PLAYERS];


public OnFilterScriptInit()
{
    FuelTimer = SetTimer("SubFuel", 12000, true);
    print("----------------------------------");
    print(" Fuel System by RyDeR - Loaded - ");
    print("----------------------------------");
   
    BlackBox = TextDrawCreate(354.000000, 422.000000, "_");
    TextDrawBackgroundColor(BlackBox, 255);
    TextDrawFont(BlackBox, 1);
    TextDrawLetterSize(BlackBox, 0.509999, 1.000000);
    TextDrawColor(BlackBox, -1);
    TextDrawSetOutline(BlackBox, 0);
    TextDrawSetProportional(BlackBox, 1);
    TextDrawSetShadow(BlackBox, 1);
    TextDrawUseBox(BlackBox, 1);
    TextDrawBoxColor(BlackBox, 0xFF80001A);
    TextDrawTextSize(BlackBox, 277.000000, 51.000000);
   
    new
      i;
     
    while (i != GetMaxPlayers())
    {
        Fuel[i] = TextDrawCreate(258.000000, 421.000000, " ");
        TextDrawBackgroundColor(Fuel[i], 255);
        TextDrawFont(Fuel[i], 1);
        TextDrawLetterSize(Fuel[i], 0.250000, 1.100000);
        TextDrawColor(Fuel[i], -1);
        TextDrawSetOutline(Fuel[i], 0);
        TextDrawSetProportional(Fuel[i], 1);
        TextDrawSetShadow(Fuel[i], 1);

        Moving[i] = TextDrawCreate(354.000000, 422.000000, "_");
        TextDrawBackgroundColor(Moving[i], 255);
        TextDrawFont(Moving[i], 1);
        TextDrawLetterSize(Moving[i], 0.509999, 1.000000);
        TextDrawColor(Moving[i], -1);
        TextDrawSetOutline(Moving[i], 0);
        TextDrawSetProportional(Moving[i], 1);
        TextDrawSetShadow(Moving[i], 1);
        TextDrawUseBox(Moving[i], 1);
        TextDrawBoxColor(Moving[i], 0xFF8000C1);
        TextDrawTextSize(Moving[i], 277.000000, 51.000000);
        ++i;
    }
   
    new
        v;
       
    while (v != MAX_VEHICLES)
    {
      Benzin[v] = random(100);
        ++v;
    }
    return 1;
}

public OnFilterScriptExit()
{
    new
        i,
        v;
       
    while (i != GetMaxPlayers())
    {
        TextDrawDestroy(Fuel[i]);
        TextDrawDestroy(Moving[i]);
        ++i;
    }
    TextDrawDestroy(BlackBox);
    KillTimer(FuelTimer);
   
    while (v != MAX_VEHICLES)
    {
      Benzin[v] = 100;
        ++v;
    }
    return 1;
}

forward SubFuel();
public SubFuel()
{
    new
      i;
     
    while (i != GetMaxPlayers())
    {
      if (IsPlayerInAnyVehicle(i))
      {
          new string[128];
        if(Benzin[GetPlayerVehicleID(i)] <0) Benzin[GetPlayerVehicleID(i)] = 0;
          if(IsPlayerInAnyVehicle(i))
          {
            Benzin[GetPlayerVehicleID(i)]-=1;
            format(string, 128, "Fuel:    %%%d", Benzin[GetPlayerVehicleID(i)]);
            TextDrawSetString(Fuel[i], string), TextDrawShowForPlayer(i, Fuel[i]),
                    TextDrawShowForPlayer(i, BlackBox),
                        TextDrawTextSize(Moving[i], (354.0 - (Benzin[GetPlayerVehicleID(i)] / DIVBY)), 0.000000),
                            TextDrawShowForPlayer(i, Moving[i]);
          }
          if (Benzin[GetPlayerVehicleID(i)] < 1)
            {
                Benzin[GetPlayerVehicleID(i)] = 0;
            GameTextForPlayer(i, "~n~~n~~n~~n~~n~~n~~n~~w~You don't have fuel in your vehicle.", 4000, 3);
            TogglePlayerControllable(i, false);
            RemovePlayerFromVehicle(i);
            }
        }
        else
        {
          TextDrawHideForPlayer(i, Fuel[i]),
                TextDrawHideForPlayer(i, BlackBox),
                    TextDrawHideForPlayer(i, Moving[i]);
          GameTextForPlayer(i, " ", 100, 3);
          TogglePlayerControllable(i, true);
        }
        ++i;
    }
    return 1;
}

public OnVehicleSpawn(vehicleid)
{
    Benzin[vehicleid] = random(100);
}

public OnPlayerConnect(playerid)
{
    PortableFuel[playerid] = false;
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    TextDrawHideForPlayer(playerid, Fuel[playerid]);
    TextDrawHideForPlayer(playerid, Moving[playerid]);
    TextDrawHideForPlayer(playerid, BlackBox);
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    TextDrawHideForPlayer(playerid, Fuel[playerid]);
    TextDrawHideForPlayer(playerid, Moving[playerid]);
    TextDrawHideForPlayer(playerid, BlackBox);
    return 1;
}

dcmd_fill (playerid, params[])
{
    new
        miktar,
        string[128],
        string2[128],
        string3[128],
        string4[128],
        Fiyat,
        Sum;
       
    if (!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_RED, ">> You are not in any vehicle to refill!");
    if (!IsAtGasStation(playerid)) return SendClientMessage(playerid, COLOR_RED, ">> You are not in a gas station!");
    if (!strlen(params)) return SendClientMessage(playerid, COLOR_RED, ">> /fill [amount in 0 - 100 l]");
    miktar = strval(params);
    if (miktar < 1 || miktar > 100) return SendClientMessage(playerid, COLOR_RED, ">> Wrong amount in liters! (0-100l)");
    if (Benzin[GetPlayerVehicleID(playerid)] >= 100) return SendClientMessage(playerid, COLOR_RED, ">> You can't refill. Your car is full!");
    Fiyat = (miktar * 2);
    format(string2, 128, ">> You don't have money enough! You need $%d.", Fiyat);
    if (GetPlayerMoney(playerid) < Fiyat) return SendClientMessage(playerid, COLOR_RED, string2);
    GivePlayerMoney(playerid, -Fiyat);
    format(string, 128, ">> You have filled your vehicle for %d liters. Cost: $%d.", miktar, Fiyat);
    SendClientMessage(playerid, COLOR_LIME, string);
    Benzin[GetPlayerVehicleID(playerid)] += miktar;
    if (Benzin[GetPlayerVehicleID(playerid)] > 100) Sum = miktar*2-Benzin[GetPlayerVehicleID(playerid)]+100, GivePlayerMoney(playerid, Sum), format(string4, 128, ">> You have choose a too large amount of liters that your car can't accept. Here's your change($%d).", Sum), SendClientMessage(playerid, COLOR_ORANGE, string4), Benzin[GetPlayerVehicleID(playerid)] = 100;
    format(string3, 128, "Fuel:    %%%d", Benzin[GetPlayerVehicleID(playerid)]);
    TextDrawSetString(Fuel[playerid], string3),
        TextDrawShowForPlayer(playerid, Fuel[playerid]),
            TextDrawTextSize(Moving[playerid], (354.0 - (Benzin[GetPlayerVehicleID(playerid)] / DIVBY)), 0.000000),
                TextDrawShowForPlayer(playerid, Moving[playerid]);
    return 1;
}

dcmd_buyfuel (playerid, params[])
{
    #pragma unused params
    if (!IsAtGasStation(playerid)) return SendClientMessage(playerid, COLOR_RED, ">> You are not in a gas station!");
    if (PortableFuel[playerid] == true) return SendClientMessage(playerid, COLOR_RED, ">> You can't have more than one tank.");
    SendClientMessage(playerid, COLOR_LIME, ">> You have bought a little fuel tank. You can use it when your fuel is low. (/usefuel)");
    PortableFuel[playerid] = true;
    return 1;
}

dcmd_usefuel (playerid, params[])
{
    new
      string[128];
     
    #pragma unused params
    if (!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_RED, ">> You are not in any vehicle!");
    if (Benzin[GetPlayerVehicleID(playerid)] >= 40) return SendClientMessage(playerid, COLOR_RED, ">> You have fuel enough.");
    SendClientMessage(playerid, COLOR_LIME, ">> You used your fuel tank. (Fuel +25)");
    Benzin[GetPlayerVehicleID(playerid)] += 25;
    PortableFuel[playerid] = false;
    format(string, 128, "Fuel:    %%%d", Benzin[GetPlayerVehicleID(playerid)]);
    TextDrawSetString(Fuel[playerid], string),
        TextDrawShowForPlayer(playerid, Fuel[playerid]),
            TextDrawTextSize(Moving[playerid], (354.0 - (Benzin[GetPlayerVehicleID(playerid)] / DIVBY)), 0.000000),
                TextDrawShowForPlayer(playerid, Moving[playerid]);
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    dcmd (fill, 4, cmdtext);
    dcmd (buyfuel, 7, cmdtext);
    dcmd (usefuel, 7, cmdtext);
    return 0;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    new
      string[128],
        string2[128];
       
   
    if(newstate == PLAYER_STATE_DRIVER)
    {
        format(string, 128, "Fuel:    %%%d", Benzin[GetPlayerVehicleID(playerid)]);
        TextDrawSetString(Fuel[playerid], string),
            TextDrawShowForPlayer(playerid, Fuel[playerid]),
                TextDrawShowForPlayer(playerid, BlackBox),
                    TextDrawTextSize(Moving[playerid], (354.0 - (Benzin[GetPlayerVehicleID(playerid)] / DIVBY)), 0.000000),
                        TextDrawShowForPlayer(playerid, Moving[playerid]);
      if (Benzin[GetPlayerVehicleID(playerid)] < 1)
        {
            Benzin[GetPlayerVehicleID(playerid)] = 1;
            format(string2, 128, "Fuel:    %%%d", Benzin[GetPlayerVehicleID(playerid)]);
            TextDrawSetString(Fuel[playerid], string2),
                TextDrawShowForPlayer(playerid, Fuel[playerid]),
                    TextDrawTextSize(Moving[playerid], (354.0 - (Benzin[GetPlayerVehicleID(playerid)] / DIVBY)), 0.000000),
                        TextDrawShowForPlayer(playerid, Moving[playerid]);
        }
        if(Benzin[GetPlayerVehicleID(playerid)] < 1)
        {
          Benzin[GetPlayerVehicleID(playerid)] = 0;
            GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~n~~n~~w~You don't have fuel in your vehicle.", 4000, 3);
        RemovePlayerFromVehicle(playerid);
        }
    }
    else if (newstate == PLAYER_STATE_ONFOOT)
    {
      TextDrawHideForPlayer(playerid, Fuel[playerid]),
            TextDrawHideForPlayer(playerid, BlackBox),
            TextDrawHideForPlayer(playerid, Moving[playerid]);
      TogglePlayerControllable(playerid, true);
    }
    return 1;
}

stock IsAtGasStation(playerid)
{
  if(IsPlayerConnected(playerid))
    {
        // LV Gas Station 1
        if(IsPlayerInRangeOfPoint(playerid, 7.0,2194.349853,2457.038330,10.820312))
        {
          return 1;
        }
        // LV Gas Station 1
        else if(IsPlayerInRangeOfPoint(playerid, 7.0,2197.349853,2457.038330,10.820312))
        {
          return 1;
    }
    // return 0;
}
}
Reply
#4

use not [pwn] xD
Reply
#5

Quote:
Originally Posted by Namaco
use not [pwn] xD
Haha sorry, thought it was [pwn] :P, edited, any idea?
Reply
#6

No body knows? C'monnn
Reply
#7

No one knows? come on it can't be that hard i've seen alot of servers with it :S
Reply
#8

well create a timer like this
Код:
SetTimerEx("refillcar",1000,1,"d",playerid);
then create the "refillcar"
Код:
forward refillcar(playerid);
public refillcar(playerid)
{
Fuel[playerid]++;
}
note that this will refill and not stop refilling, to make it stop after x times you need to create 3 new variables, 1 for the amount it needs to refill, another to count up to that number and another one for the timer.
like this.

top of the script
Код:
new refilltimes[MAX_PLAYERS];
new refillcount[MAX_PLAYERS];
new refilltimer[MAX_PLAYERS];
then in the /refill command
Код:
refilltimes[playerid] = 100-Fuel[playerid];
refillcount[playerid] = 0;
killtimer(refilltimer[playerid]);
refilltimer[playerid] = SetTimerEx("refillcar",1000,1,"d",playerid);
then in the timer
Код:
if(refillcount[playerid] == refilltimes[playerid]) killtimer(refilltimer[playerid]);
refillcount[playerid]++;
Reply
#9

Quote:
Originally Posted by cessil
well create a timer like this
Код:
SetTimerEx("refillcar",1000,1,"d",playerid);
then create the "refillcar"
Код:
forward refillcar(playerid);
public refillcar(playerid)
{
Fuel[playerid]++;
}
note that this will refill and not stop refilling, to make it stop after x times you need to create 3 new variables, 1 for the amount it needs to refill, another to count up to that number and another one for the timer.
like this.

top of the script
Код:
new refilltimes[MAX_PLAYERS];
new refillcount[MAX_PLAYERS];
new refilltimer[MAX_PLAYERS];
then in the /refill command
Код:
refilltimes[playerid] = 100-Fuel[playerid];
refillcount[playerid] = 0;
killtimer(refilltimer[playerid]);
refilltimer[playerid] = SetTimerEx("refillcar",1000,1,"d",playerid);
then in the timer
Код:
if(refillcount[playerid] == refilltimes[playerid]) killtimer(refilltimer[playerid]);
refillcount[playerid]++;
Is it possible I can make it stop once it hits 100, or moves away from the range of view point?
Reply
#10

did you even read what I wrote?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)