Advertisement
Guest User

Untitled

a guest
Oct 16th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.70 KB | None | 0 0
  1. local rms_is_present = {}
  2.  
  3. local rms_skybox = {
  4.     "stars.png",
  5.     "stars.png",
  6.     "rms.png",
  7.     "stars.png",
  8.     "stars.png",
  9.     "stars.png",
  10. }
  11.  
  12. -- When a player runs /rms it should change the sky, send a chat message, and start playing the song
  13. -- When they do /rms again I want it to set the sky back, send a chat message, and stop the song for
  14. -- That person only. Having rms_sound be local in the register_chatcommand function breaks it too.
  15.  
  16. local function summon_rms(player_name)
  17.     rms_is_present[player_name] = true
  18.     minetest.get_player_by_name(player_name):set_sky({}, "skybox", rms_skybox)
  19.  
  20.     -- Starts here
  21.     local rms_sound = minetest.sound_play("rms", {
  22.         to_player = player_name,
  23.         gain = 2.0
  24.     })
  25. end
  26.  
  27. local function dismiss_rms(player_name)
  28.     rms_is_present[player_name] = false
  29.     minetest.get_player_by_name(player_name):set_sky({}, "regular", {})
  30.    
  31.     -- Crash happens here
  32.     minetest.sound_stop(rms_sound)
  33. end
  34.  
  35.  
  36. minetest.register_on_joinplayer(function(player)
  37.         rms_is_present[player:get_player_name()] = false
  38.     end
  39. )
  40.  
  41. minetest.register_chatcommand("rms", {
  42.     func = function(name, param)
  43.  
  44.         -- Summon RMS if he isn't already present
  45.         if rms_is_present[name] == false then
  46.             minetest.chat_send_player(name, "*You feel the sudden urge to install Gentoo...*")
  47.             summon_rms(name)
  48.  
  49.             minetest.after(146, function()
  50.                 dismiss_rms(name)
  51.             end
  52.             )
  53.         -- Dismiss RMS if he is present
  54.         else
  55.             minetest.chat_send_player(name, "OH NO! Your proprietary software scared RMS away!")
  56.             dismiss_rms(name)
  57.         end
  58.     end
  59. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement