[Question] Altering player physic via items

Post Reply
User avatar
Emetchi
Member
Posts: 11
Joined: Fri Dec 29, 2017 22:39
GitHub: FinnRules
In-game: Emetchi or FinnRules

[Question] Altering player physic via items

by Emetchi » Post

In the past two months, I have been having a blast making my own mod (which I hope to finalize and release eventually) using google, some discord friends, and Rubenwardy's book (huge thanks to him for that) as guides. This is my first project related to coding other than a class I'm taking in JS, so I hope you can excuse a little lack of knowledge on my part.

Anyway, my question is, how (if possible) would I go about creating items that can be used to alter player physics using the API? (ie, craftitem that the player can click to set gravity to a certain value)

Any help is appreciated (especially code snippets, because it helps to copy working code and mess around with it)
Hey, a signature, how quaint.

User avatar
GreenXenith
Member
Posts: 1356
Joined: Wed Oct 28, 2015 01:26
GitHub: GreenXenith
Location: UTC-8:00
Contact:

Re: [Question] Altering player physic via items

by GreenXenith » Post

By the way, this belongs here viewforum.php?f=47 :P

The lua_api is a handy thing ;)

Anywhos, line 3730-3740 says this:

Code: Select all

* `set_physics_override(override_table)`
    * `override_table` is a table with the following fields:
        * `speed`: multiplier to default walking speed value (default: `1`)
        * `jump`: multiplier to default jump value (default: `1`)
        * `gravity`: multiplier to default gravity value (default: `1`)
        * `sneak`: whether player can sneak (default: `true`)
        * `sneak_glitch`: whether player can use the new move code replications
          of the old sneak side-effects: sneak ladders and 2 node sneak jump
          (default: `false`)
        * `new_move`: use new move/sneak code. When `false` the exact old code
          is used for the specific old sneak behaviour (default: `true`)
So if you wanted to do something with an item, you would do something like

Code: Select all

minetest.register_craftitem("mymod:jumpything", {
	description = "use to jump higher",
	inventory_image = "default_stick.png",
	on_use = function(user)
		user:set_physics_override("gravity",2) --this part is wrong. I dont know how to do it properly - just mess around with it.
	end,
})
YouTube | Mods | Patreon | Minetest Discord @greenxenith

You should not be able to read this message.

User avatar
Pyrollo
Developer
Posts: 385
Joined: Mon Jan 08, 2018 15:14
GitHub: pyrollo
In-game: Naj
Location: Paris

Re: [Question] Altering player physic via items

by Pyrollo » Post

It's even better to use Player Effects Framework (see this forum post).

Player effects handles concurent effects from different mods. If your mod modifies player physics using the API and another mod does this also in the same time, this may lead to unwanted situations.
[ Display Modpack ] - [ Digiterms ] - [ Crater MG ] - [ LATE ]

User avatar
Emetchi
Member
Posts: 11
Joined: Fri Dec 29, 2017 22:39
GitHub: FinnRules
In-game: Emetchi or FinnRules

Re: [Question] Altering player physic via items

by Emetchi » Post

Thanks for the tips! Going to work on the mod later today, hopefully everything will work!

edit: still haven't gotten things to work
Hey, a signature, how quaint.

User avatar
Emetchi
Member
Posts: 11
Joined: Fri Dec 29, 2017 22:39
GitHub: FinnRules
In-game: Emetchi or FinnRules

Re: [Question] Altering player physic via items

by Emetchi » Post

Anyone have anything else I can try?
Hey, a signature, how quaint.

Byakuren
Member
Posts: 818
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

Re: [Question] Altering player physic via items

by Byakuren » Post

FinnRules wrote:Anyone have anything else I can try?
What's blocking you?
Every time a mod API is left undocumented, a koala dies.

User avatar
Emetchi
Member
Posts: 11
Joined: Fri Dec 29, 2017 22:39
GitHub: FinnRules
In-game: Emetchi or FinnRules

Re: [Question] Altering player physic via items

by Emetchi » Post

Byakuren wrote:
FinnRules wrote:Anyone have anything else I can try?
What's blocking you?
I tried a bunch of version of the code given, and they all crashed the game. My guess is that it tries to execute the playereffect command but the player username has not been property acquired.
Hey, a signature, how quaint.

Byakuren
Member
Posts: 818
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

Re: [Question] Altering player physic via items

by Byakuren » Post

What was the error? What was your (full) code?
Every time a mod API is left undocumented, a koala dies.

User avatar
paramat
Developer
Posts: 3700
Joined: Sun Oct 28, 2012 00:05
GitHub: paramat
IRC: paramat
Location: UK

Re: [Question] Altering player physic via items

by paramat » Post

Maybe

Code: Select all

user:set_physics_override({speed = 2, jump = 2, gravity = 0.5})
?
Do post the whole error message.

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests