Jump to content

[REL] Vehicle Fuel Script v1.5 Public BETA[CLOSED]


Recommended Posts

  • Replies 97
  • Created
  • Last Reply

Top Posters In This Topic

I made it to not be in minus, but the minus be as owe which gas station knows and about which you can inform yourself, and later come to pay it off. They your owing label will disappear, and when you can get fuel again (max allowed owe: 500$ or 1000$).

Expect this sooner or later, because whole system is in an runnable state currently, and now the script has its server part too.

Cheers ;)

Nidza

Link to comment

Hey, I'm just reading through your source for this and I've noticed something odd. You have "oX,oY,oZ = getElementPosition(getLocalPlayer())" (found in cvehiclefuel_c.lua) to be triggered on onClientResourceStart. I find this strikingly odd because you later use this co-ordinate position to check the distance of the first render of the distance. Theoretically, wouldn't this mean that if when the resource is started, the player does not immediately get into a vehicle, but decides to walk all the way from one side of the map to another, and then get into a vehicle, the distance measured on the first render would be large enough to take away a large proportion of the fuel. I'm not too sure that I'm convinced that it would even work properly if one player exits a vehicle and then walks a great distance before entering another.

It's just some food for thought.

(PS: Yes I have tested and my theory is correct)

EDIT:

Solution is to change oX,oY,oZ = getElementPosition(getLocalPlayer()) from being triggered by onClientResourceStart and move it to be triggered by onClientVehicleEnter.

Link to comment
I found a bug again ^^ (it´s good so it´s bug free when you fixed it :) )

On every marker on the server i get gas! and when i don´t in a verhicle it says "go in a vehicle first (or so)"

Fix that by editing the file cvehiclefuel.lua from:

function onEnterRefillArea(player,sDimension) 
    triggerClientEvent("onGasRefill",getRootElement(),true) 
end 
addEventHandler("onMarkerHit",getRootElement(),onEnterRefillArea) 
  
function onExitRefillArea(playerplayer,sDimension) 
        triggerClientEvent("onGasRefill",getRootElement(),false) 
end 
addEventHandler("onMarkerLeave",getRootElement(),onExitRefillArea) 

to:

function onEnterRefillArea(player,sDimension) 
    local veh isPlayerInVehicle ( player ) 
    if ( veh == true ) then 
        triggerClientEvent("onGasRefill",getRootElement(),true) 
    end 
end 
addEventHandler("onMarkerHit",getRootElement(),onEnterRefillArea) 
  
function onExitRefillArea(playerplayer,sDimension) 
    local veh isPlayerInVehicle ( player ) -- Check if the player is in a vehicle 
    if ( veh == true ) then -- If they are, therefore "true", then continue with the function 
        triggerClientEvent("onGasRefill",getRootElement(),false) 
    end -- The "else" part doesn't need to be defined, because we don't want anything to happen, if it isn't true. 
end 
addEventHandler("onMarkerLeave",getRootElement(),onExitRefillArea) 

Essentially, it serves as a check to make to that the player is in a vehicle when they 'hit' the markers. This should stop it spitting out that message about not being in a vehicle.

Link to comment
Hey, I'm just reading through your source for this and I've noticed something odd. You have "oX,oY,oZ = getElementPosition(getLocalPlayer())" (found in cvehiclefuel_c.lua) to be triggered on onClientResourceStart. I find this strikingly odd because you later use this co-ordinate position to check the distance of the first render of the distance. Theoretically, wouldn't this mean that if when the resource is started, the player does not immediately get into a vehicle, but decides to walk all the way from one side of the map to another, and then get into a vehicle, the distance measured on the first render would be large enough to take away a large proportion of the fuel. I'm not too sure that I'm convinced that it would even work properly if one player exits a vehicle and then walks a great distance before entering another.

It's just some food for thought.

(PS: Yes I have tested and my theory is correct)

EDIT:

Solution is to change oX,oY,oZ = getElementPosition(getLocalPlayer()) from being triggered by onClientResourceStart and move it to be triggered by onClientVehicleEnter.

