SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 28/05/2012, 10:20 AM   #1
ricardo178
High-roller
 
ricardo178's Avatar
 
Join Date: Dec 2010
Posts: 1,598
Reputation: 91
Default Custom Fuel system taking 2 fuel instead of 1.

Hello there. I made my own fuel system, very simple. I have set a timer under OnPlayerEnterVehicle, that leads to function CFuel every 2 Minutes. That works, but, than, it loses 2 fuel, instead of 1...

Here is the code:

pawn Code:
Under OnPlayerStateChange, after checking if player is in vehicle...

SetTimer("CFuel", 120000, true);

Than, the function..

forward CFuel(playerid);
public CFuel(playerid)
{
    new vid;
    vid = GetPlayerVehicleID(playerid);
    format(file, sizeof(file), "RRP/vehicles/%d.ini", vid);
    if(fexist(file))
    {
        if(dini_Int(file, "Fuel") <= 0)
        {
            SendClientMessage(playerid, COLOR_LIGHTRED, "You are out of fuel.");
            GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective);
            SetVehicleParamsEx(vid,false,lights,alarm,doors,bonnet,boot,objective);
            return 1;
        }
        if(dini_Int(file, "Fuel") <= 100)
        {
            dini_IntSet(file, "Fuel", dini_Int(file, "Fuel")-1);
            return 1;
        }
        return 1;
    }
    return 1;
}
ricardo178 is offline   Reply With Quote
Old 28/05/2012, 10:21 AM   #2
Vince
Spam Machine
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 10,071
Reputation: 2655
Default Re: Custom Fuel system taking 2 fuel instead of 1.

SetTimerEx.
__________________
Vince is offline   Reply With Quote
Old 28/05/2012, 10:22 AM   #3
Face9000
Banned
 
Join Date: Jan 2010
Location: Pigland
Posts: 3,351
Reputation: 190
Default Re: Custom Fuel system taking 2 fuel instead of 1.

pawn Code:
if(dini_Int(file, "Fuel") == 0)
        {
            SendClientMessage(playerid, COLOR_LIGHTRED, "You are out of fuel.");
            GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective);
            SetVehicleParamsEx(vid,false,lights,alarm,doors,bonnet,boot,objective);
            return 1;
        }
        if(dini_Int(file, "Fuel") <= 100)
        {
            dini_IntSet(file, "Fuel", dini_Int(file, "Fuel")-=1);
            return 1;
        }

Try it,idk if works.
Face9000 is offline   Reply With Quote
Old 28/05/2012, 11:17 AM   #4
iGetty
High-roller
 
iGetty's Avatar
 
Join Date: Sep 2010
Location: Falkirk, Scotland
Posts: 1,753
Reputation: 224
Default Re: Custom Fuel system taking 2 fuel instead of 1.

Also; you want to define the variable for the timer name. So then you can kill it when the player get's out.
iGetty is offline   Reply With Quote
Old 28/05/2012, 11:20 AM   #5
milanosie
High-roller
 
milanosie's Avatar
 
Join Date: Dec 2011
Location: Amsterdam, Netherlands
Posts: 1,662
Reputation: 379
Default Re: Custom Fuel system taking 2 fuel instead of 1.

SetTimer is a global timer for every player,

Use SetTimerEx instead to only set it for the player,
milanosie is offline   Reply With Quote
Old 28/05/2012, 11:41 AM   #6
ricardo178
High-roller
 
ricardo178's Avatar
 
Join Date: Dec 2010
Posts: 1,598
Reputation: 91
Default Re: Custom Fuel system taking 2 fuel instead of 1.

Thanks guys. I fixed it.. The problem was i setted the timmer before checking if player is inside vehicle, so it probably was setting everytime player state change.
ricardo178 is offline   Reply With Quote
Old 27/04/2013, 10:16 AM   #7
Zaer0
Little Clucker
 
Zaer0's Avatar
 
Join Date: Apr 2013
Posts: 5
Reputation: 3
Default Re: Custom Fuel system taking 2 fuel instead of 1.

awesome
__________________
My Work

[ URL="http://forum.sa-mp.com/showthread.php?t=433396"]Kacc Fuel Depot[ /URL]
Zaer0 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fuel[i] -= 1; (Insted of taking 1, takes all fuel) HondaCBR Scripting Help 2 15/04/2012 01:03 PM
Fuel System Help CoaPsyFactor Help Archive 2 30/07/2010 10:36 PM
Fuel system [help] aleancuervo Help Archive 4 17/04/2010 01:56 AM
[Help] Fuel System Pantontini Help Archive 6 28/04/2009 11:50 PM


All times are GMT. The time now is 07:56 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.