Advertisement
EngiN33R

Equipment Module for the Space RPG mod

Jun 7th, 2011
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.24 KB | None | 0 0
  1. estack={}
  2.  
  3. estack.hwpage=initArray2(32,0)
  4. estack.shpage=initArray2(32,0)
  5.  
  6. function inZoneComm(x,y)
  7.     for z in ipairs(zones) do
  8.         if (zones[z]~=nil and zones[z].comm~=nil and x>=zones[z].comm.x1 and x<=zones[z].comm.x2 and y>=zones[z].comm.y1 and y<=zones[z].comm.y2) then
  9.             return z
  10.         end
  11.     end
  12. end
  13.  
  14. function maintmenu(id)
  15.     menu(id,"BASE MENU,Trade Commodities,Buy Equipment,Buy Ships")
  16. end
  17.  
  18. function getweapon(b,n)
  19.     if (basedata[b].hardware[n]~=nil) then
  20.         return equipment[basedata[b].hardware[n].type].name.."|"..equipment[basedata[b].hardware[n].type].price
  21.     end
  22. end
  23.  
  24. function getship(b,n)
  25.     if (basedata[b].aships[n]~=nil) then
  26.         return ships[basedata[b].aships[n].type].name.."|"..ships[basedata[b].aships[n].type].price
  27.     end
  28. end
  29.  
  30. function hasnext(p,z,m)
  31.     if (m==1) then
  32.         if (#basedata[z].hardware>=1+(8*(p-1))) then
  33.             return "Next"
  34.         end
  35.     end
  36.     if (m==2) then
  37.         if (#basedata[z].aships>=1+(8*(p-1))) then
  38.             return "Next"
  39.         end
  40.     end
  41.     return ""
  42. end
  43.  
  44. function hwmenu(id,p)
  45.     print(p)
  46.     print(1+(8*(p-1)))
  47.     print(inZoneComm(player(id,"tilex"),player(id,"tiley")),1+(8*(p-1)))
  48.     print(getweapon(inZoneComm(player(id,"tilex"),player(id,"tiley")),1+(8*(p-1))))
  49.     hasnext(p,inZoneComm(player(id,"tilex"),player(id,"tiley")),1)
  50.     menu(id,"EQUIPMENT PURCHASE,"..getweapon(inZoneComm(player(id,"tilex"),player(id,"tiley")),1+(8*(p-1)))..","..getweapon(inZoneComm(player(id,"tilex"),player(id,"tiley")),2+(8*(p-1)))..","..getweapon(inZoneComm(player(id,"tilex"),player(id,"tiley")),3+(8*(p-1)))..","..getweapon(inZoneComm(player(id,"tilex"),player(id,"tiley")),4+(8*(p-1)))..","..getweapon(inZoneComm(player(id,"tilex"),player(id,"tiley")),5+(8*(p-1)))..","..getweapon(inZoneComm(player(id,"tilex"),player(id,"tiley")),6+(8*(p-1)))..","..getweapon(inZoneComm(player(id,"tilex"),player(id,"tiley")),7+(8*(p-1)))..","..getweapon(inZoneComm(player(id,"tilex"),player(id,"tiley")),8+(8*(p-1)))..","..hasnext(p,inZoneComm(player(id,"tilex"),player(id,"tiley")),1))
  51.     estack.hwpage[id]=p
  52. end
  53.  
  54. function shmenu(id,p)
  55.     menu(id,"SHIP PURCHASE,"..getship(inZoneComm(player(id,"tilex"),player(id,"tiley")),1+(8*(p-1)))..","..getship(inZoneComm(player(id,"tilex"),player(id,"tiley")),2+(8*(p-1)))..","..getship(inZoneComm(player(id,"tilex"),player(id,"tiley")),3+(8*(p-1)))..","..getship(inZoneComm(player(id,"tilex"),player(id,"tiley")),4+(8*(p-1)))..","..getship(inZoneComm(player(id,"tilex"),player(id,"tiley")),5+(8*(p-1)))..","..getship(inZoneComm(player(id,"tilex"),player(id,"tiley")),6+(8*(p-1)))..","..getship(inZoneComm(player(id,"tilex"),player(id,"tiley")),7+(8*(p-1)))..","..getship(inZoneComm(player(id,"tilex"),player(id,"tiley")),8+(8*(p-1)))..","..hasnext(p,inZoneComm(player(id,"tilex"),player(id,"tiley")),1))
  56.     estack.shpage[id]=p
  57. end
  58.  
  59. function hwdets(id)
  60.     menu(id,"HARDWARE DETAILS,Purchase,Info")
  61. end
  62.  
  63. function shdets(id)
  64.     menu(id,"SHIP DETAILS,Purchase,Info")
  65. end
  66.  
  67. addhook("menu","eqsel")
  68. function eqsel(id,menu,sel)
  69.     if (menu=="BASE MENU") then
  70.         if (sel==1) then
  71.             trademenu(id,inZoneComm(player(id,"tilex"),player(id,"tiley")))
  72.         end
  73.         if (sel==2) then
  74.             hwmenu(id,1)
  75.         end
  76.         if (sel==3) then
  77.             shmenu(id,1)
  78.         end
  79.     end
  80.     if (menu=="EQUIPMENT PURCHASE") then
  81.         if (sel>=1 and sel<=8) then
  82.             hwdets(id)
  83.             estack.hwbuy[id]=sel+(8*(estack.hwpage-1))
  84.         end
  85.         if (sel==9) then
  86.             hwmenu(id,sel+(8*(estack.hwpage-1)))
  87.         end
  88.     end
  89.     if (menu=="SHIP PURCHASE") then
  90.         if (sel>=1 and sel<=8) then
  91.             shdets(id)
  92.             estack.shbuy[id]=sel+(8*(estack.shpage-1))
  93.         end
  94.         if (sel==9) then
  95.             shmenu(id,sel+(8*(estack.shpage-1)))
  96.         end
  97.     end
  98.     if (menu=="HARDWARE DETAILS") then
  99.         if (sel==1) then
  100.             insertInInventory(id,basedata[inZoneComm(player(id,"tilex"),player(id,"tiley"))].hardware[estack.hwbuy[id]].type)
  101.             credits[id]=credits[id]-equipment[basedata[inZoneComm(player(id,"tilex"),player(id,"tiley"))].hardware[estack.hwbuy[id]].type].price
  102.         end
  103.         if (sel==2) then
  104.             msg2(id,equipment[basedata[inZoneComm(player(id,"tilex"),player(id,"tiley"))].hardware[estack.hwbuy[id]].type].desc)
  105.         end
  106.     end
  107.     if (menu=="SHIP DETAILS") then
  108.         if (sel==1) then
  109.             shipt[id]=estack.shbuy[id]
  110.         end
  111.         if (sel==2) then
  112.             msg2(id,ships[basedata[inZoneComm(player(id,"tilex"),player(id,"tiley"))].aships[estack.shbuy[id]].type].desc)
  113.         end
  114.     end
  115. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement