#1

as i said in my old topic i added my fuel problem but noone took any notice so ill do it here

My Problem Is As Follows: My Fuel System Works Fine But I Can Fuel Anywhere So Can Someone Help Me With Fuel Stations Code Below:

Code:
// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT

#include <a_samp>
new fuel[MAX_VEHICLES]; //fuel per vehicle
forward timer_fuel_lower(); //timer for lowering the fuel value
forward timer_refuel(playerid); //timer to refuel vehicle
new isrefuelling[MAX_PLAYERS] = 0; //bool to check if player is already refuelling
new Text:td_fuel[MAX_PLAYERS]; //textdraw with fuel
#define Yellow 0xFFFF00AA

public OnFilterScriptInit()
{
	print("\n--------------------------------------");
	print(" Fuel System by Zoe Loaded!!");
	print("--------------------------------------\n");
	for(new i=0;i<MAX_VEHICLES;i++) {
      fuel[i] = 100; //sets every car's fuel to 100 in a loop
    }
    SetTimer("timer_fuel_lower",4200,true); //sets the timer to drop the fuel
	return 1;
}

public OnPlayerSpawn(playerid)
{
    td_fuel[playerid] = TextDrawCreate(45,324,"Fuel: 100"); //create the textdraw at position
    TextDrawBackgroundColor(td_fuel[playerid],0x00000033); //setting an nice backgroundcolor
    TextDrawFont(td_fuel[playerid],3); //font type of textdraw
    TextDrawLetterSize(td_fuel[playerid],0.699999,1.700000); //size...
    TextDrawColor(td_fuel[playerid],0x000000ff); //color
    TextDrawSetShadow(td_fuel[playerid],3); //dropping the shadow
	return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (!strcmp("/refuel",cmdtext,true,7)) {
        if (!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,0xFFC800FF,"You are not in an vehicle!"); //if a player isnt in a vehicle, it stops here
        if (isrefuelling[playerid]) return SendClientMessage(playerid,0xFFC800FF,"You are already refuelling!"); //if a player is already refuelling, it stops here
        if (GetPlayerMoney(playerid) - 80 <0) return SendClientMessage(playerid,0xFFC800FF,"You dont have enough money!"); //if a player doesnt have $80 anymore, it stops here
        GivePlayerMoney(playerid,-80); //Sets the player's cash -$80
        SetCameraBehindPlayer(playerid); //Sets the camera behind the player (looks better because the player will be frozen for a few secs)
        TogglePlayerControllable(playerid,0); //freezes the player so he cant drive and refuel at the same time
        isrefuelling[playerid] = 1; //setting isrefuelling to 1 so the player cant spam /refuel
        TextDrawSetString(td_fuel[playerid],"Refuelling..."); //changing textdraw to /refuel
        SetTimerEx("timer_refuel",4500,false,"i",playerid); //setting refueltimer
        return 1;
    }

    return 0;
}

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,"Fuel:%i",fuel[vid]); //quickly doing a small update on fuel (so it wont jump from 100 to its real value)
        TextDrawSetString(td_fuel[playerid],string);
        TextDrawShowForPlayer(playerid,td_fuel[playerid]); //showing if an player is a driver or passenger of the ar
    } else {
        TextDrawHideForPlayer(playerid,td_fuel[playerid]); //hiding if a player isnt driving/or an passenger
    }
    return 1;
}

public timer_fuel_lower()
{
    for(new i=0;i<MAX_PLAYERS;i++) { //loop for all players
        if (isrefuelling[i]) continue; //stop when a player is already refuelling
        new vid = GetPlayerVehicleID(i); //getting vehicle ID
        if (GetPlayerVehicleSeat(i) == 0) { //if the player is a driver (it should only lower the fuel when theres an driver!)
            fuel[vid] = fuel[vid] -1; //lowering fuel value
            if (fuel[vid]<1) //if fuel is empty
            {
                fuel[vid] = 0; //setting fuel to 0 (else the timer will set it to -1 -2 -3 etc before removing player)
                RemovePlayerFromVehicle(i); //remove player out of vehicle
                GameTextForPlayer(i,"~r~You are out of ~w~fuel~r~!",5000,4); //show text
            }
        }
        new string[125];format(string,sizeof string,"Fuel:%i",fuel[vid]); //preparing string with next fuel value
        TextDrawSetString(td_fuel[i],string); //updating textdraw
    }
    return 1;
}

public timer_refuel(playerid)
{
    new vid = GetPlayerVehicleID(playerid);
    fuel[vid] = fuel[vid] = 100; //restoring fuel to 100
    isrefuelling[playerid] = 0;//resetting anti-spam thingy :3
    TextDrawSetString(td_fuel[playerid],"Fuel:100"); //small update on textdraw
    TogglePlayerControllable(playerid,1); //unfreeze player
}
Please Can Someone Help Me

Regards
[Nuclear]Phoebe
AKA Bella

(Please Excuse My Habit of Caps On Every Word As It's What I Do)
Reply
#2

Quote:
Originally Posted by [HLF]Southclaw
View Post
Well first you need to get the positions of all fuel stations you want in San Andreas.
Next you need to add distance checks to the '/refuel' command, to check if the player is near a fuel station position.

Obviously you don't want to have a ton of if statements in your command, you need to have an array of positions and use a loop to check the distance between you and each position.

Understand? if not I will guide you through it
nope i am quite a new scripter i need some help please guide me
Reply
#3

Phoebe try IsPlayerInRangeOfPoint thats easy!
Reply
#4

wouldn't be easier to store all the positions in a file and load it up using DINI but i need some help with it as i dont know how to do that, now about IsPlayerinRangeOfPoint if i chose that it would take DAYS to load EVERY SINGLE Fuel Station into IsPlayerInRangeOfPoint
Reply
#5

PHP Code:
public OnPlayerCommandText(playeridcmdtext[])
{
    if (!
strcmp("/refuel",cmdtext,true,7)) {
        if (!
IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,0xFFC800FF,"You are not in an vehicle!"); //if a player isnt in a vehicle, it stops here
        
if (isrefuelling[playerid]) return SendClientMessage(playerid,0xFFC800FF,"You are already refuelling!"); //if a player is already refuelling, it stops here
        
if (GetPlayerMoney(playerid) - 80 <0) return SendClientMessage(playerid,0xFFC800FF,"You dont have enough money!"); //if a player doesnt have $80 anymore, it stops here
        
GivePlayerMoney(playerid,-80); //Sets the player's cash -$80
        
SetCameraBehindPlayer(playerid); //Sets the camera behind the player (looks better because the player will be frozen for a few secs)
        
TogglePlayerControllable(playerid,0); //freezes the player so he cant drive and refuel at the same time
        
isrefuelling[playerid] = 1//setting isrefuelling to 1 so the player cant spam /refuel
        
TextDrawSetString(td_fuel[playerid],"Refuelling..."); //changing textdraw to /refuel
        
SetTimerEx("timer_refuel",4500,false,"i",playerid); //setting refueltimer
        
return 1;
    }
    return 
0;

Under

PHP Code:
if (!strcmp("/refuel",cmdtext,true,7)) { 
Add this

PHP Code:
if(IsPlayerInRangeOfPoint(playeridFloat:rangeFloat:xFloat:yFloat:z)) return SendClientMessage(playerid,0xFFFFFFFF,"You are not at a Gas Station"); 
And Edit the Float:range, Float:X, Float:Y, Float:Z, To the Required Location Code.
Reply
#6

Quote:
Originally Posted by [HLF]Southclaw
View Post
@BATAD that's for one position, he needs it for many, if you read his post.


@Phoebe I shall tell you how to do it, give me a few minutes to write
She* im a girl
Reply
#7

Quote:
Originally Posted by [HLF]Southclaw
View Post
@BATAD that's for one position, he needs it for many, if you read his post.


@Phoebe I shall tell you how to do it, give me a few minutes to write
She can Do this

PHP Code:
if(IsPlayerInRangeOfPoint(playeridFloat:rangeFloat:xFloat:yFloat:z) || IsPlayerInRangeOfPoint(playeridFloat:rangeFloat:xFloat:yFloat:z) ||
    
IsPlayerInRangeOfPoint(playeridFloat:rangeFloat:xFloat:yFloat:z) || IsPlayerInRangeOfPoint(playeridFloat:rangeFloat:xFloat:yFloat:z) || 
And So on, Until she's Done all of the Positions
Reply
#8

FUCK THAT i have like 100 odd positions to put in u can forget that Batad
Reply
#9

Quote:
Originally Posted by [Nuclear]Phoebe
View Post
FUCK THAT i have like 100 odd positions to put in u can forget that Batad
What do you expect ?, It won't work, Unless you do that, Anyway, I'll see if i can get ya some Gas Station Tele Codes, But, Don't get your Hopes up, I got Alot of things to do.
Reply
#10

Quote:
Originally Posted by [HLF]Southclaw
View Post
@BATAD that's for one position, he needs it for many, if you read his post.


@Phoebe


Ok, so you want to load the positions from a file? First thing I'm going to say is you don't need DINI for this

Secondly, you need to do is make sure the positions are in the file in the correct format "x, y, z"
If you saved them using /save in game then you will have an extra parameter for the rotation, don't worry about that.

For example one line in the file should look like this:
359.8384, -1285.4875, 12.3564, 180.3853 (maybe an extra parameter here for rotation)


So if you have a file full of co-ordinate sets now I'll show you how to read form them and save to a file.

First thing is you need a global variable at the top of your script to save all the data form the file in while you use them in the script.

Step 1
new gStationPos[enter your amount of fuel station slots here][3];

That declares an array variable with the amount of cells for your sets of co-ordinates for fuel stations, each with 3 'sub' cells of their own that each contain either the X, Y or Z of the position.

Step 2
Now you need a function to call when your gamemode loads to put all the file data into that variable, so you can use it in your command.

pawn Code:
LoadFileData()
{
    new sLine[64], iSlot, File:fuelDataFile;
    fuelDataFile = fopen("Your fuel station data file .ini", io_read); // Opens your fuel station position file, don't forget to put your file name/directory in the first parameter
    while(fread(fuelDataFile, sLine))
    {
        sscanf(sLine, "p<,>fff", gStationPos[iSlot][0], gStationPos[iSlot][1], gStationPos[iSlot][2]);
        // 'sscanf' Splits the line of text that is read from the file into 3 values of data and assigns them to the cells of gStationPos,
        // The first cell is defined by the variable 'iSlot' which starts off as 0, but when the loop restarts it adds 1 to the variable,
        // Meaning that the next time the code is executed it puts the data into the same variable but in the Next cell.

        iSlot++; // Increases the slot variable by one so next time it calls it will put the data into the next cell of the array.
    }
    fclose(fuelDataFile); // Closes the file, as it is no longer needed for data extraction
}
Now when you call this function on OnGameModeInit or OnFilterScriptInit it will load the file and put the data into the global variable you declared earlier.


Step 3
Now you need to put the check on the command, this involves a simple loop and check to see if the player is near Any of the positions


pawn Code:
if(!strcmp("/refuel",cmdtext,true,7))
{
    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,0xFFC800FF,"You are not in an vehicle!"); //if a player isnt in a vehicle, it stops here
    if(isrefuelling[playerid]) return SendClientMessage(playerid,0xFFC800FF,"You are already refuelling!"); //if a player is already refuelling, it stops here
    if(GetPlayerMoney(playerid) - 80 <0) return SendClientMessage(playerid,0xFFC800FF,"You dont have enough money!"); //if a player doesnt have $80 anymore, it stops here

    for(new i;i< put your number of fuel stations here, same number you used in Step 1 ;i++)
    {
        if(!IsPlayerInRangeOfPoint(playerid, 5.0, gStationPos[i][0], gStationPos[i][1], gStationPos[i][2])
        // This checks if the player is NOT near a fuel station, if they are then the code will continue
        // But if they aren't the code will send the player this message and go no further because of the use of 'return'
        {
            return SendClientMessage(playerid, 0xFF0000FF, "You must be near a fuel station");
        }
    }

    GivePlayerMoney(playerid,-80); //Sets the player's cash -$80
    SetCameraBehindPlayer(playerid); //Sets the camera behind the player (looks better because the player will be frozen for a few secs)
    TogglePlayerControllable(playerid,0); //freezes the player so he cant drive and refuel at the same time
    isrefuelling[playerid] = 1; //setting isrefuelling to 1 so the player cant spam /refuel
    TextDrawSetString(td_fuel[playerid],"Refuelling..."); //changing textdraw to /refuel
    SetTimerEx("timer_refuel",4500,false,"i",playerid); //setting refueltimer
    return 1;
}


That should work, keep in mind this was written entirely from theory, no tests and I am renowned for making small mistakes (or large ones!)

Hope it helps you still
Great Tutorial, You made it, Eh ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)