Guest User

Untitled

a guest
Feb 24th, 2020
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 79.76 KB | None | 0 0
  1. playerTable = {
  2.   P1 = {
  3.     color = "red", playerZone = "zoneP1", playerName = "Player One", grave_pos = { - 12.84, 4.12, - 58.74}
  4.     , skullDeadPos = { - 5.85, 4.32, - 7.22}, survDiedPos = { - 5.76, 4.36, - 9.26}, survDiedRot = {323.13, 90.00, 90.00}
  5.     , cannibalizeResourcePos = {}, gainedResourcePos = {}, rolePosition = {}
  6.     , gridGUID = "d6d0e5", skullDeadToken = "11ddbb", extraBleed = "d7a48a", bleedTool = "a6b9f6", extraSlots = "696d34"
  7.     , affinityRed = "eb1f26", affinityGreen = "17e382", affinityBlue = "e915b0", zoneGraveyard = "zoneGraveyard_Left"
  8.     , fistToothToken = "6d4a2a", frenzyToken = ""
  9.   }
  10.   , P2 = {
  11.     color = "yellow", playerZone = "zoneP2", playerName = "Player Two", grave_pos = { - 12.84, 4.12, - 58.74}
  12.     , skullDeadPos = { - 2.82, 4.32, - 7.22}, survDiedPos = { - 2.79, 4.54, - 9.26}, survDiedRot = {0.00, 90.00, 90.00}
  13.     , cannibalizeResourcePos = {}, gained_resource_pos = {}, rolePosition = {}
  14.     , gridGUID = "f24977", skullDeadToken = "7e71e0", extraBleed = "4de12c", bleedTool = "a4f09f", extraSlots = "02f864"
  15.     , affinityRed = "429814", affinityGreen = "e1e89f", affinityBlue = "e9db49", zoneGraveyard = "zoneGraveyard_Left"
  16.     , fistToothToken = "099bb2", frenzyToken = ""
  17.   }
  18.   , P3 = {
  19.     color = "green", playerZone = "zoneP3", playerName = "Player Three", grave_pos = {12.84, 4.12, - 58.74}
  20.     , skullDeadPos = {2.44, 4.32, - 7.21}, survDiedPos = {2.44, 4.55, - 9.26}, survDiedRot = {270.00, 180.00, 0.00}
  21.     , cannibalizeResourcePos = {}, gained_resource_pos = {}, rolePosition = {}
  22.     , gridGUID = "d7d8ee", skullDeadToken = "c7d338", extraBleed = "e51595", bleedTool = "06764c", extraSlots = "b044de"
  23.     , affinityRed = "48c3e9", affinityGreen = "c54f3c", affinityBlue = "7d41b3", zoneGraveyard = "zoneGraveyard_Right"
  24.     , fistToothToken = "bce349", frenzyToken = ""
  25.   }
  26.   , P4 = {
  27.     color = "blue", playerZone = "zoneP4", playerName = "Player Four", grave_pos = {12.84, 4.12, - 58.74}
  28.     , skullDeadPos = {5.55, 4.32, - 7.22}, survDiedPos = {5.51, 4.56, - 9.26}, survDiedRot = {303.87, 88.95, 90.95}
  29.     , cannibalizeResourcePos = {}, gained_resource_pos = {}, rolePosition = {}
  30.     , gridGUID = "f14367", skullDeadToken = "b2fefd", extraBleed = "a40619", bleedTool = "'cb6334'", extraSlots = "2916f5"
  31.     , affinityRed = "dee6a3", affinityGreen = "c2c15a", affinityBlue = "d130c1", zoneGraveyard = "zoneGraveyard_Right"
  32.     , fistToothToken = "868eb0", frenzyToken = ""
  33.   }
  34. }
  35.  
  36. weapon = {strength = 0, speed = 2, accuracy = 2, luck = 1, name = "FistAndTooth"}
  37. wounds = {"headH", "bodyL", "bodyH", "waistL", "waistH", "armsL", "armsH", "legsL", "legsH"}
  38.  
  39. -- cannibalizeResourcePos = {-33.20, 2, -35.90} -- surv sheet pos
  40. -- gained_resource_pos = {-14.16, 1.08, -18.80}   -- avatar pos
  41.  
  42. -- extraSlots = '696d34'
  43. -- extraSlots_pos_on = {-30.88, 0.24, -35.79}
  44. extraSlots_rot = {3.12, 0.00, 0.00}
  45.  
  46. -- momentum_Counter = '7dd43d'
  47. -- momentum_on_pos = { - 7.40, 4.17, - 8.19}
  48.  
  49. -- Offset Positions
  50. offsets = {
  51.   movToken = {x = -0.18, y = 6, z = 2.19}
  52.   , spdToken = {x = 0.48, y = 6, z = 2.19}
  53.   , accToken = {x = 1.15, y = 6, z = 2.19}
  54.   , strToken = {x = 1.78, y = 6, z = 2.19}
  55.   , lckToken = {x = 2.44, y = 6, z = 2.19}
  56.   , evaToken = {x = 3.13, y = 6, z = 2.19}
  57.   , negativeZ = 1.09
  58.   , extraBleed = {x = 0.2, y = 0, z = 0}
  59.   , weaponProf = {x = 2.95, y = 1.08, z = 2.14}
  60. }
  61.  
  62. statsBag = {}
  63.  
  64. SurvSheetScript = "357074"
  65.  
  66. SurvMemBag = 'c1d766'
  67. survivorBags = {
  68.   male = {
  69.     {mesh = "http://pastebin.com/raw/tg6gzM2f", diffuse = "http://u.cubeupload.com/redcore/standingman.jpg"},
  70.     {mesh = "http://pastebin.com/raw/hnx90H3a", diffuse = "http://u.cubeupload.com/redcore/walkingman.jpg"}
  71.   },
  72.   female = {
  73.     {mesh = "http://pastebin.com/raw/GK305Abh", diffuse = "http://u.cubeupload.com/redcore/woman1.jpg"},
  74.     {mesh = "http://pastebin.com/raw/GGj34rtV", diffuse = "http://u.cubeupload.com/redcore/woman2.jpg"}
  75.   }
  76. }
  77.  
  78. function onload(saved_data)
  79.   -- ÄNDERN!!!!!!!!!!!
  80.   -- affinity_red = getObjectFromGUID('eb1f26')
  81.   -- affinity_green = getObjectFromGUID('17e382')
  82.   -- affinity_blue = getObjectFromGUID('e915b0')
  83.  
  84.   -- zones
  85.   zonesTable = Global.getTable('zones')
  86.   survCardsTable = Global.getTable('survCards')
  87.   menuTokensTable = Global.getTable('menu_tokens')
  88.   user_settings = Global.getTable('user_settings')
  89.  
  90.   zoneShowdown = getObjectFromGUID(Global.getTable('zonesDestruct').zoneShowdown.guid)
  91.   zoneSurvivorStatus = getObjectFromGUID(Global.getTable('zonesDestruct').zoneSurvivorStatus.guid)
  92.   zoneInjuryBoard = getObjectFromGUID(zonesTable.zoneInjuryBoard.guid)
  93.   zoneInnovations = getObjectFromGUID(zonesTable.zoneInnovations.guid)
  94.  
  95.   gameBox = getObjectFromGUID(Global.getTable('bags').gameBox.guid)
  96.  
  97.   statsBag = {
  98.     strTokenPos = getObjectFromGUID(Global.getTable('bags_stats').bag_str.guid)
  99.     , strTokenNeg = getObjectFromGUID(Global.getTable('bags_stats_neg').bag_str.guid)
  100.     , accTokenPos = getObjectFromGUID(Global.getTable('bags_stats').bag_acc.guid)
  101.     , accTokenNeg = getObjectFromGUID(Global.getTable('bags_stats_neg').bag_acc.guid)
  102.     , movTokenPos = getObjectFromGUID(Global.getTable('bags_stats').bag_mov.guid)
  103.     , movTokenNeg = getObjectFromGUID(Global.getTable('bags_stats_neg').bag_mov.guid)
  104.     , spdTokenPos = getObjectFromGUID(Global.getTable('bags_stats').bag_spd.guid)
  105.     , spdTokenNeg = getObjectFromGUID(Global.getTable('bags_stats_neg').bag_spd.guid)
  106.     , lckTokenPos = getObjectFromGUID(Global.getTable('bags_stats').bag_lck.guid)
  107.     , lckTokenNeg = getObjectFromGUID(Global.getTable('bags_stats_neg').bag_lck.guid)
  108.     , evaTokenPos = getObjectFromGUID(Global.getTable('bags_stats').bag_eva.guid)
  109.     , evaTokenNeg = getObjectFromGUID(Global.getTable('bags_stats_neg').bag_eva.guid)
  110.   }
  111.  
  112.   -- need update
  113.   token_startShowdown = getObjectFromGUID('9091f8')
  114.   grave_stone_object = getObjectFromGUID("416864")
  115.  
  116.  
  117.   for i, v in pairs(playerTable) do
  118.     local survSheet = nil
  119.     local zonePlayer = getObjectFromGUID(zonesTable[v.playerZone].guid)
  120.     local survCard = getObjectFromGUID(survCardsTable[v.color].guid)
  121.     for k, object in pairs(zonePlayer.getObjects()) do
  122.       if object.getVar("isSurvSheet") then
  123.         survSheet = object
  124.         getObjectFromGUID(v.gridGUID).setVar("survSheetGUID", object.getGUID())
  125.         getObjectFromGUID(v.gridGUID).setColorTint(getObjectFromGUID(user_settings["settings_" .. i .. "_token"].guid).getColorTint())
  126.       end
  127.     end
  128.     Wait.time(function() checkTokenDelayed(zonePlayer, survCard, survSheet, i) end, 2)
  129.   end
  130.  
  131. end
  132.  
  133. function toggleCheckBox(params)
  134.   local name = params.id:sub(1, - 3)
  135.   local num = tonumber(params.id:sub(-2))
  136.  
  137.   if params.obj.UI.getAttribute(params.id, "value") == "false" then
  138.     params.obj.UI.setAttribute(params.id, "value", "true")
  139.     params.obj.UI.setAttribute(params.id, "color", "#000000")
  140.   else
  141.     params.obj.UI.setAttribute(params.id, "value", "false")
  142.     params.obj.UI.setAttribute(params.id, "color", "#00000000")
  143.   end
  144. end
  145.  
  146. function counter(params)
  147.   local possibleHL = {head = 0, body = 0, waist = 0, arms = 0, legs = 0}
  148.   for h, _ in pairs(possibleHL) do
  149.     if params.value == h then
  150.       local hasCrystalSkin = false
  151.       local zonePlayer = nil
  152.       local activePlayer = ""
  153.       for k, v in pairs(playerTable) do
  154.         if params.obj.getGUID() == v.gridGUID then
  155.           zonePlayer = getObjectFromGUID(zonesTable[v.playerZone].guid)
  156.           activePlayer = k
  157.         end
  158.       end
  159.  
  160.       for _, obj in pairs(zonePlayer.getObjects()) do
  161.         if obj.getName() == "Crystal Skin" then
  162.           hasCrystalSkin = true
  163.         end
  164.       end
  165.  
  166.       for _, obj in pairs(zonePlayer.getObjects()) do
  167.         if obj.tag == 'Card' then
  168.           local descript = obj.getDescription()
  169.           if (string.find(descript, 'armor') and (not hasCrystalSkin)) or string.find(descript, 'accessory') or string.find(descript, 'shield') or string.find(descript, 'set') then
  170.             possibleHL = checkCardString(possibleHL, descript, activePlayer)
  171.           end -- end if string.find
  172.         end -- end if obj.tag
  173.       end -- end for loop
  174.       params.obj.UI.setAttribute(params.value, "text", math.max(math.min(tonumber(params.obj.UI.getAttribute(params.value, "text")) + tonumber(params.id), possibleHL[params.value]), 0))
  175.  
  176.       return
  177.     end
  178.   end
  179.  
  180.   local stats = {movement = "mov", speed = "spd", accuracy = "acc", strength = "str", luck = "lck", evasion = "eva"}
  181.   local bag = nil
  182.   local pos = params.obj.getPosition()
  183.   if params.id == "+1" then
  184.     bag = Global.getTable('bags_stats')
  185.     pos = {x = pos.x + offsets[stats[params.value] .. "Token"].x, y = pos.y + offsets[stats[params.value] .. "Token"].y, z = pos.z + offsets[stats[params.value] .. "Token"].z}
  186.   elseif params.id == "-1" then
  187.     bag = Global.getTable('bags_stats_neg')
  188.     pos = {x = pos.x + offsets[stats[params.value] .. "Token"].x, y = pos.y + offsets[stats[params.value] .. "Token"].y, z = pos.z + negativeZ}
  189.   end
  190.  
  191.   spawn_token({obj = params.obj, bag = getObjectFromGUID(bag["bag_" .. stats[params.value]].guid), pos = pos})
  192.  
  193. end
  194.  
  195. function spawn_token(params)
  196.   -- params.obj, params.bag, params.pos
  197.   local bag = params.bag
  198.   local token_pos = params.pos
  199.   local gridObject = params.obj
  200.   local rot = {0, 180, 0}
  201.   local token = bag.takeObject({position = token_pos, rotation = rot, smooth = false})
  202.   token.setScale({0.25, 0.25, 0.25})
  203.  
  204.   if gridObject.getName() == "Inventory P1" then
  205.     table_toGet = "stats_red"
  206.   elseif gridObject.getName() == "Inventory P2" then
  207.     table_toGet = "stats_yellow"
  208.   elseif gridObject.getName() == "Inventory P3" then
  209.     table_toGet = "stats_green"
  210.   elseif gridObject.getName() == "Inventory P4" then
  211.     table_toGet = "stats_blue"
  212.   end
  213.  
  214.   phase = Global.getTable(table_toGet).phase
  215.   if phase == nil then
  216.     phase = Global.getTable('temp').phase
  217.   end
  218.  
  219.   if phase == "endOfround" then
  220.     token.setDescription('temp, end of round')
  221.  
  222.   elseif phase == "endOfattack" then
  223.     token.setDescription('temp, end of attack')
  224.  
  225.   elseif phase == "endOfwoundattempt" then
  226.     token.setDescription('temp, end of wound attempt')
  227.  
  228.   elseif phase == "endOfwound" then
  229.     token.setDescription('temp, end of wound')
  230.  
  231.   elseif phase == "haze" then
  232.     token.setDescription('temp, haze')
  233.  
  234.   else
  235.     token.setDescription('token, plus1mov')
  236.   end
  237. end
  238.  
  239. function collision(params)
  240.   local obj = params.collision_info.collision_object
  241.   local grid = params.obj
  242.   if obj.getVar("isSurvSheet") then
  243.     grid.setVar("survSheetGUID", obj.guid)
  244.   elseif obj.getName() == "Monster Controller" then
  245.     for k, v in pairs(playerTable) do
  246.       if v.gridGUID == grid.getGUID() then
  247.         for _, figure in ipairs(zoneShowdown.getObjects()) do
  248.           if figure.getName() == v.playerName then
  249.             figure.highlightOn(figure.getColorTint(), 500)
  250.           end
  251.         end
  252.       end
  253.     end
  254.   end
  255. end
  256.  
  257. function collisionExit(params)
  258.   local obj = params.collision_info.collision_object
  259.   local grid = params.obj
  260.   if obj.getVar("isSurvSheet") then
  261.     grid.setVar("survSheetGUID", "")
  262.   elseif obj.getName() == "Monster Controller" then
  263.     for k, v in pairs(playerTable) do
  264.       if v.gridGUID == grid.getGUID() then
  265.         for _, figure in ipairs(zoneShowdown.getObjects()) do
  266.           if figure.getName() == v.playerName then
  267.             figure.highlightOff()
  268.           end
  269.         end
  270.       end
  271.     end
  272.   end
  273. end
  274.  
  275. --------------------------------------------------------------------------------
  276. --                           TABLE OF CONTENTS                                --
  277. --                   Scripts created by Maximo and Kijan                      --
  278. --------------------------------------------------------------------------------
  279.  
  280. -- Weapon and Armor ------------------------------------------------------------
  281. -- function checkWeapon
  282. -- function SetWeapon
  283. -- function FistWeapon
  284. -- function CleanWeapon
  285. -- function reset_Weapon_Prof
  286. -- function resetArmor
  287. -- function checkCards
  288. -- function removeCard
  289.  
  290.  
  291. -- Tokens ----------------------------------------------------------------------
  292. -- function checkToken
  293. -- function checkTokenDelayed
  294. -- function parseEffects
  295.  
  296.  
  297. -- Event Handlers --------------------------------------------------------------
  298. -- function onObjectEnterScriptingZone
  299. -- function onObjectLeaveScriptingZone
  300. -- function onObjectDestroyed
  301. -- function onPickedUp
  302. -- function onCollisionEnter
  303. -- function onCollisionExit
  304.  
  305. -- Survivor Died ---------------------------------------------------------------
  306. -- function survDied
  307. -- function get_basic_for_cannibalize
  308. -- function set_skull_dead_token
  309. -- function updatePopulation
  310.  
  311. -- Save Survivor ---------------------------------------------------------------
  312. -- function buttonClick_SaveSurv
  313. -- function saveSurv
  314. -- function setModel
  315.  
  316. -- Utility Functions -----------------------------------------------------------
  317. -- function findProximity
  318. -- function get_player_pos
  319. -- function wait
  320. -- function set_portrait_buttons
  321. -- function return_role
  322.  
  323. -- Buttons ---------------------------------------------------------------------
  324. -- function initCustomButtons
  325. -- function initButtonsTable
  326. -- function clickedToggle
  327. -- function setupButton
  328. -- function createpm
  329. -- function add
  330. -- function diceStats
  331.  
  332. -- END TABLE OF CONTENTS -------------------------------------------------------
  333.  
  334. function clickedSurvDied(params)
  335.  
  336.   local HL_discard_pos = Global.getTable("HL_discard_pos")
  337.   local zonePlayer = nil
  338.   local msgColor = nil
  339.   local activePlayer = ""
  340.   for k, v in pairs(playerTable) do
  341.     if params.obj.getGUID() == v.gridGUID then
  342.       zonePlayer = getObjectFromGUID(zonesTable[v.playerZone].guid)
  343.       activePlayer = k
  344.       msgColor = getObjectFromGUID(user_settings["settings_" .. k .. "_token"].guid).getColorTint()
  345.     end
  346.   end
  347.  
  348.   if zonePlayer == nil then
  349.     printToAll("Grid (", params.obj.getGUID(), ") not found in playerTable! (clickedSurvDied)", {1, 0, 0})
  350.     return
  351.   end
  352.  
  353.   local phase = token_startShowdown.getDescription()
  354.  
  355.   -- Check Death Principle
  356.   for _, object in ipairs(zoneInnovations.getObjects()) do
  357.     if object.getName() == "Cannibalize" then
  358.       Wait.time(function() get_basic_for_cannibalize(activePlayer) end, 2)
  359.       broadcastToAll("Cannibalize ~ The Settlement gained 1 Basic Resource", {1, 1, 1})
  360.     elseif object.getName() == "Graves" then
  361.       if phase == "showdown started" then
  362.         broadcastToAll("Graves ~ Gain 2 Endeavors", {1, 1, 1})
  363.       elseif phase == "showdown ended" then
  364.         broadcastToAll("Graves ~ Gain 1 Endeavor", {1, 1, 1})
  365.       end
  366.     end -- end Death Principle
  367.   end
  368.  
  369.   if phase == "showdown started" then
  370.     -- Bone Whisperer
  371.     for k, v in pairs(playerTable) do
  372.  
  373.       local zone = getObjectFromGUID(zonesTable[v.playerZone].guid)
  374.       local objectsInZone = zone.getObjects()
  375.       for _, object in ipairs(objectsInZone) do
  376.         if object.getName() == "Bone Whisperer" then
  377.           local skull_token = getObjectFromGUID("dcdc21")
  378.           skull_token.clone({position = get_player_pos(v.playerName)})
  379.         end
  380.       end
  381.     end -- end Bone Whisperer
  382.  
  383.     -- When a Survivor Dies - Monster AI Card effects
  384.     for _, card in ipairs(zoneInjuryBoard.getObjects()) do
  385.  
  386.       -- Enraged
  387.       if card.getName() == "Enraged" then
  388.         broadcastToAll("Enraged ~ was discarded when a Survivor Dies", {1, 1, 1})
  389.         card.setPosition(HL_discard_pos)
  390.  
  391.         -- Deep Paralysis
  392.       elseif card.getName() == "Deep Paralysis" then
  393.         broadcastToAll("Deep Paralysis ~ was discarded when a Survivor Dies", {1, 1, 1})
  394.         card.setPosition(HL_discard_pos)
  395.  
  396.         -- You've Already Lost
  397.       elseif card.getName() == "You've Already Lost" then
  398.         broadcastToAll("You've Already Lost ~ was discarded when a Survivor Dies", {1, 1, 1})
  399.         card.setPosition(HL_discard_pos)
  400.  
  401.         -- Upstage
  402.       elseif card.getName() == "Upstage" then
  403.         broadcastToAll("Upstage ~ was discarded when a Survivor Dies", {1, 1, 1})
  404.         card.setPosition(HL_discard_pos)
  405.  
  406.         -- God Parasites
  407.       elseif card.getName() == "God Parasites" then
  408.         broadcastToAll("God Parasites ~ was discarded when a Survivor Dies", {1, 1, 1})
  409.         card.setPosition(HL_discard_pos)
  410.  
  411.         -- Screaming
  412.       elseif card.getName() == "Screaming" then
  413.         broadcastToAll("Screaming ~ was discarded when a Survivor Dies", {1, 1, 1})
  414.         card.setPosition(HL_discard_pos)
  415.       end
  416.     end -- end
  417.  
  418.     local hasOrator = false
  419.     for _, object in ipairs(zonePlayer.getObjects()) do
  420.       if object.getName() == "Orator of Death" then
  421.         hasOrator = true
  422.       end
  423.     end
  424.  
  425.     if hasOrator then
  426.       for _, object in ipairs(zonePlayer.getObjects()) do
  427.         if object.getVar("isSurvSheet") then
  428.           broadcastToAll(object.getName() .. " was the Orator of Death", {1, 1, 1})
  429.         end
  430.       end
  431.  
  432.       for _, object in ipairs(zoneShowdown.getObjects()) do
  433.         local rotZ = object.getRotation().z
  434.  
  435.         for k, v in pairs(playerTable) do
  436.           if playerTable[activePlayer].playerName ~= v.playerName and object.getName() == v.playerName and (rotZ > 165 and rotZ < 195) then
  437.             object.setRotation({0, 0, 0})
  438.             broadcastToAll("You were Encouraged by their Dying Words", getObjectFromGUID(user_settings["settings_" .. k .. "_token"].guid).getColorTint())
  439.           end
  440.         end
  441.       end
  442.     end
  443.  
  444.     -- When a Survivor Dies
  445.  
  446.     for k, v in pairs(playerTable) do
  447.       if playerTable[activePlayer].playerName ~= v.playerName then
  448.         for _, object in ipairs(getObjectFromGUID(zonesTable[v.playerZone].guid).getObjects()) do
  449.           local grid = getObjectFromGUID(v.gridGUID)
  450.           local pos = v.gainedResourcePos
  451.           local effects = {"Ruthless", "Vengeance", "Revenge"}
  452.  
  453.           for _, effect in pairs(effects) do
  454.             if object.getName() == effect then
  455.               local scale = object.getScale()
  456.               broadcastToAll(v.playerName .. " ~ " .. effect .. " ~ Effect Triggered", getObjectFromGUID(user_settings["settings_" .. k .. "_token"].guid).getColorTint())
  457.               object.setScale({0.49, 1.00, 0.49})
  458.               object.clone({position = pos})
  459.               object.setScale(scale)
  460.             end
  461.           end
  462.         end
  463.       end
  464.     end
  465.  
  466.     Wait.time(function() set_skull_dead_token(activePlayer) end, 1)
  467.   end
  468.  
  469.   updatePopulation()
  470.   resetArmor(activePlayer)
  471.  
  472.   local survSheetGUID = params.obj.getVar("survSheetGUID")
  473.   if survSheetGUID ~= "" then
  474.     getObjectFromGUID(survSheetGUID).call("onSave")
  475.   end
  476.  
  477.   local pos = params.obj.getPosition()
  478.  
  479.   --Gets Gravestone Marker
  480.   graveObj = grave_stone_object.clone({position = {pos.x, pos.y, pos.z - 8}, rotation = {0, 0, 0}})
  481.   Wait.condition(function() survDiedButton(graveObj, msgColor, activePlayer) Wait.time(function() survDied(graveObj, getObjectFromGUID(survSheetGUID), msgColor, activePlayer) end, 0.2) end, function() return checkLoaded(graveObj) end)
  482.  
  483. end
  484.  
  485. function burySurvivor(activePlayer)
  486.   local objectsInZone = getObjectFromGUID(zonesTable[playerTable[activePlayer].zoneGraveyard].guid).getObjects()
  487.   graveObj.setPosition({playerTable[activePlayer].grave_pos.x - #objectsInZone * 1.64, playerTable[activePlayer].grave_pos.y, playerTable[activePlayer].grave_pos.z})
  488.   graveObj.removeButton(0)
  489.   broadcastToAll("Population Updated", {1, 1, 1})
  490. end
  491.  
  492. -- Weapon and Armor ------------------------------------------------------------
  493. function checkWeaponEx(params)
  494.   checkWeapon(params[1])
  495. end
  496.  
  497. function checkWeapon(activePlayer)
  498.   local foundWeapon = nil
  499.   local selector = nil
  500.   local gridObject = getObjectFromGUID(playerTable[activePlayer].gridGUID)
  501.   local pos = gridObject.getPosition()
  502.   pos.x = pos.x - 0.03
  503.   pos.y = pos.y + 0.6
  504.   for i = 0, 2 do
  505.     for j = 0, 2 do
  506.       foundWeapon = nil
  507.       selector = nil
  508.       local hitList = Physics.cast({
  509.         origin = {pos.x + i * 1.5, pos.y, pos.z - j * 1.35},
  510.         direction = {0, 1, 0},
  511.         type = 2,
  512.         size = {1, 1, 1},
  513.         max_distance = 0,
  514.         debug = true
  515.       })
  516.       for _, entry in ipairs(hitList) do
  517.         if entry.hit_object.getDescription():find("weapon") then
  518.           foundWeapon = entry.hit_object
  519.         end
  520.         if entry.hit_object.getName() == "Selected Weapon" then
  521.           selector = entry.hit_object
  522.         end
  523.       end
  524.       if foundWeapon ~= nil and selector ~= nil then
  525.         -- sets GUID so any functions on the weapon can be called
  526.         gridObject.setVar("weaponGUID", foundWeapon.getGUID())
  527.         -- sets Weapon name and description
  528.         SetWeapon({obj = gridObject, WpnStat = {foundWeapon.getName(), foundWeapon.getDescription()}})
  529.         return
  530.       end
  531.     end
  532.   end
  533.   SetWeapon({obj = gridObject, WpnStat = {"Bases", "Bases"}})
  534.   gridObject.setVar("weaponGUID", playerTable[activePlayer].fistToothToken)
  535. end
  536.  
  537. function SetWeapon(params)
  538.   local WpnStat = params.WpnStat
  539.   local gridObject = params.obj
  540.   if WpnStat ~= nil then
  541.     local survSheet = getObjectFromGUID(gridObject.getVar("survSheetGUID"))
  542.     local WeaponName = WpnStat[1]
  543.     if WeaponName ~= 'Bases' then
  544.       local weapon = {}
  545.       local descript = WpnStat[2]
  546.       local regxEverythingExceptComma = '([^,]+)'
  547.       local BaseSpeed = 0
  548.       local Basecrit = 0
  549.       local BaseStr = 0
  550.       local Baseacc = 0
  551.  
  552.       for x in string.gmatch(descript, regxEverythingExceptComma) do
  553.         if x:find("spd") then
  554.           BaseSpeed = tonumber(string.match (x, "%d+"))
  555.         end
  556.  
  557.         if x:find("acc") then
  558.           if x:find("acc%+weaponProf") then
  559.             if survSheet ~= nil then
  560.               for wp = 1, 8 do
  561.                 if survSheet.UI.getAttribute("weaponProficiency0" .. wp, "value") == "true" then
  562.                   Baseacc = Baseacc + 1
  563.                 end
  564.               end
  565.             end
  566.           else
  567.             Baseacc = tonumber(string.match(x, "%d+"))
  568.           end
  569.         end
  570.  
  571.         if x:find("str") then
  572.           if x:find("str%+insanity") then
  573.             BaseStr = tonumber(survSheet.UI.getAttribute("insanity", "text"))
  574.           elseif x:find("str%+courage") then
  575.             if survSheet ~= nil then
  576.               for wp = 1, 9 do
  577.                 if survSheet.UI.getAttribute("courage0" .. wp, "value") == "true" then
  578.                   BaseStr = BaseStr + 1
  579.                 end
  580.               end
  581.             end
  582.           else
  583.             BaseStr = tonumber(string.match(x, "%d+"))
  584.           end
  585.         end
  586.  
  587.         if x:find("lck") then
  588.           Basecrit = tonumber(string.match(x, "%d+"))
  589.         end
  590.       end
  591.  
  592.       weapon["strength"] = BaseStr
  593.       weapon["speed"] = BaseSpeed
  594.       weapon["accuracy"] = 10 - Baseacc
  595.       weapon["luck"] = Basecrit
  596.       weapon['name'] = WeaponName
  597.  
  598.       gridObject.setTable("weapon", weapon)
  599.  
  600.     else
  601.       FistWeapon(gridObject)
  602.     end
  603.   end
  604.   Wait.frames(function() diceStats(gridObject) end, 1)
  605. end
  606.  
  607. function FistWeapon(gridObject)
  608.   local activePlayer = ""
  609.   local zonePlayer = nil
  610.   local msgColor = nil
  611.   for k, v in pairs(playerTable) do
  612.     if gridObject.getGUID() == v.gridGUID then
  613.       zonePlayer = getObjectFromGUID(zonesTable[v.playerZone].guid)
  614.       activePlayer = k
  615.       msgColor = getObjectFromGUID(user_settings["settings_" .. k .. "_token"].guid).getColorTint()
  616.     end
  617.   end
  618.  
  619.   if zonePlayer == nil then
  620.     printToAll("Grid (", gridObject.getGUID(), ") not found in playerTable! (FistWeapon)", {1, 0, 0})
  621.     return
  622.   end
  623.  
  624.   weapon['strength'] = 0
  625.   weapon['speed'] = 2
  626.   weapon['accuracy'] = 2
  627.   weapon['luck'] = 1
  628.   weapon['name'] = "FistAndTooth"
  629.  
  630.   for _, object in ipairs(zonePlayer.getObjects()) do
  631.     -- Monster Claw Style
  632.     if object.getName() == "Monster Claw Style" then
  633.       weapon['strength'] = weapon['strength'] + 1
  634.       weapon['accuracy'] = weapon['accuracy'] + 1
  635.       broadcastToColor("Monster Claw Style ~ (+1) Accuracy ~ (+1) Strength Calculated", playerTable[activePlayer].color, msgColor)
  636.     end
  637.  
  638.     -- Brawler Armor
  639.     if object.getName() == "Brawler Armor" then
  640.       weapon['accuracy'] = weapon['accuracy'] + 2
  641.       broadcastToColor("Brawler Armor Set ~ (+2) Accuracy Calculated", playerTable[activePlayer].color, msgColor)
  642.     end
  643.  
  644.     -- Death Touch
  645.     if object.getName() == "Death Touch" then
  646.       weapon['strength'] = weapon['strength'] + 1
  647.       broadcastToColor("Death Touch ~ (+1) Strength Calculated", playerTable[activePlayer].color, msgColor)
  648.     end
  649.   end
  650.  
  651.   gridObject.setTable("weapon", weapon)
  652. end
  653.  
  654. function CleanWeapon()
  655.   printToAll("Need gridObject to function in CleanWeapon", {1, 0, 0})
  656.   FistWeapon(gridObject)
  657.   Wait.frames(function() diceStats(gridObject) end, 1)
  658. end
  659.  
  660. -- Kijan
  661. -- maximo is it needed?
  662. -- function reset_Weapon_Prof()
  663. --  -- Enables Weapon Prof / Mastery
  664. --  local pos = fistToothToken.getPosition()
  665. --  local hitList = Physics.cast({
  666. --      origin          = {pos.x, pos.y, pos.z - 4},
  667. --      direction       = {0, 1, 0},
  668. --      type                = 2,
  669. --      size                = {1, 1, 1},
  670. --      max_distance    = 0,
  671. --  })
  672. --  for _, entry in ipairs(hitList) do
  673. --      if string.find(entry.hit_object.getDescription(), "proficiency, mastery") then
  674. --          entry.hit_object.setPosition(weapon_prof_pos)
  675. --          broadcastToAll("Your Weapon Proficiency / Mastery was Enabled", msg_color)
  676. --      end
  677. --  end
  678. -- end
  679.  
  680. function resetArmor(activePlayer)
  681.  
  682.   local zonePlayer = getObjectFromGUID(zonesTable[playerTable[activePlayer].playerZone].guid)
  683.   local gridObject = getObjectFromGUID(playerTable[activePlayer].gridGUID)
  684.   for _, wound in pairs(wounds) do
  685.     gridObject.UI.setAttribute(wound, "value", "false")
  686.     gridObject.UI.setAttribute(wound, "color", "#00000000")
  687.   end
  688.  
  689.   local objs = zonePlayer.getObjects()
  690.  
  691.   hasCrystalSkin = false
  692.   for _, obj in pairs(objs) do
  693.     if obj.getName() == "Crystal Skin" then
  694.       hasCrystalSkin = true
  695.     end
  696.   end
  697.  
  698.   local possibleHL = {head = 0, body = 0, waist = 0, arms = 0, legs = 0}
  699.  
  700.   for _, obj in pairs(objs) do
  701.     if obj.tag == 'Card' then
  702.       local descript = obj.getDescription()
  703.       if (string.find(descript, 'armor') and (not hasCrystalSkin)) or string.find(descript, 'accessory') or string.find(descript, 'shield') or string.find(descript, 'set') then
  704.         possibleHL = checkCardString(possibleHL, descript, activePlayer)
  705.       end -- end if string.find
  706.     end -- end if obj.tag
  707.   end -- end for loop
  708.  
  709.   for location, value in pairs(possibleHL) do
  710.     gridObject.UI.setAttribute(location, "text", value)
  711.   end
  712.  
  713.   -- reset_Weapon_Prof()
  714.  
  715.   --removes extra bleeding tokens for unconscious Fighter
  716.   local extraBleedPos = gridObject.getPosition()
  717.   extraBleedPos = {x = extraBleedPos.x + offsets.extraBleed.x, y = extraBleedPos.y + offsets.extraBleed.y - 3, z = extraBleedPos.z + offsets.extraBleed.z}
  718.  
  719.   getObjectFromGUID(playerTable[activePlayer].extraBleed).setPosition(extraBleedPos)
  720.  
  721.   --resets stat mods
  722.   for k, object in pairs(objs) do
  723.     local desc = object.getDescription()
  724.     if string.find(desc, 'token') or string.find(desc, "temp") then
  725.       object.destruct()
  726.     end
  727.   end
  728.  
  729.   --removes extra bleeding tokens for unconscious Fighter
  730.   local bleedTool = getObjectFromGUID(playerTable[activePlayer].bleedTool)
  731.   local isExtraButtons = bleedTool.getVar("extraBleed")
  732.   if isExtraButtons == true then
  733.     bleedTool.removeButton(5)
  734.     bleedTool.removeButton(6)
  735.     bleedTool.setVar("extraBleed", false)
  736.   end
  737.  
  738.   --this is the line that updates the tokens
  739.   survSheet = getObjectFromGUID(gridObject.getVar("survSheetGUID"))
  740.   if survSheet ~= nil then
  741.     getObjectFromGUID(SurvSheetScript).call("resetStats", {obj = survSheet})
  742.     getObjectFromGUID(SurvSheetScript).call("resetBrain", {obj = survSheet})
  743.   end
  744.   checkToken(survSheet, zonePlayer)
  745. end
  746.  
  747. function removeCard(descript, activePlayer)
  748.   local gridObject = getObjectFromGUID(playerTable[activePlayer].gridGUID)
  749.   local possibleHL = {head = 0, body = 0, waist = 0, arms = 0, legs = 0}
  750.   if string.find(descript, 'armor') or string.find(descript, 'accessory') or string.find(descript, 'shield') or string.find(descript, 'set') then
  751.     possibleHL = checkCardString(possibleHL, descript, activePlayer)
  752.   end
  753.   for location, value in pairs(possibleHL) do
  754.     gridObject.UI.setAttribute(location, "text", gridObject.UI.getAttribute(location, "text") - value)
  755.   end
  756. end
  757.  
  758. function checkCardString(possibleHL, descript, activePlayer)
  759.   for location, bonus in pairs(possibleHL) do
  760.     if string.find(descript, location) then
  761.       possibleHL[location] = bonus + tonumber(string.match(string.match(descript, '%d' .. location), '%d'))
  762.     end
  763.   end
  764.   return possibleHL
  765. end
  766.  
  767. -- Event Handlers --------------------------------------------------------------
  768. function onObjectEnterScriptingZone(zone, enter_object)
  769.   if enter_object ~= nil then
  770.     -------------------------- Start Body For Loop -----------------------------
  771.     local activePlayer = ""
  772.     local gridObject = nil
  773.     local msgColor = nil
  774.     local survCard = nil
  775.     for k, v in pairs(playerTable) do
  776.       if zonesTable[v.playerZone].guid == zone.getGUID() then
  777.         activePlayer = k
  778.         survCard = getObjectFromGUID(survCardsTable[v.color].guid)
  779.         msgColor = getObjectFromGUID(user_settings["settings_" .. k .. "_token"].guid).getColorTint()
  780.       end
  781.     end
  782.     if activePlayer ~= "" then
  783.       gridObject = getObjectFromGUID(playerTable[activePlayer].gridGUID)
  784.       local descript = enter_object.getDescription()
  785.       local rotZ = enter_object.getRotation().z
  786.  
  787.       -- Survivor Portrait
  788.       if enter_object.getName() == "Portrait" then
  789.         enter_object.setDescription(playerTable[activePlayer].playerName)
  790.         enter_object.call("clearButtons")
  791.         enter_object.call("createButtons")
  792.       end
  793.  
  794.       -- Heavy Gear while using People of the Sun
  795.       if string.find(descript, "heavy") then
  796.         local zoneNewSurvivors = getObjectFromGUID(zonesTable.zoneNewSurvivors.guid)
  797.         for _, obj in ipairs(zoneNewSurvivors.getObjects()) do
  798.           if string.find(obj.getDescription(), "sun") then
  799.             sunCampaign_loaded = true
  800.           end
  801.         end
  802.         if sunCampaign_loaded then
  803.           broadcastToAll("People of the Sun cannot use 'Heavy' Gear", {1, 1, 1})
  804.         end
  805.       end
  806.  
  807.       -- Darkness Awareness
  808.       if string.find(descript, "disorder") then
  809.         for k, v in pairs(playerTable) do
  810.           for _, obj in ipairs(getObjectFromGUID(zonesTable[v.playerZone].guid).getObjects()) do
  811.             if obj.getName() == "Darkness Awareness" then
  812.               if k == "P1" then
  813.                 broadcastToAll("Darkness Awareness ~ A Survivor gained a Disorder ~ You gain (+1) Survival and 1 Synapse Token", getObjectFromGUID(user_settings["settings_" .. k .. "_token"].guid).getColorTint())
  814.               elseif k == "P2" then
  815.                 broadcastToAll("Darkness Awareness ~ A Survivor gained a Disorder ~ You gain (+1) Survival and 1 Synapse Token", getObjectFromGUID(user_settings["settings_" .. k .. "_token"].guid).getColorTint())
  816.               elseif k == "P3" then
  817.                 broadcastToAll("Darkness Awareness ~ A Survivor gained a Disorder ~ You gain (+1) Survival and 1 Synapse Token", getObjectFromGUID(user_settings["settings_" .. k .. "_token"].guid).getColorTint())
  818.               elseif k == "P4" then
  819.                 broadcastToAll("Darkness Awareness ~ A Survivor gained a Disorder ~ You gain (+1) Survival and 1 Synapse Token", getObjectFromGUID(user_settings["settings_" .. k .. "_token"].guid).getColorTint())
  820.               end
  821.             end
  822.           end
  823.         end
  824.       end
  825.  
  826.       -- -- Lantern Helm
  827.       -- if enter_object.getName() == "Lantern Helm" and (rotZ > 165 and rotZ < 195) then
  828.       --   isDeaf.setRotation({0, 0, 180})
  829.       --   -- Glyph of Solitude
  830.       -- elseif enter_object.getName() == "Glyph of Solitude" and (rotZ > 165 and rotZ < 195) then
  831.       --   isDeaf.setRotation({0, 0, 180})
  832.       --   -- Deaf
  833.       -- elseif enter_object.getName() == "Deaf" then
  834.       --   isDeaf.setRotation({0, 0, 180})
  835.       -- end
  836.  
  837.       if ((enter_object.getName() == "Lantern Helm" or enter_object.getName() == "Glyph of Solitude") and (rotZ > 165 and rotZ < 195)) or enter_object.getName() == "Deaf" then
  838.         for _, object in ipairs(zone.getObjects()) do
  839.           if object.getName() == "isDeaf" then
  840.             object.setRotation({0, 0, 180})
  841.           end
  842.         end
  843.       end
  844.  
  845.       -- Husk of Destiny
  846.       -- Stark Raving
  847.       if enter_object.getName() == "Husk of Destiny" or enter_object.getName() == "Stark Raving" then
  848.         for _, obj in ipairs(zone.getObjects()) do
  849.           if obj.getName() == "isInsane" then
  850.             obj.setRotation({0, 0, 180})
  851.           end
  852.         end
  853.       end
  854.  
  855.       -- True Blade
  856.       if enter_object.getName() == "True Blade" then
  857.         for _, object in ipairs(zone.getObjects()) do
  858.           local desc = object.getDescription()
  859.           if string.find(desc, "sword") then
  860.             object.setDescription(desc .. ", deadly, true blade")
  861.           end
  862.         end
  863.       end
  864.       if string.find(descript, "sword") then
  865.         for _, object in ipairs(zone.getObjects()) do
  866.           if object.getName() == "True Blade" then
  867.             enter_object.setDescription(enter_object.getDescription() .. ", deadly, true blade")
  868.           end
  869.         end
  870.       end
  871.  
  872.       -- Emotionless
  873.       if enter_object.getName() == "Strength" and enter_object.getDescription() == 'token, plus1str' then
  874.         for _, object in ipairs(zone.getObjects()) do
  875.           if object.getName() == "Emotionless" then
  876.             broadcastToAll("Emotionless ~ You cannot gain (+1) Strength Tokens", msgColor)
  877.             enter_object.destroy()
  878.           end
  879.         end
  880.       end
  881.  
  882.       --Creates Armor Set Buttons on Survivor Cards
  883.       checkForArmorSets(enter_object.getName(), survCard, "create")
  884.  
  885.       -- Momentum
  886.       -- maximo
  887.       if enter_object.getName() == "Momentum" then
  888.         local obj = gameBox.takeObject({guid = momentum_Counter, position = momentum_on_pos, rotation = {0, 180, 0}, smooth = false})
  889.         obj.setLock(true)
  890.         survCard.call("createMomentumButton")
  891.       end
  892.  
  893.       -- Hissing Cockroach
  894.       if enter_object.getName() == "Hissing Cockroach" then
  895.         insanity = tonumber(gridObject.getVar("survSheetGUID").UI.getAttribute("insanity", "text"))
  896.         for _, obj in ipairs(zone.getObjects()) do
  897.           if (obj.getName() == "Husk of Destiny" or obj.getName() == "Stark Raving" or insanity >= 3) then
  898.             broadcastToAll("You are Insane and must consume the Hissing Cockroach", msgColor)
  899.             break
  900.           end
  901.         end
  902.       end -- end
  903.  
  904.       -- Possessed
  905.       -- maximo Why do you flip, set scale, clone and destroy? why not only setpos without clone and destroy? ;)
  906.       -- also for Hamstrung and Ruptured Muscle
  907.       if enter_object.getName() == "Possessed" then
  908.         for _, obj in ipairs(zone.getObjects()) do
  909.           local desc = obj.getDescription()
  910.           if string.find(desc, "fighting art") and (rotZ < 10 and rotZ > 350) then
  911.             local pos = obj.getPosition()
  912.             obj.flip()
  913.             obj.setScale({0.47, 1.00, 0.47})
  914.             obj.clone({position = pos})
  915.             obj.destroy()
  916.           elseif string.find(desc, "proficiency") then
  917.             obj.destroy()
  918.           end
  919.         end
  920.         broadcastToAll("Possessed ~ You cannot use Fighting Arts or Weapon Proficiencies", msgColor)
  921.       end -- end possessed
  922.  
  923.       -- Hamstrung Card Check
  924.       if enter_object.getName() == "Hamstrung" then
  925.         for _, object in ipairs(zone.getObjects()) do
  926.           local desc = object.getDescription()
  927.           if string.find(desc, "fighting art") and (rotZ < 10 or rotZ > 350) then
  928.             local pos = object.getPosition()
  929.             object.flip()
  930.             object.setScale({0.47, 1.00, 0.47})
  931.             object.clone({position = pos})
  932.             object.destroy()
  933.           elseif string.find(desc, "ability") and (rotZ < 10 or rotZ > 350) then
  934.             local pos = object.getPosition()
  935.             object.flip()
  936.             object.setScale({0.47, 1.00, 0.47})
  937.             object.clone({position = pos})
  938.             object.destroy()
  939.           end
  940.         end
  941.         broadcastToAll("Hamstrung ~ You can no longer Activate Fighting Arts or Abilities", msgColor)
  942.       end -- end Hamstrung
  943.  
  944.       -- Ruptured Muscle
  945.       if enter_object.getName() == "Ruptured Muscle" then
  946.         for _, object in ipairs(zone.getObjects()) do
  947.           local desc = object.getDescription()
  948.           if string.find(desc, "fighting art") and (rotZ < 10 or rotZ > 350) then
  949.             local pos = object.getPosition()
  950.             object.flip()
  951.             object.setScale({0.47, 1.00, 0.47})
  952.             object.clone({position = pos})
  953.             object.destroy()
  954.           end
  955.         end
  956.         broadcastToAll("Ruptured Muscle ~ You can no longer Activate Fighting Arts", msgColor)
  957.       end -- end Ruptured Muscle
  958.  
  959.       if (enter_object.getName() == "Strength"
  960.         or enter_object.getName() == "Speed"
  961.         or enter_object.getName() == "Accuracy"
  962.         or enter_object.getName() == "Movement Token"
  963.         or enter_object.getName() == "Evasion"
  964.       or enter_object.getName() == "Luck") then
  965.         -- Altered Destiny
  966.         if rotZ > 165 then
  967.           for _, object in ipairs(zone.getObjects()) do
  968.             if object.getName() == "Altered Destiny" and (rotZ < 10 or rotZ > 350) then
  969.               -- have to work on it for other token to spawn
  970.               -- Kijan
  971.               object.setRotation({0, 180, 0})
  972.               broadcastToAll("Altered Destiny ~ You gain a Positive Token Instead", msgColor)
  973.             end
  974.           end
  975.         end -- end Altered Destiny
  976.         -- Reset Display Stats on Avatars
  977.         Wait.time(function() set_portrait_buttons(survCard) end, 0.25)
  978.       end
  979.  
  980.       -- Eternal Will
  981.       if enter_object.getName() == "Eternal Will" and (rotZ < 10 or rotZ > 350) then
  982.         -- check for injuries
  983.         injury = 0
  984.         hasInjuries = false
  985.         for _, object in ipairs(zone.getObjects()) do
  986.           if string.find(object.getDescription(), "injury") then
  987.             hasInjuries = true
  988.             injury = injury + 1
  989.           end
  990.         end -- end check for injuries
  991.         -- if has injuries gain +1 acc and +1 str
  992.         if hasInjuries then
  993.           for i = 1, injury do
  994.             statsBag.accTokenPos.takeObject({position = {offsets.accToken.x, offsets.accToken.y + i * 0.5, offsets.accToken.z}, rotation = {0, 180, 0}})
  995.             statsBag.strTokenPos.takeObject({position = {offsets.strToken.x, offsets.strToken.y + i * 0.5, offsets.strToken.z}, rotation = {0, 180, 0}})
  996.           end
  997.           broadcastToAll("Eternal Will ~ You gained (+1) Accuracy and (+1) Strength for each Injury", msgColor)
  998.         end
  999.       end -- end Eternal Will
  1000.  
  1001.       -- Check for already has Eternal Will when gaining an injury
  1002.       hasEternalWill = false
  1003.       if enter_object.getDescription() == "essential, character, injury, drawn, copy" then
  1004.         for _, object in ipairs(zone.getObjects()) do
  1005.           if object.getName() == "Eternal Will" and (rotZ < 10 or rotZ > 350) then
  1006.             hasEternalWill = true
  1007.           end
  1008.         end
  1009.         if hasEternalWill then
  1010.           statsBag.accTokenPos.takeObject({position = {offsets.accToken.x, offsets.accToken.y, offsets.accToken.z}, rotation = {0, 180, 0}})
  1011.           statsBag.strTokenPos.takeObject({position = {offsets.strToken.x, offsets.strToken.y, offsets.strToken.z}, rotation = {0, 180, 0}})
  1012.           broadcastToAll("Eternal Will ~ You gained (+1) Accuracy ~ (+1) Strength for this injury", msgColor)
  1013.         end
  1014.       end -- end Eternal Will
  1015.  
  1016.       -- When you gain a Bleeding Token
  1017.       if enter_object.getName() == "Bleeding" then
  1018.         for _, object in ipairs(zone.getObjects()) do
  1019.  
  1020.           -- Ink Blood Bow
  1021.           if object.getName() == "Ink Blood Bow" then
  1022.             local token = statsBag.strTokenPos.takeObject({rotation = {0, 180, 0}, position = {offsets.strToken.x, offsets.strToken.y, offsets.strToken.z}})
  1023.             token.setDescription("token, plus1str, str_inkBow")
  1024.             broadcastToAll("Ink Blood Bow ~ You gained a (+1) Strength Token for gaining this Bleeding Token", msgColor)
  1025.           end
  1026.  
  1027.           -- Way of the Rust
  1028.           if object.getName() == "Way of the Rust" and (rotZ < 10 or rotZ > 350) then
  1029.             local token = statsBag.evaTokenPos.takeObject({position = offsets.evaToken, rotation = {0, 180, 0}})
  1030.             token.setDescription("token, plus1eva, eva_wayOfRust")
  1031.             broadcastToAll("Way of the Rust ~ You gained a (+1) Evasion Token for gaining this Bleeding Token", msgColor)
  1032.           end
  1033.         end
  1034.       end
  1035.  
  1036.       -- Red Power Core
  1037.       if enter_object.getName() == "Red Power Core" then
  1038.         for _, object in ipairs(zone.getObjects()) do
  1039.           if object.getName() == "Nuclear Knife" or object.getName() == "Nuclear Scythe" then
  1040.             object.setDescription(object.getDescription() .. ", sharp")
  1041.             broadcastToAll("Your " .. object.getName() .. " gained 'Sharp'", msgColor)
  1042.           end
  1043.         end
  1044.         -- Blue Power Core
  1045.       elseif enter_object.getName() == "Blue Power Core" then
  1046.         for _, object in ipairs(zone.getObjects()) do
  1047.           if object.getName() == "Nuclear Knife" or object.getName() == "Nuclear Scythe" then
  1048.             object.setDescription(object.getDescription() .. ", 2lck")
  1049.             broadcastToAll("Your " .. object.getName() .. " gained 'Deadly 2'", msgColor)
  1050.           end
  1051.         end
  1052.       end
  1053.       -- Nuclear Knife
  1054.       -- Nuclear Scythe
  1055.       if enter_object.getName() == "Nuclear Knife" or enter_object.getName() == "Nuclear Scythe" then
  1056.         for _, object in ipairs(zone.getObjects()) do
  1057.  
  1058.           -- Red Power Core
  1059.           if object.getName() == "Red Power Core" then
  1060.             local desc = enter_object.getDescription()
  1061.             enter_object.setDescription(desc .. ", sharp")
  1062.             broadcastToAll("Your " .. enter_object.getName() .. " gained 'Sharp'", {1, 1, 1})
  1063.  
  1064.             -- Blue Power Core
  1065.           elseif object.getName() == "Blue Power Core" then
  1066.             local desc = enter_object.getDescription()
  1067.             enter_object.setDescription(desc .. ", 2lck")
  1068.             broadcastToAll("Your " .. enter_object.getName() .. " gained 'Deadly 2'", msgColor)
  1069.           end
  1070.         end
  1071.       end -- end Power Cores
  1072.  
  1073.       --Black Sword
  1074.       if enter_object.getName() == "Black Sword" then
  1075.         for _, object in ipairs(zone.getObjects()) do
  1076.           -- Sword Proficiency
  1077.           if object.getName() == "Sword" and (rotZ < 10 or rotZ > 350) then
  1078.             local new_desc = string.gsub(enter_object.getDescription(), "10str", "30str")
  1079.             enter_object.setDescription(new_desc)
  1080.             broadcastToAll("Sword Master ~ Black Sword gained (+20) Strength", msgColor)
  1081.           end
  1082.         end
  1083.       end
  1084.       if enter_object.getName() == "Sword" and (rotZ < 10 or rotZ > 350) then
  1085.         for _, object in ipairs(zone.getObjects()) do
  1086.           if object.getName() == "Black Sword" then
  1087.             local new_desc = string.gsub(object.getDescription(), "10str", "30str")
  1088.             object.setDescription(new_desc)
  1089.             broadcastToAll("Sword Master ~ Black Sword gained (+20) Strength", msgColor)
  1090.           end
  1091.         end
  1092.       end -- end Black Sword
  1093.  
  1094.       -- Crystal Skin
  1095.       hasGloom = false
  1096.       if enter_object.getName() == "Crystal Skin" then
  1097.         for _, object in ipairs(zone.getObjects()) do
  1098.           if object.getName() == "Gloom Mehndi" then
  1099.             hasGloom = true
  1100.           end
  1101.         end
  1102.       end
  1103.       if hasGloom then
  1104.         local deck = getObjectFromGUID(Global.getTable("decks_toSearch").deckSTRANGE.guid)
  1105.         foundCard = false
  1106.         for _, card in ipairs(deck.getObjects()) do
  1107.           -- Crystal Sword Mold
  1108.           if string.find(card.description, "crystal sword mold") then
  1109.             foundCard = true
  1110.             deck.takeObject({guid = card.guid, position = playerTable[activePlayer].gained_resource_pos, callback_owner = Global, callback = "flipCard"})
  1111.           end
  1112.         end
  1113.         if foundCard then
  1114.           broadcastToAll("You gained the Crystal Sword Mold", msgColor)
  1115.         end
  1116.       end -- end Gloom Mehndi
  1117.  
  1118.       if enter_object.getName() == "Sword of Silence" then
  1119.         local survSheet = getObjectFromGUID(gridObject.getVar("survSheetGUID"))
  1120.         -- Get Understanding Value
  1121.         local understanding = 0
  1122.         for i = 1, 9 do
  1123.           if survSheet.UI.getAttribute("understanding0" .. i, "value") == "true" then
  1124.             understanding = understanding + 1
  1125.           end
  1126.         end -- end
  1127.  
  1128.         if understanding >= 5 then
  1129.           enter_object.setDescription(enter_object.getDescription() .. ", sharp")
  1130.           broadcastToAll("Sword of Silence ~ gained sharp due to your understanding", msgColor)
  1131.         end
  1132.       end
  1133.  
  1134.       -- Tool belt
  1135.       if enter_object.getName() == "Tool Belt" then
  1136.         for _, object in ipairs(zone.getObjects()) do
  1137.           local desc = object.getDescription()
  1138.  
  1139.           -- Bone Sickle
  1140.           if object.getName() == "Bone Sickle" then
  1141.             object.setDescription('gear, weapon, tool, bonesmith, 3spd, 5acc, 1str, green_up, copy')
  1142.             broadcastToAll("Tool Belt ~ Your Bone Sickle lost 'frail' and gained (+1) Speed and (+3) Accuracy", msgColor)
  1143.           end
  1144.  
  1145.           -- Bone Pickaxe
  1146.           if object.getName() == "Bone Pickaxe" then
  1147.             object.setDescription('gear, weapon, tool, bonesmith, 2spd, 5acc, 2str, green_up, copy')
  1148.             broadcastToAll("Tool Belt ~ Your Bone Pickaxe lost 'frail' and gained (+1) Speed and (+3) Accuracy", msgColor)
  1149.           end
  1150.         end
  1151.       end
  1152.       if enter_object.getName() == "Bone Sickle" then
  1153.         for _, object in ipairs(zone.getObjects()) do
  1154.           if object.getName() == "Tool Belt" then
  1155.             object.setDescription('gear, weapon, tool, bonesmith, 3spd, 5acc, 1str, green_up, copy')
  1156.             broadcastToAll("Tool Belt ~ Your Bone Sickle lost 'frail' and gained (+1) Speed and (+3) Accuracy", msgColor)
  1157.           end
  1158.         end
  1159.       end
  1160.       if enter_object.getName() == "Bone Pickaxe" then
  1161.         for _, object in ipairs(zone.getObjects()) do
  1162.           if object.getName() == "Tool Belt" then
  1163.             object.setDescription('gear, weapon, tool, bonesmith, 2spd, 5acc, 2str, green_up, copy')
  1164.             broadcastToAll("Tool Belt ~ Your Bone Pickaxe lost 'frail' and gained (+1) Speed and (+3) Accuracy", msgColor)
  1165.           end
  1166.         end
  1167.       end -- end Tool Belt
  1168.  
  1169.       -- Shielded Quiver
  1170.       if enter_object.getName() == "Shielded Quiver" then
  1171.         for _, object in ipairs(zone.getObjects()) do
  1172.           if string.find(object.getDescription(), "arrow") then
  1173.             object.call("setStartAmmoPlus1")
  1174.           end
  1175.         end
  1176.       end
  1177.       if string.find(descript, "arrow") then
  1178.         for _, object in ipairs(zone.getObjects()) do
  1179.           if object.getName() == "Shielded Quiver" then
  1180.             object.call("setStartAmmoPlus1")
  1181.           end
  1182.         end
  1183.       end -- end shielded quiver
  1184.  
  1185.       -- Quiver & Sun String
  1186.       if enter_object.getName() == "Quiver & Sun String" then
  1187.         local obj = gameBox.takeObject({guid = playerTable[activePlayer].extraSlots, position = gridObject.getPosition(), rotation = {0, 180, 0}, smooth = false})
  1188.         obj.setLock(true)
  1189.       end
  1190.  
  1191.       -- Silk Body Suit
  1192.       if enter_object.getName() == "Silk Body Suit" then
  1193.         for _, object in ipairs(zone.getObjects()) do
  1194.           local desc = object.getDescription()
  1195.           if string.find(desc, 'heavy') or string.find(desc, 'metal') then
  1196.             broadcastToAll("Silk Body Suit ~ You cannot use this ~ You have 'Heavy' or 'Metal' Gear", msgColor)
  1197.           end
  1198.         end
  1199.       end
  1200.       if string.find(descript, "heavy") or string.find(descript, "metal") then
  1201.         for _, object in ipairs(zone.getObjects()) do
  1202.           if object.getName() == "Silk Body Suit" then
  1203.             broadcastToAll("You cannot use Silk Body Suit while ----> " .. enter_object.getName() .. " is in your grid", msgColor)
  1204.           end
  1205.         end
  1206.       end -- end silk body suit
  1207.  
  1208.       --Resize Resources to fit card grid
  1209.       if string.find(descript, "resource") then
  1210.         enter_object.setScale({0.87, 1.00, 0.87})
  1211.       end -- resize resources
  1212.  
  1213.       if enter_object.getVar("isSurvSheet") then
  1214.         gridObject.setVar("survSheetGUID", enter_object.getGUID())
  1215.         gridObject.UI.setAttribute("movement", "text", enter_object.UI.getAttribute("movement", "text"))
  1216.         gridObject.UI.setAttribute("evasion", "text", enter_object.UI.getAttribute("evasion", "text"))
  1217.         enter_object.setVar("GridGUID", gridObject.getGUID())
  1218.         checkToken(enter_object, zone)
  1219.       end
  1220.  
  1221.       if enter_object.getVar("isKdmEffectsObject") then
  1222.         if gridObject.getVar("survSheetGUID") ~= "" then
  1223.           parseEffects(enter_object.call("getEffects"), 1, getObjectFromGUID(gridObject.getVar("survSheetGUID")))
  1224.         end
  1225.       end
  1226.  
  1227.       -- checks for gear bonus
  1228.       if enter_object.tag == 'Card' then
  1229.         if string.find(descript, 'armor') or string.find(descript, 'accessory') or string.find(descript, 'shield') or string.find(descript, 'set') or string.find(descript, 'set') then
  1230.           local possibleHL = {head = 0, body = 0, waist = 0, arms = 0, legs = 0}
  1231.           possibleHL = checkCardString(possibleHL, descript, activePlayer)
  1232.           for location, value in pairs(possibleHL) do
  1233.             gridObject.UI.setAttribute(location, "text", gridObject.UI.getAttribute(location, "text") + value)
  1234.           end
  1235.         end -- end if string.find(descript, 'armor')
  1236.       end -- if enter_object.tag == 'Card'
  1237.       Wait.frames(function() diceStats(gridObject) end, 1)
  1238.     end -- if activePlayer ~= "" then
  1239.   end -- end if enter_object ~= nil
  1240. end
  1241.  
  1242.  
  1243.  
  1244. function onObjectLeaveScriptingZone(zone, leave_object)
  1245.   if leave_object ~= nil then
  1246.     ----------------------------- Start Body ---------------------------------
  1247.     local activePlayer = ""
  1248.     local msgColor = nil
  1249.     local survCard = nil
  1250.     for k, v in pairs(playerTable) do
  1251.       if zonesTable[v.playerZone].guid == zone.getGUID() then
  1252.         activePlayer = k
  1253.         survCard = getObjectFromGUID(survCardsTable[v.color].guid)
  1254.         msgColor = getObjectFromGUID(user_settings["settings_" .. k .. "_token"].guid).getColorTint()
  1255.       end
  1256.     end
  1257.     if activePlayer ~= "" then
  1258.  
  1259.       local descript = leave_object.getDescription()
  1260.       local rotZ = leave_object.getRotation().z
  1261.  
  1262.       -- Reset Display Stats on Avatars
  1263.       if (leave_object.getName() == "Strength"
  1264.         or leave_object.getName() == "Speed"
  1265.         or leave_object.getName() == "Accuracy"
  1266.         or leave_object.getName() == "Movement Token"
  1267.         or leave_object.getName() == "Evasion"
  1268.       or leave_object.getName() == "Luck") then
  1269.         Wait.time(function() set_portrait_buttons(survCard) end, 0.25)
  1270.       end -- end display stats on avatars
  1271.  
  1272.       if ((leave_object.getName() == "Lantern Helm" or leave_object.getName() == "Glyph of Solitude") and (rotZ > 165 and rotZ < 195)) or leave_object.getName() == "Deaf" then
  1273.         for _, object in ipairs(zone.getObjects()) do
  1274.           if object.getName() == "isDeaf" then
  1275.             object.setRotation({0, 0, 0})
  1276.           end
  1277.         end
  1278.       end
  1279.  
  1280.       -- Husk of Destiny
  1281.       -- Stark Raving
  1282.       if leave_object.getName() == "Husk of Destiny" or leave_object.getName() == "Stark Raving" then
  1283.         for _, object in ipairs(zone.getObjects()) do
  1284.           if object.getName() == "isInsane" then
  1285.             object.setRotation({0, 0, 0})
  1286.           end
  1287.         end
  1288.       end
  1289.  
  1290.       if leave_object.getName() == "Sword of Silence" then
  1291.         if string.find(descript, ", sharp") then
  1292.           leave_object.setDescription("gear, weapon, melee, sword, other, 2spd, 5acc, 6str, sentient, irreplaceable, unique, blue_left, red_up, green_right, copy")
  1293.           broadcastToAll("Sword of Silence ~ lost sharp", msgColor)
  1294.         end
  1295.       end
  1296.  
  1297.       -- Ink Blood Bow
  1298.       if leave_object.getName() == "Bleeding" then
  1299.         hasInkBow = false
  1300.         count_blood = 0
  1301.         count_strength = 0
  1302.         for _, object in ipairs(zone.getObjects()) do
  1303.           if object.getName() == "Ink Blood Bow" then
  1304.             hasInkBow = true
  1305.           end
  1306.           if object.getName() == "Bleeding" then
  1307.             count_blood = count_blood + 1
  1308.           end
  1309.           if string.find(object.getDescription(), "str_inkBow") then
  1310.             count_strength = count_strength + 1
  1311.             str_token = object
  1312.           end
  1313.         end
  1314.         if hasInkBow then
  1315.           -- maximo
  1316.           -- why loop that trigger only once?^^
  1317.           for i = 1, 2 do
  1318.             str_token.destroy()
  1319.             break
  1320.           end
  1321.         end
  1322.       end
  1323.  
  1324.       -- True Blade
  1325.       if leave_object.getName() == "True Blade" then
  1326.         for _, object in ipairs(zone.getObjects()) do
  1327.           local desc = object.getDescription()
  1328.           if string.find(desc, "sword") and string.find(desc, ", deadly, true blade") then
  1329.             local new_desc = string.gsub(desc, ", deadly, true blade", "")
  1330.             object.setDescription(new_desc)
  1331.           end
  1332.         end
  1333.       end
  1334.  
  1335.       -- Bitter Frenzy
  1336.       if leave_object.getName() == "Bitter Frenzy" then
  1337.         getObjectFromGUID(playerTable[activePlayer].frenzyToken).setRotationSmooth({0, 180, 0}, false, false)
  1338.       end
  1339.  
  1340.       -- Fist & Tooth
  1341.       if leave_object.getName() == "Fist & Tooth" then
  1342.         survCard.call("remove_Fist_and_Tooth")
  1343.       end
  1344.  
  1345.       checkForArmorSets(leave_object.getName(), survCard, "remove")
  1346.  
  1347.       -- Momentum
  1348.       -- maximo
  1349.       if leave_object.getName() == "Momentum" then
  1350.         for _, obj in ipairs(zoneSurvivorStatus.getObjects()) do
  1351.           if obj.getName() == "momentum_Counter" and obj.getDescription() == color then
  1352.             gameBox.putObject(obj)
  1353.             survCard.call("removeMomentumButton")
  1354.           end
  1355.         end
  1356.       end
  1357.  
  1358.       -- Eternal Will
  1359.       if leave_object.getName() == "Eternal Will" then
  1360.         injury = 0
  1361.         hasInjuries = false
  1362.         for _, object in ipairs(zone.getObjects()) do
  1363.           local desc = object.getDescription()
  1364.           if string.find(desc, "injury") then
  1365.             hasInjuries = true
  1366.             injury = injury + 1
  1367.           end
  1368.           if hasInjuries then
  1369.             if object.getName() == "Strength" then
  1370.               for i = 1, injury do
  1371.                 object.destroy()
  1372.               end
  1373.             end
  1374.             if object.getName() == "Accuracy" then
  1375.               for i = 1, injury do
  1376.                 object.destroy()
  1377.               end
  1378.             end
  1379.           end -- end if hasInjuries
  1380.         end -- end for loop
  1381.       end -- end Eternal Will
  1382.  
  1383.       -- Red Power Core
  1384.       if leave_object.getName() == "Red Power Core" then
  1385.         for _, obj in ipairs(zone.getObjects()) do
  1386.           if obj.getName() == "Nuclear Knife" or obj.getName() == "Nuclear Scythe" then
  1387.             local desc = string.gsub(obj.getDescription(), ", sharp", "")
  1388.             obj.setDescription(desc)
  1389.             broadcastToAll("Your " .. obj.getName() .. " lost 'Sharp'", msgColor)
  1390.           end
  1391.         end
  1392.         -- Blue Power Core
  1393.       elseif leave_object.getName() == "Blue Power Core" then
  1394.         for _, object in ipairs(zone.getObjects()) do
  1395.           if object.getName() == "Nuclear Knife" or object.getName() == "Nuclear Scythe" then
  1396.             local desc = string.gsub(object.getDescription(), ", 2lck", "")
  1397.             object.setDescription(desc)
  1398.             broadcastToAll("Your " .. object.getName() .. " lost 'Deadly 2'", msgColor)
  1399.           end
  1400.         end
  1401.       end
  1402.  
  1403.       -- Nuclear Knife
  1404.       if leave_object.getName() == "Nuclear Knife" then
  1405.         if string.find(descript, ", 2lck") or string.find(descript, ", sharp") then
  1406.           leave_object.setDescription("gear, weapon, dragon armory, 3spd, 6acc, 3str, copy")
  1407.         end
  1408.  
  1409.         -- Nuclear Scythe
  1410.       elseif leave_object.getName() == "Nuclear Scythe" then
  1411.         --local desc = leave_object.getDescription()
  1412.         if string.find(descript, ", 2lck") or string.find(descript, ", sharp") then
  1413.           leave_object.setDescription("gear, weapon, dragon armory, 2spd, 6acc, 4str, copy")
  1414.         end
  1415.       end -- end Power Cores, Nuclear
  1416.  
  1417.       --Black Sword
  1418.       if leave_object.getName() == "Black Sword" then
  1419.         if string.find(descript, "20str") then
  1420.           local new_desc = string.gsub(descript, "30str", "10str")
  1421.           leave_object.setDescription(new_desc)
  1422.         end
  1423.       end -- end Black Sword
  1424.  
  1425.       -- Tool belt
  1426.       -- maximo
  1427.       if leave_object.getName() == "Tool Belt" then
  1428.         for _, object in ipairs(zone.getObjects()) do
  1429.           if object.getName() == "Bone Sickle" then
  1430.             object.setDescription('gear, weapon, tool, bonesmith, 2spd, 8acc, 1str, green_up, frail, copy')
  1431.             broadcastToAll("Tool Belt ~ Your Bone Sickle lost 'frail' and gained (+1) Speed and (+3) Accuracy", msgColor)
  1432.           end
  1433.           if object.getName() == "Bone Pickaxe" then
  1434.             object.setDescription('gear, weapon, tool, bonesmith, 1spd, 8acc, 2str, green_up, frail, copy')
  1435.             broadcastToAll("Tool Belt ~ Your Bone Pickaxe lost 'frail' and gained (+1) Speed and (+3) Accuracy", msgColor)
  1436.           end
  1437.         end
  1438.       end
  1439.       if leave_object.getName() == "Bone Sickle" then
  1440.         leave_object.setDescription('gear, weapon, tool, bonesmith, 2spd, 8acc, 1str, green_up, frail, copy')
  1441.       end
  1442.       if leave_object.getName() == "Bone Pickaxe" then
  1443.         leave_object.setDescription('gear, weapon, tool, bonesmith, 1spd, 8acc, 2str, green_up, frail, copy')
  1444.       end -- end Tool Belt
  1445.  
  1446.       -- Shielded Quiver
  1447.       if leave_object.getName() == "Shielded Quiver" then
  1448.         for _, object in ipairs(zone.getObjects()) do
  1449.           local desc = object.getDescription()
  1450.           if string.find(desc, "ammunition") then
  1451.             object.call("setStartAmmo")
  1452.           end
  1453.         end
  1454.       end -- end shielded quiver
  1455.  
  1456.       -- Quiver & Sun String
  1457.       if leave_object.getName() == "Quiver & Sun String" then
  1458.         for _, obj in ipairs(zone.getObjects()) do
  1459.           if obj.getName() == "Extra Slots" then
  1460.             gameBox.putObject(obj)
  1461.           end
  1462.         end
  1463.       end -- end
  1464.  
  1465.       --Resize resources to fit card grid
  1466.       if leave_object.tag == 'Card' then
  1467.         if string.find(descript, "resource") then
  1468.           leave_object.setScale({1.10, 1.00, 1.10})
  1469.         end
  1470.       end -- end resource size
  1471.  
  1472.       if leave_object.getVar("isSurvSheet") then
  1473.         getObjectFromGUID(playerTable[activePlayer].gridGUID).setVar("survSheetGUID", "")
  1474.         getObjectFromGUID(SurvSheetScript).call("resetStats", {obj = leave_object})
  1475.         getObjectFromGUID(SurvSheetScript).call("resetBrain", {obj = leave_object})
  1476.         leave_object.setVar("GridGUID", "")
  1477.       end
  1478.  
  1479.       if leave_object.getVar("isKdmEffectsObject") then
  1480.         local survSheet = nil
  1481.         survSheet = getObjectFromGUID(getObjectFromGUID(playerTable[activePlayer].gridGUID).getVar("survSheetGUID"))
  1482.         if survSheet ~= nil then
  1483.           parseEffects(leave_object.call("getEffects"), - 1, survSheet)
  1484.         end
  1485.       end
  1486.  
  1487.       --gear bonus
  1488.       if leave_object.tag == 'Card' then
  1489.         removeCard(leave_object.getDescription(), activePlayer)
  1490.       end
  1491.       Wait.frames(function() diceStats(getObjectFromGUID(playerTable[activePlayer].gridGUID)) end, 1)
  1492.  
  1493.     end -- end if activePlayer ~= ""
  1494.  
  1495.   end -- end if leave_object ~= nil
  1496. end
  1497.  
  1498.  
  1499. function onObjectDestroyed(dying_object)
  1500.  
  1501.   for k, v in pairs(playerTable) do
  1502.     zone = getObjectFromGUID(zonesTable[v.playerZone].guid)
  1503.     for _, obj in pairs(zone.getObjects()) do
  1504.       if obj == dying_object then
  1505.         onObjectLeaveScriptingZone(zone, dying_object)
  1506.       end
  1507.     end
  1508.   end
  1509. end
  1510.  
  1511. -- Survivor Died ---------------------------------------------------------------
  1512. function survDiedButton(graveObj, msgColor, activePlayer)
  1513.   graveObj.setScale({1.35, 1.35, 1.35})
  1514.   graveObj.setLock(true)
  1515.   graveObj.createButton({
  1516.     -- click_function = 'burySurvivor',
  1517.     click_function = function() burySurvivor(activePlayer) end,
  1518.     function_owner = self,
  1519.     label = 'Bury this Survivor',
  1520.     position = {0, 0, - 0.6},
  1521.     rotation = {0, 180, 0},
  1522.     scale = { 0.5, 1, 0.5},
  1523.     width = 2700,
  1524.     height = 400,
  1525.     font_size = 300,
  1526.     color = {0, 0, 0},
  1527.     font_color = msgColor
  1528.   })
  1529. end
  1530.  
  1531. function survDied(graveObj, survSheet, msgColor, activePlayer)
  1532.   --Gets Survivor Storage Bag
  1533.   infiBag = getObjectFromGUID(SurvMemBag)
  1534.   bag = infiBag.clone({position = graveObj.getPosition()})
  1535.   setModel(bag, survSheet, msgColor)
  1536.   Wait.time(
  1537.     function()
  1538.       bag.call('recallZone', {zonesTable[playerTable[activePlayer].playerZone].guid, self.guid, true})
  1539.       return_role(activePlayer)
  1540.       graveObj.setName(bag.getName())
  1541.     end
  1542.     , 0.2
  1543.   )
  1544. end
  1545.  
  1546. function get_basic_for_cannibalize()
  1547.   deckBasicResourcesZone = getObjectFromGUID(zonesTable.deckBasicResources.guid)
  1548.   for _, obj in ipairs(deckBasicResourcesZone.getObjects()) do
  1549.     if obj.getName() == "Basic Resources Deck" then
  1550.       obj.shuffle()
  1551.       obj.takeObject({top = true, position = playerTable[activePlayer].cannibalizeResourcePos, callback_owner = Global, callback = "flipCard"})
  1552.       broadcastToAll("Cannibalize Death Principle Triggered", {1, 1, 1})
  1553.       break
  1554.     end
  1555.   end
  1556. end
  1557.  
  1558. function set_skull_dead_token(activePlayer)
  1559.   -- Spawns Dead Skull Token
  1560.   local skull_dead_token = gameBox.takeObject({guid = playerTable[activePlayer].skullDeadToken, position = playerTable[activePlayer].skullDeadPos, rotation = {0.00, 180.00, 0.00}, smooth = false, callback = "lockShadowToken", callback_owner = Global})
  1561.   getObjectFromGUID(menuTokensTable[playerTable[activePlayer].color].guid).call("removeButtons_all")
  1562.   getObjectFromGUID(survCardsTable[playerTable[activePlayer].color].guid).call("clearButtons")
  1563.  
  1564.   --Sets Survivor miniature on survCards
  1565.   found_dreadedTrophies = false
  1566.   for _, card in ipairs(zoneInjuryBoard.getObjects()) do
  1567.     -- Dreaded Trophies
  1568.     if card.getName() == "Dreaded Trophies" then
  1569.       found_dreadedTrophies = true
  1570.     end
  1571.   end
  1572.  
  1573.   for _, object in ipairs(zoneShowdown.getObjects()) do
  1574.     if object.getName() == playerTable[activePlayer].playerName then
  1575.       object.setScale({0.25, 0.25, 0.25})
  1576.       if found_dreadedTrophies then
  1577.         trophy_count = 0
  1578.         for _, surv in ipairs(zoneInjuryBoard.getObjects()) do
  1579.           if string.find(surv.getName(), "Player") then
  1580.             trophy_count = trophy_count + 1
  1581.           end
  1582.         end
  1583.         if trophy_count < 1 then
  1584.           object.setPosition({ - 2.64, 4.63, - 20.40})
  1585.         elseif trophy_count == 1 then
  1586.           object.setPosition({ - 2.64, 4.63, - 21.40})
  1587.         elseif trophy_count == 2 then
  1588.           object.setPosition({ - 2.65, 4.63, - 22.44})
  1589.         end
  1590.       else
  1591.         object.setRotation(surv_died_rot)
  1592.         object.setPosition(surv_died_pos)
  1593.         object.setScale({0.25, 0.25, 0.25})
  1594.         object.setLock(true)
  1595.       end
  1596.     end
  1597.   end
  1598. end
  1599.  
  1600. function updatePopulation()
  1601.   local zoneSettlement = getObjectFromGUID(zonesTable.zoneSettlement.guid)
  1602.   for _, object in ipairs(zoneSettlement.getObjects()) do
  1603.     if string.find(object.getDescription(), "SettlementSheet") then
  1604.       object.call("add", {"population", - 1})
  1605.     end
  1606.   end
  1607. end
  1608.  
  1609. -- Save Survivor ---------------------------------------------------------------
  1610. function clickedSaveSurv(params)
  1611.   local activePlayer = ""
  1612.   for k, v in pairs(playerTable) do
  1613.     if v.gridGUID == params.obj.getGUID() then
  1614.       activePlayer = k
  1615.     end
  1616.   end
  1617.  
  1618.   local pos = params.obj.getPosition()
  1619.   local hitList = Physics.cast({
  1620.     origin = {pos.x, pos.y + 2, pos.z - 8},
  1621.     direction = {0, 1, 0},
  1622.     type = 2,
  1623.     size = {3, 1, 3},
  1624.     max_distance = 0,
  1625.   })
  1626.   for _, entry in ipairs(hitList) do
  1627.     if next(hitList) ~= nil then
  1628.       broadcastToColor("Move Current saved Survivor First!", playerTable.color, getObjectFromGUID(user_settings["settings_" .. activePlayer .. "_token"].guid).getColorTint())
  1629.       return
  1630.     end
  1631.   end
  1632.  
  1633.   resetArmor(activePlayer)
  1634.  
  1635.   -- Destined
  1636.   for _, object in ipairs( getObjectFromGUID(zonesTable[playerTable[activePlayer].playerZone].guid).getObjects()) do
  1637.     if object.getName() == "Destined" then
  1638.       broadcastToColor("Destined ~ If you do not Depart, lose all Survival and Insanity", player_color, msg_color)
  1639.     end
  1640.   end
  1641.  
  1642.   infiBag = getObjectFromGUID(SurvMemBag)
  1643.   local bag = infiBag.clone({position = {pos.x, pos.y, pos.z - 8}})
  1644.   setModel(bag)
  1645.   Wait.time(function() saveSurv(bag) end, 0.3)
  1646. end
  1647.  
  1648. function saveSurv(bag)
  1649.   bag.call('recallZone', {zonesTable[playerTable[activePlayer].playerZone].guid, params.obj.getGUID()})
  1650.   -- activePlayer instead of role
  1651.   return_role(activePlayer)
  1652. end
  1653.  
  1654. function setModel(bag, survSheet, msgColor)
  1655.   if survSheet.UI.getAttribute("male", "value") then
  1656.     local rand = math.random(#survivorBags.male)
  1657.     bag.setCustomObject({mesh = survivorBags.male[rand].mesh, diffuse = survivorBags.male[rand].diffuse})
  1658.   else
  1659.     local rand = math.random(#survivorBags.female)
  1660.     bag.setCustomObject({mesh = survivorBags.female[rand].mesh, diffuse = survivorBags.female[rand].diffuse})
  1661.   end
  1662.   bag.setColorTint(msgColor)
  1663. end
  1664.  
  1665.  
  1666.  
  1667.  
  1668.  
  1669. -- Utility Functions -----------------------------------------------------------
  1670. -- function findProximity(targetPos, object)
  1671. --   local objectPos = object.getPosition()
  1672. --   local xDistance = math.abs(targetPos.x - objectPos.x)
  1673. --   local zDistance = math.abs(targetPos.z - objectPos.z)
  1674. --   local distance = xDistance^2 + zDistance^2
  1675. --   return math.sqrt(distance)
  1676. -- end
  1677.  
  1678. function get_player_pos(PlayerName)
  1679.   for _, object in ipairs(zoneShowdown.getObjects()) do
  1680.     if object.getName() == PlayerName then
  1681.       pos_player = object.getPosition()
  1682.     end
  1683.   end
  1684.   return pos_player
  1685. end
  1686.  
  1687. function set_portrait_buttons(survCard)
  1688.   local pos = survCard.getPosition()
  1689.   local hitList = Physics.cast({
  1690.     origin = {pos.x, pos.y, pos.z},
  1691.     direction = {0, 1, 0},
  1692.     type = 2,
  1693.     size = {2, 2, 2},
  1694.     max_distance = 0,
  1695.   })
  1696.   for _, entry in ipairs(hitList) do
  1697.     if entry.hit_object.getName() == "Portrait" then
  1698.       entry.hit_object.call("createButtons")
  1699.     end
  1700.   end
  1701. end
  1702.  
  1703. function return_role(activePlayer)
  1704.   local hitList = Physics.cast({
  1705.     origin = playerTable[activePlayer].rolePosition,
  1706.     direction = {0, 1, 0},
  1707.     type = 2,
  1708.     size = {1, 1, 1},
  1709.     max_distance = 0
  1710.   })
  1711.   for _, entry in ipairs(hitList) do
  1712.     if string.find(entry.hit_object.getDescription(), "role") then
  1713.       getObjectFromGUID(playerTable[activePlayer].gridGUID).setVar("role", entry.hit_object.getName())
  1714.     end
  1715.     if entry.hit_object.getName() == "Portrait" then
  1716.       local pos = getObjectFromGUID(playerTable[activePlayer].gridGUID).getPosition()
  1717.       entry.hit_object.setPosition({pos.x, 10, pos.z - 8})
  1718.     end
  1719.   end
  1720. end
  1721.  
  1722. function deleteCard(objGUID)
  1723.   printToAll("Need activePlayer for deleteCard!", {1, 0, 0})
  1724.   obj = getObjectFromGUID(objGUID[1])
  1725.   removeCard(obj.getDescription(), activePlayer)
  1726.   obj.destruct()
  1727. end
  1728.  
  1729. function diceStatsEx(params)
  1730.   diceStats(params[1])
  1731. end
  1732.  
  1733. function diceStats(gridObject)
  1734.   survSheet = getObjectFromGUID(gridObject.getVar("survSheetGUID"))
  1735.  
  1736.   if survSheet == nil then
  1737.     return
  1738.   end
  1739.   -- local EvaBtn = FullCharSheet.getTable("buttons")
  1740.   -- if EvaBtn == nil then
  1741.   --    return
  1742.   -- end
  1743.   local monstr = getObjectFromGUID(Global.getTable("boards").boardMonster.guid)
  1744.   local butn = {toughness = {label = 0}, evasion = {label = 0}, luck = {label = 0}}
  1745.   local weapon = gridObject.getTable("weapon")
  1746.   if weapon == nil then return end
  1747.   if monstr ~= nil then
  1748.     butn = monstr.getTable("buttons")
  1749.   end
  1750.  
  1751.   -- buttons['attack'].label
  1752.   gridObject.UI.setAttribute("speed", "text", tonumber(survSheet.UI.getAttribute("speed", "text")) + weapon['speed'])
  1753.   -- buttons['wound'].label =
  1754.   gridObject.UI.setAttribute("strength", "text", tonumber(butn['toughness'].label) - tonumber(survSheet.UI.getAttribute("strength", "text")) - weapon['strength'])
  1755.   -- buttons['hit'].label =
  1756.   gridObject.UI.setAttribute("accuracy", "text", 10 - tonumber(survSheet.UI.getAttribute("accuracy", "text")) - weapon['accuracy'] + tonumber(butn['evasion'].label))
  1757.   -- buttons['crit'].label =
  1758.   gridObject.UI.setAttribute("luck", "text", 10 + tonumber(butn['luck'].label) - tonumber(survSheet.UI.getAttribute("luck", "text")) - weapon['luck'])
  1759.  
  1760.   gridObject.UI.setAttribute("movement", "text", survSheet.UI.getAttribute("movement", "text"))
  1761.   gridObject.UI.setAttribute("evasion", "text", survSheet.UI.getAttribute("evasion", "text"))
  1762.  
  1763.   -- portrait stat display
  1764.   -- portrait_attack = tonumber(survSheet.UI.getAttribute("speed", "text")) + weapon['speed']
  1765.   -- portrait_wound = tonumber(butn['toughness'].label) - tonumber(survSheet.UI.getAttribute("strength", "text")) - weapon['strength']
  1766.   -- portrait_hit = 10 - tonumber(survSheet.UI.getAttribute("accuracy", "text")) - weapon['accuracy'] + tonumber(butn['evasion'].label)
  1767.   -- portrait_crit = 10 + tonumber(butn['luck'].label) - tonumber(survSheet.UI.getAttribute("luck", "text")) - weapon['luck']
  1768.  
  1769. end
  1770.  
  1771.  
  1772. -- end InventoryP1 -------------------------------------------------------------
  1773.  
  1774.  
  1775. -- Tokens ----------------------------------------------------------------------
  1776. function checkToken(survSheet, zonePlayer)
  1777.   for _, v in pairs(zonePlayer.getObjects()) do
  1778.     if v.getVar("isKdmEffectsObject") then
  1779.       if survSheet ~= nil then
  1780.         parseEffects(v.call("getEffects"), 1, survSheet)
  1781.       end
  1782.     end
  1783.   end
  1784. end
  1785.  
  1786. function checkTokenDelayed(zonePlayer, survCard, survSheet, activePlayer)
  1787.   for _, object in ipairs(zonePlayer.getObjects()) do
  1788.     -- Momentum
  1789.     if object.getName() == "Momentum" then
  1790.       survCard.call("createMomentumButton")
  1791.     end
  1792.  
  1793.     checkForArmorSets(object.getName(), survCard, "create")
  1794.   end
  1795.  
  1796.   if survSheet ~= nil then
  1797.     getObjectFromGUID(SurvSheetScript).call("resetStats", {obj = survSheet})
  1798.     Wait.frames(function() checkToken(survSheet, zonePlayer) end, 1)
  1799.   end
  1800.  
  1801.   Wait.frames(function() checkWeapon(activePlayer) end, 2)
  1802. end
  1803.  
  1804. function checkForArmorSets(name, survCard, createRemove)
  1805.   -- Crossarm Block
  1806.   if name == "Crossarm Block" then
  1807.     survCard.call(createRemove .. "CrossarmBlockButton")
  1808.   end
  1809.  
  1810.   -- Century Shoulder Pads
  1811.   if name == "Century Shoulder Pads" or name == "Calcified Shoulder Pads" then
  1812.     survCard.call(createRemove .. "RipplePatternButton")
  1813.   end
  1814.  
  1815.   -- Fencing
  1816.   if name == "Fencing" then
  1817.     survCard.call(createRemove .. "FencingButton")
  1818.   end
  1819.   -- Steadfast
  1820.   if name == "Steadfast" then
  1821.     survCard.call(createRemove .. "SteadfastButton")
  1822.   end
  1823.  
  1824.   -- Stalwart
  1825.   if name == "Stalwart" then
  1826.     survCard.call(createRemove .. "StalwartButton")
  1827.   end
  1828.  
  1829.   -- Leather Armor
  1830.   -- Burnt Nerves
  1831.   if name == "Leather Armor" or name == "Burnt Nerves" then
  1832.     survCard.call(createRemove .. "BashButton")
  1833.   end
  1834.  
  1835.   -- Honorable
  1836.   if name == "Honorable" then
  1837.     local buttons = survCard.getButtons()
  1838.     for i, v in pairs(buttons) do
  1839.       if createRemove == "create" and v.label == "Attack Blind" then
  1840.         survCard.removeButton(v.index)
  1841.         survCard.call('create_Honorable_Button')
  1842.       elseif createRemove == "remove" and v.label == "Honorable" then
  1843.         survCard.removeButton(v.index)
  1844.         survCard.call('create_AttackBlind_Button')
  1845.       end
  1846.     end
  1847.   end
  1848. end
  1849.  
  1850. function parseEffects(effects, multiplier, survSheet)
  1851.   for i, v in pairs(effects) do
  1852.     if i == "move" then
  1853.       i = "movement"
  1854.     end
  1855.     survSheet.UI.setAttribute(i, "text", survSheet.UI.getAttribute(i, "text") + (v * multiplier))
  1856.   end
  1857. end
  1858.  
  1859. function checkLoaded(obj)
  1860.   if not obj.loading_custom and not obj.spawning then
  1861.     return true
  1862.   end
  1863.  
  1864.   return false
  1865. end
  1866.  
  1867.  
  1868. --------------------------------------------------------------------------------
  1869.  
  1870. -- Survivor Sheet Code
  1871. NEXT = 1
  1872. PREV = -1
  1873.  
  1874. playerTable = {
  1875.   P1 = {msg_color = {0.118, 0.53, 1}}
  1876.   , P2 = {msg_color = {0.192, 0.701, 0.168}}
  1877.   , P3 = {msg_color = {0.905, 0.898, 0.172}}
  1878.   , P4 = {msg_color = {1, 0.14, 0}}
  1879. }
  1880.  
  1881. function toggleCheckBox(params)
  1882.   local name = params.id:sub(1, - 3)
  1883.   local num = tonumber(params.id:sub(-2))
  1884.   if params.id == "female" or params.id == "femaleB" then
  1885.     params.obj.UI.setAttribute("male", "value", "false")
  1886.     params.obj.UI.setAttribute("male", "color", "#00000000")
  1887.     params.obj.UI.setAttribute("maleB", "value", "false")
  1888.     params.obj.UI.setAttribute("maleB", "color", "#00000000")
  1889.   elseif params.id == "male" or params.id == "maleB" then
  1890.     params.obj.UI.setAttribute("female", "value", "false")
  1891.     params.obj.UI.setAttribute("female", "color", "#00000000")
  1892.     params.obj.UI.setAttribute("femaleB", "value", "false")
  1893.     params.obj.UI.setAttribute("femaleB", "color", "#00000000")
  1894.   end
  1895.   if params.obj.UI.getAttribute(params.id, "value") == "false" and checkForPreviousNext(params.obj, name, num, PREV) then
  1896.     params.obj.UI.setAttribute(params.id, "value", "true")
  1897.     params.obj.UI.setAttribute(params.id, "color", "#000000")
  1898.     if params.id:sub(-1) == "B" then
  1899.       params.obj.UI.setAttribute(params.id:sub(1, - 2), "value", "true")
  1900.       params.obj.UI.setAttribute(params.id:sub(1, - 2), "color", "#000000")
  1901.     end
  1902.     params.obj.UI.setAttribute(params.id .. "B", "value", "true")
  1903.     params.obj.UI.setAttribute(params.id .. "B", "color", "#000000")
  1904.  
  1905.   elseif num == nil or not checkForPreviousNext(params.obj, name, num, NEXT) then
  1906.     params.obj.UI.setAttribute(params.id, "value", "false")
  1907.     params.obj.UI.setAttribute(params.id, "color", "#00000000")
  1908.     if params.id:sub(-1) == "B" then
  1909.       params.obj.UI.setAttribute(params.id:sub(1, - 2), "value", "false")
  1910.       params.obj.UI.setAttribute(params.id:sub(1, - 2), "color", "#00000000")
  1911.     end
  1912.     params.obj.UI.setAttribute(params.id .. "B", "value", "false")
  1913.     params.obj.UI.setAttribute(params.id .. "B", "color", "#00000000")
  1914.   end
  1915. end
  1916.  
  1917. function checkForPreviousNext(obj, name, num, prevNext)
  1918.   if num ~= nil then
  1919.     if obj.UI.getAttribute(name .. string.format("%02d", num + prevNext), "value") ~= nil then
  1920.       if obj.UI.getAttribute(name .. string.format("%02d", num + prevNext), "value") == "true" then
  1921.         return true
  1922.       else
  1923.         return false
  1924.       end
  1925.     else
  1926.       return prevNext == PREV and true or false
  1927.     end
  1928.   end
  1929.   return true
  1930. end
  1931.  
  1932. function onValueChanged(params)
  1933.   params.obj.UI.setAttribute(params.id, "text", params.value)
  1934.   if params.id:find("name") and params.id ~= "nickname" then
  1935.     params.obj.UI.setAttribute("name", "text", params.value)
  1936.     params.obj.UI.setAttribute("nameB", "text", params.value)
  1937.     params.obj.UI.setAttribute("nameFamily", "text", params.value)
  1938.     params.obj.setName(params.value)
  1939.   end
  1940. end
  1941.  
  1942. function counter(params)
  1943.   local amount = tonumber(params.id)
  1944.   local isInsane = (tonumber(params.obj.UI.getAttribute("insanity", "text")) > 2) and true or false
  1945.   local grid = nil
  1946.   if params.grid ~= "" then
  1947.     grid = getObjectFromGUID(params.grid)
  1948.   end
  1949.  
  1950.   if params.value == "survival" then
  1951.     local apathetic = false
  1952.     -- when survival is been added
  1953.     if amount > 0 then
  1954.       if grid ~= nil then
  1955.         local bounds = grid.getBounds()
  1956.         local hitlist = Physics.cast({
  1957.           origin = bounds.center,
  1958.           direction = {0, 5, 0},
  1959.           type = 3,
  1960.           size = bounds.size,
  1961.           max_distance = 0,
  1962.           debug = false
  1963.         }) -- returns {{Vector point, Vector normal, float distance, Object hit_object}, ...}
  1964.  
  1965.         for _, t in pairs(hitlist) do
  1966.           if t.hit_object.getName() == "Thrill Seeker" then
  1967.             local check_current_phase_tok = getObjectFromGUID('9091f8')
  1968.             local desc = check_current_phase_tok.getDescription()
  1969.             if desc == "Showdown Started" then
  1970.               amount = amount + 1
  1971.               broadcastToAll("Thrill Seeker ~ You gained an Additional Survival", msg_color)
  1972.             end
  1973.           elseif t.hit_object.getName() == "Apathetic" then
  1974.             amount = 0
  1975.             broadcastToAll("Apathetic ~ You cannot gain Survival", msg_color)
  1976.           end
  1977.         end
  1978.       end
  1979.  
  1980.  
  1981.       -- when survival is been removed
  1982.     elseif amount < 0 then
  1983.       if grid ~= nil then
  1984.         local bounds = grid.getBounds()
  1985.         local hitlist = Physics.cast({
  1986.           origin = bounds.center,
  1987.           direction = {0, 5, 0},
  1988.           type = 3,
  1989.           size = bounds.size,
  1990.           max_distance = 0,
  1991.           debug = false
  1992.         }) -- returns {{Vector point, Vector normal, float distance, Object hit_object}, ...}
  1993.  
  1994.         for _, t in pairs(hitlist) do
  1995.           if t.hit_object.getName() == "Immortal" and isInsane then
  1996.             amount = 0
  1997.             broadcastToAll("Immortal ~ You cannot spend Survival while insane", msg_color)
  1998.           elseif t.hit_object.getName() == "Prey" and not isInsane then
  1999.             amount = 0
  2000.             broadcastToAll("Prey ~ You can only spend Survival while insane", msg_color)
  2001.           elseif t.hit_object.getName() == "Apathetic" then
  2002.             amount = 0
  2003.             broadcastToAll("Apathetic ~ You cannot use Survival", msg_color)
  2004.           elseif t.hit_object.getName() == "Ghostly Beauty" then
  2005.             amount = amount * 2
  2006.             if tonumber(params.obj.UI.getAttribute(params.value, "text")) + amount < 0 then
  2007.               amount = 0
  2008.               broadcastToAll("Ghostly Beauty ~ You cannot spend survival because it is doubled", msg_color)
  2009.             else
  2010.               broadcastToAll("Ghostly Beauty ~ Your Survival use was Doubled", msg_color)
  2011.             end
  2012.           end
  2013.         end
  2014.       end
  2015.     end
  2016.   end
  2017.  
  2018.   if params.value == "insanity" and amount > 0 and grid ~= nil then
  2019.     local bounds = grid.getBounds()
  2020.     local hitlist = Physics.cast({
  2021.       origin = bounds.center,
  2022.       direction = {0, 5, 0},
  2023.       type = 3,
  2024.       size = bounds.size,
  2025.       max_distance = 0,
  2026.       debug = false
  2027.     }) -- returns {{Vector point, Vector normal, float distance, Object hit_object}, ...}
  2028.  
  2029.     for _, t in pairs(hitlist) do
  2030.       if t.hit_object.getName() == "Ghostly Beauty" then
  2031.         amount = amount * 2
  2032.         broadcastToAll("Ghostly Beauty ~ Doubled all Insanity you gain", msg_color)
  2033.       end
  2034.     end
  2035.   end
  2036.  
  2037.   local value = tonumber(params.obj.UI.getAttribute(params.value, "text")) + amount
  2038.   local base = tonumber(params.obj.UI.getAttribute(params.value, "base")) + amount
  2039.  
  2040.   if params.value == "survival" or params.value == "insanity" then
  2041.     value = math.max(value, 0)
  2042.     base = math.max(base, 0)
  2043.   end
  2044.  
  2045.   if params.value == "survival" then
  2046.     -- zoneGuid = Global.getTable("zones").zoneSettlement.guid
  2047.         -- zoneObj = getObjectFromGUID(zoneGuid).getObjects()
  2048.         -- for _, v in pairs(zoneObj) do
  2049.         --  if v.getDescription() == "SettlementSheet" then
  2050.         --      survlimit = v.getTable("buttons").survival_limit.label
  2051.         --  end
  2052.         -- end
  2053.     survlimit = 4
  2054.     value = math.min(value, survlimit)
  2055.     base = math.min(base, survlimit)
  2056.   end
  2057.  
  2058.   params.obj.UI.setAttribute(params.value, "text", value)
  2059.   params.obj.UI.setAttribute(params.value, "base", base)
  2060.  
  2061.   if params.value ~= "survival" and params.value ~= "insanity" and grid ~= nil then
  2062.     Wait.frames(function() getObjectFromGUID(grid.getVar("gridScript")).call("diceStatsEx", {grid}) end, 1)
  2063.   end
  2064.  
  2065. end
  2066.  
  2067. function resetStats(params)
  2068.   for _, v in pairs({'movement', 'speed', 'accuracy', 'strength', 'luck', 'evasion'}) do
  2069.     params.obj.UI.setAttribute(v, "text", params.obj.UI.getAttribute(v, "base"))
  2070.   end
  2071. end
  2072.  
  2073. function resetBrain(params)
  2074.   params.obj.UI.setAttribute("brainL", "value", "false")
  2075.   params.obj.UI.setAttribute("brainL", "color", "#00000000")
  2076. end
Add Comment
Please, Sign In to add comment