Kijan

Main Script for all the GRIDS

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