Jump to content

[HELP] I want to add a recipe that only admin or map creator can use


Recommended Posts

Hello everyone, have a nice day

As the title says, I want to add a recipe that only admins or map creators can use or a keyboard shortcut that can only be added for individuals.

local birds = AddRecipe("book_birds",    {Ingredient("papyrus", 2),Ingredient("bird_egg", 2)},GLOBAL.RECIPETABS.MAGIC, TECH.NONE, nil, nil, nil, nil, "achivbookbuilder") --add recipe

AddPlayerPostInit(function(inst)
	inst:AddTag("achivbookbuilder") -- add tag use recipe
end)

please help me with this problem, thank you very much

Edited by GhostMonster_it
Link to comment
Share on other sites

You can use TheNet:GetIsServerAdmin() for check it. Probably it will only work with keyboard shorcut, like:
 

TheInput:AddKeyDownHandler(KEY_K, function() -- KEY_K is a number in contants.lua 
    --Code
end)

Don't forget to use GLOBAL :encouragement:

  • Thanks 1
Link to comment
Share on other sites

On 6/8/2022 at 2:12 AM, Leonidas IV said:

You can use TheNet:GetIsServerAdmin() for check it. Probably it will only work with keyboard shorcut, like:
 


TheInput:AddKeyDownHandler(KEY_K, function() -- KEY_K is a number in contants.lua 
    --Code
end)

Don't forget to use GLOBAL :encouragement:

I tried this syntax but when I launch the mod, everyone in the map can get the recipe, not only admins have this recipe
Do you have another way to do it?

local _G = GLOBAL
 local bird = AddRecipe ( "book_birds" , { Ingredient ( "papyrus" , 2 ), Ingredient ( "bird_egg" , 2 )}, GLOBAL . RECIPETABS . MAGIC , TECH . NONE , nil , nil , nil , nil , "achivbookbuilder" ) 
AddPlayerPostInit ( function ( inst ) 
    if (_G.TheNet:GetIsServerAdmin() and TheNet:GetIsServer()) then
		inst : AddTag ( "achivbookbuilder" ) 
  end 
end )
		
		
		   
      	
  
Edited by GhostMonster_it
Link to comment
Share on other sites

11 hours ago, GhostMonster_it said:

I tried this syntax but when I launch the mod, everyone in the map can get the recipe, not only admins have this recipe
Do you have another way to do it?

First of all, this command to add crafts is outdated. With the menu update, it is done differently, see AddRecipe2 on modutil.lua.

As I said, probably the TheNet:GetIsServerAdmin() function will not work inside the player's prefab, since it doesn't receive the entity (inst). It checks if the client (the player that is not hosting it) is admin, and this happens on the client side, not on the server, where crafts and tags are defined.

  • Thanks 1
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...