Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --current version
- script.on_load(
- function()
- global.subtick = 0
- end
- )
- function on_sneak(event)
- local you = game.players[event.player_index]
- if (sneak == false or sneak == nil) then
- sneak = true
- else
- sneak = false
- end
- you.print("Key pressed (debug) sneak=" .. tostring(sneak))
- end
- function on_tick(event)
- if subtick==nil then
- subtick = 0
- end
- subtick = subtick + 1
- for _, player in pairs(game.players) do
- if (subtick >= 2 and not player.walking_state.walking) then
- subtick = 0
- sneak = false
- end
- if player.walking_state.walking then
- if sneak then
- player.print("sneakin")
- player.character_running_speed_modifier = -0.5
- else
- player.print("no sneakin")
- player.character_running_speed_modifier = 0
- end
- end
- end
- end
- script.on_event("sneak_modifier", on_sneak)
- script.on_event("crawl_modifier", on_crawl)
- script.on_event(defines.events.on_tick, on_tick)
- -------------old version below
- -- toggles only when I press the key, needs to chnage when I hold / relese the key
- script.on_event("sneak_modifier",
- function(event)
- -- global.sneak = false
- local you = game.players[event.player_index]
- if (sneak == false or sneak == nil) then
- sneak = true
- sneaki = "true"
- else
- sneak = false
- sneaki = "false"
- end
- you.print("Key pressed (debug) sneak=" .. sneaki)
- end
- )
- function on_tick(event)
- for _, player in pairs(game.players) do
- if player.walking_state.walking then
- player.print("Walkin")
- if sneak then
- player.print("sneakin")
- else
- player.print("no sneakin")
- end
- end
- end
- end
- script.on_event(defines.events.on_tick, on_tick)
Advertisement
Add Comment
Please, Sign In to add comment