Page 1 of 1

Fuel that increase acceleration

Posted: Fri Jul 31, 2015 8:17 am
by cpy
Any idea if there is a way to make fuel that will increase acceleration of trains/cars/tank and perhaps increase max speed?

Re: Fuel that increase acceleration

Posted: Fri Jul 31, 2015 8:22 am
by BurnHard
Are you looking for something like the "Back to the Future" Presto-Logs perhaps? :D

http://vignette3.wikia.nocookie.net/btt ... 1005034604
Image
http://vignette1.wikia.nocookie.net/btt ... 0211084131
Image

Re: Fuel that increase acceleration

Posted: Fri Jul 31, 2015 8:27 am
by cpy
More like nitrous oxide and hydrazine. I have everything prepared, items, recipes and tech. Now i need help how to make them work with trains and cars to give them better acceleration/max speed and not being just fuel.

Re: Fuel that increase acceleration

Posted: Fri Jul 31, 2015 9:45 am
by Xyfi
You can use the following Lua/Entity variables to influence speed / fuel consumption:

effectivity_modifier
consumption_modifier
friction_modifier

So you wan't to consume some item (i.e. nitrous oxide) on a button press of something?

Re: Fuel that increase acceleration

Posted: Fri Jul 31, 2015 9:59 am
by cpy
I would like that but, i absolutely have no idea how to code special fuel slot for trains and cars and bind some buttons to it and work in multiplayer.

Baby steps with just better fuel and then maybe if someone knows how to do it i would, hey maybe someone else would find this useful too then. Thanks for parameter info!

So where do i put this friction_modifier? When I put vehicle_friction_modifier or friction_modifier to my new fuel item it does not seem to do anything.

Re: Fuel that increase acceleration

Posted: Fri Jul 31, 2015 10:38 am
by Xyfi
Friction is used to calculate the speed/acceleration (and deceleration?) of a car based on the terrain it's driving on. You can access it for instance by:

Control.lua

Code: Select all

game.on_event(defines.events.on_built_entity, function(event)
   local entity = event.built_entity
   if entity.name == "car" then
     entity.friction_modifier = 0.5
   end
end)
The above code will make a car much faster by reducing friction on all terrains.

It should be possible to access the fuel-inventory of a car, but you can't add an additional inventory. What you could do is access the regular inventory of the car and see if it has a stack of "Nitrous boosts" and consume one and temporarily reduce friction in game.on_tick.

You can access the cars inventories through Lua/Entity.get_inventory(index), but I don't know what inventory is on what index, so you'll have to do some digging.

Re: Fuel that increase acceleration

Posted: Fri Jul 31, 2015 10:40 am
by cpy
Wouldn't this modify speed at all times no matter what fuel is used? I want cars and trains to go different speeds depending on fuel used.

I need effect based on fuel type, i can modify car speed once, but that is not point of all this.

Re: Fuel that increase acceleration

Posted: Fri Jul 31, 2015 10:46 am
by Xyfi
cpy wrote:Wouldn't this modify speed at all times no matter what fuel is used? I want cars and trains to go different speeds depending on fuel used.

I need effect based on fuel type, i can modify car speed once, but that is not point of all this.
I moddified the post a bit with some extra information.

The problem with making the car go a certain speed for a certain fuel is that you can't access what type of fuel the car is using at the moment.

Re: Fuel that increase acceleration

Posted: Fri Jul 31, 2015 10:48 am
by cpy
I'll just use old roadworks script for that now. I was hoping there is new mod api for that or something that does not require use of scripts.

Re: Fuel that increase acceleration

Posted: Fri Jul 31, 2015 11:19 am
by Xyfi
cpy wrote:I'll just use old roadworks script for that now. I was hoping there is new mod api for that or something that does not require use of scripts.
Hmm, neven seen that mod before, I'll check out it's code for sure.

Update
He pretty much uses what I summed up above, checking the fuel-inventory and adjusting the car's parameters accoringly and rechecking every few ticks. So the speed of the car is based on whatever is in the fuel-inventory rather than the actual fuel it is using.

Re: Fuel that increase acceleration

Posted: Fri Jul 31, 2015 11:23 am
by cpy
Looks like game does not know what is game.find_entities_filtered crap.

When roadworks try to call

local entities = game.find_entities_filtered{area = {{carPosition.x - 0.75, carPosition.y - 0.75}, {carPosition.x + 0.75, carPosition.y + 0.75}}, type="simple-entity"}

Re: Fuel that increase acceleration

Posted: Fri Jul 31, 2015 11:41 am
by Xyfi
cpy wrote:Looks like game does not know what is game.find_entities_filtered crap.

When roadworks try to call

local entities = game.find_entities_filtered{area = {{carPosition.x - 0.75, carPosition.y - 0.75}, {carPosition.x + 0.75, carPosition.y + 0.75}}, type="simple-entity"}
It has been changed (assuming you mod for .12.1), you have to call find_entities_filtered now on Lua/Surface. You can get the surface via game.surface[1](.find_entities_filtered).

By the way I posted a modding API request for your perticular needs here, let's hope kovarex picks up on it.

Re: Fuel that increase acceleration

Posted: Fri Jul 31, 2015 11:48 am
by cpy
Where did you read all about those surface changes? Anyway i decided to remove that part of script since factorio now handles surfaces internally and it probably is faster way to do it than use custom script now.

Re: Fuel that increase acceleration

Posted: Fri Jul 31, 2015 11:58 am
by Xyfi
I search find_entities_filtered on the wiki and was lead to Lua/Surface.