1. 程式人生 > 其它 >2021-01-09

2021-01-09

技術標籤:筆記

----------饑荒rpc-模板,會用用,不會拉倒---------
if TheNet:GetIsClient()then
–客機接受指令

	AddModRPCHandler("cy_forge", "Pmstore", function ()  end)

end

if TheNet:GetIsServer()then
–主機執行指令

local function jiemianFn(player,str)


local kt=player
local x,y,z = kt.Transform:GetWorldPosition()

--------------------------程式碼刷神器

for i=1 ,20 do
local name= string.format(“lr_weapon_%02d”, i) --神器範圍1到20
if str==name then
–GLOBAL.SpawnPrefab(name)
local item = SpawnPrefab(name)
local kt=player
local x,y,z = kt.Transform:GetWorldPosition()
– kt.components.inventory:GiveItem(item)–
item.Transform:SetPosition(x,y,z)

kt.components.health:DoDelta(-100)
end

end

if str == “choujiang2” then
kt.components.talker:Say(“消耗100hp,抽取怪物…”)
–local i = math.ceil(math.random(1,14))–神器範圍1到14
-----
local listguaiwu = {
–四季boss
“moose”, “antlion”, “bearger”, “deerclops”,
–領地boss
“dragonfly”, “malbatross”, “beequeen”, “klaus”, “crabking”, “toadstool”, “toadstool_dark”, “minotaur”,

–骨架
“stalker”, “stalker_forest”, “stalker_atrium”,
–暗影boss
“shadow_knight”, “shadow_rook”, “shadow_bishop”,
–樹精
“leif”, “leif_sparse”, “deciduoustree”,
–怪物首領
“spiderqueen”, “warg”, “claywarg”, “gingerbreadwarg”, “spat”,
–辣味料理
–“bonestew_spice_chili”, “meatballs_spice_chili”, “kabobs_spice_chili”, “honeyham_spice_chili”, “honeynuggets_spice_chili”, “surfnturf_spice_chili”, “seafoodgumbo_spice_chili”, “fishsticks_spice_chili”, “californiaroll_spice_chili”, “fishtacos_spice_chili”, “ceviche_spice_chili”, “unagi_spice_chili”, “lobsterdinner_spice_chili”, “lobsterbisque_spice_chili”, “barnaclestuffedfishhead_spice_chili”, “barnaclinguine_spice_chili”, “barnaclepita_spice_chili”, “barnaclesushi_spice_chili”, “turkeydinner_spice_chili”, “baconeggs_spice_chili”, “perogies_spice_chili”, “hotchili_spice_chili”, “pepperpopper_spice_chili”, “frogglebunwich_spice_chili”, “guacamole_spice_chili”, “monsterlasagna_spice_chili”, “mandrakesoup_spice_chili”, “mashedpotatoes_spice_chili”, “potatotornado_spice_chili”, “pumpkincookie_spice_chili”, “stuffedeggplant_spice_chili”, “salsa_spice_chili”, “vegstinger_spice_chili”, “ratatouille_spice_chili”, “asparagussoup_spice_chili”, “flowersalad_spice_chili”, “meatysalad_spice_chili”, “leafymeatsouffle_spice_chili”, “leafymeatburger_spice_chili”, “leafloaf_spice_chili”, “dragonpie_spice_chili”, “jammypreserves_spice_chili”, “fruitmedley_spice_chili”, “trailmix_spice_chili”, “bananapop_spice_chili”, “watermelonicle_spice_chili”, “icecream_spice_chili”, “waffles_spice_chili”, “butterflymuffin_spice_chili”, “powcake_spice_chili”, “taffy_spice_chili”, “jellybean_spice_chili”, “bonesoup_spice_chili”, “freshfruitcrepes_spice_chili”, “moqueca_spice_chili”, “monstertartare_spice_chili”, “voltgoatjelly_spice_chili”, “glowberrymousse_spice_chili”, “potatosouffle_spice_chili”, “frogfishbowl_spice_chili”, “gazpacho_spice_chili”, “dragonchilisalad_spice_chili”, “nightmarepie_spice_chili”, “wetgoop_spice_chili”,
–蒜蓉料理
– “bonestew_spice_garlic”, “meatballs_spice_garlic”, “kabobs_spice_garlic”, “honeyham_spice_garlic”, “honeynuggets_spice_garlic”, “surfnturf_spice_garlic”, “seafoodgumbo_spice_garlic”, “fishsticks_spice_garlic”, “californiaroll_spice_garlic”, “fishtacos_spice_garlic”, “ceviche_spice_garlic”, “unagi_spice_garlic”, “lobsterdinner_spice_garlic”, “lobsterbisque_spice_garlic”, “barnaclestuffedfishhead_spice_garlic”, “barnaclinguine_spice_garlic”, “barnaclepita_spice_garlic”, “barnaclesushi_spice_garlic”, “turkeydinner_spice_garlic”, “baconeggs_spice_garlic”, “perogies_spice_garlic”, “hotchili_spice_garlic”, “pepperpopper_spice_garlic”, “frogglebunwich_spice_garlic”, “guacamole_spice_garlic”, “monsterlasagna_spice_garlic”, “mandrakesoup_spice_garlic”, “mashedpotatoes_spice_garlic”, “potatotornado_spice_garlic”, “pumpkincookie_spice_garlic”, “stuffedeggplant_spice_garlic”, “salsa_spice_garlic”, “vegstinger_spice_garlic”, “ratatouille_spice_garlic”, “asparagussoup_spice_garlic”, “flowersalad_spice_garlic”, “meatysalad_spice_garlic”, “leafymeatsouffle_spice_garlic”, “leafymeatburger_spice_garlic”, “leafloaf_spice_garlic”, “dragonpie_spice_garlic”, “jammypreserves_spice_garlic”, “fruitmedley_spice_garlic”, “trailmix_spice_garlic”, “bananapop_spice_garlic”, “watermelonicle_spice_garlic”, “icecream_spice_garlic”, “waffles_spice_garlic”, “butterflymuffin_spice_garlic”, “powcake_spice_garlic”, “taffy_spice_garlic”, “jellybean_spice_garlic”, “bonesoup_spice_garlic”, “freshfruitcrepes_spice_garlic”, “moqueca_spice_garlic”, “monstertartare_spice_garlic”, “voltgoatjelly_spice_garlic”, “glowberrymousse_spice_garlic”, “potatosouffle_spice_garlic”, “frogfishbowl_spice_garlic”, “gazpacho_spice_garlic”, “dragonchilisalad_spice_garlic”, “nightmarepie_spice_garlic”, “wetgoop_spice_garlic”,
–鹹味料理
– “bonestew_spice_salt”, “meatballs_spice_salt”, “kabobs_spice_salt”, “honeyham_spice_salt”, “honeynuggets_spice_salt”, “surfnturf_spice_salt”, “seafoodgumbo_spice_salt”, “fishsticks_spice_salt”, “californiaroll_spice_salt”, “fishtacos_spice_salt”, “ceviche_spice_salt”, “unagi_spice_salt”, “lobsterdinner_spice_salt”, “lobsterbisque_spice_salt”, “barnaclestuffedfishhead_spice_salt”, “barnaclinguine_spice_salt”, “barnaclepita_spice_salt”, “barnaclesushi_spice_salt”, “turkeydinner_spice_salt”, “baconeggs_spice_salt”, “perogies_spice_salt”, “hotchili_spice_salt”, “pepperpopper_spice_salt”, “frogglebunwich_spice_salt”, “guacamole_spice_salt”, “monsterlasagna_spice_salt”, “mandrakesoup_spice_salt”, “mashedpotatoes_spice_salt”, “potatotornado_spice_salt”, “pumpkincookie_spice_salt”, “stuffedeggplant_spice_salt”, “salsa_spice_salt”, “vegstinger_spice_salt”, “ratatouille_spice_salt”, “asparagussoup_spice_salt”, “flowersalad_spice_salt”, “meatysalad_spice_salt”, “leafymeatsouffle_spice_salt”, “leafymeatburger_spice_salt”, “leafloaf_spice_salt”, “dragonpie_spice_salt”, “jammypreserves_spice_salt”, “fruitmedley_spice_salt”, “trailmix_spice_salt”, “bananapop_spice_salt”, “watermelonicle_spice_salt”, “icecream_spice_salt”, “waffles_spice_salt”, “butterflymuffin_spice_salt”, “powcake_spice_salt”, “taffy_spice_salt”, “jellybean_spice_salt”, “bonesoup_spice_salt”, “freshfruitcrepes_spice_salt”, “moqueca_spice_salt”, “monstertartare_spice_salt”, “voltgoatjelly_spice_salt”, “glowberrymousse_spice_salt”, “potatosouffle_spice_salt”, “frogfishbowl_spice_salt”, “gazpacho_spice_salt”, “dragonchilisalad_spice_salt”, “nightmarepie_spice_salt”, “wetgoop_spice_salt”,
–甜味料理
– “bonestew_spice_sugar”, “meatballs_spice_sugar”, “kabobs_spice_sugar”, “honeyham_spice_sugar”, “honeynuggets_spice_sugar”, “surfnturf_spice_sugar”, “seafoodgumbo_spice_sugar”, “fishsticks_spice_sugar”, “californiaroll_spice_sugar”, “fishtacos_spice_sugar”, “ceviche_spice_sugar”, “unagi_spice_sugar”, “lobsterdinner_spice_sugar”, “lobsterbisque_spice_sugar”, “barnaclestuffedfishhead_spice_sugar”, “barnaclinguine_spice_sugar”, “barnaclepita_spice_sugar”, “barnaclesushi_spice_sugar”, “turkeydinner_spice_sugar”, “baconeggs_spice_sugar”, “perogies_spice_sugar”, “hotchili_spice_sugar”, “pepperpopper_spice_sugar”, “frogglebunwich_spice_sugar”, “guacamole_spice_sugar”, “monsterlasagna_spice_sugar”, “mandrakesoup_spice_sugar”, “mashedpotatoes_spice_sugar”, “potatotornado_spice_sugar”, “pumpkincookie_spice_sugar”, “stuffedeggplant_spice_sugar”, “salsa_spice_sugar”, “vegstinger_spice_sugar”, “ratatouille_spice_sugar”, “asparagussoup_spice_sugar”, “flowersalad_spice_sugar”, “meatysalad_spice_sugar”, “leafymeatsouffle_spice_sugar”, “leafymeatburger_spice_sugar”, “leafloaf_spice_sugar”, “dragonpie_spice_sugar”, “jammypreserves_spice_sugar”, “fruitmedley_spice_sugar”, “trailmix_spice_sugar”, “bananapop_spice_sugar”, “watermelonicle_spice_sugar”, “icecream_spice_sugar”, “waffles_spice_sugar”, “butterflymuffin_spice_sugar”, “powcake_spice_sugar”, “taffy_spice_sugar”, “jellybean_spice_sugar”, “bonesoup_spice_sugar”, “freshfruitcrepes_spice_sugar”, “moqueca_spice_sugar”, “monstertartare_spice_sugar”, “voltgoatjelly_spice_sugar”, “glowberrymousse_spice_sugar”, “potatosouffle_spice_sugar”, “frogfishbowl_spice_sugar”, “gazpacho_spice_sugar”, “dragonchilisalad_spice_sugar”, “nightmarepie_spice_sugar”, “wetgoop_spice_sugar”,
–發條生物
“knight”, “bishop”, “rook”, “knight_nightmare”, “bishop_nightmare”, “rook_nightmare”,
–蜘蛛
“spider”, “spider_warrior”, “spider_hider”, “spider_spitter”, “spider_dropper”, “spider_moon”, “mushgnome”,
–獵犬
“hound”, “firehound”, “icehound”, “mutatedhound”, “clayhound”,
–小動物
“rabbit”, “frog”, “perd”, “catcoon”, “mole”, “bat”,

}
 local  shengchengwup =  listguaiwu[math.random(# listguaiwu)]
		local name= string.format(shengchengwup)  --生成程式碼
	--GLOBAL.SpawnPrefab(name)
	local item = SpawnPrefab(name)
		-- kt.components.inventory:GiveItem(item)--
		item.Transform:SetPosition(x,y,z)
		kt.components.health:DoDelta(-100)

end
--------------------------測試程式碼直接if–end

if str== “choujiang3” then

		kt.components.talker:Say("消耗10hp獲得一個打包紙...")

kt.components.health:DoDelta(-10)

		 --獲取當前玩家座標
		   -- local x,y,z = kt.Transform:GetWorldPosition() 
		--local i = math.ceil(math.random(1,14))--神器範圍1到14
		--local name= string.format("lr_weapon_%02d", i)  --生成
	--GLOBAL.SpawnPrefab(name)
	local name= string.format("giftwrap")
	local item = SpawnPrefab(name)
		 kt.components.inventory:GiveItem(item)
         
           
	
		end

---------------------------------測試神器程式碼

if str== “choujiang3” then

		kt.components.talker:Say("消耗10hp獲得一個打包紙...")

kt.components.health:DoDelta(-10)

		 --獲取當前玩家座標
		   -- local x,y,z = kt.Transform:GetWorldPosition() 
		--local i = math.ceil(math.random(1,14))--神器範圍1到14
		--local name= string.format("lr_weapon_%02d", i)  --生成
	--GLOBAL.SpawnPrefab(name)
	local name= string.format("giftwrap")
	local item = SpawnPrefab(name)
		 kt.components.inventory:GiveItem(item)
         
           
	
		end

---------------------調整玩家高度
if str == “texonedeng” then
–對應fnstr 的if判定
kt.components.health:DoDelta(1)
local x,y,z =kt.Transform:GetWorldPosition() --獲取當前玩家座標
local pt = Vector3(x, y+2, z)
–local pt = Vector3(x+math.random(-10, 10), y, z+math.random(-10, 10))–隨機座標值 增加-10到10之間
kt.Transform:SetPosition(pt:Get())
end

	 local x,y,z = player.Transform:GetWorldPosition() --獲取當前玩家座標
	  local entm = TheSim:FindEntities(x,y,z,10)--獲取當前玩家座標10碼範圍
	  local  ssjieguo = false--搜尋結果=假
	  for k, v in pairs (entm) do--查詢entms  範圍內
             if v.prefab== "moshi" then--如果查詢結果裡有moshi
			 ssjieguo =true--變更搜尋結果=真
			 break --跳出for迴圈
			 end
	    end
		
		if  ssjieguo ==true then --如果查詢結果為真
		
		else if player.components.talker then --如果玩家有說話元件
		 player.components.talker:Say("搜尋完畢,沒發現目標物品."..tostring(str).."")
		 end
	end
	
	
	
------------------------------	
	end
	------------------
	AddModRPCHandler("cy_forge", "Pmstore", jiemianFn)--客機宣告rpc

end

–其他介面中傳送rpc資料
local fnstr =“choujiang2”–執行命令=choujiang2
SendModRPCToServer(GetModRPC(“cy_forge”, “Pmstore”),fnstr)–傳送rpc資料fnstr–到上面程式碼實現