GLOBAL.setmetatable(env,{__index=function(t,k) return GLOBAL.rawget(GLOBAL,k) end}) local TraderShop = require "screens/tradershop" require "recipe" local newrecipes = {} for i = 1,6 do local ornament = "halloween_ornament_"..tostring(i) AddRecipe2(ornament,{Ingredient(ornament,1)},RECIPETABS.NONE,TECH.NONE) table.insert(newrecipes, ornament) AllRecipes[ornament].canbuild = function(recipe,inst, pt, rotation, current_prototyper) return false,"неа" end end for i = 1,4 do local ornament = "winter_food"..tostring(i) AddRecipe2(ornament,{Ingredient(ornament,1)},RECIPETABS.NONE,TECH.NONE) table.insert(newrecipes, ornament) AllRecipes[ornament].canbuild = function(recipe,inst, pt, rotation, current_prototyper) return false,"неа" end end AddPlayerPostInit(function(inst) inst:DoPeriodicTask(1,function() local pos = Vector3(inst.Transform:GetWorldPosition()) local targets = TheSim:FindEntities(pos.x, pos.y, pos.z, 3) local trader = false for _,target in pairs(targets) do if target.prefab == "wanderingtrader" then trader = true end end if trader then for _,recipe in pairs(newrecipes) do AllRecipes[recipe].canbuild = function(recipe,inst, pt, rotation, current_prototyper) return true,"додеп" end end else for _,recipe in pairs(newrecipes) do AllRecipes[recipe].canbuild = function(recipe,inst, pt, rotation, current_prototyper) return false,"додеп" end end end end) end) local function IsAdmin(player) return player and TheNet:GetClientTableForUser(player.userid).admin or TheNet:GetIsServerAdmin() end function _G.c_settrades() if IsAdmin(ThePlayer) then TheFrontEnd:PushScreen(TraderShop(ThePlayer)) end end AddPrefabPostInit("world",function(inst) inst:AddComponent("recipechanger") inst.components.recipechanger.recipetochange = newrecipes if not TheWorld.ismastersim then return end inst.crafts = { {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, } TheWorld:ListenForEvent("ms_playerjoined",function() for _,table in pairs(TheWorld.crafts) do if table.recipename then for _,table in pairs(TheWorld.crafts) do print("Вот твоя таблица епта"..tostring(table)) if table.recipename then local recipename = table.recipename local amount = table.amount local json_cc = json.encode(table.craftcomponents) local json_nc = json.encode(table.numcomponents) local slotnumber = table.slot for k,player in pairs(AllPlayers) do SendModRPCToClient(GetClientModRPC("CRAFTS","CHANGERECIPECLIENT"),player.userid,recipename,amount,json_cc,json_nc,slotnumber) end end end end end end) end) local function ChangeRecipe(inst, rec, am, json_cc, json_nc, s) if not IsAdmin(inst) then return end local slotnumber = s or 1 local cc = json.decode(json_cc) local nc = json.decode(json_nc) print("RPC gotten") TheWorld.components.recipechanger.amount = tonumber(am) TheWorld.components.recipechanger:SetIngredients(cc,nc) TheWorld.components.recipechanger.recname = tostring(rec) TheWorld.components.recipechanger.slotnumber = tonumber(slotnumber) TheWorld.components.recipechanger:Change() TheWorld.crafts[tonumber(slotnumber)] = { recipename = tostring(rec), amount = tonumber(am), craftcomponents = cc, numcomponents = nc, slot = slotnumber } TheWorld:DoTaskInTime(0.5,function() for _,table in pairs(TheWorld.crafts) do print("Вот твоя таблица епта"..tostring(table)) if table.recipename then local recipename = table.recipename local amount = table.amount local json_cc = json.encode(table.craftcomponents) local json_nc = json.encode(table.numcomponents) local slotnumber = table.slot for k,player in pairs(AllPlayers) do SendModRPCToClient(GetClientModRPC("CRAFTS","CHANGERECIPECLIENT"),player.userid,recipename,amount,json_cc,json_nc,slotnumber) end end end end) end local function ChangeRecipeClient(rec, am, json_cc, json_nc, slotnumber) print("Клиент рпс готтен") print(rec, am, json_cc, json_nc,slotnumber) local cc = json.decode(json_cc) local nc = json.decode(json_nc) TheWorld.components.recipechanger.amount = tonumber(am) TheWorld.components.recipechanger:SetIngredients(cc,nc) TheWorld.components.recipechanger.recname = tostring(rec) TheWorld.components.recipechanger.slotnumber = tonumber(slotnumber) TheWorld.components.recipechanger:Change() end AddModRPCHandler("MYCRAFTS","CHANGERECIPE",ChangeRecipe) AddClientModRPCHandler("CRAFTS","CHANGERECIPECLIENT",ChangeRecipeClient)