Jump to content

[Help]How to make meteor bring marble or other gems?


Recommended Posts

@Jupiters:

AddPrefabPostInit("shadowmeteor", function(inst)	local function myexplode(inst)		if inst:IsOnValidGround() then			local extraloot = {				marble = 0.4,				redgem = 0.3,				bluegem = 0.3,				purplegem = 0.1,				orangegem = 0.1,				yellowgem = 0.1,				greengem = 0.1,			}			for k, v in pairs(extraloot) do				if math.random() <= v then					local drop = GLOBAL.SpawnPrefab(k)					if drop ~= nil then						local x, y, z = inst.Transform:GetWorldPosition()						drop.Transform:SetPosition(x, y, z)						if drop.components.inventoryitem ~= nil then							drop.components.inventoryitem:OnDropped(true)						end					end				end			end		end	end	local function mystrike(inst)		inst.mystriketask = nil		inst:DoTaskInTime(0.33, myexplode)	end	local _SetSize = inst.SetSize	inst.SetSize = function(inst, sz, mod)		_SetSize(inst, sz, mod)		inst.mystriketask = inst:DoTaskInTime(1.1, mystrike)	endend)
Link to comment
Share on other sites

@DarkXero

Much appreciated. Hum.......I have another idea in my mind. How to make the turfs such as carpeted turf have more functions. For instance, it can gain heat and keep warn in winter, it can gain sanity when night, or it can proof the rain, etc.

Link to comment
Share on other sites

@Jupiters:

if not GLOBAL.TheNet:GetIsServer() then	returnend-- Gives 30 insulation for Winter, -30 insulation for Summer-- Winter insulation delays freezing, Summer insulation delays overheating-- The closer to 0, the quicker the freezing/overheating comesAddComponentPostInit("temperature", function(self)	local _GetInsulation = self.GetInsulation	self.GetInsulation = function(self)		local winterInsulation, summerInsulation = _GetInsulation(self)		local tile, data = self.inst:GetCurrentTileType()		if tile == GLOBAL.GROUND.CARPET then			winterInsulation = winterInsulation + 30			summerInsulation = summerInsulation - 30		end		return math.max(0, winterInsulation), math.max(0, summerInsulation)	endend)-- Standing on a carpet during the night only is like wearing a top hatAddPlayerPostInit(function(inst)	if inst.components.sanity then		local _crfn = inst.components.sanity.custom_rate_fn		inst.components.sanity.custom_rate_fn = function(inst)			local ret = 0			if _crfn then				ret = _crfn(inst)			end			if GLOBAL.TheWorld.state.isnight then				local tile, data = inst:GetCurrentTileType()				if tile == GLOBAL.GROUND.CARPET then					local carpet_delta = GLOBAL.TUNING.DAPPERNESS_MED					ret = ret + carpet_delta				end			end			return ret		end	endend)-- Things with moisture stay dry when standing on carpetAddComponentPostInit("moisture", function(self)	local _GetMoistureRate = self.GetMoistureRate	self.GetMoistureRate = function(self)		local tile, data = self.inst:GetCurrentTileType()		if tile == GLOBAL.GROUND.CARPET then			return 0		end		return _GetMoistureRate(self)	endend)

entity:GetCurrentTileType() does the trick.

Link to comment
Share on other sites

@Jupiters:

AddComponentPostInit("locomotor", function(self)	if self.inst:HasTag("player") then		local _UGSM = self.UpdateGroundSpeedMultiplier		self.UpdateGroundSpeedMultiplier = function(self)			_UGSM(self)			local tile, data = self.inst:GetCurrentTileType()			if tile == GLOBAL.GROUND.CARPET then				if self.carpetfast == nil then					self:SetExternalSpeedMultiplier(self.inst, "CarpetSpeed", 1.5)					self.carpetfast = true				end			else				if self.carpetfast == true then					self:RemoveExternalSpeedMultiplier(self.inst, "CarpetSpeed")					self.carpetfast = nil				end			end		end	endend)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...