Jump to content

[Help Request] Attempting to combine effects

Recommended Posts

I apologize if the title is a little confusing but it seem sound in my head. Anyways, I've been digging around mods and posts for some time now and managed to pull useful tidbits out from all over the place. Now that I have solid template running, I decided to take the plunge to try to make more unique mechanics despite being new to whole thing. (Yeah I'm probably way over my head, but my creativity won't stop clawing at my face)


My two goals are:

Make a character imitate a building's aura  & Using the Meteor spawner to generate specific items


For the first one I found a code for granting a character with the ability to start with a science tier. Which was this.

inst.components.builder.science_bonus = 1

then a code with an "aura"

inst.components.sanity.neg_aura_mult = 0.4

and tried to fuse the two together so it would become an aura that gave science effect.

inst .components.builder.science_bonus_aura = 1

Obviously this didn't work like I hope (since I probably don't know how the logic works).


For number 2, I'm still researching so maybe just any tips on where I should look would be a most gracious act. 


*I've looked into the meteorspawner.lua already and pulled out the entire script in an attempt to make some sense out of it.


Again thank you to anyone who simply came to read this. I appreciate any assistance I can get. 

Link to comment
Share on other sites

You are going to have to create your own aura. Or you can use what the science machine uses.


You can try putting this inside your character's prefab:

local common_postinit(inst)	-- other code goes here	inst:AddTag("prototyper")	inst:AddTag("level1")endlocal master_postinit(inst)	-- other code goes here	inst:AddComponent("prototyper")	inst.components.prototyper.trees = TUNING.PROTOTYPER_TREES.SCIENCEMACHINEend

so it makes you like a science machine.


You want items in meteorites. How so? Constant loot in them, random, or what?

Link to comment
Share on other sites

@DarkXero, it actually sounds like they're wanting to give off an aura to other players when they build an item. They should be looking into the sanityaura component in order to accomplish that and listening for the "builditem" and "buildstructure" events.



local function CalcSanityAura(inst, observer)    if inst.aura_active then        return AmountOfSanityToRegenerate    end    return 0endlocal function ActivateAura(inst)    inst.aura_active = not inst.aura_active -- This should work, but haven't tried it lately. If it doesn't simply check the state with an if-else and change it. Code is provided if this line doesn't work, simply comment this one out and uncomment the following code.    -- if inst.aura_active then        -- inst.aura_active = false    -- else        -- inst.aura_active = true    -- end    if inst.task == nil then        inst.task = inst:DoTaskInTime(# of Seconds for aura to be active., function(inst) inst.aura_active = false end)    else        inst.task:Cancel()        inst.task = inst:DoTaskInTime(# of Seconds for aura to be active., function(inst) inst.aura_active = false end    endendlocal function master_postinit(inst)    inst.aura_active = false    inst:AddComponent("sanityaura")    inst.components.sanityaura.aurafn = CalcSanityAura    inst:ListenForEvent("builditem", ActivateAura)    inst:ListenForEvent("buildstructure", ActivateAura)end 

This will activate your sanity aura every time you build an item or structure and will cancel the cancellation of it if you build a new item or structure to "renew" the time limit of the aura.

Link to comment
Share on other sites

@Kzisor, that works.

But he's trying to do a building aura. As in, a science machine.


Although now that I think of it, maybe my idea wasn't that good, since the science bonus wouldn't apply when somebody is near him and a science machine. Prototypers don't stack.

Link to comment
Share on other sites

@DarkXero, I might have misunderstood what the OP wanted. I interpreted it as they are wanting to give off an aura after building an item or structure, but after re-reading it, it sounds like they are wanting to become a science machine. Either way, they have code for both scenarios and can choose which one better suits their needs. ;)

Link to comment
Share on other sites

Thank you both for the quick response! I am sorry for causing such confusion.

For the first one I thank you DarkXero, that was definitely what I was going for. The "becoming" a science machine factor. It was suppose to be a character effect, that imitate the act of being able "teach" other people how to make higher tiers of item when neither of them has access to a science machine.

Kzisor I also wish to incorporate your code as well. As such may I bother you a little by asking for a simple explaination of how it works?

From what I understand, it make the character emit the [sanity gain] bonus for prototyping, instead of just adding it to the origin character.

Base on this, I'm assuming I can use the "listen" function to check for an "event" such as health dropping below a certain point?.


Part 2 is a lot more confusing and my poor wording probably didn't help. So I'll try again at explaining.

I want a character to be able to passively send a command prompt to the server to call up the "meteorspawning" event when a "condition/effect" has been met. (Such as Health or Sanity dropping below a certain threshold). Based on what I learned from Kzisor's example, I suppose I have to incorporate the "listen" command.