I know, I have my reasons but I mistaked. I'm C programmer, so just to be assured that variables exists I put them on start of code as nils, like for a setup.

So my solution is just to change it to nil on the start and add checking system to render event which will set oX,oY,oZ to current x,y,z if player wasn't in any vehicle.

And yes your solution is ok, but as I said the things I learned with C I'm not gonna change. I'll use them as nils for awareness of that that player is in vehicle even before he is physically in, and event is called when he is in. It will work this way too anyways

I'll try both of this ways to see if some of them has any unstable parts (but I'm pretty sure that your won't have bugs, except some timing unstableness (two events)).

Thanks for spotting that bug btw.

I found a bug again ^^ (it´s good so it´s bug free when you fixed it :) )

On every marker on the server i get gas! and when i don´t in a verhicle it says "go in a vehicle first (or so)"

Fix that by editing the file cvehiclefuel.lua from:

function onEnterRefillArea(player,sDimension) 
    triggerClientEvent("onGasRefill",getRootElement(),true) 
end 
addEventHandler("onMarkerHit",getRootElement(),onEnterRefillArea) 
  
function onExitRefillArea(playerplayer,sDimension) 
        triggerClientEvent("onGasRefill",getRootElement(),false) 
end 
addEventHandler("onMarkerLeave",getRootElement(),onExitRefillArea) 

to:

function onEnterRefillArea(player,sDimension) 
    local veh isPlayerInVehicle ( player ) 
    if ( veh == true ) then 
        triggerClientEvent("onGasRefill",getRootElement(),true) 
    end 
end 
addEventHandler("onMarkerHit",getRootElement(),onEnterRefillArea) 
  
function onExitRefillArea(playerplayer,sDimension) 
    local veh isPlayerInVehicle ( player ) -- Check if the player is in a vehicle 
    if ( veh == true ) then -- If they are, therefore "true", then continue with the function 
        triggerClientEvent("onGasRefill",getRootElement(),false) 
    end -- The "else" part doesn't need to be defined, because we don't want anything to happen, if it isn't true. 
end 
addEventHandler("onMarkerLeave",getRootElement(),onExitRefillArea) 

Essentially, it serves as a check to make to that the player is in a vehicle when they 'hit' the markers. This should stop it spitting out that message about not being in a vehicle.

About this. You are right, but i don't want that, so because player is in the vehicle it will still refill on every gas station.

I'm interested is it possible to in a map file add element data like:

Because that could help a lot.

EDIT: I found that as correct thanks to lil_Toady on IRC ;)

Don't check bugs anymore in this release because v2 is coming soon so its useless, because some bugs I already got fixed. You'll get another release for that ;)

If anyone wants to collaborate in this project on anyway (testing it, scripting it, giving ideas for it) please contact me over PM for my MSN or Skype address.

Cheers ;)

Nidza

Edited by Guest
Link to comment

I was looking over your script and was wondering why do you have this code in there ?

  
function drawFuelBar() 
    fBar = guiCreateProgressBar(598,158,154,25,false) 
    guiSetVisible(fBar,false) 
end 
addEventHandler("onClientPlayerJoin",getRootElement(),drawFuelBar) 
  

You make a fuel bar in onClientResourceStart(). Won't this then remake a fuel bar each time a player joins ?

Link to comment

Don't check bugs anymore in this release because v2 is coming soon so its useless, because some bugs I already got fixed. You'll get another release for that ;)

If you already fixed that the fuel is refilling at every marker on the map just skip reading this post =)

To avoid that refilling is triggered on every marker in the map you will have to change getRootElement () to either every specific marker element or to a parent element of the markers from the cvvehiclefuel resource.

I changed the cvehiclefuel to this because i think the resource root element must be the parent of all marker elements that are created through the .map file but i have no idea if it works =)

function onEnterRefillArea(player,sDimension) 
    triggerClientEvent("onGasRefill",getRootElement(),true) 
end 
addEventHandler("onMarkerHit",getResourceRootElement(getThisResource()),onEnterRefillArea) 
  
function onExitRefillArea(playerplayer,sDimension) 
        triggerClientEvent("onGasRefill",getRootElement(),false) 
end 
addEventHandler("onMarkerLeave",getResourceRootElement(getThisResource),onExitRefillArea) 

Edit: Maybe you can get directly the root element of the marker.map file by using this:

function onEnterRefillArea(player,sDimension) 
    triggerClientEvent("onGasRefill",getRootElement(),true) 
end 
addEventHandler("onMarkerHit",getResourceMapRootElement(getThisResource()),onEnterRefillArea) 
  
function onExitRefillArea(playerplayer,sDimension) 
        triggerClientEvent("onGasRefill",getRootElement(),false) 
end 
addEventHandler("onMarkerLeave",getResourceMapRootElement(getThisResource()),onExitRefillArea) 

Link to comment

Thats an pretty simple way, but I have started to work it out this way:

- Add Element data directly in mapfile (isstation="true")

- Read Element data.

- If returns false its not my marker forget it :P

- Else do what you got to do

And are you EVER coming to MSN man? Haven't talked long time ago :)

EDIT: Have you blocked me maybe? :lol:

Cheers ;)

Nidza

Link to comment

Although you can add element data, the more acceptable way (and the way the upcoming editor will work) is to create a new element type.

  
<gaspump posX="500" posY="200" posZ="20" /> 
  

Then in the onResourceLoad event, get the set of all gaspump elements (getElementsByType) and create markers for them.

For example (untested):

  
-- get all the gaspump elements in the resource just started 
local pumps = getElementsByType ( "gaspump", getResourceRootElement(loadedResource) )   
for theKey,thePump in ipairs(pumps) do  
    -- not sure this works, you may need to use getElementData on posX, Y and Z 
    local x,y,z = getElementPosition(thePump)  
    -- create our representation (this could be anything, even more than one element) 
    local pumpMarker = createMarker ( x,y,z, "cylinder", 10, 255, 0, 0, 255)  
    -- make the marker we've created a child of the gaspump element (so it's deleted when the map is and we can easily retrieve data from the original element using getElementParent) 
    setElementParent(pumpMarker, thePump)  
end 

You've then got a marker for each of the pumps, which is a child of the 'gaspump' marker.

Then, in your onMarkerHit handler you just need to use:

if getElementType(getElementParent(source)) == "gaspump" then 
-- whatever you want here 
end 

This will check that the marker being hit is a child of a 'gaspump' element. Alternatively, you can use addEventHandler to attach your handler to each individual gaspump element when you load them. This avoids the check in the handler and is marginally more efficient.

The -major- benefit of this method is that you're hiding the 'representation' of the gaspump from the map file. The map file doesn't know that you're using a marker, you decide that. If in the future you decide you want to show gaspumps as objects or as a different kind of marker, you can do that just by modifying your script, without having to get any map makers to change their maps. This is a very widely used method in programming - separating the model (the data) from the view (what you see).

I hope this helps, if you don't understand, feel free to ask on IRC or here.

Link to comment

Cool, thanks I added 11 and found 2 which still ain't added, so I'm still gonna have some job. :P

Update on development progress (v2 most notable changes):

- a new mapsystem (eAi's idea)

- blips showing and hiding when you are nearby (like on real radar map in GTA:SA)

- partially finished paying system

Ideas:

- bind keys to allow player to add specific amount of fuel (ex. "l" = 10% ; "k" = 1%)

- to have price moved from 10$ per 1% (way too much) to 1.5$ per 1% (15 per 10% ; 10% ~ 1l; Xoomer 1l price: 14.99)

P.S. inform me do you like the ideas, give your ideas and advice me if you got something interesting, like eAi did. Also go on with bug catching this time I'm gonna make it bug free as much as possible in v2 (but first check out other bug posts!)

P.S.S. eAi your mapsystem advice was so excellent! It fixed me several bugs at once and allowed me some new features :)

P.S.S.S. A big thanks to the people from IRC who helped me (lil_Toady,50p,NeO_Cazomino,Hankey,MeKorea,eAi,well Borov too :P,and the rest) , and standed by me when I needed help ;)

Cheers ;)

Nidza

Link to comment
Instead of using some special keys for refueling, why not make some special window for refueling? In the window you could see a progress bar for the refueling and also the price for the fuel you have refueled so far.

Because of a simple reason:

When peoples are in a rush they would only go thorough checkpoint, and pressing keys would slow them down a bit, but getting in job with GUI when they are in some kind of endurance race or etc? :S

Your idea practically is interesting, and if some more people requests it, it could be done.

Cheers ;)

Nidza

Link to comment
Why not creating a colshape and start refilling when player stops completely?

Again reason (^^):

Although I could do that I already got markers for it which are highly viewable, and colshapes are used to show and hide blips, so I would need to rewrite mapsystem (again :|) for it.

EDIT: Ok I readed again your post. So you mean when player stops fully :)

Well that might be done to make sure to players don't just "fly" through checkpoints, but I'll for start work with it + mine keys idea. (remember this is just development its possible to be changed for full release so don't be too worried)

The Main reason:

My cash owing system won't work well if it auto refills because timer has to go in short periods (but in this case too short).

So for now I'll ease up the work by adding it on the keys, because with them you can choose "exactly" how much fuel you want, and spend money as much as you want (I'm not meaning on too much, if you need to buy weapons or something too).

And if I would make a command for adding specified amount that would be slowing down the player a lot.

So I think its going to be best to have two keys binded, one for 10% adding, and another for 1% adding.

If you think that these idea is not ok, comment then.

Cheers ;)

Nidza

Link to comment

You wouldn't have to rewrite the mapsystem. Just create colshape instead of marker. You still get the coords from "map" then just take away 10 from the x ad 10 to x and take away 10 from y & add 10 to y, so it will make your colshape a square. That's just an idea, you can always ignore it.

Link to comment
You wouldn't have to rewrite the mapsystem. Just create colshape instead of marker. You still get the coords from "map" then just take away 10 from the x ad 10 to x and take away 10 from y & add 10 to y, so it will make your colshape a square. That's just an idea, you can always ignore it.

No idea is ok man, but I want to gas stations be slightly visible.

And my development is heavily slowed down, because I can't load wiki...

I can load only MTA forum, community and nothing mode at ALL. :x

Cheers :(

Nidza

Link to comment

Just make the marker AND a col shape. That way you can see the gas station and refill in the col shape - I think this would work much better than binding keys to small amounts of fuel. You could a HUD display showing the fuel refilling and your money dropping. When done you just drive away.

Link to comment

There is a serious bug in this script. It allows the vehicle/person to fuel on ANY marker. This is a serious bug as you see "You must be in a vehicle to fuel" as you enter and exit any building with door markers.

Link to comment
There is a serious bug in this script. It allows the vehicle/person to fuel on ANY marker. This is a serious bug as you see "You must be in a vehicle to fuel" as you enter and exit any building with door markers.

Maybe a Solution:

  
setElementData ( marker, "isGasPumpMarker", true ) 
  

On mark hit get the ElementData when it is true do the rest

NVM

Edited by Guest
Link to comment
There is a serious bug in this script. It allows the vehicle/person to fuel on ANY marker. This is a serious bug as you see "You must be in a vehicle to fuel" as you enter and exit any building with door markers.

AS I ALREADY SAID: Some bugs are fixed already, and you should read other posts before posting. eAi's map idea has fixed that bug.

But v2.0 will be here after DP3 goes out unfortunately, because some functions I'm gonna need will be implemented in DP3, so this script won't be part of DP3 release most probably.

Cheers ;)

Nidza

Link to comment

No way I would stop developing this. :)

I'll go until I do everything planned/asked to be done.

Even when this calms down, and someone digs it from the archive, feel free to make even EPIC bumps, and I'll do what you asked to be done if its possible!

BTW: Cheers, this got up to 300 downloads! Thanks for everyone who gave it a chance, and voted for it also!

Expect v2.0 soon!

Cheers ;)

Nidza

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...