diff --git a/README.md b/README.md index 25c00ba..443be0d 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,5 @@ To use this mod, extract the zip file to the '**mods**' your Project Zomboid dir Your newly created folder should be in the root of your '**mods**' folder. So it looks like ```bash - C:\Users\%username%\Zomboid\mods/Random Corpses + C:\Users\%username%\Zomboid\mods\Random Corpses ``` -(or whatever the foldername you extracted it to.) \ No newline at end of file diff --git a/Random Corpses/media/lua/client/Movables/TrashAndCorpses_ISMoveableSpriteProps.lua b/Random Corpses/media/lua/client/Movables/TrashAndCorpses_ISMoveableSpriteProps.lua new file mode 100644 index 0000000..05a9dac --- /dev/null +++ b/Random Corpses/media/lua/client/Movables/TrashAndCorpses_ISMoveableSpriteProps.lua @@ -0,0 +1,33 @@ +require "Movables/ISMovableSpriteProps" + + +function ISMoveableSpriteProps:instanceItem(_spriteNameOverride) + if self.isMoveable then + local item; + if self.customItem then + item = instanceItem(self.customItem); + else + if self.isMultiSprite then + item = instanceItem("Moveables.Moveable"); + else + item = instanceItem("Moveables."..self.spriteName); + end + --item = instanceItem("Moveables."..self.spriteName); --instanceItem("Moveables.Moveable"); + end + local spriteName = _spriteNameOverride or self.spriteName; + if self.type == "Window" then -- Some corrections + if not self.spriteProps:Is("SmashedTileOffset") or self.spriteProps:Val("SmashedTileOffset") == 0 then + return nil; -- cant instance broken windows + end + elseif self.type == "WindowObject" and self.isClosedState then + spriteName = self.sheetName .. tostring(self.spriteID+4); + end + if self.customItem then + item:setActualWeight(self.weight); + return item; + elseif item and item:ReadFromWorldSprite(spriteName) then + item:setActualWeight(self.weight); + return item; + end + end +end diff --git a/Random Corpses/media/lua/client/Movables/X_ISMoveableSpriteProps_Pickup.lua.bak b/Random Corpses/media/lua/client/Movables/X_ISMoveableSpriteProps_Pickup.lua.bak new file mode 100644 index 0000000..48e1418 --- /dev/null +++ b/Random Corpses/media/lua/client/Movables/X_ISMoveableSpriteProps_Pickup.lua.bak @@ -0,0 +1,39 @@ +require "Movables/ISMoveableSpriteProps" + +local old_ISMoveableSpriteProps_instanceItem = ISMoveableSpriteProps.instanceItem + +function ISMoveableSpriteProps:instanceItem(_spriteNameOverride) + --local spriteName = _spriteNameOverride or self.spriteName + if self.isMoveable then + local item; + if self.customItem then + item = instanceItem(self.customItem); + else + if self.isMultiSprite then + item = instanceItem("Moveables.Moveable"); + else + item = instanceItem("Moveables."..self.spriteName); + end + --item = instanceItem("Moveables."..self.spriteName); --instanceItem("Moveables.Moveable"); + end + local spriteName = _spriteNameOverride or self.spriteName; + if self.type == "Window" then -- Some corrections + if not self.spriteProps:Is("SmashedTileOffset") or self.spriteProps:Val("SmashedTileOffset") == 0 then + return nil; -- cant instance broken windows + end + elseif self.type == "WindowObject" and self.isClosedState then + spriteName = self.sheetName .. tostring(self.spriteID+4); + end + --print("SPRITE NAME - " .. tostring(spriteName)) + if item + + --and item:ReadFromWorldSprite(spriteName) + + then + item:setActualWeight(self.weight); + return item; + end + end +end + + diff --git a/Random Corpses/media/lua/client/ScatteredTrashes_Hook_Client.lua b/Random Corpses/media/lua/client/ScatteredTrashes_Hook_Client.lua new file mode 100644 index 0000000..d2bcc64 --- /dev/null +++ b/Random Corpses/media/lua/client/ScatteredTrashes_Hook_Client.lua @@ -0,0 +1,34 @@ + + +local function trashSquare_Hook(square) + --print("HOOK") + + local mData = square:getModData() + if mData.trashSquare then return end + if mData.specialSquare then return end + -- trashSquare(square) + -- if not isClient then + -- trashSquare(square) + -- else + -- local player = getPlayer() + -- -- print("Sending trash call to server! - " .. tostring(player)) + -- sendClientCommand( player, "PA_Trash", "Spawn", { + -- x = square:getX(), y = square:getY(), z = square:getZ() + -- }) + -- end + if isClient == true then + local player = getPlayer(0) + -- print("Sending trash call to server! - " .. tostring(player)) + sendClientCommand( player, "PA_Trash", "Spawn", { + x = square:getX(), y = square:getY(), z = square:getZ() + }) + return + end + trashSquare(square) + -- end + +end + + +Events.LoadGridsquare.Add(trashSquare_Hook) -- every time a grid square is loaded, checks for any vehicle spawn list entries + diff --git a/Random Corpses/media/lua/server/Items/X_scatteredTrash_distribution_definition.lua b/Random Corpses/media/lua/server/Items/X_scatteredTrash_distribution_definition.lua new file mode 100644 index 0000000..a843524 --- /dev/null +++ b/Random Corpses/media/lua/server/Items/X_scatteredTrash_distribution_definition.lua @@ -0,0 +1,9 @@ +require "Items/Distributions" +require "Items/ProceduralDistributions" +require "Vehicles/VehicleDistributions" + + +SuburbsDistributions["all"]["Trash"] = SuburbsDistributions["all"]["bin"] + +SuburbsDistributions["all"]["TrashPaper"] = SuburbsDistributions["all"]["filingcabinet"] + diff --git a/Random Corpses/media/lua/server/PA_Trash_ClientComms.lua b/Random Corpses/media/lua/server/PA_Trash_ClientComms.lua new file mode 100644 index 0000000..d602d9d --- /dev/null +++ b/Random Corpses/media/lua/server/PA_Trash_ClientComms.lua @@ -0,0 +1,31 @@ +-- this method was copied from the excellent Skateboard mod by Dislaik https://steamcommunity.com/sharedfiles/filedetails/?id=2728300240 +-- I considered making new code from scratch, albeit I would still be "copying their homework", but decided against, for the sake of ease of comprehension + conistency +if not isServer() then return end +local Commands = {} +Commands.PA_Trash = {} + +Commands.PA_Trash.Spawn = function(origin, args) + -- print("Trash command recieved " .. tostring(origin) .. " - " .. tostring(args)) + local cell = origin:getCell() + -- if not cell then print("No cell!") return end + + local x = args.x + local y = args.y + local z = args.z + -- print("Trash command recieved " .. tostring(origin) .. " - " .. tostring(cell) .. " - " .. tostring(args)) + -- print("Trash command recieved " .. tostring(x) .. " - " .. tostring(y) .. " - " .. tostring(z)) + local square = cell:getGridSquare(x, y, z) or cell:getOrCreateGridSquare( x, y, x) + -- local square = args.square + -- if not square then print("No square!") return end + -- print("Recieved trash call from client -" .. tostring(origin) .. " - " .. tostring(square)) + trashSquare(square) + +end + +local onClientCommand = function(module, command, player, args) + if Commands[module] and Commands[module][command] then + Commands[module][command](player, args) + end +end + +Events.OnClientCommand.Add(onClientCommand) diff --git a/Random Corpses/media/lua/server/camping/ScatteredTrash_CampingFuel.lua b/Random Corpses/media/lua/server/camping/ScatteredTrash_CampingFuel.lua new file mode 100644 index 0000000..d2947da --- /dev/null +++ b/Random Corpses/media/lua/server/camping/ScatteredTrash_CampingFuel.lua @@ -0,0 +1,69 @@ +require "Camping/camping_fuel" + +----------------------- Add Fuel for Campfire ----------------------- + + local i = 0 + + while i < 54 do + local trash = ("trash_01_" .. (tostring(i))) + campingFuelType[trash]= 15.0/60 + campingLightFireType[trash]= 15.0/60 + i = i +1 + + end + + + -- campingFuelType.trash_01_0 = 5.0/60 + -- campingFuelType["trash_01_0"] = 5.0/60 + -- campingFuelType.trash_01_1 = 5.0/60 + -- campingFuelType["trash_01_1"] = 5.0/60 + -- campingFuelType.trash_01_2 = 5.0/60 + -- campingFuelType["trash_01_2"] = 5.0/60 + -- campingFuelType.trash_01_3 = 5.0/60 + -- campingFuelType["trash_01_3"] = 5.0/60 + -- campingFuelType.trash_01_4 = 5.0/60 + -- campingFuelType["trash_01_4"] = 5.0/60 + -- campingFuelType.trash_01_5 = 5.0/60 + -- campingFuelType["trash_01_5"] = 5.0/60 + -- campingFuelType.trash_01_6 = 5.0/60 + -- campingFuelType["trash_01_6"] = 5.0/60 + -- campingFuelType.trash_01_7 = 5.0/60 + -- campingFuelType["trash_01_7"] = 5.0/60 + -- campingFuelType.trash_01_8 = 5.0/60 + -- campingFuelType["trash_01_8"] = 5.0/60 + -- campingFuelType.trash_01_9 = 5.0/60 + -- campingFuelType["trash_01_9"] = 5.0/60 + -- campingFuelType.trash_01_10 = 5.0/60 + -- campingFuelType["trash_01_10"] = 5.0/60 + -- campingFuelType.trash_01_11 = 5.0/60 + -- campingFuelType["trash_01_11"] = 5.0/60 + + +-- ----------------------- Add Starter for Campfire ----------------------- + + -- campingLightFireType.trash_01_0 = 5.0/60 + -- campingLightFireType["trash_01_0"] = 5.0/60 + -- campingLightFireType.trash_01_1 = 5.0/60 + -- campingLightFireType["trash_01_1"] = 5.0/60 + -- campingLightFireType.trash_01_2 = 5.0/60 + -- campingLightFireType["trash_01_2"] = 5.0/60 + -- campingLightFireType.trash_01_3 = 5.0/60 + -- campingLightFireType["trash_01_3"] = 5.0/60 + -- campingLightFireType.trash_01_4 = 5.0/60 + -- campingLightFireType["trash_01_4"] = 5.0/60 + -- campingLightFireType.trash_01_5 = 5.0/60 + -- campingLightFireType["trash_01_5"] = 5.0/60 + -- campingLightFireType.trash_01_6 = 5.0/60 + -- campingLightFireType["trash_01_7"] = 5.0/60 + -- campingLightFireType.trash_01_1 = 5.0/60 + -- campingLightFireType["trash_01_1"] = 5.0/60 + -- campingLightFireType.trash_01_1 = 5.0/60 + -- campingLightFireType["trash_01_1"] = 5.0/60 + -- campingLightFireType.trash_01_1 = 5.0/60 + -- campingLightFireType["trash_01_1"] = 5.0/60 + -- campingLightFireType.trash_01_1 = 5.0/60 + -- campingLightFireType["trash_01_1"] = 5.0/60 + -- campingLightFireType.trash_01_11 = 5.0/60 + -- campingLightFireType["trash_01_11"] = 5.0/60 + + diff --git a/Random Corpses/media/lua/shared/Definitions/ScatteredTrash_ButtonIcons.lua b/Random Corpses/media/lua/shared/Definitions/ScatteredTrash_ButtonIcons.lua new file mode 100644 index 0000000..9cfc9cc --- /dev/null +++ b/Random Corpses/media/lua/shared/Definitions/ScatteredTrash_ButtonIcons.lua @@ -0,0 +1,11 @@ +require "Definitions/ContainerButtonIcons" + +ContainerButtonIcons = ContainerButtonIcons or {} + +local t = {} + +t.Trash= getTexture("media/textures/Trash.png") +t.TrashPaper= getTexture("media/textures/TrashPaper.png") + +ContainerButtonIcons.Trash = t.Trash +ContainerButtonIcons.TrashPaper = t.TrashPaper \ No newline at end of file diff --git a/Random Corpses/media/lua/shared/ScatteredTrashes.lua b/Random Corpses/media/lua/shared/ScatteredTrashes.lua new file mode 100644 index 0000000..19d7bb6 --- /dev/null +++ b/Random Corpses/media/lua/shared/ScatteredTrashes.lua @@ -0,0 +1,145 @@ +-- local function hasWaterObject(square) + -- for i=0, square:getObjects():size()-1 do + -- local v = square:getObjects():get(i); + -- if instanceof(v, "IsoObject") and v:getSprite() and v:getSprite():getProperties() and v:getSprite():getProperties():Is(IsoFlagType.water) then + -- --print("Water Tile") + -- return true; + -- end + -- end +-- end + +function trashSquare(square) + -- print("SQUARE 1") + local mData = square:getModData() + if mData.trashSquare then return end + if mData.specialSquare then return end + mData.trashSquare = true + square:transmitModdata() + --if mData.trashSquare then return end + if ZombRand(0,5) ~= 0 then return end + if not square then return end + if checkBlockedSquare(square) == false then return false end + if mData.stashSquare then return end + if not square:getZone() then return end + --if square:hasFloor(false) then return end + if not square:getZone():getType() then return end + --if square:isVehicleIntersecting() then return end + --if not square:isNotBlocked(true) then return end + local zoneType = square:getZone():getType() + local vehicleZone = nil + if getVehicleZoneAt and getVehicleZoneAt(square:getX(), square:getY(), square:getZ()) then + vehicleZone = getVehicleZoneAt(square:getX(), square:getY(), square:getZ()) + end + -- print("SQUARE 2") + local cell = getCell() + + --if hasWaterObject(square) then return false end + + if not square:isOutside() then + + if square:getZ() > 0 and not square:hasFloor(true) then return end + + --if ZombRand(0,49)== 0 then + if ZombRand(0,10)== 0 then + local body = createRandomDeadBody(square, 200 ) + + if body and ZombRand(0,3) == 0 then -- used so that all spawned bodies are not on their backs + body:setFallOnFront(true) + end + mData.specialSquare = true + end + return + end + if square:getZ() > 0 and not square:hasFloor(true) then return end + local vehicleZoneType = nil + if vehicleZone and vehicleZone:getType() then vehicleZoneType = vehicleZone:getType() end + --if vehicleZone and vehicleZone:getName():contains("trafficjam") then + if vehicleZoneType and vehicleZoneType:contains("trafficjam") then + --if ZombRand(0,99)== 0 then + if ZombRand(0,20)== 0 then + --print("Crash Corpse") + local body = createRandomDeadBody(square, 200 ) + --if body then body:setSkeleton(true) end + if body and ZombRand(0,3) == 0 then -- used so that all spawned bodies are not on their rbacks + body:setFallOnFront(true) + end + mData.specialSquare = true + end + elseif vehicleZone then + + --if ZombRand(0,199)== 0 then + if ZombRand(0,40)== 0 then + --print("Car Corpse") + local body = createRandomDeadBody(square, 200 ) + if body and ZombRand(0,3) == 0 then -- used so that all spawned bodies are not on their rbacks + body:setFallOnFront(true) + end + mData.specialSquare = true + end + elseif zoneType =="Nav" then + + --if ZombRand(0,1999)== 0 then + if ZombRand(0,400)== 0 then + --print("Corpse Spawn") + local body = createRandomDeadBody(square, 200 ) + if body and ZombRand(0,3) == 0 then -- used so that all spawned bodies are not on their rbacks + body:setFallOnFront(true) + end + mData.specialSquare = true + end + elseif zoneType == "TownZone" or zoneType == "ZoneStory" or zoneType == "TrailerPark" then + + --if square:getZ() > 0 and ZombRand(0,3999)== 0 then + if square:getZ() > 0 and ZombRand(0,800)== 0 then + --print("Roof Corpse Spawn") + local body = createRandomDeadBody(square, 200 ) + --if body then body:setSkeleton(true) end + if body and ZombRand(0,3) == 0 then -- used so that all spawned bodies are not on their rbacks + body:setFallOnFront(true) + end + mData.specialSquare = true + -- end + --elseif square:getZ()==0 and ZombRand(0,399)== 0 then + elseif square:getZ()==0 and ZombRand(0,80)== 0 then + --print("Corpse Spawn") + local body = createRandomDeadBody(square, 200 ) + --if body then body:setSkeleton(true) end + if body and ZombRand(0,3) == 0 then -- used so that all spawned bodies are not on their rbacks + body:setFallOnFront(true) + end + mData.specialSquare = true + end + + elseif zoneType == "Vegitation" or zoneType == "Farm" then + + --if ZombRand(0,1999)== 0 then + if ZombRand(0,400)== 0 then + --print("Corpse Spawn") + local body = createRandomDeadBody(square, 200 ) + if body and ZombRand(0,3) == 0 then -- used so that all spawned bodies are not on their rbacks + body:setFallOnFront(true) + end + mData.specialSquare = true + end + elseif zoneType == "Forest" then + --if ZombRand(0,99999)== 0 then + if ZombRand(0,2000)== 0 then + --print("Corpse Spawn") + local body = createRandomDeadBody(square, 200 ) + if body and ZombRand(0,3) == 0 then -- used so that all spawned bodies are not on their rbacks + body:setFallOnFront(true) + end + mData.specialSquare = true + end + elseif zoneType == "DeepForest" then + if ZombRand(0,20000)== 0 then + --print("Corpse Spawn") + local body = createRandomDeadBody(square, 200 ) + if body and ZombRand(0,3) == 0 then -- used so that all spawned bodies are not on their rbacks + body:setFallOnFront(true) + end + mData.specialSquare = true + end + end + square:transmitModdata() +end diff --git a/Random Corpses/media/lua/shared/ScatteredTrashes_Hook.lua b/Random Corpses/media/lua/shared/ScatteredTrashes_Hook.lua new file mode 100644 index 0000000..7525369 --- /dev/null +++ b/Random Corpses/media/lua/shared/ScatteredTrashes_Hook.lua @@ -0,0 +1,13 @@ + + +-- local function trashSquare_Hook(square) + -- --print("HOOK") + -- if square:getModData().trashSquare then return end + -- if square:getModData().specialSquare then return end + -- trashSquare(square) + +-- end + + +-- Events.LoadGridsquare.Add(trashSquare_Hook) -- every time a grid square is loaded, checks for any vehicle spawn list entries + diff --git a/Random Corpses/media/lua/shared/TheGoodShit_SquareSpawnChecks.lua b/Random Corpses/media/lua/shared/TheGoodShit_SquareSpawnChecks.lua new file mode 100644 index 0000000..a97f47e --- /dev/null +++ b/Random Corpses/media/lua/shared/TheGoodShit_SquareSpawnChecks.lua @@ -0,0 +1,98 @@ +function checkDeadZone(square) + if not square then square = getPlayer():getSquare() end + if not square then print("Player Square Failure!") return false end + if (not square:getZone() and square:getZone():getType()) then return false end + if (not getVehicleZoneAt(square:getX(), square:getY(), square:getZ())) then return false end + if (not square:getRoom() and not square:getRoom():getName() ) then return false end +end + +function isFreeTile( _square ) + if not _square or _square:Is("BlocksPlacement") or _square:Is(IsoFlagType.canBeCut) or _square:Is("tree") then + return false; + end + return true; +end + +function hasWaterObject(square) + for i=0, square:getObjects():size()-1 do + local v = square:getObjects():get(i); + if instanceof(v, "IsoObject") and v:getSprite() and v:getSprite():getProperties() and v:getSprite():getProperties():Is(IsoFlagType.water) then + --print("Water Tile") + return true; + end + end +end + +function checkBlockedSquare(square) + if not square then square = getPlayer():getSquare() end + if not square then + --print("Player Square Failure!") + return false + end + if not isFreeTile(square) then + --print("Not Free Tile") + return false + end + if square:isVehicleIntersecting() then + --print("Vehicle Intersecting!") + return false + end + if hasWaterObject(square) then + --print("Water!") + return false + end + if square:HasStairs() then + --print("Stairs!") + return false + end + if not square:hasFloor(true) then + --print("No Floor!") + return false + end + local door = square:getDoor(true) or square:getDoor(false) or square:haveDoor() + if door then + --print("Door!") + return false + end + if square:Is("IsTable") then + --print("Table!") + return false + end + if square:Is("IsTableTop") then + --print("Is TableTop!") + return false + end + if square:isSolid() then + --print("Solid!") + return false + end + if square:isSolidTrans() then + --print("Solid Trans!") + return false + end + local cell = square:getCell() -- the cell wont change. no need to getWorld():getCell() every step of the loop + local x, y, z = square:getX(), square:getY(), square:getZ() + local square2 = cell:getGridSquare(x-1, y, z) + if square2 and square:getDoorFrameTo(square2) then + --print("Door Frame!") + return false + end + local square2 = cell:getGridSquare(x+1, y, z) + if square2 and square:getDoorFrameTo(square2) then + --print("Door Frame!") + return false + end + local square2 = cell:getGridSquare(x, y-1, z) + if square2 and square:getDoorFrameTo(square2) then + --print("Door Frame!") + return false + end + local square2 = cell:getGridSquare(x, y+1, z) + if square2 and square:getDoorFrameTo(square2 ) then + --print("Door Frame!") + return false + end + return true +end + + \ No newline at end of file diff --git a/Random Corpses/media/lua/shared/Translate/EN/IG_UI_EN.txt b/Random Corpses/media/lua/shared/Translate/EN/IG_UI_EN.txt new file mode 100644 index 0000000..14199c1 --- /dev/null +++ b/Random Corpses/media/lua/shared/Translate/EN/IG_UI_EN.txt @@ -0,0 +1,10 @@ +IGUI_EN = { + -- All the UI text used in game + -- InventoryPane + + IGUI_ContainerTitle_Trash = "Trash", + IGUI_ContainerTitle_TrashPaper = "Scattered Papers", + + + +} diff --git a/Random Corpses/media/lua/shared/trash_spawners.lua b/Random Corpses/media/lua/shared/trash_spawners.lua new file mode 100644 index 0000000..b609769 --- /dev/null +++ b/Random Corpses/media/lua/shared/trash_spawners.lua @@ -0,0 +1,32 @@ +require "ScatteredStashes" + +function scattered_trash(square) + local roll = ZombRand(0,51) + if roll > 12 then roll = roll + 3 end + local sprite_type = tostring("trash_01_" .. tostring(roll)) + if not sprite_type then return end + local newSprite = (IsoObject.new(getCell(), square, sprite_type)); + if not newSprite then + print("NO NEW SPRITE!") + return false + end + if newSprite and newSprite:getProperties() then + if newSprite:getProperties():Val("ContainerType") or newSprite:getProperties():Val("container") then + newSprite:createContainersFromSpriteProperties() --end + + end + end + newSprite:getModData().forage = false + square:getObjects():add(newSprite) + square:RecalcProperties() + square:getModData().specialSquare = true + + newSprite:transmitCompleteItemToServer() + newSprite:transmitCompleteItemToClients() + + + + + + return newSprite +end diff --git a/Random Corpses/media/scattered_trashes.tiles b/Random Corpses/media/scattered_trashes.tiles new file mode 100644 index 0000000..cc2361f Binary files /dev/null and b/Random Corpses/media/scattered_trashes.tiles differ diff --git a/Random Corpses/media/textures/Trash.png b/Random Corpses/media/textures/Trash.png new file mode 100644 index 0000000..0b0ce60 Binary files /dev/null and b/Random Corpses/media/textures/Trash.png differ diff --git a/Random Corpses/media/textures/TrashPaper.png b/Random Corpses/media/textures/TrashPaper.png new file mode 100644 index 0000000..9caad54 Binary files /dev/null and b/Random Corpses/media/textures/TrashPaper.png differ diff --git a/Random Corpses/mod.info b/Random Corpses/mod.info new file mode 100644 index 0000000..53b2660 --- /dev/null +++ b/Random Corpses/mod.info @@ -0,0 +1,6 @@ +name=Random Corpses +poster=poster.png +id=Random Corpses +description= +url= +tiledef=scattered_trashes 951 \ No newline at end of file