In very simple logic I suppose I want something like:Listen. If player health < player_maxhealth/2 then"spawn meteor"

Next, I want to change this meteor effect by adding additional items to the list so it would not spawn only boulders (let's just say for example I want the meteor to come down and become a gemstone instead of a rock). 


Again thank you all for your help so far! May I enter your names into your names into my special thanks list DarkXero & Kzisor?

Link to comment
Share on other sites

@Hyaciao, in simple terms yes that is correct as to how that works, however, you will need to search for the proper events to listen for to get the health and sanity change. Look into the health and sanity components for the events they push.


Also please give credit where it's due, no matter who helps you it's a sign of respect.

Link to comment
Share on other sites

@Hyaciao, when the health of something changes, the DoDelta function has been ran.

When that function runs, a healthdelta event gets pushed to the entity that has the health component.


Concretely, this

self.inst:PushEvent("healthdelta", {oldpercent = old_percent, newpercent = self:GetPercent(), overtime = overtime, cause = cause, afflicter = afflicter, amount = amount})

so you can check on the new health percent by doing

inst:ListenForEvent("healthdelta", function(inst, data) --data being the info between {}	if data.newpercent < 0.5 then -- health below 50%		print("Hello World") -- we print a message on the console	endend)

Now regarding the meteor.

Instead of using listen or command prompt, the best way to express yourself is always natural language.

For now, I know that when somebody reaches half health, I send a meteor to their head.



However, that raises the questions:


Only one meteor? Not a meteor shower?


Somebody just reached half health, we bring the meteor now as the health went from 75 to a number below a threshold? Or do we wait until something special happens, like the guy makes a campfire? Or do we have a countdown? Or the guy playing has to press the Z key to send a message to the server telling "gimme my meteor"?


What about after the meteor falls down? We are still at half health. We keep bringing meteors down?


Or maybe it's that simple. Guy gets hit, goes below certain health, one meteor with extra stuff falls. Somebody could exploit that with spider glands: go below threshold, meteor falls, heal a bit, go below again, meteor falls... rinse and repeat.

Link to comment
Share on other sites

Oh wow that's perfect. Thank you so much! I didn't know about the healthdelta existence.


And to answer everything. It should be spawning only 1 meteor on the target's head the moment the player reaches below a certain threshold. And to combat the potential abused I planned to make it drop only 1 false meteor (so a unique item such as gloomer's flower.)

And as long as that item exists in the game, the force meteor spawn event cannot exist occur again.

Link to comment
Share on other sites

I don't understand. False meteor? There are no false meteors. There are meteors.

Meteors exist from when the shadow appears on the floor, to when they collide, crash, and drop their loot.

Then there is no more meteor. So another can perfectly appear.


Or are you telling me you think meteors are the rocks that exist when a meteor crashes with the earth?

How does your method avoid the player mining it and triggering another one in quick succession then?

Link to comment
Share on other sites

Ah I should stop using weird terms to describe things. When I said False meteor I meant, an object that spawns but it isn't the original (meteor rock). Like perhaps gears appear at the end of the shadow sequence instead of a mineable rock.

I didn't know that the "meteor" (from shadow to when it drops it's loot) is 1 entity. I thought the (meteor_spawn) merely called for the animation to create a shadow and call up the sound effect. And at the end of that event, an object (meteor) is created. [i was planning to change that created (meteor) object into a unique item]

As for the server abuse prevention, it was suppose to be something like, make the server check for the existence of this "custom" item. And while the "custom" item persists in the world it prevents the spawn_meteor event to occur.

Edited by Hyaciao
Link to comment
Share on other sites

local function onemeteor(inst, data)	local specialitem = GLOBAL.TheSim:FindFirstEntityWithTag("myuniqueitem")	if not specialitem and data.newpercent < 0.5 then		local x, y, z = inst.Transform:GetWorldPosition()		local meteor = GLOBAL.SpawnPrefab("shadowmeteor")		meteor.Transform:SetPosition(x, y, z + 5)		meteor:DoTaskInTime(0.6, function()			for k, v in pairs(meteor.loot) do				meteor.loot[k] = nil			end			table.insert(meteor.loot, {prefab = "yourprefab", chance = 1})		end)	endendAddPlayerPostInit(function(inst)	inst:ListenForEvent("healthdelta", onemeteor)end)-- in your unique prefab's lua file, put inst:AddTag("myuniqueitem")-- that way, like glommer's flower, you will only have one of these per world

Well, there you go, have fun.

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

  • Create New...