[SOLVED]Give privs programmatically in singleplayer

Post Reply
Nordal
Member
Posts: 158
Joined: Mon Jul 30, 2018 15:46
GitHub: Nordall

[SOLVED]Give privs programmatically in singleplayer

by Nordal » Post

I try to write a game and want to give privs to singleplayer:

Code: Select all

minetest.get_player_privs("single_player", privileges)
print(dump(privileges))
local has, missing = minetest.check_player_privs("singleplayer", {
        interact=true, zoom=true, fly=true, fast=true, noclip=true,
        home=true })
if not has then
    minetest.set_player_privs("singleplayer", missing)
end
minetest.get_player_privs("singleplayer", privileges)
print(dump(privileges))
Errormessage:

Code: Select all

2019-01-15 21:24:36: ERROR[Main]: .../minetest-dev_test/minetest/bin/../builtin/game/auth.lua:93: attempt to index local 'auth_entry' (a nil value)
2019-01-15 21:24:36: ERROR[Main]: stack traceback:
2019-01-15 21:24:36: ERROR[Main]: 	.../minetest-dev_test/minetest/bin/../builtin/game/auth.lua:93: in function 'set_player_privs'
2019-01-15 21:24:36: ERROR[Main]: 	...../games/landors_game/mods/character/privileges/init.lua:8: in main chunk
2019-01-15 21:24:36: ERROR[Main]: Siehe debug.txt für Details.
I tried to write the privs in minetest.conf on minetest-level and on game-level but neither works. That's why I try it programmatically. rubenwardy's explanation in his guide is very good. But how to adress singleplayer?

Related Problem is, I get this error all the time:

Code: Select all

2019-01-15 21:25:25: ERROR[Main]: Bitte wählen Sie einen Namen!
How can I give me a name as singleplayer?

I'm not sure if this is the right place to post problems. If not, I'm sorry. Please tell me the right place then.
Last edited by Nordal on Fri Jul 19, 2019 23:23, edited 1 time in total.
CFS - still widely unknown

User avatar
rubenwardy
Moderator
Posts: 6977
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: Give privs programmatically in singleplayer

by rubenwardy » Post

You can't modify privileges whilst the game is loading.

You should also never hard code names like that.

Do this instead:

Code: Select all

minetest.register_on_joinplayer(function(player)
    local privs = minetest.get_player_privs(player:get_player_name())
    privs.interact = true
    privs.zoom = true
    privs.fly = true
    privs.fast = true
    privs.noclip = true
    privs.home = true
    minetest.set_player_privs(player:get_player_name(), privs)
end)
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

Nordal
Member
Posts: 158
Joined: Mon Jul 30, 2018 15:46
GitHub: Nordall

[SOLVED]Re: Give privs programmatically in singleplayer

by Nordal » Post

Thank you!! This is an elegant solution.

Code: Select all

register_on_joinplayer
makes any tests on privs unnecessary.
CFS - still widely unknown

wziard
Member
Posts: 127
Joined: Mon Oct 29, 2018 19:12

Re: Give privs programmatically in singleplayer

by wziard » Post

Also note that to take a priv away, you need to set it to nil (i.e. remove it from the list), not false. (that has bitten me before :-) )

User avatar
niwla23
Member
Posts: 118
Joined: Sat Nov 17, 2018 17:40
In-game: Niwla

Re: Give privs programmatically in singleplayer

by niwla23 » Post

It is singleplayer, not single_player, but thats not your problem...

Nordal
Member
Posts: 158
Joined: Mon Jul 30, 2018 15:46
GitHub: Nordall

Re: Give privs programmatically in singleplayer

by Nordal » Post

wziard wrote:Also note that to take a priv away, you need to set it to nil (i.e. remove it from the list), not false. (that has bitten me before :-) )
Good to know. Thank's for sharing your experince!
CFS - still widely unknown

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests