Advertisement
robn

Pioneer Body Shop

Apr 27th, 2011
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.45 KB | None | 0 0
  1. local shop_flavours = {
  2.     "{surname} Ship Restorations",
  3.     "{surname} Panel Services",
  4.     "{name} Paint Works",
  5. }
  6.  
  7. local ads = {}
  8.  
  9. local onChat = function (dialog, ref, option)
  10.     local ad = ads[ref]
  11.  
  12.     if option == 0 then
  13.         dialog:Clear();
  14.  
  15.         dialog:SetTitle(ad.title)
  16.         dialog:SetMessage("Select a service.")
  17.  
  18.         dialog:AddOption("One-colour body respray ($200)", 1)
  19.         dialog:AddOption("Two-colour body respray ($400)", 2)
  20.         dialog:AddOption("Registration change ($500)", 3)
  21.         dialog:AddOption("Hang up.", -1);
  22.  
  23.         return
  24.     end
  25.  
  26.     if option == -1 then
  27.         dialog:Close()
  28.         return
  29.     end
  30.  
  31.     if option == 1 then
  32.         if Game.player:GetMoney() < 200 then
  33.             UI.Message("", "You do not have enough money.")
  34.         else
  35.             Game.player:SetPrimaryColour(Engine.rand:Number(), Engine.rand:Number(), Engine.rand:Number())
  36.             Game.player:AddMoney(-200)
  37.             UI.Message("", "Looking good!")
  38.             dialog:Refresh()
  39.         end
  40.     end
  41.  
  42.     if option == 2 then
  43.         if Game.player:GetMoney() < 400 then
  44.             UI.Message("", "You do not have enough money.")
  45.         else
  46.             Game.player:SetPrimaryColour(Engine.rand:Number(), Engine.rand:Number(), Engine.rand:Number())
  47.             Game.player:SetSecondaryColour(Engine.rand:Number(), Engine.rand:Number(), Engine.rand:Number())
  48.             Game.player:AddMoney(-400)
  49.             UI.Message("", "Nice!")
  50.             dialog:Refresh()
  51.         end
  52.     end
  53.  
  54.     if option == 3 then
  55.         if Game.player:GetMoney() < 500 then
  56.             UI.Message("", "You do not have enough money.")
  57.         else
  58.             Game.player:SetLabel(
  59.                 string.format("%c%c-%04d", Engine.rand:Integer(65,65+26), Engine.rand:Integer(65,65+26), Engine.rand:Integer(0,9999))
  60.             )
  61.             Game.player:AddMoney(-500)
  62.             UI.Message("", "Fantastic!")
  63.             dialog:Refresh()
  64.         end
  65.     end
  66. end
  67.  
  68. local onDelete = function (ref)
  69.     ads[ref] = nil
  70. end
  71.  
  72. local onCreateBB = function (station)
  73.     local rand = Rand:New(station:GetSeed())
  74.  
  75.     local n = Engine.rand:Integer(1, #shop_flavours)
  76.  
  77.     local ad = {
  78.         title   = string.interp(shop_flavours[n], { surname = NameGen.Surname(rand), name = NameGen.FullName(rand, rand:Integer(0,1)) }),
  79.         station = station,
  80.     }
  81.  
  82.     local ref = station:AddAdvert(ad.title, onChat, onDelete)
  83.     ads[ref] = ad;
  84. end
  85.  
  86. local serialize = function ()
  87.     return { ads = ads }
  88. end
  89.  
  90. local unserialize = function (data)
  91.     for k,ad in pairs(data.ads) do
  92.         local ref = ad.station:AddAdvert(ad.title, onChat, onDelete)
  93.         ads[ref] = ad
  94.     end
  95. end
  96.  
  97. EventQueue.onCreateBB:Connect(onCreateBB)
  98.  
  99. Serializer:Register("BodyShop", serialize, unserialize)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement