Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /c
- _trainActionSeconds = 30
- _actionEndTick = nil
- _announceAction = true
- function PlayerInTrain(player)
- if player.vehicle ~= nil and player.vehicle.name == "locomotive" then
- return true
- else
- return false
- end
- end
- function SchedulePlayerAction(player, action, endMessage)
- _actionEndTick = game.tick + (60 * _trainActionSeconds)
- local direction = CalculateDirection(player, action)
- script.on_nth_tick(1, function() DoAction(player, action, direction, endMessage) end)
- end
- function CalculateDirection(player, action)
- if player.vehicle.train.speed > 0 then
- return defines.riding.acceleration.accelerating
- elseif player.vehicle.train.speed < 0 then
- return defines.riding.acceleration.reversing
- else
- return nil
- end
- end
- function DoAction(player, action, direction, endMessage)
- if _actionEndTick == nil or game.tick > _actionEndTick then
- _actionEndTick = nil
- _announceAction = true
- script.on_nth_tick(1, nil)
- game.print(player.name .. endMessage)
- TrainGoDirection(player, defines.riding.acceleration.nothing)
- return
- end
- if not PlayerInTrain(player) then
- return
- end
- if direction == nil then
- direction = CalculateDirection(player, action)
- if direction ~= nil then
- script.on_nth_tick(1, function() DoAction(player, action, direction, endMessage) end)
- else
- game.print(player.name .. " Move and you will continue in that direction, come hell or high water!")
- return
- end
- end
- if action == "forwards" then
- if _announceAction then
- game.print(player.name .. " Forwards!!!")
- _announceAction = false
- end
- TrainGoDirection(player, direction)
- end
- end
- function TrainGoDirection(player, direction)
- if not PlayerInTrain(player) then
- return
- end
- local new_riding_state = player.riding_state
- new_riding_state.acceleration = direction
- player.riding_state = new_riding_state
- end
- for _, player in pairs(game.connected_players) do
- if not PlayerInTrain(player) then
- game.print(player.name .. " isn't in a train, booo")
- break
- end
- game.print(player.name .. " is in a train and will beat the queues COLONEL WILL STYLE")
- player.vehicle.train.manual_mode = true
- SchedulePlayerAction(player, "forwards", " beat the queues")
- end
Advertisement
Add Comment
Please, Sign In to add comment