Advertisement
Guest User

game main

a guest
May 2nd, 2016
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 118.88 KB | None | 0 0
  1. local scw, sch = term.getSize()
  2.  
  3. os.loadAPI("graphics")
  4.  
  5. term.clear()
  6. buffer1 = graphics.addBuffer()
  7.  
  8. local playerMdl = {
  9.     {{0,128,256,0},
  10.      {128,128,128,256},
  11.      {0,4096,16,0},
  12.      {4096,16,512,0},
  13.      {4096,4096,256,128},
  14.      {4096,128,256,0},
  15.      {0,8,8,0},
  16.      { 0,4096,4096,0},
  17.     },
  18.     {},
  19.     {{0,0,0,0,0},
  20.      {0,0,128,256,0},
  21.      {0,128,128,128,256},
  22.      {0,0,4096,16,0},
  23.      {0,4096,256,256,0},
  24.      {4096,4096,128,256,128},
  25.      {0,4096,8,8,8},
  26.      {4096,8,8,0,4096}},
  27. }
  28.  
  29.  
  30. local ghostMdl = {
  31.     {{0,128,128,0,0}, -- default
  32.     {128,256,256,128,0},
  33.     {0,256,256,0,0},
  34.     {128,16,16,128,0},
  35.     {16384,16,16,16384,0},
  36.     {16384,512,8,16384,0},
  37.     {0,0,512,0,0}},
  38.     {{0,128,128,0,0}, -- attack
  39.     {0,128,128,0,0},
  40.     {0,256,256,0,0},
  41.     {128,16,16,128,0},
  42.     {16384,16,16,16384,0},
  43.     {0,512,8,0,0},
  44.     {0,0,512,0,0}},
  45. }
  46. local zombie1Mdl = {
  47.     {{0,4096,4096,0},
  48.     {0,8192,32,0},
  49.     {128,256,256,128},
  50.     {8192,128,128,8192},
  51.     {0,128,256,0},
  52.     {0,8192,8,0},
  53.     {0,4096,4096,0}}
  54. }
  55. local habitant1Mdl = {
  56.     {{0,128,128,0},
  57.     {0,16,16,0},
  58.     {4096,256,256,4096},
  59.     {4096,8,8,4096},
  60.     {0,256,256,0},
  61.     {0,256,256,0},
  62.     {0,4096,4096,0}},
  63. }
  64. local habitant2Mdl = {
  65.     {{0,128,128,0},
  66.     {0,16,16,0},
  67.     {128,256,256,4096},
  68.     {4096,8,8,4096},
  69.     {0,256,256,0},
  70.     {0,256,256,0},
  71.     {0,4096,4096,0}},
  72. }
  73. local habitant3Mdl = {
  74.     {{0,128,128,0},
  75.     {0,16,16,0},
  76.     {128,256,256,4096},
  77.     {4096,512,512,4096},
  78.     {0,256,256,0},
  79.     {0,256,256,0},
  80.     {0,4096,4096,0}},
  81. }
  82. local tailor1Mdl = {
  83.     {{0,128,128,0},
  84.     {0,16,16,0},
  85.     {4096,256,256,4096},
  86.     {4096,16,16,4096},
  87.     {0,256,256,0},
  88.     {0,256,256,0},
  89.     {0,4096,4096,0}},
  90. }
  91. local bsmith1Mdl = {
  92.     {{0,128,128,0},
  93.     {0,16,16,0},
  94.     {4096,256,256,4096},
  95.     {4096,2,2,4096},
  96.     {0,256,256,0},
  97.     {0,256,256,0},
  98.     {0,4096,4096,0}},
  99. }
  100. local apothecary1Mdl = {
  101.     {{0,128,128,0},
  102.     {0,16,16,0},
  103.     {4096,256,256,4096},
  104.     {4096,32,32,4096},
  105.     {0,256,256,0},
  106.     {0,256,256,0},
  107.     {0,4096,4096,0}},
  108. }
  109. local greenslimeMdl = {
  110.     {{0,0,32,8192,8192,0,0},
  111.     {0,8192,8192,8192,8192,32,0},
  112.     {0,8192,32,8192,32,8192,0},
  113.     {0,8192,32,8192,32,8192,8192},
  114.     {8192,32,8192,8192,8192,8192,32},
  115.     {8192,8192,256,8192,8192,8192,256}},
  116. }
  117. local silversnakeMdl = {
  118.     {{0,0,256,128,128,256,0,0,256,256,128,128,256,128},
  119.     {256,256,128,0,0,256,128,128,128,0,0,0,0,0}},
  120. }
  121. local femaleghostMdl = {
  122.     {{0,2048,2048,0,0},
  123.     {2048,1,1,2048,0},
  124.     {2048,1,1,2048,0},
  125.     {128,128,128,128,0},
  126.     {1,128,128,1,0},
  127.     {1,512,8,1,0},
  128.     {0,0,512,0,0}},
  129. }
  130. local spiritofplaceMdl = {
  131.     {{0,0,0,0,0},
  132.     {0,1,1,0,0},
  133.     {0,1,1,0,0},
  134.     {128,128,128,128,0},
  135.     {1,128,128,1,0},
  136.     {1,512,8,1,0},
  137.     {0,0,512,0,0}},
  138. }
  139. local bushMdl = {
  140.     {{0,0,8192,32,0,0},
  141.     {0,8192,8192,32,8192,0},
  142.     {0,32,8192,8192,32,8192,0},
  143.     {8192,8192,4096,8192,32,8192},
  144.     {4096,8192,8192,4096,8192,8192}},
  145. }
  146. local stoneturtleMdl = {
  147.     {{0,0,256,16,256,16,256,0,0},
  148.     {0,256,16,256,16,256,16,256,4096},
  149.     {256,128,256,128,256,128,256,128,256}},
  150. }
  151. local woodMdl = {
  152.     {{0,32,8192,8192,0,0},
  153.     {32,32,32,8192,32,0},
  154.     {8192,32,8192,8192,8192,8192},
  155.     {32,8192,4096,8192,8192,8192},
  156.     {0,8192,4096,4096,8192,4096},
  157.     {8192,0,128,4096,0,8192},
  158.     {0,128,4096,4096,0,8192},
  159.     {0,4096,4096,128,0,0},
  160.     {4096,0,128,4096,0,0}},
  161. }
  162. local sceletonarcherMdl = {
  163.     {{0,128,128,0,0},
  164.     {0,256,256,0,0},
  165.     {128,256,0,128,0},
  166.     {256,256,256,256,4096},
  167.     {256,0,256,256,4096},
  168.     {0,256,128,4096,0},
  169.     {0,256,256,0,0},
  170.     {0,256,256,0,0}},
  171. }
  172. local venomousghoulMdl = {
  173.     {{0,128,128,0},
  174.     {0,8192,8192,0},
  175.     {128,512,256,128},
  176.     {256,256,512,256},
  177.     {256,128,128,8192},
  178.     {0,128,128,0},
  179.     {0,4096,4096,0}},
  180. }
  181. local decayingghoulMdl = {
  182.     {{0,128,128,0},
  183.     {0,1,8192,0},
  184.     {128,128,128,128},
  185.     {256,128,128,1},
  186.     {32768,256,256,256},
  187.     {0,256,256,0},
  188.     {0,4096,4096,0}},
  189. }
  190. local stonegolemMdl = {
  191.     {{0,0,128,128,0,0},
  192.     {0,0,128,128,0,0},
  193.     {128,256,256,256,256,128},
  194.     {128,128,256,256,128,128},
  195.     {128,128,256,256,128,128},
  196.     {0,0,256,256,0,0},
  197.     {0,0,256,256,0,0},
  198.     {0,0,128,128,0,0}},
  199. }
  200. local ironturtleMdl = {
  201.     {{0,0,256,512,256,512,256,0,0},
  202.     {0,256,512,256,512,256,512,256,128},
  203.     {256,128,256,128,256,128,256,128,256}},
  204. }
  205. local copperoreMdl = {
  206.     {{0,0,2,128,0},
  207.     {256,128,128,4096,128}},
  208. }
  209. local treerootMdl = {
  210.     {{0,4096,0},
  211.     {0,4096,4096},
  212.     {4096,4096,128}},
  213. }
  214. local ironoreMdl = {
  215.     {{0,0,128,128,0},
  216.     {256,128,128,256,128}},
  217. }
  218. local gravelMdl = {
  219.     {{0,0,256,256,0},
  220.     {256,128,256,256,128}},
  221. }
  222. local windelmentalMdl = {
  223.     {{0,0,256,256,0,0},
  224.     {0,0,256,256,0,0},
  225.     {0,128,0,0,128,0},
  226.     {128,0,256,256,0,128},
  227.     {256,128,0,256,128,256},
  228.     {0,0,256,0,0,0},
  229.     {0,0,0,256,0,0}}
  230.  
  231. }
  232. local goblinheghtuMdl = {
  233.     {{0,4096,4096,0,0,0},
  234.     {0,4096,4096,0,0,0},
  235.     {256,256,128,256,0,4096},
  236.     {256,128,256,256,4096,0},
  237.     {0,256,256,4096,0,0},
  238.     {0,256,4096,0,0,0},
  239.     {0,4096,4096,0,0,0}},
  240. }
  241. local devilmaggotMdl = {
  242.     {{0,16,16,0},
  243.     {16,32768,32768,16},
  244.     {16,32768,32768,16},
  245.     {2,16,16,2},
  246.     {0,16,16,0},
  247.     {4096,2,2,4096},
  248.     {4096,0,0,4096}},
  249. }
  250. local zombiewarriorMdl = {
  251.     {{0,128,128,0},
  252.     {0,8192,256,0},
  253.     {4096,16,16,4096},
  254.     {4096,256,256,4096},
  255.     {0,128,256,0},
  256.     {0,256,256,0},
  257.     {0,128,128,0}},
  258. }
  259. local sagespiritMdl = {
  260.     {{0,0,0,0,0}, -- default
  261.     {0,1,1,0,0},
  262.     {0,1,1,0,0},
  263.     {128,8,8,128,0},
  264.     {256,8,8,256,0},
  265.     {256,512,8,256,0},
  266.     {0,0,512,0,0}},
  267. }
  268. local soullessMdl = {
  269.     {{0,1,128,0},
  270.     {0,1,1,0},
  271.     {4096,256,256,4096},
  272.     {4096,16,128,4096},
  273.     {0,128,256,0},
  274.     {0,128,256,0},
  275.     {0,4096,4096,0}},
  276. }
  277.  
  278.  
  279. local itemimg = {
  280. [1]={
  281.     {8,8,8,8,8,8,8},
  282.     {8,8,2,2,2,8,8},
  283.     {8,2,16,16,16,2,8},
  284.     {2,16,16,16,2,8,8},
  285.     {8,2,2,2,8,8,8},   
  286.     },
  287. [2]={
  288.     {8,8,8,4096,4096,4096,8},    
  289.     {8,8,4096,4096,4096,8,8},
  290.     {8,4096,4096,4096,8,8,8},
  291.     {4096,4096,4096,8,8,8,8},
  292.     {8,4096,4096,4096,4096,8,8},
  293.     },
  294. [3]={
  295.     {8,8,8,8,8,8,8},
  296.     {4096,4096,128,128,128,4096,4096},
  297.     {4096,4096,4096,256,4096,4096,4096},
  298.     {8,4096,4096,4096,4096,4096,8},
  299.     {8,4096,128,4096,128,4096,8},
  300.     },
  301. [4]={
  302.     {8,8,4096,4096,4096,8,8},
  303.     {8,4096,4096,4096,4096,8,8},
  304.     {8,4096,4096,4096,4096,4096,8},
  305.     {8,8,4096,4096,4096,4096,8},
  306.     {8,8,4096,4096,4096,8,8},
  307.     },
  308. [5]={
  309.     {512,512,512,512,512,512,4096},
  310.     {512,512,512,4096,512,4096,512},
  311.     {512,512,512,512,4096,512,512},
  312.     {512,512,4096,4096,512,4096,512},
  313.     {512,4096,4096,512,512,512,512},
  314.     },
  315. [6]={
  316.     {8,8,4096,4096,4096,8,8},
  317.     {8,4096,4096,4096,4096,8,8},
  318.     {8,4096,4096,4096,4096,8,8},
  319.     {8,8,4096,4096,4096,4096,8},
  320.     {8,8,4096,4096,4096,8,8},
  321.     },
  322. [7]={
  323.     {8,4096,4096,4096,4096,4096,8},
  324.     {4096,4096,128,128,128,4096,4096},
  325.     {4096,128,128,128,128,128,4096},
  326.     {4096,4096,128,128,128,4096,4096},
  327.     {8,8,8,8,8,8,8},
  328.     },
  329. [8]={
  330.     {8,8,8,8,8,8,8},
  331.     {8,8,128,128,128,8,8},
  332.     {8,128,256,256,256,128,8},
  333.     {128,256,256,256,128,8,8},
  334.     {8,128,128,128,8,8,8}, 
  335.     },
  336. [9]={
  337.     {8,8,8,8,8,8,8},
  338.     {8,8,8,256,8,8,8},
  339.     {8,8,256,256,256,8,8},
  340.     {8,8,16,16,16,8,8},
  341.     {8,8,16,16,16,8,8},
  342.     },
  343. [10]={
  344.     {8,8,8,8,32,32,8},
  345.     {8,8,8,8192,8192,32,8},
  346.     {8,8,32,8192,8192,32,8},
  347.     {8,32,8192,8192,32,8,8},
  348.     {8,8,8,32,32,32,8},
  349.     },
  350. [11]={
  351.     {8,8,128,128,128,8,8},
  352.     {8,128,128,128,128,8,8},
  353.     {8,128,128,128,128,128,8},
  354.     {8,8,128,128,128,128,8},
  355.     {8,8,128,128,128,8,8},
  356.     },
  357. [12]={
  358.     {16,16,4096,4096,4096,16,16},
  359.     {16,16,256,256,256,16,16},
  360.     {16,16,256,256,256,16,16},
  361.     {16,16,256,256,256,16,16},
  362.     {16,16,16384,16384,16384,16,16},
  363.     },
  364. [13]={
  365.     {16,16,4096,4096,4096,16,16},
  366.     {16,16,256,256,256,16,16},
  367.     {16,16,256,256,256,16,16},
  368.     {16,16,256,256,256,16,16},
  369.     {16,16,2048,2048,2048,16,16},
  370.     }, 
  371. [14]={
  372.     {8,8,8,8,8,8,8},
  373.     {8,8,2,2,2,8,8},
  374.     {8,2,2,2,2,2,8},
  375.     {2,2,2,2,2,8,8},
  376.     {8,2,2,2,8,8,8},   
  377.     },
  378. [15]={
  379.     {8,4096,4096,4096,4096,4096,8},
  380.     {8,4096,4096,4096,4096,4096,8},
  381.     {8,4096,4096,8,4096,4096,8},
  382.     {8,4096,128,8,128,4096,8},
  383.     {8,128,4096,8,4096,128,8}, 
  384.     },
  385. [16]={
  386.     {8,256,8,8,8,256,8},
  387.     {256,8,8,8,8,8,256},
  388.     {8,256,8,8,8,256,8},
  389.     {8,8,2,2,2,8,8},
  390.     {8,8,8,2,8,8,8},
  391.     },
  392. [17]={
  393.     {8,8,1024,1024,1024,8,8},
  394.     {8,1024,1024,1024,64,1024,8},
  395.     {8,1024,1024,1024,1024,1024,8},
  396.     {8,1024,4,4,4,1024,8},
  397.     {8,8,8,8,8,8,8},
  398.     },
  399. [18]={
  400.     {512,512,512,512,512,512,4096},
  401.     {512,512,512,4096,512,4096,512},
  402.     {512,512,512,512,4096,512,512},
  403.     {512,512,128,256,512,4096,512},
  404.     {512,128,256,512,512,512,512},
  405.     },
  406. [19]={
  407.     {512,512,512,512,512,512,4096},
  408.     {512,512,512,128,512,4096,512},
  409.     {512,512,512,512,128,512,512},
  410.     {512,512,128,256,512,128,512},
  411.     {512,128,256,512,512,512,512},
  412.     },
  413. [20]={
  414.     {8,256,8,8,8,256,8},
  415.     {256,8,8,8,8,8,256},
  416.     {8,256,8,8,8,256,8},
  417.     {8,8,1,256,1,8,8},
  418.     {8,8,8,1,8,8,8},
  419.     },
  420. [21]={
  421.     {32768,32768,32768,32768,128,4096,4096},
  422.     {32768,32768,32768,128,4096,4096,4096},
  423.     {32768,32768,128,4096,4096,4096,4096},
  424.     {32768,128,4096,4096,4096,4096,4096},
  425.     {128,4096,4096,4096,4096,4096,4096},
  426. },
  427. [22]={
  428.     {8,4096,4096,4096,4096,4096,8},
  429.     {4096,4096,128,128,128,4096,4096},
  430.     {4096,4096,128,128,128,4096,4096},
  431.     {4096,4096,128,128,128,4096,4096},
  432.     {256,8,8,8,8,8,256},
  433.     }, -- шапка
  434. [23]={
  435.     {8,128,4096,4096,4096,128,8},
  436.     {8,4096,4096,4096,4096,4096,8},
  437.     {8,4096,4096,8,4096,4096,8},
  438.     {8,256,256,8,256,256,8},
  439.     {8,4096,256,8,256,4096,8},
  440.     }, -- штаны
  441. [24]={
  442.     {8,8,8,8,8,8,8},
  443.     {4096,4096,128,128,128,4096,4096},
  444.     {4096,4096,256,4096,256,4096,4096},
  445.     {8,4096,4096,256,4096,4096,8},
  446.     {8,4096,256,4096,256,4096,8},
  447.     }, -- броня
  448. [25]={
  449.     {8,8,256,4096,4096,4096,8},
  450.     {8,8,4096,4096,4096,8,8},
  451.     {8,4096,4096,4096,8,8,8},
  452.     {4096,256,4096,8,8,8,8},
  453.     {8,4096,4096,4096,4096,4096,8},
  454.     }, -- сапог
  455. [26]={
  456.     {16,16,4096,4096,4096,16,16},
  457.     {16,16,256,256,256,16,16},
  458.     {16,16,256,256,256,16,16},
  459.     {16,16,16384,16384,16384,16,16},
  460.     {16,16,16384,16384,16384,16,16},
  461.     },
  462. [27]={
  463.     {16,16,4096,4096,4096,16,16},
  464.     {16,16,256,256,256,16,16},
  465.     {16,16,256,256,256,16,16},
  466.     {16,16,2048,2048,2048,16,16},
  467.     {16,16,2048,2048,2048,16,16},
  468.     }, 
  469. [28]={
  470.     {16,16,4096,4096,4096,16,16},
  471.     {16,16,256,256,256,16,16},
  472.     {16,16,16384,16384,16384,16,16},
  473.     {16,16,16384,16384,16384,16,16},
  474.     {16,16,16384,16384,16384,16,16},
  475.     },
  476. [29]={
  477.     {16,16,4096,4096,4096,16,16},
  478.     {16,16,256,256,256,16,16},
  479.     {16,16,2048,2048,2048,16,16},
  480.     {16,16,2048,2048,2048,16,16},
  481.     {16,16,2048,2048,2048,16,16},
  482.     }, 
  483. [30]={
  484.     {16,16,4096,4096,4096,16,16},
  485.     {16,16,16384,16384,16384,16,16},
  486.     {16,16,16384,16384,16384,16,16},
  487.     {16,16,16384,16384,16384,16,16},
  488.     {16,16,16384,16384,16384,16,16},
  489.     },
  490. [31]={
  491.     {16,16,4096,4096,4096,16,16},
  492.     {16,16,2048,2048,2048,16,16},
  493.     {16,16,2048,2048,2048,16,16},
  494.     {16,16,2048,2048,2048,16,16},
  495.     {16,16,2048,2048,2048,16,16},
  496.     },
  497. [32]={
  498.     {8,8,8,8,256,256,256},
  499.     {8,256,256,256,256,256,128},
  500.     {256,4096,4096,128,256,128,8},
  501.     {256,4096,4096,128,128,8,8},
  502.     {8,256,128,8,8,8,8},
  503.     },
  504. [33]={
  505.     {512,512,512,512,512,128,512},
  506.     {512,128,512,512,4096,512,512},
  507.     {512,512,128,4096,512,512,512},
  508.     {512,256,128,128,512,512,512},
  509.     {256,256,256,512,128,512,512},
  510.     },
  511. [34]={
  512.     {8,8,8,256,8,8,8},
  513.     {8,16,16,256,16,16,8},
  514.     {16,16,16,16,16,16,16},
  515.     {8,256,256,16,16,16,8},
  516.     {8,8,8,256,8,8,8},
  517.     },
  518. [35]={
  519.     {8,8,8,8,8,8,8},
  520.     {4096,4096,128,128,128,4096,4096},
  521.     {4096,256,4096,4096,4096,256,4096},
  522.     {8,4096,4096,4096,4096,4096,8},
  523.     {8,4096,4096,4096,4096,4096,8},
  524.     },
  525. [36]={
  526.     {8,128,4096,128,4096,128,8},
  527.     {8,4096,256,4096,256,4096,8},
  528.     {8,4096,4096,8,4096,4096,8},
  529.     {8,4096,4096,8,4096,4096,8},
  530.     {8,256,4096,8,4096,256,8},
  531.     },
  532. [37]={
  533.     {8,128,128,128,128,8,8},
  534.     {8,8,4096,4096,4096,128,8},
  535.     {8,8,8,4096,4096,4096,8},
  536.     {8,8,8,8,4096,4096,4096},
  537.     {8,256,4096,4096,4096,4096,8},
  538.     },
  539. [38]={
  540.     {8,8,4096,128,4096,8,8},
  541.     {8,4096,128,4096,128,4096,8},
  542.     {8,4096,256,256,256,4096,8},
  543.     {8,4096,256,256,256,4096,8},
  544.     {8,8,8,8,8,8,8},
  545.     },
  546. [39]={
  547.     {8,8,8,128,8,8,8},
  548.     {8,256,256,128,256,256,8},
  549.     {256,256,256,256,256,256,256},
  550.     {8,128,128,256,256,256,8},
  551.     {8,8,8,128,8,8,8},
  552.     },
  553. [40]={
  554.     {512,512,512,512,512,128,512},
  555.     {512,128,512,512,4096,512,512},
  556.     {512,512,128,4096,512,512,512},
  557.     {512,256,128,128,512,512,512},
  558.     {256,128,256,512,128,512,512},
  559.     },
  560. [41]={
  561.     {8,8,8,128,128,8,8},
  562.     {8,8,2,2,16,2,8},
  563.     {8,2,2,16,2,2,2},
  564.     {8,2,4096,4096,4096,2,2},
  565.     {8,8,2,4096,4096,2,8},
  566.     },
  567. [42]={
  568.     {4096,4096,128,128,128,4096,4096},
  569.     {256,256,256,256,256,256,256},
  570.     {8,4096,128,256,128,4096,8},
  571.     {8,256,256,256,256,256,8},
  572.     {8,256,128,256,128,256,8},
  573.     },
  574. [43]={
  575.     {8,4096,4096,128,4096,4096,8},
  576.     {8,128,256,256,256,128,8},
  577.     {8,256,256,8,256,256,8},
  578.     {8,4096,256,8,256,4096,8},
  579.     {8,256,4096,8,4096,256,8},
  580.     },
  581. [44]={
  582.     {8,4096,256,4096,256,8,8},
  583.     {8,8,4096,4096,4096,8,8},
  584.     {8,8,8,4096,4096,4096,8},
  585.     {8,8,8,8,4096,4096,4096},
  586.     {8,4096,4096,4096,4096,4096,128},
  587.     },
  588. [45]={
  589.     {8,256,8,8,8,256,8},
  590.     {256,8,8,8,8,8,256},
  591.     {8,256,8,8,8,256,8},
  592.     {8,8,1,256,1,8,8},
  593.     {8,8,1,8,1,8,8},
  594.     },
  595. [46]={
  596.     {8,16,8,8,8,16,8},
  597.     {16,8,8,8,8,8,16},
  598.     {8,16,8,8,8,16,8},
  599.     {8,8,16,1,16,8,8},
  600.     {8,8,1,1,1,8,8},
  601.     },
  602. [47]={
  603.     {8,8,8,8,8,8,8},
  604.     {8,128,8,8,8,8,8},
  605.     {128,256,128,128,8,8,8},
  606.     {256,256,256,256,128,8,8},
  607.     {128,256,256,256,128,128,256},
  608.     },
  609. [48]={
  610.     {512,512,512,512,512,512,128},
  611.     {512,128,128,512,512,4096,512},
  612.     {512,512,512,128,4096,512,512},
  613.     {512,512,8,256,128,512,512},
  614.     {512,8,256,256,512,128,512},
  615.     },
  616. [49]={
  617.     {512,4096,512,512,512,512,512},
  618.     {512,512,16,512,512,128,512},
  619.     {512,512,512,16,128,512,512},
  620.     {512,512,512,128,4096,256,512},
  621.     {512,512,128,512,256,4096,256},
  622.     },
  623. [50]={
  624.     {512,512,512,128,128,512,128},
  625.     {512,512,512,256,256,16,512},
  626.     {512,512,256,256,128,256,128},
  627.     {512,256,256,128,256,256,128},
  628.     {256,256,128,256,256,512,512},
  629.     },
  630. }
  631.  
  632. imgWoodenhouse1 = {
  633.     {0,0,0,0,0,0,16,16,0,0,0,0,0,0},
  634.     {0,0,0,0,0,16,128,128,16,0,0,0,0,0},
  635.     {0,0,0,16,16,128,256,256,256,16,16,0,0,0},
  636.     {0,16,16,256,256,256,256,256,256,256,256,16,16,0},
  637.     {16,4096,4096,4096,4096,4096,4096,4096,4096,4096,4096,4096,4096,16},
  638.     {0,4096,4096,256,256,128,128,128,128,256,256,4096,4096,0},
  639.     {0,4096,256,4096,256,128,32768,32768,128,256,4096,256,4096,0},
  640.     {0,4096,256,256,4096,256,256,256,256,4096,256,256,4096,0},
  641.     {0,4096,4096,4096,4096,4096,4096,4096,4096,4096,4096,4096,4096,0},
  642.     {0,4096,4096,4096,4096,4096,4096,4096,4096,4096,4096,4096,4096,0},
  643.     {0,128,128,256,128,128,256,128,128,256,128,128,256,128,0},
  644.     {0,256,128,128,128,128,128,256,128,256,128,128,256,128,0},
  645.     }
  646.  
  647.  
  648.  
  649. local emptyArmorImageHelmet = {
  650.     {128,256,256,256,256,256,128},
  651.     {256,256,256,256,256,256,256},
  652.     {256,128,128,256,128,128,256},
  653.     {256,128,128,128,128,128,256},
  654.     {128,128,128,128,128,128,128},
  655. }
  656. local emptyArmorImageBodywear = {
  657.     {128,128,128,128,128,128,128},
  658.     {256,256,128,128,128,256,256},
  659.     {256,256,256,256,256,256,256},
  660.     {128,256,256,256,256,256,128},
  661.     {128,256,256,256,256,256,128},
  662. }
  663. local emptyArmorImagePants = {
  664.     {128,256,256,256,256,256,128},
  665.     {128,256,256,256,256,256,128},
  666.     {128,256,256,128,256,256,128},
  667.     {128,256,256,128,256,256,128},
  668.     {128,256,256,128,256,256,128},
  669. }
  670. local emptyArmorImageFootwear = {
  671.     {128,128,128,128,128,128,128},
  672.     {128,128,256,256,128,128,256},
  673.     {128,128,256,256,128,128,256},
  674.     {128,256,256,256,128,256,256},
  675.     {256,256,256,128,256,256,256},
  676. }
  677. local emptyArmorImagePendant = {
  678.     {128,128,128,128,128,128,128},
  679.     {256,128,128,128,128,128,256},
  680.     {128,256,128,128,128,256,128},
  681.     {128,128,256,256,256,128,128},
  682.     {128,128,128,256,128,128,128},
  683. }
  684. local emptyArmorImageWeapon = {
  685.     {128,128,128,128,128,128,256},
  686.     {128,128,128,256,128,256,128},
  687.     {128,128,128,128,256,128,128},
  688.     {128,128,128,256,128,256,128},
  689.     {128,256,256,128,128,128,128},
  690. }
  691.  
  692. local dialogwindow1 = {
  693.     {["text"] = "Hello, good man!"},
  694.     {["text"] = "Quests", ["action"] = "dialog",
  695.     ["do"] = {
  696.     {["text"] = "Take quests"},
  697.     {["text"] = ">Decaying ghoul", ["action"] = "getquest", ["do"] = 5},
  698.     {["text"] = ">Turtles", ["action"] = "getquest", ["do"] = 4},
  699.     {["text"] = ">Swamp slugs", ["action"] = "getquest", ["do"] = 3},  
  700.     {["text"] = ">Zombies", ["action"] = "getquest", ["do"] = 1},
  701.     {["text"] = ">Ghost", ["action"] = "getquest", ["do"] = 2},
  702.     {["text"] = "Later", ["action"] = "close", ["do"] = 0},
  703.     }},
  704.     {["text"] = "See you later", ["action"] = "close", ["do"] = 0}
  705. }
  706. local dialogwindow2 = {
  707.     {["text"] = "I do not need help..."},
  708.     {["text"] = "See you later", ["action"] = "close", ["do"] = 0}
  709. }
  710. local dialogwindow3 = {
  711.     {["text"] = ""},
  712.     {["text"] = "Goods and services", ["action"] = "trade", ["do"] = 1},
  713.     {["text"] = "Create item", ["action"] = "crafting", ["do"] = 1},
  714.     {["text"] = "Quests", ["action"] = "dialog",
  715.     ["do"] = {
  716.     {["text"] = "Take quests"},
  717.     {["text"] = "Later", ["action"] = "close", ["do"] = 0},
  718.     }},
  719.     {["text"] = "See you later", ["action"] = "close", ["do"] = 0}
  720. }
  721. local dialogwindow4 = {
  722.     {["text"] = ""},
  723.     {["text"] = "Goods and services", ["action"] = "trade", ["do"] = 2},
  724.     {["text"] = "Create item", ["action"] = "crafting", ["do"] = 2},
  725.     {["text"] = "Quests", ["action"] = "dialog",
  726.     ["do"] = {
  727.     {["text"] = "Take quests"},
  728.     {["text"] = ">Parasites", ["action"] = "getquest", ["do"] = 7},
  729.     {["text"] = ">A living iron", ["action"] = "getquest", ["do"] = 6},
  730.     {["text"] = "Later", ["action"] = "close", ["do"] = 0},
  731.     }},
  732.     {["text"] = "See you later", ["action"] = "close", ["do"] = 0}
  733. }
  734. local dialogwindow5 = {
  735.     {["text"] = ""},
  736.     {["text"] = "Goods and services", ["action"] = "trade", ["do"] = 3},
  737.     {["text"] = "Quests", ["action"] = "dialog",
  738.     ["do"] = {
  739.     {["text"] = "Take quests"},
  740.     {["text"] = ">Tree roots", ["action"] = "getquest", ["do"] = 9},
  741.     {["text"] = ">Green foliage", ["action"] = "getquest", ["do"] = 8},
  742.     {["text"] = "Later", ["action"] = "close", ["do"] = 0},
  743.     }},    
  744.     {["text"] = "See you later", ["action"] = "close", ["do"] = 0}
  745. }
  746. local dialogwindow6 = {
  747.     {["text"] = ""},
  748.     {["text"] = "Goods and services", ["action"] = "trade", ["do"] = 2},
  749.     {["text"] = "Create item", ["action"] = "crafting", ["do"] = 2},
  750.     {["text"] = "Quests", ["action"] = "dialog",
  751.     ["do"] = {
  752.     {["text"] = "Take quests"},
  753.     {["text"] = "Later", ["action"] = "close", ["do"] = 0},
  754.     }},
  755.     {["text"] = "See you later", ["action"] = "close", ["do"] = 0}
  756. }
  757. local dialogwindow7 = {
  758.     {["text"] = "Hello, good man!"},
  759.     {["text"] = "Quests", ["action"] = "dialog",
  760.     ["do"] = {
  761.     {["text"] = "Take quests"},
  762.     {["text"] = ">Soullsess soldiers", ["action"] = "getquest", ["do"] = 11},
  763.     {["text"] = ">Ghosts", ["action"] = "getquest", ["do"] = 10},  
  764.     {["text"] = "Later", ["action"] = "close", ["do"] = 0},
  765.     }},
  766.     {["text"] = "See you later", ["action"] = "close", ["do"] = 0}
  767. }
  768.  
  769. local tradewindow = {
  770. [1]={  
  771.     {["item"] = 5, ["cost"] = 82},
  772.     {["item"] = 6, ["cost"] = 86},
  773.     {["item"] = 7, ["cost"] = 85},
  774.     {["item"] = 8, ["cost"] = 85},
  775.     {["item"] = 14, ["cost"] = 82},
  776.     {["item"] = 21, ["cost"] = 147},
  777.     {["item"] = 22, ["cost"] = 151},
  778.     {["item"] = 23, ["cost"] = 148},
  779.     {["item"] = 24, ["cost"] = 148},   
  780.     {["item"] = 37, ["cost"] = 257},
  781.     {["item"] = 38, ["cost"] = 262},
  782.     {["item"] = 39, ["cost"] = 259},
  783.     {["item"] = 40, ["cost"] = 258},
  784.     {["item"] = 43, ["cost"] = 403},
  785.     {["item"] = 44, ["cost"] = 412},
  786.     {["item"] = 45, ["cost"] = 410},
  787.     {["item"] = 46, ["cost"] = 410},
  788.     },
  789. [2]={
  790.     {["item"] = 17, ["cost"] = 245},
  791.     {["item"] = 35, ["cost"] = 573},
  792.     {["item"] = 42, ["cost"] = 804},
  793.     {["item"] = 19, ["cost"] = 188},   
  794.     {["item"] = 18, ["cost"] = 260},
  795.     },
  796. [3]={
  797.     {["item"] = 26, ["cost"] = 25},
  798.     {["item"] = 27, ["cost"] = 25},
  799.     {["item"] = 28, ["cost"] = 45},
  800.     {["item"] = 29, ["cost"] = 45},
  801.     {["item"] = 30, ["cost"] = 70},
  802.     {["item"] = 31, ["cost"] = 70},
  803.     {["item"] = 32, ["cost"] = 105},
  804.     {["item"] = 33, ["cost"] = 105},
  805.     },
  806. }
  807. local craftingwindow = {
  808. [1]={
  809.     {["item"] = 5, ["recipe"] = {{9,1},{10,1},{36,1}}, ["cost"] = 0},
  810.     {["item"] = 6, ["recipe"] = {{9,1},{10,2},{36,1}}, ["cost"] = 0},
  811.     {["item"] = 7, ["recipe"] = {{9,2},{10,1},{36,1}}, ["cost"] = 0},
  812.     {["item"] = 8, ["recipe"] = {{9,1},{10,1},{36,1}}, ["cost"] = 0},
  813.     {["item"] = 21, ["recipe"] = {{9,2},{20,1},{36,1}}, ["cost"] = 0},
  814.     {["item"] = 22, ["recipe"] = {{9,2},{20,2},{36,1}}, ["cost"] = 0},
  815.     {["item"] = 23, ["recipe"] = {{9,3},{20,1},{36,1}}, ["cost"] = 0},
  816.     {["item"] = 24, ["recipe"] = {{9,2},{20,1},{36,1}}, ["cost"] = 0},
  817.     {["item"] = 37, ["recipe"] = {{9,3},{20,2},{41,2},{13,1}}, ["cost"] = 0},
  818.     {["item"] = 38, ["recipe"] = {{9,3},{20,3},{41,2},{13,1}}, ["cost"] = 0},
  819.     {["item"] = 39, ["recipe"] = {{9,4},{20,2},{41,2},{13,1}}, ["cost"] = 0},
  820.     {["item"] = 40, ["recipe"] = {{9,3},{20,2},{41,2},{13,1}}, ["cost"] = 0},
  821.     {["item"] = 43, ["recipe"] = {{3,1},{20,4},{41,2},{10,1}}, ["cost"] = 0},
  822.     {["item"] = 44, ["recipe"] = {{3,2},{20,4},{41,2},{13,1}}, ["cost"] = 0},
  823.     {["item"] = 45, ["recipe"] = {{3,1},{20,4},{41,2},{13,1}}, ["cost"] = 0},
  824.     {["item"] = 46, ["recipe"] = {{3,1},{20,4},{41,2},{13,1}}, ["cost"] = 0},
  825.     },
  826. [2]={
  827.     {["item"] = 17, ["recipe"] = {{34,1},{1,3},{49,1}}, ["cost"] = 0},
  828.     {["item"] = 35, ["recipe"] = {{34,2},{1,1},{3,5},{49,1}}, ["cost"] = 0},
  829.     {["item"] = 42, ["recipe"] = {{34,1},{1,2},{3,8},{49,2}}, ["cost"] = 0},
  830.     },
  831. }
  832.  
  833. local function clicked(x,y,x1,y1,x2,y2)
  834.  if x >= x1 and x <= x2 and y >= y1 and y <= y2 then
  835.  return true
  836.  end    
  837.  return false
  838. end
  839.  
  840. local vAttackDistance = 2
  841. local VAttackPause = 1
  842.  
  843. local CDataLoad = {
  844.     {["id"] = 1, ["name"] = "Player", ["level"] = 1, ["loot"] = {["exp"] = 0, ["coins"] = 0, ["items"] = {}},
  845.     ["vrespawn"] = 0, ["roletype"] = "p", ["image"] = playerMdl[1]},
  846.     {["id"] = 2, ["name"] = "Nibner", ["level"] = 0, ["loot"] = {["exp"] = 0, ["coins"] = 0, ["items"] = {}},
  847.     ["vrespawn"] = 0, ["image"] = habitant1Mdl[1], ["roletype"] = "f",["dialog"] = dialogwindow1},
  848.     {["id"] = 3, ["name"] = "Inhabitant", ["level"] = 0, ["loot"] = {["exp"] = 0, ["coins"] = 0, ["items"] = {}},
  849.     ["image"] = habitant2Mdl[1], ["roletype"] = "f",["dialog"] = dialogwindow2},   
  850.     {["id"] = 4, ["name"] = "Zombie", ["level"] = 1, ["loot"] = {["exp"] = 2, ["coins"] = 2, ["items"] = {
  851.     {26,5},{27,5},{5,1},{6,1},{7,1},{8,1},{9,3},{10,3},{14,1},{36,3},
  852.     }}, ["atds"] = 3, ["agr"] = false, ["vrespawn"] = 30, ["image"] = zombie1Mdl[1], ["roletype"] = "e"},
  853.     {["id"] = 5, ["name"] = "Ghost", ["level"] = 2, ["loot"] = {["exp"] = 3, ["coins"] = 3, ["items"] = {
  854.     {26,5},{27,5},{5,1},{6,1},{7,1},{8,1},{14,1},{36,3},{9,3},{10,3},
  855.     }},["atds"] = 5, ["agr"] = false, ["vrespawn"] = 30, ["image"] = ghostMdl[1], ["roletype"] = "e"},
  856.     {["id"] = 6, ["name"] = "Green Slug", ["level"] = 2, ["loot"] = {["exp"] = 3, ["coins"] = 3, ["items"] = {
  857.     {26,5},{27,5},{5,1},{6,1},{7,1},{8,1},{14,1},{36,3},{12,2},{9,3},{10,3},
  858.     }},["atds"] = 3, ["agr"] = false, ["vrespawn"] = 30, ["image"] = greenslimeMdl[1], ["roletype"] = "e"},
  859.     {["id"] = 7, ["name"] = "Silver Snake", ["level"] = 2, ["loot"] = {["exp"] = 3, ["coins"] = 3, ["items"] = {
  860.     {26,5},{27,5},{5,1},{6,1},{7,1},{8,1},{14,1},{36,3},{9,3},{10,3},
  861.     }},["atds"] = 3, ["agr"] = false, ["vrespawn"] = 30, ["image"] = silversnakeMdl[1], ["roletype"] = "e"},   
  862.     {["id"] = 8, ["name"] = "Bush", ["level"] = 3, ["loot"] = {["exp"] = 4, ["coins"] = 4, ["items"] = {
  863.     {26,5},{27,5},{11,2},{5,1},{6,1},{7,1},{14,1},{8,1},{11,2},{18,1},{36,3},{9,3},{10,3},
  864.     }},["atds"] = 3, ["agr"] = false, ["vrespawn"] = 30, ["image"] = bushMdl[1], ["roletype"] = "e"},
  865.     {["id"] = 9, ["name"] = "Spirit Of Place", ["level"] = 3, ["loot"] = {["exp"] = 4, ["coins"] = 2, ["items"] = {
  866.     {26,5},{27,5},{5,1},{6,1},{7,1},{8,1},{14,1},{13,1},{18,1},{36,3},{9,3},{10,3},
  867.     }},["atds"] = 3, ["agr"] = false, ["vrespawn"] = 40, ["image"] = spiritofplaceMdl[1], ["roletype"] = "e"},
  868.     {["id"] = 10, ["name"] = "Stone Turtle", ["level"] = 4, ["loot"] = {["exp"] = 6, ["coins"] = 2, ["items"] = {
  869.     {28,5},{29,5},{11,2},{19,1},{20,2},{21,1},{22,1},{23,1},{24,1},{17,1},{18,1},{13,1},{36,3},{9,3},{10,3},
  870.     }},["atds"] = 3, ["agr"] = false, ["vrespawn"] = 30, ["image"] = stoneturtleMdl[1], ["roletype"] = "e"},
  871.     {["id"] = 11, ["name"] = "Swamp Tree", ["level"] = 4, ["loot"] = {["exp"] = 6, ["coins"] = 4, ["items"] = {
  872.     {28,5},{29,5},{11,2},{19,1},{20,2},{21,1},{22,1},{23,1},{24,1},{17,1},{18,1},{34,3},{13,1},{36,3},{9,3},{10,3},
  873.     }},["atds"] = 3, ["agr"] = false, ["vrespawn"] = 30, ["image"] = woodMdl[1], ["roletype"] = "e"},
  874.     {["id"] = 12, ["name"] = "Tailor", ["level"] = 0, ["loot"] = {["exp"] = 0, ["coins"] = 0, ["items"] = {}},
  875.     ["vrespawn"] = 0, ["image"] = tailor1Mdl[1], ["roletype"] = "f",["dialog"] = dialogwindow3},
  876.     {["id"] = 13, ["name"] = "Skeletal Archer", ["level"] = 5, ["loot"] = {["exp"] = 9, ["coins"] = 9, ["items"] = {
  877.     {28,3},{29,3},{21,1},{22,1},{23,1},{24,1},{17,1},{20,2},{34,2},{13,1},
  878.     }},["atds"] = 8, ["agr"] = true, ["vrespawn"] = 35, ["image"] = sceletonarcherMdl[1], ["roletype"] = "e"},
  879.     {["id"] = 14, ["name"] = "Female Ghost", ["level"] = 5, ["loot"] = {["exp"] = 9, ["coins"] = 4, ["items"] = {
  880.     {28,5},{29,5},{21,1},{22,1},{23,1},{24,1},{17,1},{20,1},{34,1},{13,1},
  881.     }},["atds"] = 3, ["agr"] = true, ["vrespawn"] = 40, ["image"] = femaleghostMdl[1], ["roletype"] = "e"},
  882.     {["id"] = 15, ["name"] = "Venomous Ghoul", ["level"] = 6, ["loot"] = {["exp"] = 12, ["coins"] = 6, ["items"] = {
  883.     {28,5},{29,5},{21,1},{22,1},{23,1},{24,1},{37,1},{38,1},{39,1},{40,1},{17,1},{20,1},{34,1},{41,1},{13,1},{47,1}
  884.     }},["atds"] = 3, ["agr"] = true, ["vrespawn"] = 35, ["image"] = venomousghoulMdl[1], ["roletype"] = "e"},
  885.     {["id"] = 16, ["name"] = "Decaying Ghoul", ["level"] = 9, ["loot"] = {["exp"] = 31, ["coins"] = 17, ["items"] = {
  886.     {30,12},{31,12},{37,2},{38,2},{39,2},{40,2},{35,2},{20,3},{34,3},{41,3},{13,1},{47,1}
  887.     }},["atds"] = 3, ["agr"] = true, ["vrespawn"] = 600, ["image"] = decayingghoulMdl[1], ["roletype"] = "e"},
  888.     {["id"] = 17, ["name"] = "Stone Golem", ["level"] = 7, ["loot"] = {["exp"] = 14, ["coins"] = 11, ["items"] = {
  889.     {28,5},{29,5},{37,1},{38,1},{39,1},{40,1},{17,1},{20,2},{34,2},{41,2},{13,1},
  890.     }},["atds"] = 4, ["agr"] = true, ["vrespawn"] = 35, ["image"] = stonegolemMdl[1], ["roletype"] = "e"},
  891.     {["id"] = 18, ["name"] = "Iron Turtle", ["level"] = 7, ["loot"] = {["exp"] = 14, ["coins"] = 12, ["items"] = {
  892.     {28,5},{29,5},{37,1},{38,1},{39,1},{40,1},{17,1},{20,2},{34,2},{41,2},{13,1},{47,1}
  893.     }},["atds"] = 3, ["agr"] = true, ["vrespawn"] = 30, ["image"] = ironturtleMdl[1], ["roletype"] = "e"},
  894.     {["id"] = 19, ["name"] = "Blacksmith", ["level"] = 0, ["loot"] = {["exp"] = 0, ["coins"] = 0, ["items"] = {}},
  895.     ["vrespawn"] = 0, ["image"] = bsmith1Mdl[1], ["roletype"] = "f",["dialog"] = dialogwindow4},
  896.     {["id"] = 20, ["name"] = "Copper Ore", ["level"] = 0, ["loot"] = {["exp"] = 0, ["coins"] = 0, ["items"] = {
  897.     {1,100},{1,1}
  898.     }}, ["vrespawn"] = 600, ["image"] = copperoreMdl[1], ["roletype"] = "r"},
  899.     {["id"] = 21, ["name"] = "Tree Root", ["level"] = 0, ["loot"] = {["exp"] = 0, ["coins"] = 0, ["items"] = {
  900.     {34,100},{34,1}
  901.     }}, ["vrespawn"] = 600, ["image"] = treerootMdl[1], ["roletype"] = "r"},
  902.     {["id"] = 22, ["name"] = "Iron Ore", ["level"] = 0, ["loot"] = {["exp"] = 0, ["coins"] = 0, ["items"] = {
  903.     {3,100},{3,1}
  904.     }}, ["vrespawn"] = 600, ["image"] = ironoreMdl[1], ["roletype"] = "r"},
  905.     {["id"] = 23, ["name"] = "Coarse Gravel", ["level"] = 0, ["loot"] = {["exp"] = 0, ["coins"] = 0, ["items"] = {
  906.     {49,100},{49,1}
  907.     }}, ["vrespawn"] = 600, ["image"] = gravelMdl[1], ["roletype"] = "r"}, 
  908.     {["id"] = 24, ["name"] = "Wind Elemental", ["level"] = 15, ["mhp"] = 430,
  909.     ["loot"] = {["exp"] = 42, ["coins"] = 37, ["items"] = {
  910.     }},["atds"] = 4, ["agr"] = true, ["vrespawn"] = 21600, ["image"] = windelmentalMdl[1], ["roletype"] = "m"},
  911.     {["id"] = 25, ["name"] = "Goblin Henghtu", ["level"] = 8, ["loot"] = {["exp"] = 16, ["coins"] = 14, ["items"] = {
  912.     {28,5},{29,5},{30,5},{31,5},{37,1},{38,1},{39,1},{40,1},{35,1},{20,2},{34,2},{41,2},{13,1},{47,1}
  913.     }},["atds"] = 4, ["agr"] = true, ["vrespawn"] = 35, ["image"] = goblinheghtuMdl[1], ["roletype"] = "e"},
  914.     {["id"] = 26, ["name"] = "Demonic Maggot", ["level"] = 9, ["loot"] = {["exp"] = 18, ["coins"] = 15, ["items"] = {
  915.     {30,5},{31,5},{37,1},{38,1},{39,1},{40,1},{35,1},{20,2},{34,2},{41,2},{13,1},{47,1}
  916.     }},["atds"] = 3, ["agr"] = true, ["vrespawn"] = 40, ["image"] = devilmaggotMdl[1], ["roletype"] = "e"},
  917.     {["id"] = 27, ["name"] = "Zombie Warrior", ["level"] = 10, ["loot"] = {["exp"] = 22, ["coins"] = 18, ["items"] = {
  918.     {30,5},{31,5},{37,1},{38,1},{39,1},{40,1},{35,1},{20,2},{34,2},{41,2},{13,1},{48,1}
  919.     }},["atds"] = 3, ["agr"] = true, ["vrespawn"] = 40, ["image"] = zombiewarriorMdl[1], ["roletype"] = "e"},
  920.     {["id"] = 28, ["name"] = "Sage Spirit", ["level"] = 11, ["loot"] = {["exp"] = 25, ["coins"] = 23, ["items"] = {
  921.     {30,5},{31,5},{43,1},{44,1},{45,1},{46,1},{35,1},{20,2},{34,2},{41,2},{13,1},{48,1}
  922.     }},["atds"] = 5, ["agr"] = true, ["vrespawn"] = 40, ["image"] = sagespiritMdl[1], ["roletype"] = "e"},
  923.     {["id"] = 29, ["name"] = "Soulless", ["level"] = 12, ["loot"] = {["exp"] = 27, ["coins"] = 28, ["items"] = {
  924.     {30,5},{31,5},{43,1},{44,1},{45,1},{46,1},{35,1},{20,2},{34,2},{41,2},{13,1},{48,1}
  925.     }},["atds"] = 3, ["agr"] = true, ["vrespawn"] = 40, ["image"] = soullessMdl[1], ["roletype"] = "e"},
  926.     {["id"] = 30, ["name"] = "Apothecary", ["level"] = 0, ["loot"] = {["exp"] = 0, ["coins"] = 0, ["items"] = {}},
  927.     ["vrespawn"] = 0, ["image"] = apothecary1Mdl[1], ["roletype"] = "f",["dialog"] = dialogwindow5},
  928.     {["id"] = 31, ["name"] = "Blacksmith", ["level"] = 0, ["loot"] = {["exp"] = 0, ["coins"] = 0, ["items"] = {}},
  929.     ["vrespawn"] = 0, ["image"] = bsmith1Mdl[1], ["roletype"] = "f",["dialog"] = dialogwindow6},
  930.     {["id"] = 32, ["name"] = "Koletan", ["level"] = 0, ["loot"] = {["exp"] = 0, ["coins"] = 0, ["items"] = {}},
  931.     ["image"] = habitant3Mdl[1], ["roletype"] = "f",["dialog"] = dialogwindow7},
  932. }
  933. --
  934.  
  935. local CQuestsLoad = {
  936.     {["name"] = "Living corpses", ["type"] = "k", ["targ"] = 4, ["num"] = 5, ["minlvl"] = 1, ["maxlvl"] = 100, ["comp"] = 0, ["qreward"] = {["coins"] = 10, ["xp"] = 12, ["item"] = {26,5}}},
  937.     {["name"] = "Ghost", ["type"] = "k", ["targ"] = 5, ["num"] = 1, ["minlvl"] = 1, ["maxlvl"] = 100, ["comp"] = 0, ["qreward"] = {["coins"] = 10, ["xp"] = 14, ["item"] = {27,5}}},
  938.     {["name"] = "Swamp slugs", ["type"] = "k", ["targ"] = 6, ["num"] = 10, ["minlvl"] = 2, ["maxlvl"] = 100, ["comp"] = 0, ["qreward"] = {["coins"] = 17, ["xp"] = 22, ["item"] = {25,1}}},
  939.     {["name"] = "Turtles", ["type"] = "k", ["targ"] = 10, ["num"] = 5, ["minlvl"] = 4, ["maxlvl"] = 100, ["comp"] = 0, ["qreward"] = {["coins"] = 13, ["xp"] = 12, ["item"] = {50,1}}},
  940.     {["name"] = "Decaying ghoul", ["type"] = "k", ["targ"] = 16, ["num"] = 1, ["minlvl"] = 6, ["maxlvl"] = 100, ["comp"] = 0, ["qreward"] = {["coins"] = 37, ["xp"] = 11, ["item"] = {51,1}}},
  941.     {["name"] = "Living iron", ["type"] = "k", ["targ"] = 18, ["num"] = 5, ["minlvl"] = 6, ["maxlvl"] = 100, ["comp"] = 0, ["qreward"] = {["coins"] = 17, ["xp"] = 21, ["item"] = {52,1}}},
  942.     {["name"] = "Parasites", ["type"] = "k", ["targ"] = 26, ["num"] = 10, ["minlvl"] = 9, ["maxlvl"] = 100, ["comp"] = 0, ["qreward"] = {["coins"] = 56, ["xp"] = 29, ["item"] = {55,1}}},
  943.     {["name"] = "Green foliage", ["type"] = "k", ["targ"] = 8, ["num"] = 5, ["minlvl"] = 3, ["maxlvl"] = 100, ["comp"] = 0, ["qreward"] = {["coins"] = 5, ["xp"] = 11, ["item"] = {0,0}}},
  944.     {["name"] = "Tree roots", ["type"] = "k", ["targ"] = 11, ["num"] = 5, ["minlvl"] = 4, ["maxlvl"] = 100, ["comp"] = 0, ["qreward"] = {["coins"] = 12, ["xp"] = 25, ["item"] = {0,0}}},
  945.     {["name"] = "Ghosts", ["type"] = "k", ["targ"] = 28, ["num"] = 5, ["minlvl"] = 10, ["maxlvl"] = 100, ["comp"] = 0, ["qreward"] = {["coins"] = 68, ["xp"] = 33, ["item"] = {58,1}}},
  946.     {["name"] = "Soullsess soldiers", ["type"] = "k", ["targ"] = 29, ["num"] = 10, ["minlvl"] = 11, ["maxlvl"] = 100, ["comp"] = 0, ["qreward"] = {["coins"] = 55, ["xp"] = 36, ["item"] = {57,1}}},
  947. }
  948.  
  949. local cEffectsLoad = {
  950.     {["name"] = "Health potion", ["type"] = "hpi", ["value"] = 10, ["duration"] = 10, ["icon"] = {{16384,"H"},{2,"P"}}},
  951.     {["name"] = "Mana potion", ["type"] = "mpi", ["value"] = 10, ["duration"] = 10, ["icon"] = {{2048,"M"},{2,"P"}}},
  952.     {["name"] = "Health potion", ["type"] = "hpi", ["value"] = 15, ["duration"] = 10, ["icon"] = {{16384,"H"},{2,"P"}}},
  953.     {["name"] = "Mana potion", ["type"] = "mpi", ["value"] = 15, ["duration"] = 10, ["icon"] = {{2048,"M"},{2,"P"}}},
  954.     {["name"] = "Health potion", ["type"] = "hpi", ["value"] = 25, ["duration"] = 10, ["icon"] = {{16384,"H"},{2,"P"}}},
  955.     {["name"] = "Mana potion", ["type"] = "mpi", ["value"] = 25, ["duration"] = 10, ["icon"] = {{2048,"M"},{2,"P"}}},
  956.     {["name"] = "Health potion", ["type"] = "hpi", ["value"] = 35, ["duration"] = 10, ["icon"] = {{16384,"H"},{2,"P"}}},
  957.     {["name"] = "Mana potion", ["type"] = "mpi", ["value"] = 40, ["duration"] = 10, ["icon"] = {{2048,"M"},{2,"P"}}},  
  958.     {["name"] = "Health potion", ["type"] = "hpi", ["value"] = 60, ["duration"] = 10, ["icon"] = {{16384,"H"},{2,"P"}}},
  959.     {["name"] = "Mana potion", ["type"] = "mpi", ["value"] = 65, ["duration"] = 10, ["icon"] = {{2048,"M"},{2,"P"}}},  
  960.     {["name"] = "Bleeding", ["type"] = "hpd", ["value"] = 6, ["duration"] = 10, ["icon"] = {{16384,"B"},{16,"l"}}},
  961.     {["name"] = "Bleeding", ["type"] = "hpd", ["value"] = 11, ["duration"] = 10, ["icon"] = {{16384,"B"},{16,"l"}}},
  962.     {["name"] = "Bleeding", ["type"] = "hpd", ["value"] = 18, ["duration"] = 10, ["icon"] = {{16384,"B"},{16,"l"}}},   
  963.     {["name"] = "Bleeding", ["type"] = "hpd", ["value"] = 27, ["duration"] = 10, ["icon"] = {{16384,"B"},{16,"l"}}},
  964.     {["name"] = "Bleeding", ["type"] = "hpd", ["value"] = 41, ["duration"] = 10, ["icon"] = {{16384,"B"},{16,"l"}}},   
  965.     {["name"] = "Bleeding", ["type"] = "hpd", ["value"] = 69, ["duration"] = 10, ["icon"] = {{16384,"B"},{16,"l"}}},
  966.     {["name"] = "Bleeding", ["type"] = "hpd", ["value"] = 92, ["duration"] = 10, ["icon"] = {{16384,"B"},{16,"l"}}},
  967.     {["name"] = "Warrior healing", ["type"] = "hpi", ["value"] = 10, ["duration"] = 8, ["icon"] = {{16384,"W"},{512,"H"}}},
  968.     {["name"] = "Warrior healing", ["type"] = "hpi", ["value"] = 14, ["duration"] = 8, ["icon"] = {{16384,"W"},{512,"H"}}},
  969.     {["name"] = "Warrior healing", ["type"] = "hpi", ["value"] = 28, ["duration"] = 9, ["icon"] = {{16384,"W"},{512,"H"}}},
  970.     {["name"] = "Warrior healing", ["type"] = "hpi", ["value"] = 40, ["duration"] = 9, ["icon"] = {{16384,"W"},{512,"H"}}},
  971.     {["name"] = "Warrior healing", ["type"] = "hpi", ["value"] = 56, ["duration"] = 10, ["icon"] = {{16384,"W"},{512,"H"}}},
  972.     {["name"] = "Warrior healing", ["type"] = "hpi", ["value"] = 79, ["duration"] = 10, ["icon"] = {{16384,"W"},{512,"H"}}},
  973.     {["name"] = "Warrior healing", ["type"] = "hpi", ["value"] = 94, ["duration"] = 10, ["icon"] = {{16384,"W"},{512,"H"}}},
  974. }
  975.  
  976. local cSkillsLoad = {
  977.     {["name"] = "Phisical Attack", ["distance"] = vAttackDistance, ["type"] = "attack", ["typedm"] = "p", ["level"] = 1, ["reloading"] = VAttackPause,
  978.     ["mindamage"] = {0,0,0,0,0,0,0}, ["maxdamage"] = {1,1,1,1,1,1,1}, ["manacost"] = {0,0,0,0,0,0,0}, ["eff"] = {0,0,0,0,0,0,0}},
  979.     {["name"] = "Deep Cut", ["distance"] = 4, ["type"] = "attack", ["typedm"] = "p", ["level"] = 1, ["reloading"] = 3,
  980.     ["mindamage"] = {2,3,5,7,10,13,15}, ["maxdamage"] = {2,4,6,9,11,16,19}, ["manacost"] = {5,7,8,10,12,15,19}, ["eff"] = {0,0,0,0,0,0,0}},
  981.     {["name"] = "Draw Blood", ["distance"] = 4, ["type"] = "attack", ["typedm"] = "p", ["level"] = 1, ["reloading"] = 8,
  982.     ["mindamage"] = {1,2,4,6,9,11,13}, ["maxdamage"] = {2,3,6,8,10,13,16}, ["manacost"] = {6,8,9,11,13,16,20}, ["eff"] = {11,12,13,14,15,16,17}},
  983.     {["name"] = "Stream Strike", ["distance"] = 5, ["type"] = "attack", ["typedm"] = "p", ["level"] = 1, ["reloading"] = 5,
  984.     ["mindamage"] = {3,5,8,11,14,18,23}, ["maxdamage"] = {5,8,11,14,18,23,28}, ["manacost"] = {6,9,12,15,19,25,32}, ["eff"] = {0,0,0,0,0,0,0}},
  985.     {["name"] = "Warrior Healing", ["distance"] = 0, ["type"] = "buff", ["typedm"] = "p", ["level"] = 1, ["reloading"] = 30,
  986.     ["manacost"] = {8,10,11,13,15,18,22}, ["eff"] = {18,19,20,21,22,23,24}},
  987. }
  988.  
  989. local cItemsLoad = {
  990.     {["name"] = "Copper Ingot", ["type"] = "item", ["subtype"] = "none", ["description"] = "Can be used for crafting",
  991.     ["stackable"] = true, ["maxstack"] = 99, ["cost"] = 5, ["icon"] = 1, ["ncolor"] = 1},
  992.     {["name"] = "Bronze Ingot", ["type"] = "item", ["subtype"] = "none", ["description"] = "Can be used for crafting",
  993.     ["stackable"] = true, ["maxstack"] = 99, ["cost"] = 5, ["icon"] = 14, ["ncolor"] = 1}, 
  994.     {["name"] = "Iron Ingot", ["type"] = "item", ["subtype"] = "none", ["description"] = "Can be used for crafting",
  995.     ["stackable"] = true, ["maxstack"] = 99, ["cost"] = 5, ["icon"] = 8, ["ncolor"] = 1},
  996.     {["name"] = "Purified  Iron Ingot", ["type"] = "item", ["subtype"] = "none", ["description"] = "Can be used for crafting",
  997.     ["stackable"] = true, ["maxstack"] = 99, ["cost"] = 5, ["icon"] = 8, ["ncolor"] = 1},  
  998.     {["name"] = "Rookie's Helmet", ["level"] = 1, ["type"] = "armor", ["subtype"] = "helmet", ["reqlvl"] = 1, ["description"] = "",
  999.     ["props"] = {["hp+"] = 0, ["phisdef"] = 14, ["magdef"] = 0}, ["stackable"] = false, ["cost"] = 5, ["icon"] = 7, ["ncolor"] = 1},   
  1000.     {["name"] = "Rookie's Armor", ["level"] = 1, ["type"] = "armor", ["subtype"] = "bodywear", ["reqlvl"] = 1, ["description"] = "",
  1001.     ["props"] = {["hp+"] = 0, ["phisdef"] = 16, ["magdef"] = 11}, ["stackable"] = false, ["cost"] = 5, ["icon"] = 3, ["ncolor"] = 1},  
  1002.     {["name"] = "Rookie's Pants", ["level"] = 1, ["type"] = "armor", ["subtype"] = "pants", ["reqlvl"] = 1, ["description"] = "",
  1003.     ["props"] = {["hp+"] = 0, ["phisdef"] = 15, ["magdef"] = 10}, ["stackable"] = false, ["cost"] = 5, ["icon"] = 15, ["ncolor"] = 1}, 
  1004.     {["name"] = "Rookie's Boots", ["level"] = 1, ["type"] = "armor", ["subtype"] = "footwear", ["reqlvl"] = 1, ["description"] = "",
  1005.     ["props"] = {["hp+"] = 0, ["phisdef"] = 15, ["magdef"] = 8}, ["stackable"] = false, ["cost"] = 5, ["icon"] = 2, ["ncolor"] = 1},
  1006.     {["name"] = "Animal Fur", ["type"] = "item", ["subtype"] = "none", ["description"] = "Can be used for crafting",
  1007.     ["stackable"] = true, ["maxstack"] = 99, ["cost"] = 2, ["icon"] = 4, ["ncolor"] = 1},
  1008.     {["name"] = "Rough Fur", ["type"] = "item", ["subtype"] = "none", ["description"] = "Can be used for crafting",
  1009.     ["stackable"] = true, ["maxstack"] = 99, ["cost"] = 3, ["icon"] = 6, ["ncolor"] = 1},
  1010.     {["name"] = "Vegetable Oil", ["type"] = "item", ["subtype"] = "none", ["description"] = "Can be used for crafting",
  1011.     ["stackable"] = true, ["maxstack"] = 99, ["cost"] = 1, ["icon"] = 9, ["ncolor"] = 1},
  1012.     {["name"] = "Green Slime", ["type"] = "item", ["subtype"] = "none", ["description"] = "",
  1013.     ["stackable"] = true, ["maxstack"] = 99, ["cost"] = 1, ["icon"] = 10, ["ncolor"] = 1},
  1014.     {["name"] = "Rough Cloth", ["type"] = "item", ["subtype"] = "none", ["description"] = "Can be used for crafting",
  1015.     ["stackable"] = true, ["maxstack"] = 99, ["cost"] = 1, ["icon"] = 11, ["ncolor"] = 1},
  1016.     {["name"] = "Cloth Hat", ["level"] = 1, ["type"] = "armor", ["subtype"] = "helmet", ["reqlvl"] = 1, ["description"] = "",
  1017.     ["props"] = {["hp+"] = 0, ["phisdef"] = 0, ["magdef"] = 15}, ["stackable"] = false, ["cost"] = 5, ["icon"] = 17, ["ncolor"] = 1},
  1018.     {["name"] = "Wooden Sword", ["level"] = 1, ["type"] = "weapon", ["subtype"] = "sword", ["reqlvl"] = 1, ["description"] = "",
  1019.     ["props"] = {["atds"] = 3, ["hp+"] = 0, ["phisat"] = 1, ["magat"] = 0}, ["stackable"] = false, ["cost"] = 1, ["icon"] = 5, ["ncolor"] = 16},   
  1020.     {["name"] = "Long Sword", ["level"] = 1, ["type"] = "weapon", ["subtype"] = "sword", ["reqlvl"] = 3, ["description"] = "",
  1021.     ["props"] = {["atds"] = 3, ["hp+"] = 0, ["phisat"] = 6, ["magat"] = 0}, ["stackable"] = false, ["cost"] = 1, ["icon"] = 18, ["ncolor"] = 1},
  1022.     {["name"] = "Refined Sword", ["level"] = 2, ["type"] = "weapon", ["subtype"] = "sword", ["reqlvl"] = 5, ["description"] = "",
  1023.     ["props"] = {["atds"] = 3, ["hp+"] = 0, ["phisat"] = 9, ["magat"] = 0}, ["stackable"] = false, ["cost"] = 14, ["icon"] = 19, ["ncolor"] = 1},
  1024.     {["name"] = "Copper Pendant", ["level"] = 2, ["type"] = "armor", ["subtype"] = "pendant", ["reqlvl"] = 3, ["description"] = "",
  1025.     ["props"] = {["hp+"] = 0, ["phisdef"] = 10, ["magdef"] = 13}, ["stackable"] = false, ["cost"] = 12, ["icon"] = 16, ["ncolor"] = 1},
  1026.     {["name"] = "Bone Necklace", ["level"] = 1, ["type"] = "armor", ["subtype"] = "pendant", ["reqlvl"] = 1, ["description"] = "",
  1027.     ["props"] = {["hp+"] = 0, ["phisdef"] = 6, ["magdef"] = 9}, ["stackable"] = false, ["cost"] = 5, ["icon"] = 20, ["ncolor"] = 1},
  1028.     {["name"] = "Leather", ["type"] = "item", ["subtype"] = "none", ["description"] = "Can be used for crafting",
  1029.     ["stackable"] = true, ["maxstack"] = 99, ["cost"] = 5, ["icon"] = 21, ["ncolor"] = 1},
  1030.     {["name"] = "Leather Helmet", ["level"] = 2, ["type"] = "armor", ["subtype"] = "helmet", ["reqlvl"] = 5, ["description"] = "",
  1031.     ["props"] = {["hp+"] = 0, ["phisdef"] = 21, ["magdef"] = 1}, ["stackable"] = false, ["cost"] = 12, ["icon"] = 22, ["ncolor"] = 1},
  1032.     {["name"] = "Leather Armor", ["level"] = 2, ["type"] = "armor", ["subtype"] = "bodywear", ["reqlvl"] = 5, ["description"] = "",
  1033.     ["props"] = {["hp+"] = 0, ["phisdef"] = 25, ["magdef"] = 20}, ["stackable"] = false, ["cost"] = 12, ["icon"] = 24, ["ncolor"] = 1},
  1034.     {["name"] = "Leather Pants", ["level"] = 2, ["type"] = "armor", ["subtype"] = "pants", ["reqlvl"] = 5, ["description"] = "",
  1035.     ["props"] = {["hp+"] = 0, ["phisdef"] = 24, ["magdef"] = 19}, ["stackable"] = false, ["cost"] = 12, ["icon"] = 23, ["ncolor"] = 1},
  1036.     {["name"] = "Leather Boots", ["level"] = 2, ["type"] = "armor", ["subtype"] = "footwear", ["reqlvl"] = 5, ["description"] = "",
  1037.     ["props"] = {["hp+"] = 0, ["phisdef"] = 24, ["magdef"] = 17}, ["stackable"] = false, ["cost"] = 12, ["icon"] = 25, ["ncolor"] = 1},
  1038.     {["name"] = "Long Sword", ["level"] = 2, ["type"] = "weapon", ["subtype"] = "sword", ["reqlvl"] = 3, ["description"] = "",
  1039.     ["props"] = {["atds"] = 3, ["hp+"] = 0, ["phisat"] = 6, ["magat"] = 0}, ["stackable"] = false, ["cost"] = 1, ["icon"] = 18, ["ncolor"] = 16},
  1040.     {["name"] = "Small Health Potion", ["type"] = "potion", ["subtype"] = "health", ["reqlvl"] = 1, ["description"] = "",
  1041.     ["props"] = 1, ["stackable"] = true, ["maxstack"] = 99, ["cost"] = 1, ["icon"] = 12, ["ncolor"] = 1},
  1042.     {["name"] = "Small Mana Potion", ["type"] = "potion", ["subtype"] = "mana", ["reqlvl"] = 1, ["description"] = "",
  1043.     ["props"] = 2, ["stackable"] = true, ["maxstack"] = 99, ["cost"] = 1, ["icon"] = 13, ["ncolor"] = 1},
  1044.     {["name"] = "Medium Health Potion", ["type"] = "potion", ["subtype"] = "health", ["reqlvl"] = 5, ["description"] = "",
  1045.     ["props"] = 3, ["stackable"] = true, ["maxstack"] = 99, ["cost"] = 2, ["icon"] = 26, ["ncolor"] = 1},
  1046.     {["name"] = "Medium Mana Potion", ["type"] = "potion", ["subtype"] = "mana", ["reqlvl"] = 5, ["description"] = "",
  1047.     ["props"] = 4, ["stackable"] = true, ["maxstack"] = 99, ["cost"] = 2, ["icon"] = 27, ["ncolor"] = 1},
  1048.     {["name"] = "Large Health Potion", ["type"] = "potion", ["subtype"] = "health", ["reqlvl"] = 10, ["description"] = "",
  1049.     ["props"] = 5, ["stackable"] = true, ["maxstack"] = 99, ["cost"] = 3, ["icon"] = 28, ["ncolor"] = 1},
  1050.     {["name"] = "Large Mana Potion", ["type"] = "potion", ["subtype"] = "mana", ["reqlvl"] = 10, ["description"] = "",
  1051.     ["props"] = 6, ["stackable"] = true, ["maxstack"] = 99, ["cost"] = 3, ["icon"] = 29, ["ncolor"] = 1},
  1052.     {["name"] = "Condensed Health Potion", ["type"] = "potion", ["subtype"] = "health", ["reqlvl"] = 15, ["description"] = "",
  1053.     ["props"] = 7, ["stackable"] = true, ["maxstack"] = 99, ["cost"] = 4, ["icon"] = 30, ["ncolor"] = 1},
  1054.     {["name"] = "Condensed Mana Potion", ["type"] = "potion", ["subtype"] = "mana", ["reqlvl"] = 15, ["description"] = "",
  1055.     ["props"] = 8, ["stackable"] = true, ["maxstack"] = 99, ["cost"] = 4, ["icon"] = 31, ["ncolor"] = 1},
  1056.     {["name"] = "Log", ["type"] = "item", ["subtype"] = "none", ["description"] = "Can be used for crafting",
  1057.     ["stackable"] = true, ["maxstack"] = 99, ["cost"] = 5, ["icon"] = 32, ["ncolor"] = 1},
  1058.     {["name"] = "Tempered Iron Sword", ["level"] = 3, ["type"] = "weapon", ["subtype"] = "sword", ["reqlvl"] = 8, ["description"] = "",
  1059.     ["props"] = {["atds"] = 3, ["hp+"] = 0, ["phisat"] = 22, ["magat"] = 0}, ["stackable"] = false, ["cost"] = 20, ["icon"] = 33, ["ncolor"] = 1},
  1060.     {["name"] = "Rough Thread", ["type"] = "item", ["subtype"] = "none", ["description"] = "Can be used for crafting",
  1061.     ["stackable"] = true, ["maxstack"] = 99, ["cost"] = 3, ["icon"] = 34, ["ncolor"] = 1},
  1062.     {["name"] = "Rough Helmet", ["level"] = 3, ["type"] = "armor", ["subtype"] = "helmet", ["reqlvl"] = 8, ["description"] = "",
  1063.     ["props"] = {["hp+"] = 0, ["phisdef"] = 32, ["magdef"] = 5}, ["stackable"] = false, ["cost"] = 21, ["icon"] = 38, ["ncolor"] = 1},
  1064.     {["name"] = "Deerskin Armor", ["level"] = 3, ["type"] = "armor", ["subtype"] = "bodywear", ["reqlvl"] = 8, ["description"] = "",
  1065.     ["props"] = {["hp+"] = 0, ["phisdef"] = 38, ["magdef"] = 27}, ["stackable"] = false, ["cost"] = 21, ["icon"] = 35, ["ncolor"] = 1},
  1066.     {["name"] = "Deerskin Pants", ["level"] = 3, ["type"] = "armor", ["subtype"] = "pants", ["reqlvl"] = 8, ["description"] = "",
  1067.     ["props"] = {["hp+"] = 0, ["phisdef"] = 37, ["magdef"] = 26}, ["stackable"] = false, ["cost"] = 21, ["icon"] = 36, ["ncolor"] = 1},
  1068.     {["name"] = "Deerskin Boots", ["level"] = 3, ["type"] = "armor", ["subtype"] = "footwear", ["reqlvl"] = 8, ["description"] = "",
  1069.     ["props"] = {["hp+"] = 0, ["phisdef"] = 37, ["magdef"] = 26}, ["stackable"] = false, ["cost"] = 21, ["icon"] = 37, ["ncolor"] = 1},
  1070.     {["name"] = "Wool Thread", ["type"] = "item", ["subtype"] = "none", ["description"] = "Can be used for crafting",
  1071.     ["stackable"] = true, ["maxstack"] = 99, ["cost"] = 4, ["icon"] = 39, ["ncolor"] = 1},
  1072.     {["name"] = "Heavy Sword", ["level"] = 4, ["type"] = "weapon", ["subtype"] = "sword", ["reqlvl"] = 12, ["description"] = "",
  1073.     ["props"] = {["atds"] = 3, ["hp+"] = 0, ["phisat"] = 37, ["magat"] = 0}, ["stackable"] = false, ["cost"] = 27, ["icon"] = 40, ["ncolor"] = 1},
  1074.     {["name"] = "Bronze Helmet", ["level"] = 4, ["type"] = "armor", ["subtype"] = "helmet", ["reqlvl"] = 12, ["description"] = "",
  1075.     ["props"] = {["hp+"] = 0, ["phisdef"] = 47, ["magdef"] = 10}, ["stackable"] = false, ["cost"] = 25, ["icon"] = 41, ["ncolor"] = 1},
  1076.     {["name"] = "Ring Mail", ["level"] = 4, ["type"] = "armor", ["subtype"] = "bodywear", ["reqlvl"] = 12, ["description"] = "",
  1077.     ["props"] = {["hp+"] = 0, ["phisdef"] = 51, ["magdef"] = 44}, ["stackable"] = false, ["cost"] = 26, ["icon"] = 42, ["ncolor"] = 1},
  1078.     {["name"] = "Ring Pants", ["level"] = 4, ["type"] = "armor", ["subtype"] = "pants", ["reqlvl"] = 12, ["description"] = "",
  1079.     ["props"] = {["hp+"] = 0, ["phisdef"] = 50, ["magdef"] = 45}, ["stackable"] = false, ["cost"] = 26, ["icon"] = 43, ["ncolor"] = 1},
  1080.     {["name"] = "Ring Boots", ["level"] = 4, ["type"] = "armor", ["subtype"] = "footwear", ["reqlvl"] = 12, ["description"] = "",
  1081.     ["props"] = {["hp+"] = 0, ["phisdef"] = 48, ["magdef"] = 42}, ["stackable"] = false, ["cost"] = 26, ["icon"] = 44, ["ncolor"] = 1},
  1082.     {["name"] = "Fang Necklace", ["level"] = 3, ["type"] = "armor", ["subtype"] = "pendant", ["reqlvl"] = 7, ["description"] = "",
  1083.     ["props"] = {["hp+"] = 0, ["phisdef"] = 2, ["magdef"] = 5}, ["stackable"] = false, ["cost"] = 18, ["icon"] = 45, ["ncolor"] = 1},
  1084.     {["name"] = "White Jade Amulet", ["level"] = 4, ["type"] = "armor", ["subtype"] = "pendant", ["reqlvl"] = 11, ["description"] = "",
  1085.     ["props"] = {["hp+"] = 0, ["phisdef"] = 4, ["magdef"] = 6}, ["stackable"] = false, ["cost"] = 23, ["icon"] = 46, ["ncolor"] = 1},
  1086.     {["name"] = "Gravel", ["type"] = "item", ["subtype"] = "none", ["description"] = "Can be used for crafting",
  1087.     ["stackable"] = true, ["maxstack"] = 99, ["cost"] = 5, ["icon"] = 47, ["ncolor"] = 1}, 
  1088.     {["name"] = "Leather Helmet", ["level"] = 2, ["type"] = "armor", ["subtype"] = "helmet", ["reqlvl"] = 5, ["description"] = "",
  1089.     ["props"] = {["hp+"] = 5, ["phisdef"] = 21, ["magdef"] = 1}, ["stackable"] = false, ["cost"] = 12, ["icon"] = 22, ["ncolor"] = 2048},  
  1090.     {["name"] = "Refined Sword", ["level"] = 2, ["type"] = "weapon", ["subtype"] = "sword", ["reqlvl"] = 5, ["description"] = "Unique sword: quest reward",
  1091.     ["props"] = {["str+"] = 1, ["atds"] = 3, ["hp+"] = 0, ["phisat"] = 17, ["magat"] = 0}, ["stackable"] = false, ["cost"] = 1, ["icon"] = 19, ["ncolor"] = 2048}, 
  1092.     {["name"] = "Rough Leather Armor", ["level"] = 2, ["type"] = "armor", ["subtype"] = "bodywear", ["reqlvl"] = 6, ["description"] = "",
  1093.     ["props"] = {["sur+"] = 1, ["hp+"] = 0, ["phisdef"] = 34, ["magdef"] = 26}, ["stackable"] = false, ["cost"] = 20, ["icon"] = 24, ["ncolor"] = 2048},   
  1094.     {["name"] = "Steel Sword", ["level"] = 5, ["type"] = "weapon", ["subtype"] = "sword", ["reqlvl"] = 17, ["description"] = "",
  1095.     ["props"] = {["atds"] = 3, ["hp+"] = 0, ["phisat"] = 62, ["magat"] = 0}, ["stackable"] = false, ["cost"] = 34, ["icon"] = 48, ["ncolor"] = 1},
  1096.     {["name"] = "Nature's Blade", ["level"] = 6, ["type"] = "weapon", ["subtype"] = "sword", ["reqlvl"] = 23, ["description"] = "",
  1097.     ["props"] = {["atds"] = 3, ["hp+"] = 0, ["phisat"] = 93, ["magat"] = 0}, ["stackable"] = false, ["cost"] = 40, ["icon"] = 49, ["ncolor"] = 1},
  1098.     {["name"] = "Two handed Sword", ["level"] = 4, ["type"] = "weapon", ["subtype"] = "sword", ["reqlvl"] = 10, ["description"] = "Unique sword: quest reward",
  1099.     ["props"] = {["str+"] = 1, ["atds"] = 3, ["hp+"] = 5, ["phisat"] = 40, ["magat"] = 0}, ["stackable"] = false, ["cost"] = 27, ["icon"] = 40, ["ncolor"] = 2048},
  1100.     {["name"] = "Forceblade", ["level"] = 7, ["type"] = "weapon", ["subtype"] = "sword", ["reqlvl"] = 28, ["description"] = "",
  1101.     ["props"] = {["atds"] = 3, ["hp+"] = 0, ["phisat"] = 162, ["magat"] = 0}, ["stackable"] = false, ["cost"] = 63, ["icon"] = 50, ["ncolor"] = 1},
  1102.     {["name"] = "Soul Reaper Sword", ["level"] = 5, ["type"] = "weapon", ["subtype"] = "sword", ["reqlvl"] = 12, ["description"] = "Unique sword: quest reward",
  1103.     ["props"] = {["sur+"] = 1, ["str+"] = 1, ["atds"] = 3, ["hp+"] = 0, ["phisat"] = 97, ["magat"] = 0}, ["stackable"] = false, ["cost"] = 1, ["icon"] = 48, ["ncolor"] = 2048},   
  1104.     {["name"] = "Ring Mail", ["level"] = 4, ["type"] = "armor", ["subtype"] = "bodywear", ["reqlvl"] = 11, ["description"] = "Unique armor: quest reward",
  1105.     ["props"] = {["int+"] = 1, ["hp+"] = 15, ["phisdef"] = 67, ["magdef"] = 54}, ["stackable"] = false, ["cost"] = 1, ["icon"] = 42, ["ncolor"] = 2048},
  1106.    
  1107.     {["name"] = "Warflame Battleplate", ["level"] = 15, ["type"] = "armor", ["subtype"] = "bodywear", ["reqlvl"] = 1, ["description"] = "",
  1108.     ["props"] = {["sur+"] = 100, ["str+"] = 100, ["int+"] = 100, ["hp+"] = 58, ["phisdef"] = 763, ["magdef"] = 608}, ["stackable"] = false, ["cost"] = 1, ["icon"] = 42, ["ncolor"] = 2},
  1109. }
  1110. local cBIload = {
  1111.     {["name"] = "woodenhouse", ["image"] = imgWoodenhouse1}
  1112. }
  1113.  
  1114. local worldCDataArray = {}
  1115. local cSkillsArray = {{1,0,1},{2,0,1},{3,0,1},{4,0,1},{5,0,1},{0,0,0},{0,0,0}}
  1116. local cQuestsArray = {} -- [1] = {1(id),0(killed),false(completed)}
  1117. local cEffectsArray = {}
  1118. local cBIArray = {}
  1119.  
  1120. local inventory = {["weared"] = {["helmet"] = 0, ["bodywear"] = 0, ["pants"] = 0, ["footwear"] = 0, ["weapon"] = 15, ["pendant"] = 0},
  1121. ["bag"] = {}
  1122. }
  1123.  
  1124. for f = 1, 15 do
  1125. inventory["bag"][f] = {}
  1126. inventory["bag"][f][1] = 0
  1127. inventory["bag"][f][2] = 0
  1128. end
  1129.  
  1130. local sPouseMenu = false
  1131.  
  1132. local paused = false
  1133. local globalWXC = 1
  1134. local backgroundcPos = 1
  1135. local tbackg = paintutils.loadImage("/backgroundg.img")
  1136.  
  1137. local vOpenDialogWindow = false
  1138. local vOpenQuestsWindow = false
  1139. local vOpenInventoryWindow = false
  1140. local vOpenArmorInventoryWindow = false
  1141. local vOpenstatsWindow = false
  1142.  
  1143. local playername = "Player"
  1144. local playerTurning = "r"
  1145. local cDialog = 0
  1146. local cTarget = 0
  1147. local cmp = 0
  1148. local mmp = 0
  1149. local cxp = 0
  1150. local mxp = 0
  1151. local coins = 0
  1152. local survivability = 1
  1153. local strength = 1
  1154. local intelligence = 1
  1155.  
  1156. local vpickwait = false
  1157. local vpcingupm = 0
  1158. local vcpcingup = 0
  1159. CDataLoad[1]["name"] = playername
  1160.  
  1161. local secMsgArray = {}
  1162. local tArrayms = 0
  1163.  
  1164. secMsgArray[1] = ""
  1165.  
  1166. local function addsecm(text)
  1167. secMsgArray[#secMsgArray] = text
  1168. tArrayms = 10
  1169. end
  1170.  
  1171. local function addItem(itemid,num)
  1172. local vparInvEx = 0
  1173.  for f = 1, #inventory["bag"] do
  1174.   if inventory["bag"][f][1] == 0 and inventory["bag"][f][1] ~= itemid and not cItemsLoad[itemid]["stackable"] then
  1175.   inventory["bag"][f][1] = itemid
  1176.   inventory["bag"][f][2] = num
  1177.   break
  1178.   end
  1179.  end
  1180.  if cItemsLoad[itemid]["stackable"] and vparInvEx == 0 then
  1181.   for i = 1, #inventory["bag"] do
  1182.    if inventory["bag"][i][1] == itemid then
  1183.    inventory["bag"][i][2] = inventory["bag"][i][2] + num
  1184.    vparInvEx = 1
  1185.    break
  1186.    end
  1187.   end
  1188.   if vparInvEx == 0 then
  1189.    for i = 1, #inventory["bag"] do
  1190.     if inventory["bag"][i][1] == 0 then
  1191.     inventory["bag"][i][1] = itemid
  1192.     inventory["bag"][i][2] = num   
  1193.     break
  1194.     end
  1195.    end
  1196.   end
  1197.  end
  1198.  for f = 1, 15 do
  1199.   if inventory["bag"][f][1] ~= 0 and not cItemsLoad[inventory["bag"][f][1]]["stackable"] and inventory["bag"][f][2] > 1 then
  1200.   inventory["bag"][f][2] = 1
  1201.   end
  1202.  end
  1203. end
  1204.  
  1205. -- addItem(1,1)
  1206. --[[
  1207. addItem(#cItemsLoad,1)
  1208. addItem(9,10)
  1209. addItem(10,10)
  1210. addItem(36,10)
  1211. addItem(3,10)
  1212. addItem(34,10)
  1213. addItem(20,10)
  1214. addItem(41,10)
  1215. addItem(1,10)
  1216. addItem(49,10)
  1217. addItem(42,1)
  1218. addItem(53,1)
  1219. addItem(55,1)
  1220. ]]--
  1221.  
  1222. local function addBackgroundItem(id,x,y)
  1223. cBIArray[#cBIArray+1] = {}
  1224. cBIArray[#cBIArray]["name"] = cBIload[id]["name"]
  1225. cBIArray[#cBIArray]["image"] = cBIload[id]["image"]
  1226. cBIArray[#cBIArray]["x"] = x
  1227. cBIArray[#cBIArray]["y"] = y
  1228. end
  1229.  
  1230. addBackgroundItem(1,10,13)
  1231. addBackgroundItem(1,-61,13)
  1232.  
  1233. local function addCDataUnit(id,x,y)
  1234. worldCDataArray[#worldCDataArray+1] = {}
  1235. worldCDataArray[#worldCDataArray]["sx"] = x
  1236. worldCDataArray[#worldCDataArray]["mx"] = x
  1237. worldCDataArray[#worldCDataArray]["x"] = x
  1238. worldCDataArray[#worldCDataArray]["y"] = y
  1239. worldCDataArray[#worldCDataArray]["id"] = CDataLoad[id]["id"]
  1240. local mxnum = 0
  1241.  for f = 1, #CDataLoad[id]["image"] do
  1242.   if #CDataLoad[id]["image"][f] > mxnum then
  1243.   mxnum = #CDataLoad[id]["image"][f]
  1244.   end
  1245.  end
  1246. local imgWidth = mxnum
  1247. worldCDataArray[#worldCDataArray]["width"] = imgWidth
  1248. worldCDataArray[#worldCDataArray]["height"] = #CDataLoad[id]["image"]
  1249. worldCDataArray[#worldCDataArray]["name"] = CDataLoad[id]["name"]
  1250. worldCDataArray[#worldCDataArray]["level"] = CDataLoad[id]["level"]
  1251. worldCDataArray[#worldCDataArray]["spos"] = "r"
  1252. worldCDataArray[#worldCDataArray]["image"] = CDataLoad[id]["image"]
  1253. worldCDataArray[#worldCDataArray]["mhp"] = math.ceil((15+CDataLoad[id]["level"]*1.85)*(CDataLoad[id]["level"]*0.75))
  1254. worldCDataArray[#worldCDataArray]["mhp"] = math.ceil(12+(CDataLoad[id]["level"]-1)*(3*(CDataLoad[id]["level"]*0.75)))
  1255. worldCDataArray[#worldCDataArray]["chp"] = worldCDataArray[#worldCDataArray]["mhp"]
  1256. mxp = math.ceil(CDataLoad[id]["level"]*5+(CDataLoad[id]["level"]*21.7))
  1257. mmp = math.ceil(CDataLoad[id]["level"]*5+(CDataLoad[id]["level"]*11.46))
  1258. cmp = mmp
  1259. worldCDataArray[#worldCDataArray]["phisatck"] = math.ceil(0.35+CDataLoad[id]["level"]*0.8)
  1260. worldCDataArray[#worldCDataArray]["magatck"] = math.ceil(0.75+CDataLoad[id]["level"]*0.3)
  1261. worldCDataArray[#worldCDataArray]["phisdef"] = math.ceil(8+CDataLoad[id]["level"]*2.4)
  1262. worldCDataArray[#worldCDataArray]["magdef"] = math.ceil(6+CDataLoad[id]["level"]*1.1)
  1263. worldCDataArray[#worldCDataArray]["resptime"] = 0
  1264. worldCDataArray[#worldCDataArray]["living"] = true
  1265. worldCDataArray[#worldCDataArray]["roletype"] = CDataLoad[id]["roletype"]
  1266. worldCDataArray[#worldCDataArray]["attackdistance"] = CDataLoad[id]["atds"]
  1267. worldCDataArray[#worldCDataArray]["attplayer"] = false
  1268. worldCDataArray[#worldCDataArray]["agrtime"] = 0
  1269.  if CDataLoad[id]["roletype"] == "f" then
  1270.  worldCDataArray[#worldCDataArray]["dialog"] = CDataLoad[id]["dialog"]
  1271.  end
  1272. worldCDataArray[#worldCDataArray]["effects"] = {}
  1273.  for f = 1, 8 do
  1274.  worldCDataArray[#worldCDataArray]["effects"][f] = {}
  1275.  worldCDataArray[#worldCDataArray]["effects"][f][1] = 0
  1276.  worldCDataArray[#worldCDataArray]["effects"][f][2] = 0
  1277.  end
  1278.  if CDataLoad[id]["roletype"] == "m" then
  1279.  worldCDataArray[#worldCDataArray]["mhp"] = CDataLoad[id]["mhp"]
  1280.  worldCDataArray[#worldCDataArray]["chp"] = worldCDataArray[#worldCDataArray]["mhp"]
  1281.  end
  1282. end
  1283.  
  1284. addCDataUnit(1,1,1)
  1285. for f = 1, math.random(1,10) do
  1286. addCDataUnit(20,math.random(70,4500),2)
  1287. end
  1288. for f = 1, math.random(1,10) do
  1289. addCDataUnit(21,math.random(70,4500),3)
  1290. end
  1291. for f = 1, math.random(1,10) do
  1292. addCDataUnit(22,math.random(70,4500),2)
  1293. end
  1294. for f = 1, math.random(1,10) do
  1295. addCDataUnit(23,math.random(70,4500),2)
  1296. end
  1297. addCDataUnit(2,-10,8)
  1298. addCDataUnit(3,-19,8)
  1299. addCDataUnit(12,-31,8)
  1300. addCDataUnit(19,-42,8)
  1301. addCDataUnit(30,-50,8)
  1302. addCDataUnit(4,88,8)
  1303. addCDataUnit(4,101,8)
  1304. addCDataUnit(4,125,8)
  1305. addCDataUnit(4,168,8)
  1306. addCDataUnit(4,201,8)
  1307. addCDataUnit(4,242,8)
  1308. addCDataUnit(4,260,8)
  1309. addCDataUnit(4,291,8)
  1310. addCDataUnit(5,342,9)
  1311. addCDataUnit(5,368,9)
  1312. for f = 1, 10 do
  1313. addCDataUnit(6,391+f*34-34,7)
  1314. end
  1315. for f = 1, 4 do
  1316. addCDataUnit(7,413+f*51-51,2)
  1317. end
  1318. for f = 1, 9 do
  1319. addCDataUnit(8,714+f*28-28,6)
  1320. end
  1321. for f = 1, 4 do
  1322. addCDataUnit(9,722+f*38-38,9)
  1323. end
  1324. for f = 1, 5 do
  1325. addCDataUnit(10,951+f*36-36,4)
  1326. end
  1327. for f = 1, 6 do
  1328. addCDataUnit(11,1127+f*41-41,10)
  1329. end
  1330. for f = 1, 5 do
  1331. addCDataUnit(13,1372+f*42-42,9)
  1332. end
  1333. for f = 1, 7 do
  1334. addCDataUnit(14,1387+f*39-39,9)
  1335. end
  1336. for f = 1, 8 do
  1337. addCDataUnit(15,1660+f*35-35,8)
  1338. end
  1339. addCDataUnit(16,1957,8)
  1340. for f = 1, 9 do
  1341. addCDataUnit(17,2003+f*32-32,9)
  1342. end
  1343. for f = 1, 6 do
  1344. addCDataUnit(18,2297+f*36-36,4)
  1345. end
  1346. -- addCDataUnit(24,25,9) -- wind elemental
  1347. for f = 1, 10 do
  1348. addCDataUnit(25,2539+f*39-39,8)
  1349. end
  1350. for f = 1, 9 do
  1351. addCDataUnit(26,2929+f*41-41,8)
  1352. end
  1353. addCDataUnit(31,3298,8)
  1354. addCDataUnit(32,3306,8)
  1355.  
  1356.  
  1357. for f = 1, 10 do
  1358. addCDataUnit(27,3379+f*35-35,8)
  1359. end
  1360. for f = 1, 11 do
  1361. addCDataUnit(28,3729+f*37-37,9)
  1362. end
  1363. for f = 1, 8 do
  1364. addCDataUnit(29,4135+f*34-34,8)
  1365. end
  1366. worldCDataArray[1]["mhp"] = worldCDataArray[1]["mhp"]+math.ceil(2+worldCDataArray[1]["level"]*1.5)
  1367. worldCDataArray[1]["chp"] = worldCDataArray[1]["mhp"]
  1368.  
  1369. local vSur = 0
  1370. local vStr = 0
  1371. local vInt = 0
  1372. local vHpi = 0
  1373. local vPdm = 0
  1374. local vMdm = 0
  1375. local vPdf = 0
  1376. local vMdf = 0
  1377.  
  1378. local function playerVarRef()
  1379. vAttackDistance = 2
  1380. vSur = 0
  1381. vStr = 0
  1382. vInt = 0
  1383. vHpi = 0
  1384. vPdm = 0
  1385. vMdm = 0
  1386. vPdf = 0
  1387. vMdf = 0
  1388. worldCDataArray[1]["mhp"] = math.ceil(4+survivability*11+(worldCDataArray[1]["level"]-1)*7)
  1389. mmp = math.ceil(4+intelligence*6+(worldCDataArray[1]["level"]-1)*4)
  1390. mxp = math.ceil(28+(worldCDataArray[1]["level"]-1)*34.7)
  1391. worldCDataArray[1]["phisatck"] = math.ceil(strength*0.75+(worldCDataArray[1]["level"]-1)*0.5)
  1392. worldCDataArray[1]["magatck"] = math.ceil(intelligence*0.25+(worldCDataArray[1]["level"]-1)*0.05)
  1393. worldCDataArray[1]["phisdef"] = math.ceil(strength*2.4+(worldCDataArray[1]["level"]-1)*0.85)
  1394. worldCDataArray[1]["magdef"] = math.ceil(intelligence*1.8+(worldCDataArray[1]["level"]-1)*0.5)
  1395.  if inventory["weared"]["helmet"] ~= 0 then
  1396.   if cItemsLoad[inventory["weared"]["helmet"]]["props"]["sur+"] ~= nil then
  1397.   vSur = vSur + cItemsLoad[inventory["weared"]["helmet"]]["props"]["sur+"]
  1398.   end  
  1399.   if cItemsLoad[inventory["weared"]["helmet"]]["props"]["str+"] ~= nil then
  1400.   vStr = vStr + cItemsLoad[inventory["weared"]["helmet"]]["props"]["str+"]
  1401.   end
  1402.   if cItemsLoad[inventory["weared"]["helmet"]]["props"]["int+"] ~= nil then
  1403.   vInt = vInt + cItemsLoad[inventory["weared"]["helmet"]]["props"]["int+"]
  1404.   end  
  1405.   if cItemsLoad[inventory["weared"]["helmet"]]["props"]["hp+"] ~= nil then
  1406.   vHpi = vHpi + cItemsLoad[inventory["weared"]["helmet"]]["props"]["hp+"]
  1407.   end
  1408.  vPdf = worldCDataArray[1]["phisdef"] + cItemsLoad[inventory["weared"]["helmet"]]["props"]["phisdef"]
  1409.  vMdf = worldCDataArray[1]["magdef"] + cItemsLoad[inventory["weared"]["helmet"]]["props"]["magdef"]
  1410.  end
  1411.  if inventory["weared"]["bodywear"] ~= 0 then
  1412.   if cItemsLoad[inventory["weared"]["bodywear"]]["props"]["sur+"] ~= nil then
  1413.   vSur = vSur + cItemsLoad[inventory["weared"]["bodywear"]]["props"]["sur+"]
  1414.   end  
  1415.   if cItemsLoad[inventory["weared"]["bodywear"]]["props"]["str+"] ~= nil then
  1416.   vStr = vStr + cItemsLoad[inventory["weared"]["bodywear"]]["props"]["str+"]
  1417.   end
  1418.   if cItemsLoad[inventory["weared"]["bodywear"]]["props"]["int+"] ~= nil then
  1419.   vInt = vInt + cItemsLoad[inventory["weared"]["bodywear"]]["props"]["int+"]
  1420.   end  
  1421.   if cItemsLoad[inventory["weared"]["bodywear"]]["props"]["hp+"] ~= nil then
  1422.   vHpi = vHpi + cItemsLoad[inventory["weared"]["bodywear"]]["props"]["hp+"]
  1423.   end
  1424.  vPdf = worldCDataArray[1]["phisdef"] + cItemsLoad[inventory["weared"]["bodywear"]]["props"]["phisdef"]
  1425.  vMdf = worldCDataArray[1]["magdef"] + cItemsLoad[inventory["weared"]["bodywear"]]["props"]["magdef"]
  1426.  end
  1427.  if inventory["weared"]["pants"] ~= 0 then
  1428.   if cItemsLoad[inventory["weared"]["pants"]]["props"]["sur+"] ~= nil then
  1429.   vSur = vSur + cItemsLoad[inventory["weared"]["pants"]]["props"]["sur+"]
  1430.   end  
  1431.   if cItemsLoad[inventory["weared"]["pants"]]["props"]["str+"] ~= nil then
  1432.   vStr = vStr + cItemsLoad[inventory["weared"]["pants"]]["props"]["str+"]
  1433.   end
  1434.   if cItemsLoad[inventory["weared"]["pants"]]["props"]["int+"] ~= nil then
  1435.   vInt = vInt + cItemsLoad[inventory["weared"]["pants"]]["props"]["int+"]
  1436.   end  
  1437.   if cItemsLoad[inventory["weared"]["pants"]]["props"]["hp+"] ~= nil then
  1438.   vHpi = vHpi + cItemsLoad[inventory["weared"]["pants"]]["props"]["hp+"]
  1439.   end
  1440.  vPdf = worldCDataArray[1]["phisdef"] + cItemsLoad[inventory["weared"]["pants"]]["props"]["phisdef"]
  1441.  vMdf = worldCDataArray[1]["magdef"] + cItemsLoad[inventory["weared"]["pants"]]["props"]["magdef"]  
  1442.  end
  1443.  if inventory["weared"]["footwear"] ~= 0 then
  1444.   if cItemsLoad[inventory["weared"]["footwear"]]["props"]["sur+"] ~= nil then
  1445.   vSur = vSur + cItemsLoad[inventory["weared"]["footwear"]]["props"]["sur+"]
  1446.   end  
  1447.   if cItemsLoad[inventory["weared"]["footwear"]]["props"]["str+"] ~= nil then
  1448.   vStr = vStr + cItemsLoad[inventory["weared"]["footwear"]]["props"]["str+"]
  1449.   end
  1450.   if cItemsLoad[inventory["weared"]["footwear"]]["props"]["int+"] ~= nil then
  1451.   vInt = vInt + cItemsLoad[inventory["weared"]["footwear"]]["props"]["int+"]
  1452.   end  
  1453.   if cItemsLoad[inventory["weared"]["footwear"]]["props"]["hp+"] ~= nil then
  1454.   vHpi = vHpi + cItemsLoad[inventory["weared"]["footwear"]]["props"]["hp+"]
  1455.   end  
  1456.  vPdf = worldCDataArray[1]["phisdef"] + cItemsLoad[inventory["weared"]["footwear"]]["props"]["phisdef"]
  1457.  vMdf = worldCDataArray[1]["magdef"] + cItemsLoad[inventory["weared"]["footwear"]]["props"]["magdef"]
  1458.  end
  1459.  if inventory["weared"]["pendant"] ~= 0 then
  1460.   if cItemsLoad[inventory["weared"]["pendant"]]["props"]["sur+"] ~= nil then
  1461.   vSur = vSur + cItemsLoad[inventory["weared"]["pendant"]]["props"]["sur+"]
  1462.   end  
  1463.   if cItemsLoad[inventory["weared"]["pendant"]]["props"]["str+"] ~= nil then
  1464.   vStr = vStr + cItemsLoad[inventory["weared"]["pendant"]]["props"]["str+"]
  1465.   end
  1466.   if cItemsLoad[inventory["weared"]["pendant"]]["props"]["int+"] ~= nil then
  1467.   vInt = vInt + cItemsLoad[inventory["weared"]["pendant"]]["props"]["int+"]
  1468.   end  
  1469.   if cItemsLoad[inventory["weared"]["pendant"]]["props"]["hp+"] ~= nil then
  1470.   vHpi = vHpi + cItemsLoad[inventory["weared"]["pendant"]]["props"]["hp+"]
  1471.   end  
  1472.  vPdf = worldCDataArray[1]["phisdef"] + cItemsLoad[inventory["weared"]["pendant"]]["props"]["phisdef"]
  1473.  vMdf = worldCDataArray[1]["magdef"] + cItemsLoad[inventory["weared"]["pendant"]]["props"]["magdef"]
  1474.  end
  1475.  if inventory["weared"]["weapon"] ~= 0 then
  1476.   if cItemsLoad[inventory["weared"]["weapon"]]["props"]["sur+"] ~= nil then
  1477.   vSur = vSur + cItemsLoad[inventory["weared"]["weapon"]]["props"]["sur+"]
  1478.   end  
  1479.   if cItemsLoad[inventory["weared"]["weapon"]]["props"]["str+"] ~= nil then
  1480.   vStr = vStr + cItemsLoad[inventory["weared"]["weapon"]]["props"]["str+"]
  1481.   end
  1482.   if cItemsLoad[inventory["weared"]["weapon"]]["props"]["int+"] ~= nil then
  1483.   vInt = vInt + cItemsLoad[inventory["weared"]["weapon"]]["props"]["int+"]
  1484.   end  
  1485.   if cItemsLoad[inventory["weared"]["weapon"]]["props"]["hp+"] ~= nil then
  1486.   vHpi = vHpi + cItemsLoad[inventory["weared"]["weapon"]]["props"]["hp+"]
  1487.   end  
  1488.  vPdm = worldCDataArray[1]["phisatck"] + cItemsLoad[inventory["weared"]["weapon"]]["props"]["phisat"]+(cItemsLoad[inventory["weared"]["weapon"]]["props"]["phisat"]/100*worldCDataArray[1]["level"])
  1489.  vMdm = worldCDataArray[1]["magatck"] + cItemsLoad[inventory["weared"]["weapon"]]["props"]["magat"]+(cItemsLoad[inventory["weared"]["weapon"]]["props"]["magat"]/100*worldCDataArray[1]["level"])
  1490.  vAttackDistance = cItemsLoad[inventory["weared"]["weapon"]]["props"]["atds"]
  1491.  end
  1492. worldCDataArray[1]["mhp"] = math.ceil(4+(survivability+vSur)*11+(worldCDataArray[1]["level"]-1)*7)+vHpi
  1493. mmp = math.ceil(4+(intelligence+vInt)*6+(worldCDataArray[1]["level"]-1)*4)
  1494. worldCDataArray[1]["phisatck"] = math.floor(1+(strength+vStr-1)*0.9+(worldCDataArray[1]["level"]-1)*0.0025)+vPdm
  1495. worldCDataArray[1]["magatck"] = math.floor(1+(intelligence+vInt-1)*0.25+(worldCDataArray[1]["level"]-1)*0.00015)+vMdm
  1496. worldCDataArray[1]["phisdef"] = math.ceil(5+(strength+vStr-1)*29.4+(worldCDataArray[1]["level"]-1)*4.85)+vPdf
  1497. worldCDataArray[1]["magdef"] = math.ceil(5+(intelligence+vInt-1)*22.8+(worldCDataArray[1]["level"]-1)*1.5)+vMdf
  1498. end
  1499.  
  1500. playerVarRef()
  1501.  
  1502. local function getDistance(from,x)
  1503. local dist = 0
  1504. local x1, x2 = worldCDataArray[from]["x"], x
  1505. if x1 < x2 then dist = x2-x1
  1506. elseif x1 > x2 then dist = x1-x2
  1507. else dist = 0
  1508. end
  1509. return dist
  1510. end
  1511.  
  1512. local function getDistanceToId(from,to)
  1513. local dist = 0
  1514. local x1, x2 = worldCDataArray[from]["x"], worldCDataArray[to]["x"]
  1515. if x1 < x2 then dist = x2-x1-worldCDataArray[from]["width"]
  1516. elseif x1 > x2+worldCDataArray[to]["width"] then dist = x1-x2-worldCDataArray[to]["width"]
  1517. else dist = 0
  1518. end
  1519. return dist
  1520. end
  1521.  
  1522. local function movetoward(id, x, distanceLimit)
  1523.  if getDistance(id,x) < distanceLimit and x < worldCDataArray[id]["x"] then
  1524.  worldCDataArray[id]["x"] = worldCDataArray[id]["x"] - 1
  1525.  worldCDataArray[id]["spos"] = "l"
  1526.  elseif getDistance(id,x) < distanceLimit and x > worldCDataArray[id]["x"] then
  1527.  worldCDataArray[id]["x"] = worldCDataArray[id]["x"] + 1
  1528.  worldCDataArray[id]["spos"] = "r"
  1529.  end
  1530. end
  1531.  
  1532. local function pbar(buffer,x,y,size,percent,color1,color2, ... )
  1533. if arg[3] == "rev" then percent = 100 - percent end
  1534. local fill = {}
  1535.  for f = 1, size do
  1536.  table.insert(fill,1)
  1537.  end
  1538.  for f = 1, size do
  1539.   if 100/size*f <= percent then
  1540.   fill[size-f+1] = 0
  1541.   end
  1542.  end
  1543. local color0 = 1
  1544.  for f = 1, size do
  1545.   if fill[f] == 1 then color0 = color1
  1546.   else color0 = color2
  1547.   end
  1548.  graphics.drawPixel(buffer,x+f-1,y,color0)
  1549.  graphics.dText(buffer,arg[1],x,y,arg[2])
  1550.  end
  1551. end
  1552.  
  1553. local function drawcBIArray()
  1554.  for f = 1, #cBIArray do
  1555.  graphics.addImage(buffer1,cBIArray[f]["image"],cBIArray[f]["x"]+20-globalWXC,19-cBIArray[f]["y"])
  1556.  end
  1557. end
  1558.  
  1559. local function drawCDataUnit()
  1560.  for f = 2, #worldCDataArray do
  1561.   if worldCDataArray[f]["living"] then
  1562.    if worldCDataArray[f]["spos"] == "r" then
  1563.    graphics.addImage(buffer1,worldCDataArray[f]["image"],worldCDataArray[f]["x"]+20-globalWXC,19-worldCDataArray[f]["y"])
  1564.    elseif worldCDataArray[f]["spos"] == "l" then
  1565.    graphics.addMImage(buffer1,worldCDataArray[f]["image"],worldCDataArray[f]["x"]+20-globalWXC,19-worldCDataArray[f]["y"])
  1566.    end
  1567.    if ( worldCDataArray[f]["roletype"] == "e" or worldCDataArray[f]["roletype"] == "p" or worldCDataArray[f]["roletype"] == "m" ) and cTarget ~= 0 and cTarget == f then
  1568.    pbar(buffer1,worldCDataArray[f]["x"]+20-globalWXC, 19-worldCDataArray[f]["y"]-2,4,math.ceil(worldCDataArray[f]["chp"])*100/worldCDataArray[f]["mhp"],colors.red,colors.gray,tostring(math.ceil(worldCDataArray[f]["chp"])).." ",1,"rev")
  1569.    elseif worldCDataArray[f]["roletype"] == "f" then
  1570.    graphics.dText(buffer1,"NPC",worldCDataArray[f]["x"]+20-globalWXC,19-worldCDataArray[f]["y"]-2,1)
  1571.    elseif worldCDataArray[f]["roletype"] == "r" and cTarget ~= 0 and cTarget == f and vpickwait then
  1572.    local vpercentr = math.ceil(vcpcingup*100/vpcingupm)
  1573.    pbar(buffer1,worldCDataArray[f]["x"]+20-globalWXC, 19-worldCDataArray[f]["y"]-2,4,vpercentr,colors.green,colors.gray,vpercentr.."% ",1,"rev")
  1574.    end
  1575.   end
  1576.  end
  1577. end
  1578.  
  1579. local drsmArray = {}
  1580. local ftArrayms = 0
  1581.  
  1582. local function addSMessage(text)
  1583. ftArrayms = 10
  1584.  if type(text) == "string" then
  1585.  table.insert(drsmArray,string.sub(text,1,25))
  1586.  end
  1587. end
  1588.  
  1589. addSMessage("Press E to talk")
  1590.  
  1591. local function addQuest(id)
  1592. cQuestsArray[#cQuestsArray+1] = {}
  1593. cQuestsArray[#cQuestsArray][1] = id
  1594. cQuestsArray[#cQuestsArray][2] = 0
  1595. cQuestsArray[#cQuestsArray][3] = false
  1596. addSMessage("New quest: "..CQuestsLoad[id]["name"])
  1597. end
  1598.  
  1599. local function getXP(xp)
  1600.  if mxp-cxp >= xp then
  1601.  cxp = cxp + xp
  1602.  else
  1603.  xp = xp - (mxp - cxp)
  1604.  worldCDataArray[1]["level"] = worldCDataArray[1]["level"] + 1
  1605.  cxp = xp
  1606.  playerVarRef()
  1607.  worldCDataArray[1]["chp"] = worldCDataArray[1]["mhp"]
  1608.  cmp = mmp
  1609.  end
  1610. end
  1611.  
  1612. local function takeOffItem(subtype)
  1613. addItem(inventory["weared"][subtype],1)
  1614. inventory["weared"][subtype] = 0
  1615. playerVarRef()
  1616. end
  1617.  
  1618. local function addEffect(target,effect)
  1619. local tvar1 = 0
  1620.  for t = 1, #worldCDataArray[target]["effects"] do
  1621.   if worldCDataArray[target]["effects"][t][1] == effect then
  1622.   worldCDataArray[target]["effects"][t][1] = effect
  1623.   worldCDataArray[target]["effects"][t][2] = worldCDataArray[target]["effects"][t][2] + cEffectsLoad[effect]["duration"]
  1624.   tvar1 = 1
  1625.   break
  1626.   end  
  1627.  end
  1628.  for t = 1, #worldCDataArray[target]["effects"] do
  1629.   if worldCDataArray[target]["effects"][t][1] == 0 and tvar1 == 0 then
  1630.   worldCDataArray[target]["effects"][t][1] = effect
  1631.   worldCDataArray[target]["effects"][t][2] = cEffectsLoad[effect]["duration"]
  1632.   break
  1633.   end
  1634.  end
  1635. end
  1636.  
  1637. local function target(x,y)
  1638. if not vpickwait then cTarget = 0 end
  1639.  for f = 1, #worldCDataArray do
  1640.   if not vOpenDialogWindow and clicked(x, y, worldCDataArray[f]["x"]+20-globalWXC, 19-worldCDataArray[f]["y"]-2, worldCDataArray[f]["x"]+20-globalWXC+worldCDataArray[f]["width"], 19-worldCDataArray[f]["y"]+worldCDataArray[f]["height"]) then
  1641.   if worldCDataArray[f]["living"] then cTarget = f end
  1642.   end
  1643.  end
  1644.  if not vOpenDialogWindow and clicked(x,y,1,1,10,4) then
  1645.  cTarget = 1
  1646.  end
  1647. end
  1648.  
  1649. local function createNewItem(basID)
  1650. cItemsLoad[#cItemsLoad+1] = {}
  1651. cItemsLoad[#cItemsLoad]["name"] = cItemsLoad[basID]["name"]
  1652. cItemsLoad[#cItemsLoad]["level"] = cItemsLoad[basID]["level"]
  1653. cItemsLoad[#cItemsLoad]["type"] = cItemsLoad[basID]["type"]
  1654. cItemsLoad[#cItemsLoad]["subtype"] = cItemsLoad[basID]["subtype"]
  1655. cItemsLoad[#cItemsLoad]["reqlvl"] = cItemsLoad[basID]["reqlvl"]
  1656. cItemsLoad[#cItemsLoad]["description"] = cItemsLoad[basID]["description"]
  1657. cItemsLoad[#cItemsLoad]["ncolor"] = cItemsLoad[basID]["ncolor"]
  1658.  cItemsLoad[#cItemsLoad]["props"] = {}
  1659.  if math.random(1,4) == 1 then
  1660.  cItemsLoad[#cItemsLoad]["props"]["sur+"] = math.max(math.random(cItemsLoad[basID]["level"]-cItemsLoad[basID]["level"]/2,cItemsLoad[basID]["level"]+cItemsLoad[basID]["level"]/2)-1,0)
  1661.  else
  1662.  cItemsLoad[#cItemsLoad]["props"]["sur+"] = nil
  1663.  end
  1664.  if math.random(1,4) == 1 then
  1665.  cItemsLoad[#cItemsLoad]["props"]["str+"] = math.max(math.random(cItemsLoad[basID]["level"]-cItemsLoad[basID]["level"]/2,cItemsLoad[basID]["level"]+cItemsLoad[basID]["level"]/2)-1,0)
  1666.  else
  1667.  cItemsLoad[#cItemsLoad]["props"]["str+"] = nil
  1668.  end
  1669.  if math.random(1,4) == 1 then
  1670.  cItemsLoad[#cItemsLoad]["props"]["int+"] = math.max(math.random(cItemsLoad[basID]["level"]-cItemsLoad[basID]["level"]/2,cItemsLoad[basID]["level"]+cItemsLoad[basID]["level"]/2)-1,0)
  1671.  else
  1672.  cItemsLoad[#cItemsLoad]["props"]["int+"] = nil
  1673.  end
  1674.  if math.random(1,4) == 1 then
  1675.  cItemsLoad[#cItemsLoad]["props"]["hp+"] = math.max(math.random(-cItemsLoad[basID]["level"],cItemsLoad[basID]["level"]^2),0)
  1676.  else
  1677.  cItemsLoad[#cItemsLoad]["props"]["hp+"] = 0
  1678.  end
  1679.  if cItemsLoad[basID]["type"] == "armor" then
  1680.  cItemsLoad[#cItemsLoad]["props"]["phisdef"] = cItemsLoad[basID]["props"]["phisdef"]
  1681.  cItemsLoad[#cItemsLoad]["props"]["magdef"] = cItemsLoad[basID]["props"]["magdef"]
  1682.  end
  1683.  if cItemsLoad[basID]["type"] == "weapon" then
  1684.  cItemsLoad[#cItemsLoad]["props"]["phisat"] = cItemsLoad[basID]["props"]["phisat"]
  1685.  cItemsLoad[#cItemsLoad]["props"]["magat"] = cItemsLoad[basID]["props"]["magat"]
  1686.  end
  1687. cItemsLoad[#cItemsLoad]["stackable"] = cItemsLoad[basID]["stackable"]
  1688. cItemsLoad[#cItemsLoad]["cost"] = cItemsLoad[basID]["cost"]
  1689. cItemsLoad[#cItemsLoad]["icon"] = cItemsLoad[basID]["icon"]
  1690. return #cItemsLoad
  1691. end
  1692.  
  1693. local function dPlayerInfow(buffer,x,y) -- gui
  1694. graphics.drawBox(buffer, x, y, 10, 4, 256)
  1695. graphics.dText(buffer,playername:sub(1,10).."["..worldCDataArray[1]["level"].."]",x,y,1)
  1696. local percent1 = math.ceil(worldCDataArray[1]["chp"]*100/worldCDataArray[1]["mhp"])
  1697. local percent2 = math.ceil(cmp*100/mmp)
  1698. local percent3 = math.ceil(cxp*100/mxp)
  1699. pbar(buffer,x,y+1,10,percent1,16384,128,math.ceil(worldCDataArray[1]["chp"]).."/"..math.ceil(worldCDataArray[1]["mhp"]).." ",1,"rev")
  1700. pbar(buffer,x,y+2,10,percent2,2048,128,math.ceil(cmp).."/"..math.ceil(mmp).." ",1,"rev")
  1701. pbar(buffer,x,y+3,10,percent3,16,128,math.ceil(cxp*100/mxp).."% ",1,"rev")
  1702.  for f = 1, 4 do
  1703.   if worldCDataArray[1]["effects"][f][1] ~= 0 then
  1704.   graphics.drawPixel(buffer,x+3*f-3,5,cEffectsLoad[worldCDataArray[1]["effects"][f][1]]["icon"][1][1])
  1705.   graphics.dText(buffer,cEffectsLoad[worldCDataArray[1]["effects"][f][1]]["icon"][1][2],x+3*f-3,5,1)
  1706.   graphics.drawPixel(buffer,x+3*f-2,5,cEffectsLoad[worldCDataArray[1]["effects"][f][1]]["icon"][2][1])
  1707.   graphics.dText(buffer,cEffectsLoad[worldCDataArray[1]["effects"][f][1]]["icon"][2][2],x+3*f-2,5,1)
  1708.   end
  1709.  end
  1710.  for f = 5, 8 do
  1711.   if worldCDataArray[1]["effects"][f][1] ~= 0 then
  1712.   graphics.drawPixel(buffer,x+3*f-3,6,cEffectsLoad[worldCDataArray[1]["effects"][f][1]]["icon"][1][1])
  1713.   graphics.dText(buffer,cEffectsLoad[worldCDataArray[1]["effects"][f][1]]["icon"][1][2],x+3*f-3,6,1)
  1714.   graphics.drawPixel(buffer,x+3*f-2,6,cEffectsLoad[worldCDataArray[1]["effects"][f][1]]["icon"][2][1])
  1715.   graphics.dText(buffer,cEffectsLoad[worldCDataArray[1]["effects"][f][1]]["icon"][2][2],x+3*f-2,6,1)
  1716.   end
  1717.  end
  1718. end
  1719.  
  1720. local function dSkillw(buffer,x,y) -- gui
  1721. graphics.drawBox(buffer, x, y, 16, 3, 256)
  1722. local fcol = {4096,2048,8192,1024,16384}
  1723. local fstr = {"/2","*3","@4","&5","!6"}
  1724.  for f = 1, 5 do
  1725.  graphics.drawPixel(buffer,x-1+f*3,y+1,fcol[f])
  1726.  graphics.drawPixel(buffer,x+f*3-2,y+1,fcol[f])
  1727.  graphics.dText(buffer,fstr[f],x-2+f*3,y+1,1)
  1728.  graphics.dText(buffer,cSkillsArray[f+1][2],x-2+f*3,y+2,1)
  1729.  end
  1730. end
  1731.  
  1732. local function dWCDaw(buffer,x,y) -- gui
  1733. graphics.drawBox(buffer, x, y, 12, 3, 256)
  1734. local nx = x + (math.max(math.floor((12 / 2) - (#worldCDataArray[cTarget]["name"] / 2)), 0))
  1735. graphics.dText(buffer,string.sub(worldCDataArray[cTarget]["name"],1,15),nx,y,1)
  1736.  if worldCDataArray[cTarget]["roletype"] == "e" or worldCDataArray[cTarget]["roletype"] == "p" or worldCDataArray[cTarget]["roletype"] == "m" then
  1737.  pbar(buffer,x,y+1,12,math.ceil(worldCDataArray[cTarget]["chp"])*100/worldCDataArray[cTarget]["mhp"],16384,128,math.ceil(worldCDataArray[cTarget]["chp"]).."/"..worldCDataArray[cTarget]["mhp"].." ",1,"rev")
  1738.  graphics.dText(buffer,"["..worldCDataArray[cTarget]["level"].."]",x+12-2-#tostring(worldCDataArray[cTarget]["level"]),y+1,1)
  1739.  elseif worldCDataArray[cTarget]["roletype"] == "f" then
  1740.  graphics.dText(buffer,"NPC",x+4,y+1,16)
  1741.  elseif worldCDataArray[cTarget]["roletype"] == "r" then
  1742.  graphics.dText(buffer,"Press E to",x+1,y+1,16)
  1743.  graphics.dText(buffer,"pick up",x+2,y+2,16)
  1744.  end
  1745.  for f = 1, 4 do
  1746.   if worldCDataArray[cTarget]["effects"][f][1] ~= 0 then
  1747.   graphics.drawPixel(buffer,x+3*f-3,4,cEffectsLoad[worldCDataArray[cTarget]["effects"][f][1]]["icon"][1][1])
  1748.   graphics.dText(buffer,cEffectsLoad[worldCDataArray[cTarget]["effects"][f][1]]["icon"][1][2],x+3*f-3,4,1)
  1749.   graphics.drawPixel(buffer,x+3*f-2,4,cEffectsLoad[worldCDataArray[cTarget]["effects"][f][1]]["icon"][2][1])
  1750.   graphics.dText(buffer,cEffectsLoad[worldCDataArray[cTarget]["effects"][f][1]]["icon"][2][2],x+3*f-2,4,1)
  1751.   end
  1752.  end
  1753.  for f = 5, 8 do
  1754.   if worldCDataArray[1]["effects"][f][1] ~= 0 then
  1755.   graphics.drawPixel(buffer,x+3*f-3,5,cEffectsLoad[worldCDataArray[cTarget]["effects"][f][1]]["icon"][1][1])
  1756.   graphics.dText(buffer,cEffectsLoad[worldCDataArray[cTarget]["effects"][f][1]]["icon"][1][2],x+3*f-3,5,1)
  1757.   graphics.drawPixel(buffer,x+3*f-2,5,cEffectsLoad[worldCDataArray[cTarget]["effects"][f][1]]["icon"][2][1])
  1758.   graphics.dText(buffer,cEffectsLoad[worldCDataArray[cTarget]["effects"][f][1]]["icon"][2][2],x+3*f-2,5,1)
  1759.   end
  1760.  end
  1761. end
  1762.  
  1763. local tcolor1 = 1
  1764.  
  1765. local function openDialogWindow(buffer,id,x,y)
  1766. graphics.drawBox(buffer, x+1, y+1, 16, 10, 128)
  1767. graphics.drawBox(buffer, x, y, 16, 10, 256)
  1768. local nx = x + (math.max(math.floor((16 / 2) - (#worldCDataArray[id]["name"] / 2)), 0))
  1769. graphics.dText(buffer,string.sub(worldCDataArray[id]["name"],1,15),nx,y,1)
  1770.  for f = 1, 9 - #cDialog do
  1771.  graphics.dText(buffer,string.sub(cDialog[1]["text"],1+15*f-15,1+15*f-1),x,y+f,1)
  1772.  end
  1773.  for f = 1, #cDialog-1 do
  1774.   if cDialog[#cDialog-f+1] ~= nil then
  1775.    if cDialog[#cDialog-f+1]["action"] == "getquest" then
  1776.     if CQuestsLoad[cDialog[#cDialog-f+1]["do"]]["comp"] == true then
  1777.     table.remove(cDialog,#cDialog-f+1)
  1778.     end
  1779.    end
  1780.   end  
  1781.  end
  1782.  graphics.drawLine(buffer, x, y+10 - #cDialog, x+16, y+10 - #cDialog, 128)
  1783.  for n = 1, #cDialog-1 do
  1784.   tcolor1 = 1
  1785.   if cDialog[n+1]["action"] == "getquest" then
  1786.   if CQuestsLoad[cDialog[n+1]["do"]]["comp"] ~= 0 then tcolor1 = 128 end
  1787.   end
  1788.   if cDialog[n+1] ~= nil then
  1789.    if cDialog[n+1]["action"] == "getquest" then
  1790.     if CQuestsLoad[cDialog[n+1]["do"]]["minlvl"] > worldCDataArray[1]["level"] or CQuestsLoad[cDialog[n+1]["do"]]["maxlvl"] < worldCDataArray[1]["level"] or CQuestsLoad[cDialog[n+1]["do"]]["comp"] == true then
  1791.     tcolor1 = colors.red
  1792.     end
  1793.    end
  1794.   end
  1795.  graphics.dText(buffer,string.sub(cDialog[n+1]["text"],1,16),x,y+10 - #cDialog+n,tcolor1)
  1796.  end
  1797. end
  1798.  
  1799. local ctargquest = 0
  1800.  
  1801. local function openQuestsWindow(buffer,x,y)
  1802. graphics.drawBox(buffer,x+1,y+1,35,12,128)
  1803. graphics.drawBox(buffer,x,y,35,12,256)
  1804. graphics.drawLine(buffer, x, y, x+35, y, 128)
  1805. graphics.drawLine(buffer, x+15, y, x+15, y+12, 128)
  1806. graphics.dText(buffer,"X",x+35,y,1)
  1807. graphics.dText(buffer,"Quests",x+(math.max(math.floor((35 / 2)-(6 / 2)), 0)),y,1)
  1808.  if #cQuestsArray ~= 0 then
  1809.   for f = 1, #cQuestsArray do
  1810.   graphics.dText(buffer,">"..string.sub(CQuestsLoad[cQuestsArray[f][1]]["name"],1,14),x,y+f,1)
  1811.   end
  1812.  end
  1813.  if ctargquest ~= 0 then
  1814.  graphics.dText(buffer,string.sub(CQuestsLoad[cQuestsArray[ctargquest][1]]["name"],1,19),x+16,y+1,1)
  1815.  graphics.dText(buffer,"To kill:",x+16,y+2,1)
  1816.  graphics.dText(buffer,CDataLoad[CQuestsLoad[cQuestsArray[ctargquest][1]]["targ"]]["name"].."("..cQuestsArray[ctargquest][2].."/"..CQuestsLoad[cQuestsArray[ctargquest][1]]["num"]..")",x+16,y+3,1)
  1817.  graphics.dText(buffer,"Reward",x+16,y+5,1)
  1818.  graphics.dText(buffer,"Coins: "..CQuestsLoad[cQuestsArray[ctargquest][1]]["qreward"]["coins"]..", XP: "..CQuestsLoad[cQuestsArray[ctargquest][1]]["qreward"]["xp"],x+16,y+6,1)
  1819.  if CQuestsLoad[cQuestsArray[ctargquest][1]]["qreward"]["item"][1] ~= 0 then
  1820.  graphics.dText(buffer,"item:",x+16,y+7,1)
  1821.  graphics.dText(buffer,string.sub(cItemsLoad[CQuestsLoad[cQuestsArray[ctargquest][1]]["qreward"]["item"][1]]["name"],1,15).."("..CQuestsLoad[cQuestsArray[ctargquest][1]]["qreward"]["item"][2]..")",x+16,y+8,1)
  1822.  end
  1823.  end
  1824. end
  1825.  
  1826. local ctargetitem = 0
  1827.  
  1828. local function openInventoryWindow(buffer,x,y)
  1829. graphics.drawBox(buffer,x,y,51,19,256)
  1830. graphics.drawLine(buffer, x, y, x+51, y, 128)
  1831. graphics.dText(buffer,"X",x+50,y,1)
  1832.  for f = 1, 5 do
  1833.  graphics.drawLine(buffer, x, y+f*6-6, x+40, y+f*6-6, 128)
  1834.  end
  1835.  for f = 1, 6 do
  1836.  graphics.drawLine(buffer, x+f*8-8, y+1, x+f*8-8, y+18, 128)
  1837.  end
  1838. local cy = 1
  1839.  for f = 1, #inventory["bag"] do
  1840.  local h = f
  1841.   if f < 6 then cy = y+1
  1842.   elseif f > 5 and f < 11 then cy = y+7 h = f - 5
  1843.   elseif f > 10 then cy = y+13 h = f - 10 end
  1844.    if inventory["bag"][f][1] ~= 0 then
  1845.    graphics.addImage(buffer,itemimg[cItemsLoad[inventory["bag"][f][1]]["icon"]],1+x+h*8-8,cy)
  1846.    if inventory["bag"][f][2] > 1 then graphics.dText(buffer,inventory["bag"][f][2],1+x+h*8-2-6,cy+4,1) end
  1847.    end
  1848.   end
  1849. local tinfoarray = {}
  1850. local tcolorarray = {}
  1851.  local function atrfunc(s,c)
  1852.  table.insert(tinfoarray,s)
  1853.  table.insert(tcolorarray,c)
  1854.  end
  1855.  
  1856.  if ctargetitem ~= 0 then
  1857.  local vLoadnamecolor = cItemsLoad[inventory["bag"][ctargetitem][1]]["ncolor"]
  1858.  atrfunc(string.sub(cItemsLoad[inventory["bag"][ctargetitem][1]]["name"],1,10),vLoadnamecolor)
  1859.   if #cItemsLoad[inventory["bag"][ctargetitem][1]]["name"] > 10 then
  1860.   atrfunc(string.sub(cItemsLoad[inventory["bag"][ctargetitem][1]]["name"],11,20),vLoadnamecolor)
  1861.   end
  1862.   if cItemsLoad[inventory["bag"][ctargetitem][1]]["type"] == "armor" or cItemsLoad[inventory["bag"][ctargetitem][1]]["type"] == "weapon" then
  1863.   local dsubtype = cItemsLoad[inventory["bag"][ctargetitem][1]]["subtype"]
  1864.   atrfunc(string.upper(string.sub(dsubtype,1,1))..string.sub(dsubtype,2,10),128)  
  1865.   end
  1866.   if cItemsLoad[inventory["bag"][ctargetitem][1]]["level"] ~= nil then
  1867.   atrfunc("Level "..cItemsLoad[inventory["bag"][ctargetitem][1]]["level"],1)
  1868.   end  
  1869.   if cItemsLoad[inventory["bag"][ctargetitem][1]]["type"] == "armor" or cItemsLoad[inventory["bag"][ctargetitem][1]]["type"] == "weapon" or cItemsLoad[inventory["bag"][ctargetitem][1]]["type"] == "potion" then
  1870.    if cItemsLoad[inventory["bag"][ctargetitem][1]]["reqlvl"] > worldCDataArray[1]["level"] then
  1871.    atrfunc("Level Requ",16384)
  1872.    atrfunc("ired: "..cItemsLoad[inventory["bag"][ctargetitem][1]]["reqlvl"],16384)
  1873.    end
  1874.   end
  1875.   if cItemsLoad[inventory["bag"][ctargetitem][1]]["type"] == "item" then
  1876.    if cItemsLoad[inventory["bag"][ctargetitem][1]]["level"] ~= nil then
  1877.    atrfunc("Level "..cItemsLoad[inventory["bag"][ctargetitem][1]]["level"],1)
  1878.    end
  1879.   elseif cItemsLoad[inventory["bag"][ctargetitem][1]]["type"] == "armor" then
  1880.    if cItemsLoad[inventory["bag"][ctargetitem][1]]["props"]["phisdef"] ~= nil and cItemsLoad[inventory["bag"][ctargetitem][1]]["props"]["phisdef"] ~= 0 then
  1881.    atrfunc("PDef: +"..cItemsLoad[inventory["bag"][ctargetitem][1]]["props"]["phisdef"],16)
  1882.    end
  1883.    if cItemsLoad[inventory["bag"][ctargetitem][1]]["props"]["magdef"] ~= nil and cItemsLoad[inventory["bag"][ctargetitem][1]]["props"]["magdef"] ~= 0 then
  1884.    atrfunc("MDef: +"..cItemsLoad[inventory["bag"][ctargetitem][1]]["props"]["magdef"],16)  
  1885.    end
  1886.   end
  1887.   -- ["sur+"] = 100, ["str+"] = 100, ["int+"] = 100, ["hp+"] = 58
  1888.   if cItemsLoad[inventory["bag"][ctargetitem][1]]["type"] == "weapon" then
  1889.    if cItemsLoad[inventory["bag"][ctargetitem][1]]["props"]["phisat"] ~= 0 then
  1890.    atrfunc("PAttack:",16)
  1891.    atrfunc("+"..cItemsLoad[inventory["bag"][ctargetitem][1]]["props"]["phisat"],16)
  1892.    end
  1893.    if cItemsLoad[inventory["bag"][ctargetitem][1]]["props"]["magat"] ~= 0 then
  1894.    atrfunc("MAttack:",16)
  1895.    atrfunc("+"..cItemsLoad[inventory["bag"][ctargetitem][1]]["props"]["magat"],16)
  1896.    end
  1897.   elseif cItemsLoad[inventory["bag"][ctargetitem][1]]["type"] == "potion" then
  1898.   atrfunc("Restore ",1)
  1899.   atrfunc(cEffectsLoad[cItemsLoad[inventory["bag"][ctargetitem][1]]["props"]]["value"],1)
  1900.   end
  1901.   if cItemsLoad[inventory["bag"][ctargetitem][1]]["type"] == "armor" or cItemsLoad[inventory["bag"][ctargetitem][1]]["type"] == "weapon" then
  1902.    if cItemsLoad[inventory["bag"][ctargetitem][1]]["props"]["hp+"] ~= nil and cItemsLoad[inventory["bag"][ctargetitem][1]]["props"]["hp+"] ~= 0 then
  1903.    atrfunc("HP: +"..cItemsLoad[inventory["bag"][ctargetitem][1]]["props"]["hp+"],2048)
  1904.    end  
  1905.    if cItemsLoad[inventory["bag"][ctargetitem][1]]["props"]["sur+"] ~= nil and cItemsLoad[inventory["bag"][ctargetitem][1]]["props"]["sur+"] ~= 0 then
  1906.    atrfunc("Sur: +"..cItemsLoad[inventory["bag"][ctargetitem][1]]["props"]["sur+"],2048)
  1907.    end  
  1908.    if cItemsLoad[inventory["bag"][ctargetitem][1]]["props"]["str+"] ~= nil and cItemsLoad[inventory["bag"][ctargetitem][1]]["props"]["str+"] ~= 0 then
  1909.    atrfunc("Str: +"..cItemsLoad[inventory["bag"][ctargetitem][1]]["props"]["str+"],2048)
  1910.    end
  1911.    if cItemsLoad[inventory["bag"][ctargetitem][1]]["props"]["int+"] ~= nil and cItemsLoad[inventory["bag"][ctargetitem][1]]["props"]["int+"] ~= 0 then
  1912.    atrfunc("Int: +"..cItemsLoad[inventory["bag"][ctargetitem][1]]["props"]["int+"],2048)
  1913.    end    
  1914.   end  
  1915.   if cItemsLoad[inventory["bag"][ctargetitem][1]]["description"] ~= "" then
  1916.   atrfunc(string.sub(cItemsLoad[inventory["bag"][ctargetitem][1]]["description"],1,10),128)
  1917.   end  
  1918.   if #cItemsLoad[inventory["bag"][ctargetitem][1]]["description"] > 10 then
  1919.   atrfunc(string.sub(cItemsLoad[inventory["bag"][ctargetitem][1]]["description"],11,20),128)
  1920.   end
  1921.   if #cItemsLoad[inventory["bag"][ctargetitem][1]]["description"] > 20 then
  1922.   atrfunc(string.sub(cItemsLoad[inventory["bag"][ctargetitem][1]]["description"],21,30),128)
  1923.   end
  1924.  atrfunc("Cost: "..cItemsLoad[inventory["bag"][ctargetitem][1]]["cost"]*inventory["bag"][ctargetitem][2],1)
  1925.   for f = 1, #tinfoarray do
  1926.   graphics.dText(buffer,tinfoarray[f],x+41,y+f,tcolorarray[f])
  1927.   end
  1928.  graphics.drawLine(buffer, x+41, y+18, x+51, y+18, 512)
  1929.  graphics.dText(buffer,"Throw away",x+41,y+18,1)
  1930.  end
  1931. graphics.dText(buffer,"> Armor",x+1,y+18,1)
  1932. graphics.dText(buffer,"Inventory",x+(math.max(math.floor((51 / 2)-(9 / 2)), 0)),y,1)
  1933. graphics.dText(buffer,"Coins: "..coins,x+1,y,1)
  1934. end
  1935.  
  1936. local function openArmorInventoryWindow(buffer,x,y)
  1937. graphics.drawBox(buffer,x,y,51,19,256)
  1938. graphics.drawLine(buffer, x, y, x+51, y, 128)
  1939. graphics.dText(buffer,"X",x+50,y,1)
  1940. graphics.drawLine(buffer, x, y+1, x, y+12, 128)
  1941. graphics.drawLine(buffer, x+8, y+1, x+8, y+12, 128)
  1942. graphics.drawLine(buffer, x+16, y+1, x+16, y+12, 128)
  1943. graphics.drawLine(buffer, x+24, y+1, x+24, y+12, 128)
  1944. graphics.drawLine(buffer, x, y+6, x+24, y+6, 128)
  1945. graphics.drawLine(buffer, x, y+12, x+24, y+12, 128)
  1946. graphics.drawLine(buffer, x, y+18, x+24, y+18, 128)
  1947.  if inventory["weared"]["helmet"] ~= 0 then
  1948.  graphics.addImage(buffer,itemimg[cItemsLoad[inventory["weared"]["helmet"]]["icon"]],x+1,y+1)
  1949.  ctargetitem = inventory["weared"]["helmet"]
  1950.  else graphics.addImage(buffer,emptyArmorImageHelmet,x+1,y+1)
  1951.  end
  1952.  if inventory["weared"]["bodywear"] ~= 0 then
  1953.  graphics.addImage(buffer,itemimg[cItemsLoad[inventory["weared"]["bodywear"]]["icon"]],x+1,y+7)
  1954.  ctargetitem = inventory["weared"]["bodywear"]
  1955.  else graphics.addImage(buffer,emptyArmorImageBodywear,x+1,y+7)
  1956.  end
  1957.  if inventory["weared"]["pants"] ~= 0 then
  1958.  graphics.addImage(buffer,itemimg[cItemsLoad[inventory["weared"]["pants"]]["icon"]],x+9,y+1)
  1959.  ctargetitem = inventory["weared"]["pants"]
  1960.  else graphics.addImage(buffer,emptyArmorImagePants,x+9,y+1)
  1961.  end
  1962.  if inventory["weared"]["footwear"] ~= 0 then
  1963.  graphics.addImage(buffer,itemimg[cItemsLoad[inventory["weared"]["footwear"]]["icon"]],x+9,y+7)
  1964.  ctargetitem = inventory["weared"]["footwear"]
  1965.  else graphics.addImage(buffer,emptyArmorImageFootwear,x+9,y+7)
  1966.  end
  1967.  if inventory["weared"]["pendant"] ~= 0 then
  1968.  graphics.addImage(buffer,itemimg[cItemsLoad[inventory["weared"]["pendant"]]["icon"]],x+17,y+1)
  1969.  ctargetitem = inventory["weared"]["pendant"]
  1970.  else graphics.addImage(buffer,emptyArmorImagePendant,x+17,y+1)
  1971.  end
  1972.  if inventory["weared"]["weapon"] ~= 0 then
  1973.  graphics.addImage(buffer,itemimg[cItemsLoad[inventory["weared"]["weapon"]]["icon"]],x+17,y+7)
  1974.  ctargetitem = inventory["weared"]["weapon"]
  1975.  else graphics.addImage(buffer,emptyArmorImageWeapon,x+17,y+7)
  1976.  end
  1977. graphics.dText(buffer,"< Bag",x+1,y+18,1)
  1978. graphics.dText(buffer,"Inventory",x+(math.max(math.floor((51 / 2)-(9 / 2)), 0)),y,1)
  1979. graphics.dText(buffer,"Coins: "..coins,x+1,y,1)
  1980. end
  1981.  
  1982. local function statsWindow(buffer,x,y)
  1983. graphics.drawBox(buffer,x+1,y+1,35,13,128)
  1984. graphics.drawBox(buffer,x,y,35,13,256)
  1985. graphics.drawLine(buffer, x, y, x+35, y, 128)
  1986. graphics.dText(buffer,"Player stats",x+(math.max(math.floor((35 / 2)-(12 / 2)), 0)),y,1)
  1987. graphics.dText(buffer,"X",x+35,y,1)
  1988. graphics.dText(buffer,"Player name: "..string.sub(worldCDataArray[1]["name"],1,21),x+1,y+1,1)
  1989. graphics.dText(buffer,"Player level: "..worldCDataArray[1]["level"],x+1,y+2,1)
  1990. graphics.dText(buffer,"Player HP: "..math.floor(worldCDataArray[1]["chp"]).."/"..math.floor(worldCDataArray[1]["mhp"]),x+1,y+3,1)
  1991. graphics.dText(buffer,"Player MP: "..math.floor(cmp).."/"..math.floor(mmp),x+1,y+4,1)
  1992. graphics.dText(buffer,"Player XP: "..math.floor(cxp).."/"..math.floor(mxp),x+1,y+5,1)
  1993. graphics.dText(buffer,"Physical defence "..math.floor(worldCDataArray[1]["phisdef"]),x+1,y+6,1)
  1994. graphics.dText(buffer,"Magical defense "..math.floor(worldCDataArray[1]["magdef"]),x+1,y+7,1)
  1995. graphics.dText(buffer,"Physical attack "..math.floor(worldCDataArray[1]["phisatck"]),x+1,y+8,1)
  1996. graphics.dText(buffer,"Magical attack "..math.floor(worldCDataArray[1]["magatck"]),x+1,y+9,1)
  1997. graphics.dText(buffer,"Survivability "..survivability+vSur,x+1,y+10,1)
  1998. graphics.dText(buffer,"Strength "..strength+vStr,x+1,y+11,1)
  1999. graphics.dText(buffer,"Intelligence "..intelligence+vInt,x+1,y+12,1)
  2000. end
  2001.  
  2002. local ctwindowArray = {}
  2003. local ctwindow = 0
  2004. local ctitem = 0
  2005. local ctwindowScroll = 1
  2006.  
  2007. local function tradeWindow(buffer,x,y)
  2008. graphics.drawBox(buffer,x,y,51,19,256)
  2009. graphics.drawLine(buffer, x, y, x+51, y, 128)
  2010. graphics.dText(buffer,"X",x+50,y,1)
  2011. graphics.dText(buffer,"Trade",x+(math.max(math.floor((51 / 2)-(5 / 2)), 0)),y,1)
  2012.  for f = 1, 9 do
  2013.  graphics.drawLine(buffer, x, 1+y+f*2-2, x+49, 1+y+f*2-2, 128)
  2014.  end
  2015. graphics.drawLine(buffer, x+49, 2, x+49, 19, 128)
  2016.  for f = 1, 8 do
  2017.  local ccolor = 1
  2018.  if f+4*ctwindowScroll-4 == ctitem then ccolor = 128 end
  2019.   if ctwindowArray[f+4*ctwindowScroll-4] ~= nil then
  2020.   graphics.dText(buffer,">"..string.sub(cItemsLoad[ctwindowArray[f+4*ctwindowScroll-4]["item"]]["name"],1,25),x+1,2+y+f*2-2,ccolor)
  2021.   graphics.dText(buffer,ctwindowArray[f+4*ctwindowScroll-4]["cost"].." coins",x+25,2+y+f*2-2,ccolor)
  2022.   end
  2023.  end
  2024. graphics.dText(buffer,"Name",x+1,y+1,1)
  2025. graphics.dText(buffer,"Cost",x+25,y+1,1)
  2026. graphics.drawLine(buffer, x+50, math.ceil(y+1+(ctwindowScroll*(17/(#ctwindowArray/4))-17/(#ctwindowArray/4))), x+50, math.ceil(y+1+(ctwindowScroll*(17/(#ctwindowArray/4)))), 1)
  2027. graphics.dText(buffer,"Coins: "..coins,x+1,y,1)
  2028. end
  2029.  
  2030. local ccwindowArray = {}
  2031. local ccwindow = 0
  2032. local ccwindowScroll = 1
  2033. local cctitem = 0
  2034.  
  2035. local function craftWindow(buffer,x,y)
  2036. graphics.drawBox(buffer,x,y,51,19,256)
  2037. graphics.drawLine(buffer, x, y, x+51, y, 128)
  2038. graphics.dText(buffer,"X",x+50,y,1)
  2039. graphics.dText(buffer,"Craft",x+(math.max(math.floor((51 / 2)-(5 / 2)), 0)),y,1)
  2040.  for f = 1, 9 do
  2041.  graphics.drawLine(buffer, x, 1+y+f*2-2, x+49, 1+y+f*2-2, 128)
  2042.  end
  2043. graphics.drawLine(buffer, x+49, 2, x+49, 19, 128)
  2044.  for f = 1, 8 do
  2045.   if ccwindowArray[f+4*ccwindowScroll-4] ~= nil then
  2046.   graphics.dText(buffer,">"..string.sub(cItemsLoad[ccwindowArray[f+4*ccwindowScroll-4]["item"]]["name"],1,25),x+1,2+y+f*2-2,ccolor)
  2047.   end
  2048.  end
  2049.  if cctitem ~= 0 then
  2050.  graphics.drawBox(buffer,14,7,25,9,128)
  2051.  graphics.drawBox(buffer,13,6,25,9,256)
  2052.  graphics.dText(buffer,"X",37,6,1)
  2053.  graphics.dText(buffer,"Item: "..string.sub(cItemsLoad[ccwindowArray[cctitem]["item"]]["name"],1,22),14,7,1)
  2054.  graphics.dText(buffer,"Recipe:",14,8,1)
  2055.   for f = 1, #ccwindowArray[cctitem]["recipe"] do
  2056.   local ttytextcolor = 128
  2057.    for p = 1, #inventory["bag"] do
  2058.     if inventory["bag"][p][1] == ccwindowArray[cctitem]["recipe"][f][1] and inventory["bag"][p][2] >= ccwindowArray[cctitem]["recipe"][f][2] then
  2059.     ttytextcolor = 1
  2060.     end
  2061.    end
  2062.   graphics.dText(buffer,string.sub(cItemsLoad[ccwindowArray[cctitem]["recipe"][f][1]]["name"],1,20).." ("..ccwindowArray[cctitem]["recipe"][f][2]..")",14,8+f,ttytextcolor)
  2063.   end
  2064.  graphics.drawLine(buffer, 13, 14, 37, 14, 512)
  2065.  graphics.dText(buffer,"Create item",14,14,colors.black)
  2066.  end
  2067. graphics.drawLine(buffer, x+50, math.ceil(y+1+(ccwindowScroll*(17/(#ccwindowArray/4))-17/(#ccwindowArray/4))), x+50, math.ceil(y+1+(ccwindowScroll*(17/(#ccwindowArray/4)))), 1)
  2068. end
  2069.  
  2070. local funcPauseTextArray = {"Continue","Inventory","Skills","Stats","Quests","Quit game"}
  2071.  
  2072. local function funcPause(buffer)
  2073. paused = true
  2074. graphics.drawBox(buffer,1,1,16,19,128)
  2075. graphics.drawLine(buffer,16,1,16,19,256)
  2076. graphics.drawLine(buffer,1,19,16,19,256)
  2077. graphics.dText(buffer,"Paused",5,1,1)
  2078.  for f = 1, #funcPauseTextArray do
  2079.  graphics.drawLine(buffer,1,1+f*2,16,1+f*2,256)
  2080.  graphics.dText(buffer,funcPauseTextArray[f],1+(math.max(math.floor((16 / 2) - (#funcPauseTextArray[f] / 2)), 0)),1+f*2,1)
  2081.  end
  2082. end
  2083.  
  2084. local function killEnemy(target)
  2085. worldCDataArray[target]["living"] = false
  2086.  for f = 1, #cQuestsArray do
  2087.   if worldCDataArray[target]["id"] == CQuestsLoad[cQuestsArray[f][1]]["targ"] and cQuestsArray[f][3] == false and cQuestsArray[f][2] < CQuestsLoad[cQuestsArray[f][1]]["num"] then
  2088.   cQuestsArray[f][2] = cQuestsArray[f][2] + 1
  2089.   end
  2090.  end
  2091.  for f = 1, #cQuestsArray do
  2092.   if cQuestsArray[f][3] == false and cQuestsArray[f][2] == CQuestsLoad[cQuestsArray[f][1]]["num"] then
  2093.   cQuestsArray[f][3] = true
  2094.   addSMessage("Quest "..string.sub(CQuestsLoad[cQuestsArray[f][1]]["name"],1,15).." complete")
  2095.   end
  2096.  end
  2097. worldCDataArray[target]["resptime"] = CDataLoad[worldCDataArray[target]["id"]]["vrespawn"]
  2098. getXP(CDataLoad[worldCDataArray[target]["id"]]["loot"]["exp"])
  2099. coins = coins + CDataLoad[worldCDataArray[target]["id"]]["loot"]["coins"]+math.ceil(math.random(-CDataLoad[worldCDataArray[target]["id"]]["loot"]["coins"]/2,CDataLoad[worldCDataArray[target]["id"]]["loot"]["coins"]/2))
  2100. for f = 1, #CDataLoad[worldCDataArray[target]["id"]]["loot"]["items"] do
  2101.  if 100-CDataLoad[worldCDataArray[target]["id"]]["loot"]["items"][f][2] < math.random(1,100) then
  2102.   local vxd1 = cItemsLoad[CDataLoad[worldCDataArray[target]["id"]]["loot"]["items"][f][1]]["type"]
  2103.   if vxd1 == "item" or vxd1 == "potion" then
  2104.   addItem(CDataLoad[worldCDataArray[target]["id"]]["loot"]["items"][f][1],1)
  2105.   addsecm("You get "..cItemsLoad[CDataLoad[worldCDataArray[target]["id"]]["loot"]["items"][f][1]]["name"])
  2106.   elseif vxd1 == "armor" or vxd1 == "weapon" then
  2107.    if math.random(1,2) == 1 then
  2108.    addItem(CDataLoad[worldCDataArray[target]["id"]]["loot"]["items"][f][1],1)
  2109.    addsecm("You get "..cItemsLoad[CDataLoad[worldCDataArray[target]["id"]]["loot"]["items"][f][1]]["name"])  
  2110.    else
  2111.    local nitem = createNewItem(CDataLoad[worldCDataArray[target]["id"]]["loot"]["items"][f][1])
  2112.    addItem(nitem,1)
  2113.    addsecm("You get "..cItemsLoad[nitem]["name"])    
  2114.    end
  2115.   end
  2116.  end
  2117. end
  2118.  if target == cTarget then
  2119.  cTarget = 0
  2120.  end
  2121. end
  2122.  
  2123. local function getDamage(id)
  2124. local damage = 0
  2125. local physDefRedu = worldCDataArray[1]["phisdef"]/(worldCDataArray[1]["phisdef"]+worldCDataArray[id]["level"]*40)
  2126. damage = worldCDataArray[id]["phisatck"]*(1-physDefRedu)
  2127. damage = math.max(math.random(damage-(damage/3)*2,damage+(damage/3)*2),0,1)/2
  2128.  if worldCDataArray[id]["living"] and worldCDataArray[id]["chp"] > worldCDataArray[1]["chp"] then
  2129.  worldCDataArray[id]["spos"] = "r"
  2130.  elseif worldCDataArray[id]["chp"] < worldCDataArray[1]["chp"] then
  2131.  worldCDataArray[id]["spos"] = "l"
  2132.  end
  2133.  if worldCDataArray[id]["living"] and damage < worldCDataArray[1]["chp"] then
  2134.  worldCDataArray[1]["chp"] = worldCDataArray[1]["chp"] - damage
  2135.  elseif damage >= worldCDataArray[1]["chp"] then
  2136.  worldCDataArray[1]["living"] = false
  2137.  end
  2138. end
  2139.  
  2140. local function useSkill(skill)
  2141. local cskill = cSkillsArray[skill][1]
  2142. local damage = 0
  2143. if cSkillsLoad[cskill]["type"] == "buff" then
  2144.  if cmp >= cSkillsLoad[cskill]["manacost"][cSkillsArray[skill][3]] and cSkillsArray[skill][2] == 0 then
  2145.  addEffect(1,cSkillsLoad[cskill]["eff"][cSkillsArray[skill][3]])
  2146.  cSkillsArray[skill][2] = cSkillsLoad[cskill]["reloading"]
  2147.  cmp = cmp - cSkillsLoad[cskill]["manacost"][cSkillsArray[skill][3]]
  2148.  end
  2149. elseif cSkillsLoad[cskill]["type"] == "attack" and cTarget ~= 0 then
  2150. local pdef = worldCDataArray[cTarget]["phisdef"]
  2151. local mdef = worldCDataArray[cTarget]["magdef"]
  2152. local physDefRedu = pdef/(pdef+worldCDataArray[1]["level"]*85)
  2153. local magDefRedu = mdef/(mdef+worldCDataArray[1]["level"]*85)
  2154.  if cSkillsLoad[cskill]["typedm"] == "p" then
  2155.  damage = math.max((worldCDataArray[1]["phisatck"]+math.random(cSkillsLoad[cskill]["mindamage"][cSkillsArray[skill][3]],cSkillsLoad[cskill]["maxdamage"][cSkillsArray[skill][3]]))*(1-physDefRedu),0.1)
  2156.  elseif cSkillsLoad[cskill]["typedm"] == "m" then
  2157.  damage = math.max((worldCDataArray[1]["magatck"]+math.random(cSkillsLoad[cskill]["mindamage"][cSkillsArray[skill][3]],cSkillsLoad[cskill]["maxdamage"][cSkillsArray[skill][3]]))*(1-magDefRedu),0.1)
  2158.  end
  2159.  local rtype = worldCDataArray[cTarget]["roletype"]
  2160.  if damage < worldCDataArray[cTarget]["chp"] and ( rtype == "e" or rtype == "m" ) and getDistanceToId(1,cTarget) <= cSkillsLoad[cskill]["distance"] and cmp >= cSkillsLoad[cskill]["manacost"][cSkillsArray[skill][3]] and cSkillsArray[skill][2] == 0 then
  2161.  cmp = cmp - cSkillsLoad[cskill]["manacost"][cSkillsArray[skill][3]]
  2162.  worldCDataArray[cTarget]["chp"] = worldCDataArray[cTarget]["chp"] - damage
  2163.  cSkillsArray[skill][2] = cSkillsLoad[cskill]["reloading"]
  2164.   if cSkillsLoad[cskill]["eff"][cSkillsArray[skill][3]] ~= 0 then
  2165.   addEffect(cTarget,cSkillsLoad[cskill]["eff"][cSkillsArray[skill][3]])
  2166.   end
  2167.  worldCDataArray[cTarget]["attplayer"] = true
  2168.  worldCDataArray[cTarget]["agrtime"] = 16
  2169.  elseif damage >= worldCDataArray[cTarget]["chp"] and ( rtype == "e" or rtype == "m" ) and getDistanceToId(1,cTarget) <= cSkillsLoad[cskill]["distance"] and cmp >= cSkillsLoad[cskill]["manacost"][cSkillsArray[skill][3]] and cSkillsArray[skill][2] == 0 then
  2170.  cmp = cmp - cSkillsLoad[cskill]["manacost"][cSkillsArray[skill][3]]
  2171.  worldCDataArray[cTarget]["living"] = false
  2172.   for f = 1, #cQuestsArray do
  2173.    if worldCDataArray[cTarget]["id"] == CQuestsLoad[cQuestsArray[f][1]]["targ"] and cQuestsArray[f][3] == false and cQuestsArray[f][2] < CQuestsLoad[cQuestsArray[f][1]]["num"] then
  2174.    cQuestsArray[f][2] = cQuestsArray[f][2] + 1
  2175.    end
  2176.   end
  2177.   for f = 1, #cQuestsArray do
  2178.    if cQuestsArray[f][3] == false and cQuestsArray[f][2] == CQuestsLoad[cQuestsArray[f][1]]["num"] then
  2179.    cQuestsArray[f][3] = true
  2180.    addSMessage("Quest "..string.sub(CQuestsLoad[cQuestsArray[f][1]]["name"],1,15).." complete")
  2181.    end
  2182.   end
  2183.  worldCDataArray[cTarget]["resptime"] = CDataLoad[worldCDataArray[cTarget]["id"]]["vrespawn"]
  2184.  getXP(CDataLoad[worldCDataArray[cTarget]["id"]]["loot"]["exp"])
  2185.  coins = coins + CDataLoad[worldCDataArray[cTarget]["id"]]["loot"]["coins"]+math.ceil(math.random(-CDataLoad[worldCDataArray[cTarget]["id"]]["loot"]["coins"]/2,CDataLoad[worldCDataArray[cTarget]["id"]]["loot"]["coins"]/2))
  2186.  for f = 1, #CDataLoad[worldCDataArray[cTarget]["id"]]["loot"]["items"] do
  2187.   if 100-CDataLoad[worldCDataArray[cTarget]["id"]]["loot"]["items"][f][2] < math.random(1,100) then
  2188.    local vxd1 = cItemsLoad[CDataLoad[worldCDataArray[cTarget]["id"]]["loot"]["items"][f][1]]["type"]
  2189.    if vxd1 == "item" or vxd1 == "potion" then
  2190.    addItem(CDataLoad[worldCDataArray[cTarget]["id"]]["loot"]["items"][f][1],1)
  2191.    addsecm("You get "..cItemsLoad[CDataLoad[worldCDataArray[cTarget]["id"]]["loot"]["items"][f][1]]["name"])
  2192.    elseif vxd1 == "armor" or vxd1 == "weapon" then
  2193.     if math.random(1,2) == 1 then
  2194.     addItem(CDataLoad[worldCDataArray[cTarget]["id"]]["loot"]["items"][f][1],1)
  2195.     addsecm("You get "..cItemsLoad[CDataLoad[worldCDataArray[cTarget]["id"]]["loot"]["items"][f][1]]["name"])  
  2196.     else
  2197.     local nitem = createNewItem(CDataLoad[worldCDataArray[cTarget]["id"]]["loot"]["items"][f][1])
  2198.     addItem(nitem,1)
  2199.     addsecm("You get "..cItemsLoad[nitem]["name"])  
  2200.     end
  2201.    end
  2202.   end
  2203.  end
  2204.  cSkillsArray[skill][2] = cSkillsLoad[cskill]["reloading"]
  2205.  worldCDataArray[cTarget]["attplayer"] = false
  2206.  worldCDataArray[cTarget]["agrtime"] = 0
  2207.  cTarget = 0
  2208.  end
  2209. end
  2210. end
  2211.  
  2212. local function dmain()
  2213. graphics.clearScreen(buffer1,8)
  2214. graphics.addImage(buffer1,tbackg,backgroundcPos-51,1)
  2215. graphics.addImage(buffer1,tbackg,backgroundcPos,1)
  2216. graphics.addImage(buffer1,tbackg,backgroundcPos+51,1)
  2217. drawcBIArray()
  2218. if playerTurning == "r" then graphics.addImage(buffer1,worldCDataArray[1]["image"],20,10)
  2219. else
  2220. graphics.addMImage(buffer1,worldCDataArray[1]["image"],20,10)
  2221. end
  2222. drawCDataUnit()
  2223.  if cTarget ~= 0 and getDistance(1,worldCDataArray[cTarget]["x"]) < 40 then
  2224.  if not paused then dWCDaw(buffer1,15,1) end
  2225.  else cTarget = 0
  2226.  end
  2227. dPlayerInfow(buffer1,1,1)
  2228. dSkillw(buffer1,31,1)
  2229. if cTarget ~= 0 and vOpenDialogWindow and cDialog ~= 0 then openDialogWindow(buffer1,cTarget,3,5) end
  2230.  if ftArrayms > 0 then
  2231.  graphics.dText(buffer1,drsmArray[#drsmArray],1+(math.max(math.floor((51 / 2) - (#drsmArray[#drsmArray] / 2)), 0)),5,colors.black)
  2232.  end
  2233.  if tArrayms > 0 then
  2234.  graphics.dText(buffer1,secMsgArray[#secMsgArray],1+(math.max(math.floor((51 / 2) - (#secMsgArray[#secMsgArray] / 2)), 0)),6,1)
  2235.  end
  2236. graphics.dText(buffer1,"||",50,1,1)
  2237. graphics.dText(buffer1,"||",50,2,1)
  2238. if vOpenQuestsWindow then openQuestsWindow(buffer1,8,5) end
  2239. if vOpenInventoryWindow then openInventoryWindow(buffer1,1,1) end
  2240. if vOpenArmorInventoryWindow then openArmorInventoryWindow(buffer1,1,1) end
  2241. if vOpenstatsWindow then statsWindow(buffer1,8,5) end
  2242. if ctwindow ~= 0 then tradeWindow(buffer1,1,1) end
  2243. if ccwindow ~= 0 then craftWindow(buffer1,1,1) end
  2244. -- if cTarget ~= 0 then graphics.dText(buffer1,getDistanceToId(1,cTarget),1,18,colors.black) end -- debug1
  2245. graphics.dText(buffer1,"",1,19,colors.black) -- debug2
  2246. if sPouseMenu then funcPause(buffer1) end
  2247. graphics.drawBuffer(buffer1)
  2248. end
  2249.  
  2250. local function moveplayertox(x)
  2251.  
  2252.  if x < worldCDataArray[1]["x"] then
  2253.  globalWXC = globalWXC - x
  2254.  backgroundcPos = backgroundcPos + 1
  2255.  worldCDataArray[1]["x"] = worldCDataArray[1]["x"] - x
  2256.  else
  2257.  globalWXC = globalWXC + x
  2258.  backgroundcPos = backgroundcPos - 1
  2259.  worldCDataArray[1]["x"] = worldCDataArray[1]["x"] + x
  2260.  end
  2261. dmain()
  2262. end
  2263.  
  2264. dmain()
  2265.  
  2266. local refMoveTm = 8
  2267.  
  2268. local function funcPSecond()
  2269. local tr2 = os.startTimer(0.1)
  2270.  while true do
  2271.  local e, t = os.pullEvent()
  2272.   if e == "timer" and t == tr2 and not paused then
  2273.   refMoveTm = refMoveTm - 1
  2274.   if tArrayms ~= 0 then tArrayms = tArrayms - 1 end
  2275.   if ftArrayms ~= 0 then ftArrayms = ftArrayms - 1 end
  2276.    for f = 1, #cSkillsArray do
  2277.     if cSkillsArray[f][1] ~= 0 and cSkillsArray[f][2] > 0 then
  2278.     cSkillsArray[f][2] = cSkillsArray[f][2] - 1
  2279.     end
  2280.    end
  2281.    for i = 1, #worldCDataArray do
  2282.     if ( worldCDataArray[i]["roletype"] == "e" or worldCDataArray[i]["roletype"] == "m" ) and worldCDataArray[i]["living"] then
  2283.     movetoward(i, worldCDataArray[i]["mx"], 15)
  2284.     end    
  2285.     for f = 1, #worldCDataArray[i]["effects"] do
  2286.      if worldCDataArray[i]["effects"][f][1] ~= 0 and worldCDataArray[i]["effects"][f][2] ~= 0 then
  2287.       local value = cEffectsLoad[worldCDataArray[i]["effects"][f][1]]["value"]
  2288.       local duration = cEffectsLoad[worldCDataArray[i]["effects"][f][1]]["duration"]     
  2289.       if cEffectsLoad[worldCDataArray[i]["effects"][f][1]]["type"] == "hpi" then
  2290.        if worldCDataArray[i]["chp"] + value/duration < worldCDataArray[i]["mhp"] then
  2291.        worldCDataArray[i]["chp"] = worldCDataArray[i]["chp"] + value/duration
  2292.        else worldCDataArray[i]["chp"] = worldCDataArray[i]["mhp"]
  2293.        end
  2294.       elseif cEffectsLoad[worldCDataArray[i]["effects"][f][1]]["type"] == "mpi" then       
  2295.        if cmp + value/duration < mmp then
  2296.        cmp = cmp + value/duration
  2297.        else
  2298.        cmp = mmp
  2299.        end
  2300.       elseif cEffectsLoad[worldCDataArray[i]["effects"][f][1]]["type"] == "hpd" then     
  2301.        if worldCDataArray[i]["chp"] > value/duration then
  2302.        worldCDataArray[i]["chp"] = worldCDataArray[i]["chp"] - value/duration
  2303.        else
  2304.         if i ~= 1 and worldCDataArray[i]["living"] == true then
  2305.         killEnemy(i)
  2306.         end
  2307.        end
  2308.       elseif cEffectsLoad[worldCDataArray[i]["effects"][f][1]]["type"] == "mpd" then
  2309.        if cmp > value/duration then
  2310.        cmp = cmp - value/duration
  2311.        else
  2312.        cmp = 0
  2313.        end
  2314.       end
  2315.      end
  2316.      if worldCDataArray[i]["effects"][f][1] ~= 0 then
  2317.       if worldCDataArray[i]["effects"][f][2] ~= 0 then
  2318.       worldCDataArray[i]["effects"][f][2] = worldCDataArray[i]["effects"][f][2] - 1
  2319.       else
  2320.       worldCDataArray[i]["effects"][f][1] = 0
  2321.       worldCDataArray[i]["effects"][f][2] = 0
  2322.       end
  2323.      end
  2324.     end
  2325.    end
  2326.    for f = 2, #worldCDataArray do
  2327.     if not worldCDataArray[f]["living"] and worldCDataArray[f]["resptime"] ~= 0 then
  2328.     worldCDataArray[f]["resptime"] = worldCDataArray[f]["resptime"] - 1
  2329.     worldCDataArray[f]["chp"] = worldCDataArray[f]["mhp"]
  2330.     end
  2331.     if not worldCDataArray[f]["living"] and worldCDataArray[f]["resptime"] == 0 then
  2332.     worldCDataArray[f]["living"] = true
  2333.     end
  2334.     if worldCDataArray[f]["attplayer"] == false and worldCDataArray[f]["living"] and worldCDataArray[f]["roletype"] ~= "f" and math.random(0,1) == 1 and refMoveTm == 0 then
  2335.     worldCDataArray[f]["mx"] = worldCDataArray[f]["sx"] + math.random(-8,8)
  2336.     end
  2337.     if worldCDataArray[f]["living"] and worldCDataArray[f]["roletype"] ~= "f" and worldCDataArray[f]["attplayer"] and worldCDataArray[f]["agrtime"] > 0 and getDistanceToId(1,f) <= worldCDataArray[f]["attackdistance"] then
  2338.     worldCDataArray[f]["agrtime"] = 16
  2339.     getDamage(f)
  2340.     worldCDataArray[f]["mx"] = worldCDataArray[f]["x"]
  2341.      if vpickwait then
  2342.      vcpcingup = 0
  2343.      vpcingupm = 0
  2344.      vpickwait = false
  2345.      cTarget = 0
  2346.      end
  2347.     if worldCDataArray[f]["living"] and cTarget == 0 then cTarget = f end
  2348.     elseif worldCDataArray[f]["living"] and worldCDataArray[f]["roletype"] ~= "f" and worldCDataArray[f]["attplayer"] and worldCDataArray[f]["agrtime"] > 0 and getDistanceToId(1,f) > worldCDataArray[f]["attackdistance"] then
  2349.      if worldCDataArray[f]["x"] > worldCDataArray[1]["x"] then
  2350.      worldCDataArray[f]["mx"] = worldCDataArray[1]["x"] + worldCDataArray[f]["attackdistance"] + 4
  2351.      elseif worldCDataArray[f]["x"] < worldCDataArray[1]["x"] then
  2352.      worldCDataArray[f]["mx"] = worldCDataArray[1]["x"] - worldCDataArray[f]["attackdistance"] - worldCDataArray[f]["width"]
  2353.      end
  2354.     if worldCDataArray[f]["living"] and cTarget == 0 then cTarget = f end    
  2355.      if getDistance(f,worldCDataArray[f]["sx"]) >= 18 then
  2356.      worldCDataArray[f]["agrtime"] = worldCDataArray[f]["agrtime"] - 1
  2357.      else worldCDataArray[f]["agrtime"] = 16
  2358.      end
  2359.     end
  2360.     if worldCDataArray[f]["attplayer"] and worldCDataArray[f]["agrtime"] == 8 then
  2361.     worldCDataArray[f]["attplayer"] = false
  2362.     worldCDataArray[f]["mx"] = worldCDataArray[f]["sx"]
  2363.     end
  2364.     if getDistanceToId(1,f) >= 30 then
  2365.     if cTarget == f then cTaget = 0 end
  2366.     worldCDataArray[f]["attplayer"] = false
  2367.     worldCDataArray[f]["mx"] = worldCDataArray[f]["sx"]
  2368.     end
  2369.     if getDistanceToId(1,f) <= 10 and CDataLoad[worldCDataArray[f]["id"]]["agr"] then
  2370.     worldCDataArray[f]["attplayer"] = true
  2371.     worldCDataArray[f]["agrtime"] = 16 
  2372.     end
  2373.    end  
  2374.    if cmp < mmp then
  2375.    cmp = cmp + 0.5
  2376.    else cmp = mmp
  2377.    
  2378.    end
  2379.    local chpinc = math.min(worldCDataArray[1]["level"]*0.05,0.95)
  2380.    if worldCDataArray[1]["chp"] + chpinc < worldCDataArray[1]["mhp"] then
  2381.    worldCDataArray[1]["chp"] = worldCDataArray[1]["chp"] + chpinc
  2382.    else worldCDataArray[1]["chp"] = worldCDataArray[1]["mhp"]
  2383.    end
  2384.   if refMoveTm == 0 then refMoveTm = 8 end
  2385.   dmain()
  2386.   if vpickwait then
  2387.   vcpcingup = vcpcingup + 1
  2388.   end
  2389.   if cTarget ~= 0 and vpickwait and vcpcingup == vpcingupm then
  2390.   vcpcingup = 0
  2391.   vpcingupm = 0
  2392.   vpickwait = false
  2393.    for f = 1, #CDataLoad[worldCDataArray[cTarget]["id"]]["loot"]["items"] do
  2394.     if 100-CDataLoad[worldCDataArray[cTarget]["id"]]["loot"]["items"][f][2] < math.random(1,100) then
  2395.     addItem(CDataLoad[worldCDataArray[cTarget]["id"]]["loot"]["items"][f][1],1)
  2396.     addsecm("You get "..cItemsLoad[CDataLoad[worldCDataArray[cTarget]["id"]]["loot"]["items"][f][1]]["name"])
  2397.     end
  2398.    end
  2399.   worldCDataArray[cTarget]["resptime"] = CDataLoad[worldCDataArray[cTarget]["id"]]["vrespawn"]
  2400.   worldCDataArray[cTarget]["living"] = false
  2401.   cTarget = 0
  2402.   worldCDataArray[1]["image"] = CDataLoad[1]["image"]
  2403.   end
  2404.   end
  2405.  if e == "timer" and t == tr2 then tr2 = os.startTimer(1) end
  2406.  end
  2407. end
  2408.  
  2409. cmp = mmp
  2410.  
  2411. local function active()
  2412. while true do
  2413. e, b, p3, p4, p5 = os.pullEvent()
  2414.  if e == "key" then
  2415.   -- кнопка <- A
  2416.   if ( b == 203 or b == 30 ) and not paused and not vpickwait then
  2417.   playerTurning = "l"
  2418.   globalWXC = globalWXC - 1
  2419.   backgroundcPos = backgroundcPos + 1
  2420.   worldCDataArray[1]["x"] = worldCDataArray[1]["x"] - 1
  2421.   if backgroundcPos >= 51 then backgroundcPos = 1 end  
  2422.   dmain()
  2423.   -- кнопка -> D
  2424.   elseif ( b == 205 or b == 32 ) and not paused and not vpickwait then
  2425.   playerTurning = "r"
  2426.   globalWXC = globalWXC + 1
  2427.   backgroundcPos = backgroundcPos - 1
  2428.   worldCDataArray[1]["x"] = worldCDataArray[1]["x"] + 1
  2429.   if backgroundcPos <= 0 then backgroundcPos = 51 end
  2430.   dmain()
  2431.   end
  2432.   --диалоговое окно
  2433.    -- открыть диалоговое окно 'E'
  2434.   if e == "key" and b == 18 and cTarget ~= 0 and worldCDataArray[cTarget]["roletype"] == "f" and getDistance(1,worldCDataArray[cTarget]["x"]) <= 15 and not vOpenDialogWindow then
  2435.   paused = true
  2436.   vOpenDialogWindow = true
  2437.   cDialog = worldCDataArray[cTarget]["dialog"]
  2438.   dmain()
  2439.    -- закрыть диалоговое окно 'E'
  2440.   elseif e == "key" and b == 18 and cTarget ~= 0 and worldCDataArray[cTarget]["roletype"] == "f" and getDistance(1,worldCDataArray[cTarget]["x"]) <= 15 and vOpenDialogWindow then
  2441.   paused = false
  2442.   vOpenDialogWindow = false
  2443.   cDialog = 0
  2444.   dmain()
  2445.   end
  2446.   if e == "key" and b == 27 and not paused then
  2447.   moveplayertox(3500)
  2448.   end
  2449.   -- кнопки атаки
  2450.   if b == 2 and not paused and not vpickwait then
  2451.   useSkill(1)
  2452.   dmain()
  2453.   elseif b == 3 and not paused and not vpickwait then
  2454.   useSkill(2)
  2455.   dmain()
  2456.   elseif b == 4 and not paused and not vpickwait then
  2457.   useSkill(3)
  2458.   dmain()
  2459.   elseif b == 5 and not paused and not vpickwait then
  2460.   useSkill(4)
  2461.   dmain()
  2462.   elseif b == 6 and not paused and not vpickwait then
  2463.   useSkill(5)
  2464.   dmain()
  2465.   end
  2466.  end
  2467.  if e == "mouse_click" then
  2468.   -- выбор цели лкм
  2469.   if b == 1 and not paused and not vpickwait then
  2470.   target(p3,p4)
  2471.   dmain()
  2472.   end
  2473.   -- диалоговое окно
  2474.   if b == 1 and vOpenDialogWindow and type(cDialog) == "table" and ctwindow == 0 and ccwindow == 0 then
  2475.    for f = 1, #cDialog-1 do
  2476.     if type(cDialog) == "table" and clicked(p3,p4,3,12+f+3-#cDialog,19,12+f+3-#cDialog) then
  2477.      if cDialog[f+1]["action"] == "close" then
  2478.      paused = false
  2479.      vOpenDialogWindow = false
  2480.      cDialog = 0
  2481.      dmain()
  2482.      elseif cDialog[f+1]["action"] == "dialog" then  
  2483.      cDialog = cDialog[f+1]["do"]
  2484.      dmain()
  2485.      p3, p4 = 1, 1
  2486.      elseif cDialog[f+1]["action"] == "getquest" and CQuestsLoad[cDialog[f+1]["do"]]["comp"] == 0 then
  2487.       if CQuestsLoad[cDialog[f+1]["do"]]["minlvl"] <= worldCDataArray[1]["level"] then
  2488.       addQuest(cDialog[f+1]["do"])
  2489.       CQuestsLoad[cDialog[f+1]["do"]]["comp"] = false
  2490.       paused = false
  2491.       vOpenDialogWindow = false
  2492.       cDialog = 0
  2493.       dmain()
  2494.       end
  2495.      elseif cDialog[f+1]["action"] == "getquest" and CQuestsLoad[cDialog[f+1]["do"]]["comp"] == false then
  2496.       for t = 1, #cQuestsArray do
  2497.        if cQuestsArray[t][1] == cDialog[f+1]["do"] and cQuestsArray[t][3] then
  2498.        CQuestsLoad[cDialog[f+1]["do"]]["comp"] = true
  2499.        coins = coins + CQuestsLoad[cDialog[f+1]["do"]]["qreward"]["coins"]
  2500.        getXP(CQuestsLoad[cDialog[f+1]["do"]]["qreward"]["xp"])
  2501.        if CQuestsLoad[cDialog[f+1]["do"]]["qreward"]["item"][1] ~= 0 then
  2502.        addItem(CQuestsLoad[cDialog[f+1]["do"]]["qreward"]["item"][1],CQuestsLoad[cDialog[f+1]["do"]]["qreward"]["item"][2])
  2503.        end
  2504.        paused = false
  2505.        vOpenDialogWindow = false       
  2506.        cDialog = 0
  2507.        table.remove(cQuestsArray,t)
  2508.        dmain()   
  2509.        break end
  2510.       end
  2511.      elseif cDialog[f+1]["action"] == "trade" then
  2512.      paused = true
  2513.      ctwindow = cDialog[f+1]["do"]
  2514.      ctwindowArray = tradewindow[cDialog[f+1]["do"]]
  2515.      dmain()     
  2516.      p3, p4 = 1, 1
  2517.      elseif cDialog[f+1]["action"] == "crafting" then
  2518.      paused = true
  2519.      ccwindow = cDialog[f+1]["do"]
  2520.      ccwindowArray = craftingwindow[cDialog[f+1]["do"]]
  2521.      dmain()     
  2522.      p3, p4 = 1, 1   
  2523.      end
  2524.     end
  2525.    end
  2526.   end
  2527.   -- открыть меню паузы
  2528.   if b == 1 and clicked(p3,p4,50,1,51,2) and not vOpenInventoryWindow and not vOpenstatsWindow and not vOpenQuestsWindow and not vOpenArmorInventoryWindow and ctwindow == 0 and ccwindow == 0 then
  2529.   sPouseMenu = true
  2530.   vOpenDialogWindow = false
  2531.   cDialog = 0
  2532.   dmain()
  2533.   end
  2534.   -- действия в меню паузы
  2535.  if sPouseMenu and not vOpenQuestsWindow and not vOpenstatsWindow and not vOpenQuestsWindow and not vOpenArmorInventoryWindow then
  2536.   if b == 1 and clicked(p3,p4,1,3,16,3) then
  2537.   sPouseMenu = false
  2538.   paused = false
  2539.   dmain()
  2540.   elseif b == 1 and clicked(p3,p4,1,5,16,5) then
  2541.   sPouseMenu = false
  2542.   vOpenInventoryWindow = true
  2543.   dmain()
  2544.   elseif b == 1 and clicked(p3,p4,1,7,16,7) then
  2545.  
  2546.   elseif b == 1 and clicked(p3,p4,1,9,16,9) then
  2547.   sPouseMenu = false
  2548.   vOpenstatsWindow = true
  2549.   dmain()
  2550.   elseif b == 1 and clicked(p3,p4,1,11,16,11) then
  2551.   sPouseMenu = false
  2552.   vOpenQuestsWindow = true
  2553.   dmain()
  2554.   elseif b == 1 and clicked(p3,p4,1,13,16,13) then
  2555.  
  2556.   end
  2557.  end
  2558.  -- закрыть окно заданий
  2559.   if vOpenQuestsWindow and clicked(p3,p4,43,5,43,5) then
  2560.   sPouseMenu = true
  2561.   vOpenQuestsWindow = false
  2562.   ctargquest = 0
  2563.   dmain()  
  2564.   end
  2565.  -- закрыть окно статистики
  2566.   if vOpenstatsWindow and clicked(p3,p4,43,5,43,5) then
  2567.   sPouseMenu = true
  2568.   vOpenstatsWindow = false
  2569.   dmain()  
  2570.   end
  2571.  -- закрыть окно торговли
  2572.   if ctwindow ~= 0 and clicked(p3,p4,51,1,51,1) then
  2573.   paused = false
  2574.   ctwindow = 0
  2575.   ctwindowScroll = 1
  2576.   vOpenDialogWindow = false
  2577.   cDialog = 0
  2578.   dmain()  
  2579.   end
  2580.   -- закрыть окно крафта
  2581.   if ccwindow ~= 0 and clicked(p3,p4,51,1,51,1) then
  2582.   paused = false
  2583.   ccwindow = 0
  2584.   ccitem = 0
  2585.   ccwindowScroll = 1
  2586.   vOpenDialogWindow = false
  2587.   cDialog = 0
  2588.   dmain()    
  2589.   end
  2590.   -- действия в окне крафта
  2591.   if ccwindow ~= 0 and cctitem == 0 then
  2592.    for f = 1, #ccwindowArray do
  2593.     if b == 1 and clicked(p3,p4,1,1+f*2,24,1+f*2) and ccwindowArray[f+4*ccwindowScroll-4] then
  2594.     cctitem = f+4*ccwindowScroll-4
  2595.     dmain()
  2596.     end
  2597.    end  
  2598.   elseif ccwindow ~= 0 and cctitem ~= 0 then
  2599.    if clicked(p3,p4,37,6,37,6) then
  2600.    cctitem = 0
  2601.    dmain()
  2602.    elseif clicked(p3,p4,13,14,25,14) then
  2603.    local vcompitem = 0
  2604.     for f = 1, #ccwindowArray[cctitem]["recipe"] do
  2605.      for p = 1, #inventory["bag"] do
  2606.       if inventory["bag"][p][1] == ccwindowArray[cctitem]["recipe"][f][1] and inventory["bag"][p][2] >= ccwindowArray[cctitem]["recipe"][f][2] then
  2607.       vcompitem = vcompitem + 1
  2608.       end
  2609.      end
  2610.     end
  2611.     if vcompitem == #ccwindowArray[cctitem]["recipe"] then
  2612.      for f = 1, #ccwindowArray[cctitem]["recipe"] do
  2613.       for p = 1, #inventory["bag"] do
  2614.        if inventory["bag"][p][1] == ccwindowArray[cctitem]["recipe"][f][1] and inventory["bag"][p][2] >= ccwindowArray[cctitem]["recipe"][f][2] then
  2615.        inventory["bag"][p][2] = inventory["bag"][p][2] - ccwindowArray[cctitem]["recipe"][f][2]
  2616.         if inventory["bag"][p][2] == ccwindowArray[cctitem]["recipe"][f][2] then
  2617.         inventory["bag"][p][1] = 0
  2618.         end
  2619.        end
  2620.       end
  2621.      end    
  2622.     local nitem = createNewItem(ccwindowArray[cctitem]["item"])
  2623.     addItem(nitem,1)
  2624.     cctitem = 0
  2625.     dmain()
  2626.     p3, p4 = 1, 1
  2627.     end
  2628.    end  
  2629.   end
  2630.   -- действия в окне торговли
  2631.   if ctwindow ~= 0 then
  2632.    for f = 1, #ctwindowArray do
  2633.     if b == 1 and clicked(p3,p4,1,1+f*2,24,1+f*2) and ctwindowArray[f+4*ctwindowScroll-4] ~= nil and coins >= ctwindowArray[f+4*ctwindowScroll-4]["cost"] then
  2634.     ctitem = f+4*ctwindowScroll-4
  2635.     addItem(ctwindowArray[f+4*ctwindowScroll-4]["item"],1)
  2636.     coins = coins - ctwindowArray[f+4*ctwindowScroll-4]["cost"]
  2637.     dmain()
  2638.     end
  2639.    end
  2640.   end
  2641.   -- f+4*ctwindowScroll-4
  2642.  
  2643.   -- действия в окне заданий
  2644.   if vOpenQuestsWindow and #cQuestsArray ~= 0 then  
  2645.    for f = 1, #cQuestsArray do
  2646.     if clicked(p3,p4,8,5+f,43,5+f) then
  2647.     ctargquest = f
  2648.     dmain()
  2649.     end
  2650.    end
  2651.   end
  2652.   -- закрыть окно инвентаря
  2653.   if (vOpenInventoryWindow or vOpenArmorInventoryWindow) and clicked(p3,p4,51,1,51,1) then
  2654.   sPouseMenu = true
  2655.   vOpenInventoryWindow = false
  2656.   vOpenArmorInventoryWindow = false
  2657.   ctargetitem = 0
  2658.   p3, p4 = 0, 0
  2659.   dmain()
  2660.   end
  2661.   if vOpenInventoryWindow and clicked(p3,p4,2,19,9,19) then
  2662.   ctargetitem = 0
  2663.   vOpenInventoryWindow = false
  2664.   vOpenArmorInventoryWindow = true
  2665.   dmain()
  2666.   elseif vOpenArmorInventoryWindow and clicked(p3,p4,2,19,9,19) then
  2667.   ctargetitem = 0
  2668.   vOpenInventoryWindow = true
  2669.   vOpenArmorInventoryWindow = false
  2670.   dmain()  
  2671.   end
  2672.   -- действие в окне инвентаря
  2673.   if vOpenInventoryWindow then
  2674.    if ctargetitem ~= 0 and clicked(p3,p4,41,19,50,19) then
  2675.    inventory["bag"][ctargetitem][1] = 0
  2676.    inventory["bag"][ctargetitem][2] = 0
  2677.    ctargetitem = 0
  2678.    dmain()  
  2679.    end  
  2680.   local tbt = 0
  2681.   local cy = 1
  2682.   local x, y = 1, 1
  2683.    for f = 1, #inventory["bag"] do
  2684.    local h = f
  2685.     if f < 6 then cy = y+1
  2686.     elseif f > 5 and f < 11 then cy = y+7 h = f - 5
  2687.     elseif f > 10 then cy = y+13 h = f - 10 end
  2688.     if b == 1 and inventory["bag"][f][1] ~= 0 then
  2689.      if clicked(p3,p4,1+x+h*8-8,cy,1+x+h*8-2,cy+4) and tbt == 0 then
  2690.      ctargetitem = f
  2691.      dmain()
  2692.      tbt = 1
  2693.      break
  2694.      else
  2695.      ctargetitem = 0
  2696.      dmain()
  2697.      end
  2698.     end
  2699.     if b == 2 and inventory["bag"][f][1] ~= 0 then
  2700.      if clicked(p3,p4,1+x+h*8-8,cy,1+x+h*8-2,cy+4) and cItemsLoad[inventory["bag"][f][1]]["type"] == "armor" and cItemsLoad[inventory["bag"][f][1]]["reqlvl"] <= worldCDataArray[1]["level"] then
  2701.       if inventory["weared"][cItemsLoad[inventory["bag"][f][1]]["subtype"]] == 0 then
  2702.       inventory["weared"][cItemsLoad[inventory["bag"][f][1]]["subtype"]] = inventory["bag"][f][1]
  2703.       inventory["bag"][f][1] = 0
  2704.       inventory["bag"][f][2] = 0     
  2705.       else
  2706.       local cvarwp1 = inventory["weared"][cItemsLoad[inventory["bag"][f][1]]["subtype"]]     
  2707.       inventory["weared"][cItemsLoad[inventory["bag"][f][1]]["subtype"]] = inventory["bag"][f][1]    
  2708.       inventory["bag"][f][1] = 0
  2709.       inventory["bag"][f][2] = 0     
  2710.       addItem(cvarwp1,1)
  2711.       end  
  2712.      playerVarRef()
  2713.      ctargetitem = 0
  2714.      dmain()
  2715.      break
  2716.      end
  2717.      if clicked(p3,p4,1+x+h*8-8,cy,1+x+h*8-2,cy+4) and cItemsLoad[inventory["bag"][f][1]]["type"] == "weapon" and cItemsLoad[inventory["bag"][f][1]]["reqlvl"] <= worldCDataArray[1]["level"] then
  2718.       if inventory["weared"]["weapon"] == 0 then
  2719.       inventory["weared"]["weapon"] = inventory["bag"][f][1]
  2720.       inventory["bag"][f][1] = 0
  2721.       inventory["bag"][f][2] = 0     
  2722.       else
  2723.       local cvarwp2 = inventory["weared"]["weapon"]  
  2724.       inventory["weared"]["weapon"] = inventory["bag"][f][1]     
  2725.       inventory["bag"][f][1] = 0
  2726.       inventory["bag"][f][2] = 0     
  2727.       addItem(cvarwp2,1)
  2728.       end    
  2729.      ctargetitem = 0   
  2730.      playerVarRef()
  2731.      dmain()
  2732.      break
  2733.      end         
  2734.      if clicked(p3,p4,1+x+h*8-8,cy,1+x+h*8-2,cy+4) and cItemsLoad[inventory["bag"][f][1]]["type"] == "potion" and cItemsLoad[inventory["bag"][f][1]]["reqlvl"] <= worldCDataArray[1]["level"] then
  2735.      addEffect(1,cItemsLoad[inventory["bag"][f][1]]["props"])
  2736.       if inventory["bag"][f][2] > 1 then
  2737.       inventory["bag"][f][2] = inventory["bag"][f][2] - 1
  2738.       else
  2739.       inventory["bag"][f][1] = 0
  2740.       inventory["bag"][f][2] = 0
  2741.       ctargetitem = 0
  2742.       end    
  2743.      playerVarRef()
  2744.      dmain()
  2745.      end
  2746.     end  
  2747.    end
  2748.   end
  2749.   if vOpenArmorInventoryWindow and clicked(p3,p4,2,2,7,5) and b == 2 then
  2750.   takeOffItem("helmet")
  2751.   dmain()
  2752.   elseif vOpenArmorInventoryWindow and clicked(p3,p4,2,9,7,13) and b == 2 then
  2753.   takeOffItem("bodywear")
  2754.   dmain()
  2755.   elseif vOpenArmorInventoryWindow and clicked(p3,p4,10,2,16,5) and b == 2 then
  2756.   takeOffItem("pants")
  2757.   dmain()
  2758.   elseif vOpenArmorInventoryWindow and clicked(p3,p4,10,9,16,13) and b == 2 then
  2759.   takeOffItem("footwear")
  2760.   dmain()  
  2761.   elseif vOpenArmorInventoryWindow and clicked(p3,p4,18,2,24,5) and b == 2 then
  2762.   takeOffItem("pendant")
  2763.   dmain()
  2764.   elseif vOpenArmorInventoryWindow and clicked(p3,p4,18,9,24,13) and b == 2 then
  2765.   takeOffItem("weapon")
  2766.   dmain()  
  2767.   end
  2768.  end
  2769.  if e == "mouse_scroll" then
  2770.   if ctwindow ~= 0 and b == -1 and ctwindowScroll > 1 then -- прокрутка вверх
  2771.   ctwindowScroll = ctwindowScroll - 1
  2772.   dmain()
  2773.   elseif ctwindow ~= 0 and b == 1 and ctwindowScroll < math.ceil(#ctwindowArray/4) then -- прокрутка вниз
  2774.   ctwindowScroll = ctwindowScroll + 1
  2775.   dmain()
  2776.   end
  2777.   if ccwindow ~= 0 and b == -1 and ccwindowScroll > 1 and cctitem == 0 then -- прокрутка вверх
  2778.   ccwindowScroll = ccwindowScroll - 1
  2779.   dmain()
  2780.   elseif ccwindow ~= 0 and b == 1 and ccwindowScroll < math.ceil(#ccwindowArray/4) and cctitem == 0 then -- прокрутка вниз
  2781.   ccwindowScroll = ccwindowScroll + 1
  2782.   dmain()
  2783.   end
  2784.  end
  2785.   -- выкопать 'E'
  2786.  if e == "key_up" and b == 18 and cTarget ~= 0 and worldCDataArray[cTarget]["roletype"] == "r" and getDistance(1,worldCDataArray[cTarget]["x"]) <= 5 and not paused and not vpickwait then
  2787.  vpickwait = true
  2788.  vpcingupm = math.random(12,22)
  2789.  vcpcingup = 0
  2790.  worldCDataArray[1]["image"] = playerMdl[3]
  2791.  e = "mouse_up"
  2792.  b = 1
  2793.  end
  2794. end  -- #end of the loop
  2795.  
  2796. end -- #end of the function
  2797.  
  2798.  
  2799. --[[
  2800. local ctwindowArray = {}
  2801. local ctwindow = 0
  2802. local ctitem = 0
  2803. local ctwindowScroll = 1
  2804. ]]--
  2805.  
  2806. parallel.waitForAll(active,funcPSecond)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement