SA-MP Forums Archive
2 questions - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: 2 questions (/showthread.php?tid=560246)



2 questions - Sime30 - 27.01.2015

Hi guys, how's it going?

Recently with some tests I noticed that my fuel system only works on first vehicle on server. It won't decrease on any other vehicle. I will gladly put all codes necessary.

pawn Код:
#undef MAX_VEHICLES
#define MAX_VEHICLES 500
public FuelAndSync()
{
    for(new i = 1; i <= MAX_VEHICLES; i++)
    {
        if (IsValidVehicle(i))
        {
            if(!IsABicikl(i)) // is not a bicycle
            {

                    if(VehInfo[i][Motor] == false) return 1; // engine
                    if(VehInfo[i][Gorivo] >= 0.60) // fuel
                    {
                        if(IsATruck(i)) { VehInfo[i][Gorivo] -= 0.40; }
                        else if(IsAOldCar(i)) { VehInfo[i][Gorivo] -= 0.40; } //
                                                 // ....
                    }
                    else
                    {
                        ToggleVehicleEngine(i);
                        VehInfo[i][Motor] = false;
                        VehInfo[i][NemaGoriva] = true;
                       
                        foreach (Player, j)
                        {
                            if(IsPlayerInVehicle(j, i) && GetPlayerState(j) == PLAYER_STATE_DRIVER)
                            {
                                SCM(j, COLOR_LIGHTRED, "Ostali ste bez goriva!");
                               
                            }
                        }
                    }
            }
        }
    }
And also I am wondering why my fuel shows e.g. 3.59 L when it should 3.60? Do I need to round it?


Re: 2 questions - Sid_Alexander - 27.01.2015

Try changing this:
pawn Код:
for(new i = 0; i < MAX_VEHICLES; i++)



Re: 2 questions - Sime30 - 27.01.2015

Quote:
Originally Posted by Sid_Alexander
Посмотреть сообщение
Try changing this:
pawn Код:
for(new i = 0; i < MAX_VEHICLES; i++)
Vehicle IDs start from 1 so there is no need for putting 0 here.

P.S. I already had it that way and big NOPE


Re: 2 questions - Sime30 - 27.01.2015

Can somebody help me before I go on a trip?


Re: 2 questions - Jefff - 27.01.2015

Change return 1; to continue;


Re: 2 questions - Sime30 - 27.01.2015

Return at the engine false part?


Re: 2 questions - Jefff - 27.01.2015

Yes because it stops other ids after id 0


Re: 2 questions - Sime30 - 27.01.2015

Okay, thank you very much. Wouldn't want to bother you any longer but do you know maybe why my float looks like 3.59 and not 3.60? 4.00 - 0.40...

Edited pardon


Re: 2 questions - DobbysGamertag - 27.01.2015

Have to say this:

pawn Код:
for(new i =0; i < MAX_VEHICLES; i++)
That loops through ALL vehicles...

Why not use foreach?

pawn Код:
foreach(Player, pid)
{
    switch(GetPlayerState(pid))
    {
        case PLAYER_STATE_DRIVER
        {
             new vid = GetPlayerVehicleID(pid);
             //lower the fuel...
        }
    }
}
If you want to round stuff, use floatround


Re: 2 questions - Jefff - 27.01.2015

Quote:
Originally Posted by Sime30
Посмотреть сообщение
Okay, thank you very much. Wouldn't want to bother you any longer but do you know maybe why my float looks like 3.59 and not 3.60? 4.00 - 0.40...

Edited pardon
Try this
0.4 or 0.400001 or 0.40001