0023_marletto_tower.lua 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. -------------------------
  2. --
  3. -------------------------
  4. function find(t, searched)
  5. print("searching")
  6. for index,value in ipairs(t)
  7. do
  8. print(index.." "..value)
  9. if value==searched
  10. then
  11. return index
  12. end
  13. end
  14. return nil
  15. end
  16. function contain(t, searched)
  17. print("searching")
  18. for index,value in ipairs(t)
  19. do
  20. print(index.." "..value)
  21. if value==searched
  22. then
  23. return true
  24. end
  25. end
  26. return false
  27. end
  28. function push_back(t,value)
  29. t[(#t)+1] = value
  30. end
  31. myObjects = {}
  32. name = ""
  33. visited = {}
  34. --------------------------------------------------------------
  35. function newObject_23 (ob)
  36. myObjects[ob] = {}
  37. print("Dostaje info o nowym Marletto Tower spod adresu " .. ob)
  38. print(vcmi.getPos(ob))
  39. visited[true],visited[false] = vcmi.getGnrlText(352), vcmi.getGnrlText(353)
  40. end
  41. function hoverText_23(Object)
  42. local Hero = vcmi.getSelectedHero()
  43. local ret = name.." "
  44. if Hero>-1
  45. then
  46. ret = ret..visited[contain(myObjects[ObjectAddress],Hero)]
  47. end
  48. return name..visited[contain(myObjects[ObjectAddress],Hero)]
  49. end
  50. function heroVisit_23(ObjectAddress, HeroID)
  51. print("Hero with ID " .. HeroID .. " has visited object at " .. ObjectAddress)
  52. if find(myObjects[ObjectAddress],HeroID)
  53. then
  54. print("Ten bohater juz tu byl")
  55. else
  56. print("Bierz obrone...")
  57. vcmi.changePrimSkill(HeroID, 1, 1)
  58. push_back(myObjects[ObjectAddress],HeroID)
  59. end
  60. end