Page 1 of 1

attack parameters and moving objects.

Posted: Wed Oct 23, 2013 2:51 pm
by Dysoch
can it be made possible that attack parameters can be added to cars or trains?

the game now wont startup now if you try to add the parameters to cars.

Re: attack parameters and moving objects.

Posted: Wed Oct 23, 2013 10:10 pm
by slpwnd
At the moment this is not possible. Also it is not obvious how would this work with regular weapons - like when you are in the car now you can shoot from your selected weapon.

Re: attack parameters and moving objects.

Posted: Wed Oct 23, 2013 11:11 pm
by Dysoch
Shame, really wanted to make tanks ;)

I know you can shoot in a car, but weapons mounted on a car are more stronger.

Re: attack parameters and moving objects.

Posted: Thu Oct 24, 2013 12:19 am
by FreeER
Dysoch wrote:Shame, really wanted to make tanks ;)
I know you can shoot in a car, but weapons mounted on a car are more stronger.
You could (fairly easily) use control.lua to swap out the player's weapons with a new (uncraftable) 'tank cannon' when the player enters the tank. Then they'd be able to use it just like they would their typical weapons. Of course, make sure that you reswap the weapons when they get out :)

Should be able to do something similar to this

Code: Select all

intank = false -- boolean
playerguns = nil
playerammo = nil
game.ontick(function()
if game.player.vehicle and (game.player.vehicle.name == "tank") then
  intank = true
  playerguns = util.table.deepcopy(game.player.character.getinventory(defines.inventory.playerguns))
  playerammo = util.table.deepcopy(game.player.character.getinventory(defines.inventory.playerammo))
  game.player.character.getinventory(defines.inventory.playerguns).clear()
  game.player.character.getinventory(defines.inventory.playerammo).clear()
  game.player.character.getinventory(defines.inventory.playerguns).insert{name="tankcannon", count="1"}
  game.player.character.getinventory(defines.inventory.playerammo).insert{name="tankshells", count="100000"} --this depends on how high you set the stack count
end
if not game.player.vehicle or not (game.player.vehicle.name == "tank") and intank then --if player was in tank and now is not
  intank = false
  game.player.character.getinventory(defines.inventory.playerguns).clear()
  game.player.character.getinventory(defines.inventory.playerammo).clear()
  game.player.character.getinventory(defines.inventory.playerguns) = playerguns
  game.player.character.getinventory(defines.inventory.playerammo) = playerammo
end
end)
-- note util.table.deepcopy gave error in console, I think this will work in a script though
--I had issues testing this due to the deepcopy above, simply setting playerguns=getinventory fails because it makes playerguns simply another name for the current playerguns inventory. To return weapons you may need to do a for _, gun in ipairs(playerguns) do getinv.insert{name=gun.name, count=gun.count} end, I couldn't test if you could simply set the inventory=playerguns