Jump to content

{Character perks} mining gems


Recommended Posts

26 minutes ago, Ultroman said:

I forgot to make it GLOBAL.SpawnPrefab again. Just add GLOBAL. before all the SpawnPrefab calls.

Please fix the indentation anyway. It's seriously confusing, and it hurts my heart knowing that code with this indentation exists :p

It works great! Thank you so much!! 
I honestly appreciate your time spent helping me do this code even though I'm a bit dumb sometimes (Must've been a  lil infuriating I'm sorry o_o) You've been one of the best people about it, so thank you for that too!

Can I just ask one more thing? This only applies to rock1, what would I need to do to make it imply with rock2 and rock_flintless?

Link to comment
Share on other sites

You're welcome :) And I appreciate your appreciation.

Duplicate the AddPrefabPostInit line, and change "rock1" to the names of the other rock prefabs you want to affect.Their names are:
"rock1"
"rock2"
"rock_flintless"
"rock_flintless_med"
"rock_flintless_low"
"rock_moon"
"rock_petrified_tree"
"rock_petrified_tree_med"
"rock_petrified_tree_tall"
"rock_petrified_tree_short"
"rock_petrified_tree_old"
"rock_ice"

Edited by Ultroman
Link to comment
Share on other sites

4 minutes ago, Ultroman said:

Duplicate the AddPrefabPostInit line, and change "rock1" to the names of the other rock prefabs you want to affect.Their names are:
"rock1"
"rock2"
"rock_flintless"
"rock_flintless_med"
"rock_flintless_low"
"rock_moon"
"rock_petrified_tree"
"rock_petrified_tree_med"
"rock_petrified_tree_tall"
"rock_petrified_tree_short"
"rock_petrified_tree_old"
"rock_ice"

I thought so, thought I'd check just to be sure!

Works great :D

Really though, thanks again, you have been super helpful!

Link to comment
Share on other sites

2 hours ago, IronHunter said:

What lumina said is pretty much correct, unless a component is a replicable one. They are server side only. You need to add a if statement to check if theworld is mastersim.

I can't grab any code atm. Away from pc.

 

3 hours ago, Lumina said:

Maybe you need a check somewhere to ensure that the code is only done server side and not client side ?

Ah? I'm not sure how to do that tbh >_<

an example code will help alot, thank you!

Link to comment
Share on other sites

14 hours ago, IronHunter said:

There are quite a few examples when I searched. Including a relatively recent one:

 

Just look at the Global.TheWorld.ismastersim

That checks to make sure the code is run only on the server.

Is this right? (I can't currently test it rn >_< away from pc)

404 error.png

Link to comment
Share on other sites

That code doesn't make sense:

404 error.png

AddPrefabPostInit("gemini", function(inst)
	if GLOBAL.TheWorld.ismastersim then
		cached_onwork = inst.components.workable.onwork
		inst.components.workable:SetOnWorkCallback(MyOnWork)
	end
end)
--all you really needed to do was wrap your postinit function with the if statement if GLOBAL.TheWorld.ismastersim

if statements don't use equals = they use absolute equals == or other relational operators like >= <= ~= etc.

= on its own means assigning/changing the variable pointer to a new point.

if you want to make sure inst.components.workable.onwork ~= nil then you can do that still. In your MyOnWork function, take note the component workable already checks to make sure .onwork is assigned data.

Also onwork is probably activating when you hit the rock, which is what ice does. But if you wanted it to drop when destroying it, the onfinished might make more sense.

Edited by IronHunter
Posted too early, when trying to type my post.
Link to comment
Share on other sites

2 hours ago, Ultroman said:

As always, it's hard to help without the server logs of the crash and the full mod code.

It doesn't crash, or pop up any errors it just disconnects me when I pick the character.

19 minutes ago, IronHunter said:

That code doesn't make sense:

404 error.png


AddPrefabPostInit("gemini", function(inst)
	if GLOBAL.TheWorld.ismastersim then
		inst.cached_onwork = inst.components.workable.onwork
		inst.components.workable:SetOnWorkCallback(MyOnWork)
	end
end)

if statements don't use equals = they use absolute equals == or other relational operators like >= <= ~= etc.

= on its own means assigning/changing the variable pointer to a new point.

if you want to make sure inst.components.workable.onwork ~= nil then you can do that still. In your MyOnWork function, take note the component workable already checks to make sure .onwork is assigned data.

Also onwork is probably activating when you hit the rock, which is what ice does. But if you wanted it to drop when destroying it, the onfinished might make more sense.

I put this code in and It only disconnected me when I select the character :(

(this only happens when I enabled caves, when I host without caves, I get an error message)

Gems drop during the mining process randomly, they don't drop after the rock has been destroyed.

404 error.png

Link to comment
Share on other sites

Characters don't have a workable component. You shouldn't do this to the player character. This code is for rocks, trees and other things with a workable-component. Also, if you want to make changes to your player character, you should use AddPlayerPostInit() instead. What are you trying to do to the player?

Edited by Ultroman
Link to comment
Share on other sites

1 minute ago, Ultroman said:

Characters don't have a workable component. You shouldn't do this to the player character. This code is for rocks, trees and things with a workable-component.

Do you mean I have placed it in the wrong place?

I'm honestly confused at this point :?

Link to comment
Share on other sites

The initial code I wrote was for changing the rocks.

AddPrefabPostInit("rock1", MyPostInit)

Rocks have a "workable" component, which is why the code works on them.

Why would you try to do the same to your player character? He's not a rock.

Link to comment
Share on other sites

3 minutes ago, Ultroman said:

The initial code I wrote was for changing the rocks.


AddPrefabPostInit("rock1", MyPostInit)

Rocks have a "workable" component, which is why the code works on them.

Why would you try to do the same to your player character? He's not a rock.

I think I must've confused myself somewhere, or misread something -_-

I'm sorry, I didn't expect it to be so hard...

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...