Axxx丶0 Axxx丶0
关注数: 12 粉丝数: 26 发帖数: 465 关注贴吧数: 46
新人求教 有大神能帮我批注一下代码的意思嘛??? 跪求 local MakePlayerCharacter = require "prefabs/player_common" local assets = { Asset( "ANIM", "anim/player_basic.zip" ), Asset( "ANIM", "anim/player_idles_shiver.zip" ), Asset( "ANIM", "anim/player_actions.zip" ), Asset( "ANIM", "anim/player_actions_axe.zip" ), Asset( "ANIM", "anim/player_actions_pickaxe.zip" ), Asset( "ANIM", "anim/player_actions_shovel.zip" ), Asset( "ANIM", "anim/player_actions_blowdart.zip" ), Asset( "ANIM", "anim/player_actions_eat.zip" ), Asset( "ANIM", "anim/player_actions_item.zip" ), Asset( "ANIM", "anim/player_actions_uniqueitem.zip" ), Asset( "ANIM", "anim/player_actions_bugnet.zip" ), Asset( "ANIM", "anim/player_actions_fishing.zip" ), Asset( "ANIM", "anim/player_actions_boomerang.zip" ), Asset( "ANIM", "anim/player_bush_hat.zip" ), Asset( "ANIM", "anim/player_attacks.zip" ), Asset( "ANIM", "anim/player_idles.zip" ), Asset( "ANIM", "anim/player_rebirth.zip" ), Asset( "ANIM", "anim/player_jump.zip" ), Asset( "ANIM", "anim/player_amulet_resurrect.zip" ), Asset( "ANIM", "anim/player_teleport.zip" ), Asset( "ANIM", "anim/wilson_fx.zip" ), Asset( "ANIM", "anim/player_one_man_band.zip" ), Asset( "ANIM", "anim/shadow_hands.zip" ), Asset( "SOUND", "sound/sfx.fsb" ), Asset( "SOUND", "sound/wilson.fsb" ), Asset( "ANIM", "anim/beard.zip" ), Asset( "ANIM", "anim/yohime.zip" ), Asset( "ANIM", "anim/ghost_yohime_build.zip" ), Asset( "ATLAS", "images/yohimetab.xml" ), Asset( "ATLAS", "images/yohimetab2.xml" ), Asset( "ATLAS", "images/x.xml" ), Asset( "ATLAS", "images/c.xml" ), } local prefabs = {}-- Custom starting items local start_inv = { "yohime_sword", "yohime_amulet","yohime_yuetao","moonrocknugget","moonrocknugget", }local MONSTERVISION_COLOURCUBES = { day = "images/colour_cubes/beaver_vision_cc.tex", dusk = "images/colour_cubes/beaver_vision_cc.tex", night = "images/colour_cubes/beaver_vision_cc.tex", full_moon = "images/colour_cubes/beaver_vision_cc.tex", }-- When the character is revived from human local function onbecamehuman(inst) -- Set speed when loading or reviving from ghost (optional) inst.components.locomotor.walkspeed = 4 inst.components.locomotor.runspeed = 6 inst.components.locomotor:SetExternalSpeedMultiplier(inst, "yohime_speed_mod", 1.1) end-- When loading or spawning the character local function onload(inst) inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman) if not inst:HasTag("playerghost") then onbecamehuman(inst) end end--[[ local function NightVision(inst) if not TheWorld.state.isday then inst.components.playervision:ForceNightVision(true) inst.components.playervision:SetCustomCCTable(MONSTERVISION_COLOURCUBES) else inst.components.playervision:ForceNightVision(false) inst.components.playervision:SetCustomCCTable(nil) end end ]]--local function oneat(inst, food) if food and food.components.edible and food.prefab == "yohime_yuetao" then inst.components.health:DoDelta(10 *(1-TUNING.HEALTH_ABSORPTION)) inst.components.hunger:DoDelta(45 *(1-TUNING.HUNGER_ABSORPTION)) inst.components.sanity:DoDelta(20 *(1-TUNING.SANITY_ABSORPTION)) end if food and food.components.edible and food.prefab == "yohime_yuetao_juicy" then inst.components.health:DoDelta(12 *(1-TUNING.HEALTH_ABSORPTION)) inst.components.hunger:DoDelta(48 *(1-TUNING.HUNGER_ABSORPTION)) inst.components.sanity:DoDelta(22 *(1-TUNING.SANITY_ABSORPTION)) end if food and food.components.edible and food.prefab == "yohime_yuexianjiu" then inst.components.health:DoDelta(30 *(1-TUNING.HEALTH_ABSORPTION)) inst.components.hunger:DoDelta(50 *(1-TUNING.HUNGER_ABSORPTION)) inst.components.sanity:DoDelta(40 *(1-TUNING.SANITY_ABSORPTION)) end end-- This initializes for both the server and client. Tags can be added here. local common_postinit = function(inst) -- Minimap icon inst.MiniMapEntity:SetIcon( "yohime.tex" ) inst:AddTag("yohimebuilder") --取消夜视 --local light = inst.entity:AddLight() --inst.Light:Enable(true) --inst.Light:SetRadius(10) --inst.Light:SetFalloff(.5) --inst.Light:SetIntensity(0.9) --inst.Light:SetColour(245/85,85/85,245/85) --inst:AddTag("nightvision") --inst:WatchWorldState("startnight", NightVision) --inst:WatchWorldState("startday", NightVision) --为啥取消了技能? inst:AddTag("yohime_skiller") ----便于移植的技能 inst:AddComponent("zg_keyhandler_yohime") --inst.components.zg_keyhandler_yohime:AddActionListener("yohime", KEY_Z, "z_skill") inst.components.zg_keyhandler_yohime:AddActionListener("yohime", KEY_X, "x_skill") inst.components.zg_keyhandler_yohime:AddActionListener("yohime", KEY_C, "c_skill") --inst.components.zg_keyhandler_yohime:AddActionListener("yohime", KEY_V, "v_skill") inst:AddComponent("timer") inst:ListenForEvent("timerdone", function(inst, data) --技能冷却好时 if data.name == "z_skill" then inst.z_skill = true elseif data.name == "x_skill" then inst.x_skill = true elseif data.name == "c_skill" then inst.c_skill = true end end) --inst.z_skill_cd = 30 inst.x_skill_cd = 6 inst.c_skill_cd = 2 --if not (inst.z_skill or inst.components.timer:TimerExists("z_skill")) then --inst.components.timer:StartTimer("z_skill", inst.z_skill_cd) --end if not (inst.x_skill or inst.components.timer:TimerExists("x_skill")) then inst.components.timer:StartTimer("x_skill", inst.x_skill_cd) end if not (inst.c_skill or inst.components.timer:TimerExists("c_skill")) then inst.components.timer:StartTimer("c_skill", inst.c_skill_cd) end--]] --inst.z_skill = true --inst.x_skill = true --inst.c_skill = true end-- This initializes for the server only. Components are added here. local master_postinit = function(inst) -- choose which sounds this character will play inst.soundsname = "willow" -- Uncomment if "wathgrithr"(Wigfrid) or "webber" voice is used --inst.talker_path_override = "dontstarve_DLC001/characters/" -- Stats inst.components.health:SetMaxHealth(TUNING.HEALTH) inst.components.hunger:SetMax(TUNING.HUNGER) inst.components.sanity:SetMax(TUNING.SANITY) -- Damage multiplier (optional) inst.components.combat.damagemultiplier = 1 inst.components.sanity.dapperness = 10/60 inst.components.sanity.neg_aura_mult = 0 -- Hunger rate (optional) inst.components.hunger.hungerrate = 1 * TUNING.WILSON_HUNGER_RATE local old_getattacked = inst.components.combat.GetAttacked function inst.components.combat:GetAttacked(attacker, damage, weapon, stimuli) if inst.yohimie_reflect then if attacker and attacker.components.combat then if attacker.components.combat.Zg_GetAttacked then attacker.components.combat:Zg_GetAttacked(inst, damage) else attacker.components.combat:GetAttacked(inst, damage) end end --local amulet = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.NECK or EQUIPSLOTS.BODY) --if amulet and amulet.prefab == "yohime_amulet" then -- amulet.components.finiteuses:Use(1) --end --damage = 0 end return old_getattacked(self, attacker, damage, weapon, stimuli) end inst:AddComponent("eater") inst.components.eater.healthabsorption = TUNING.HEALTH_ABSORPTION inst.components.eater.hungerabsorption = TUNING.HUNGER_ABSORPTION inst.components.eater.sanityabsorption = TUNING.SANITY_ABSORPTION inst.components.eater:SetOnEatFn(oneat) inst:AddComponent("groundpounder") inst.components.groundpounder.numRings = 2 inst.components.groundpounder.burner = false inst.components.groundpounder.groundpoundfx = "firesplash_fx" inst.components.groundpounder.groundpounddamagemult = 1 inst.components.groundpounder.groundpoundringfx = "firering_fx" inst.components.groundpounder.destroyer = false inst.components.groundpounder.destructionRings = 2 function inst.components.groundpounder:DestroyPoints(points, breakobjects, dodamage) local getEnts = breakobjects or dodamage local map = TheWorld.Map for k, v in pairs(points) do if getEnts then local ents = TheSim:FindEntities(v.x, v.y, v.z, 3, nil, self.noTags) if #ents > 0 then if breakobjects then for i, v2 in ipairs(ents) do if v2 ~= self.inst and v2:IsValid() then -- Don't net any insects when we do work if self.destroyer and v2.components.workable ~= nil and v2.components.workable:CanBeWorked() and v2.components.workable.action ~= ACTIONS.NET then v2.components.workable:Destroy(self.inst) end if v2:IsValid() and --might've changed after work? not v2:IsInLimbo() and --might've changed after work? self.burner and v2.components.fueled == nil and v2.components.burnable ~= nil and not v2.components.burnable:IsBurning() and not v2:HasTag("burnt") then v2.components.burnable:Ignite() end end end end if dodamage then for i, v2 in ipairs(ents) do if v2 ~= self.inst and v2:IsValid() and v2.components.health ~= nil and not v2.components.health:IsDead() and self.inst.components.combat:CanTarget(v2) and not (v2.components.follower and v2.components.follower.leader == inst ) and (TheNet:GetPVPEnabled() or not v2:HasTag("player")) and not v2:HasTag("wall") then --self.inst.components.combat:DoAttack(v2, nil, nil, nil, self.groundpounddamagemult) if v2.sg and v2.sg.sg and v2.sg.sg.states and v2.sg.sg.states["hit"] then v2.sg:GoToState("hit") end v2.components.health:DoFireDamage(10, nil, true) -- if v2.components.burnable then if v2.xiana_task == nil then v2.components.burnable:SpawnFX() v2.xiana_task = v2:DoPeriodicTask(1, function() v2.components.health:DoFireDamage(TUNING.SWORD_UPDATE * 2, nil, true) end) v2:DoTaskInTime(3, function() if v2.xiana_task ~= nil then v2.xiana_task:Cancel() v2.xiana_task = nil v2.components.burnable:KillFX() end end) end end if v2.components.combat then if v2.components.combat.Zg_GetAttacked then v2.components.combat:Zg_GetAttacked(inst, 30) else v2.components.combat:GetAttacked(inst, 30) end end end end end end end if map:IsPassableAtPoint(v:Get()) then SpawnPrefab(self.groundpoundfx).Transform:SetPosition(v.x, 0, v.z) end end end inst:ListenForEvent("attacked", function(inst, data) --if inst.yohime_reflect == true then local attacker = data.attacker local damage = data.damage or 0 if attacker then local dist = inst:GetPosition():Dist( attacker:GetPosition() ) if dist > 6 then if attacker.components.combat then attacker.components.combat:GetAttacked(inst, damage) end end end --end end) inst.zgsabber_fn = function(inst, data) local proj = data and data.proj if proj and proj.components.projectile then local amulet = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.NECK or EQUIPSLOTS.BODY) if amulet and amulet.prefab == "yohime_amulet" then amulet.components.finiteuses:Use(1) --damage = 0 ----不再跟踪 proj.components.projectile.homing = false proj.components.projectile.hitdist = (proj.components.projectile.hitdist or 0) / 3 local direction = ( (proj.components.projectile.dest) or Vector3(0,0,0) - proj:GetPosition() ):GetNormalized() local angle = math.acos( direction:Dot(Vector3(1, 0, 0)) ) / DEGREES ----弹道偏离 if math.random() < .5 then proj.Transform:SetRotation( angle + math.random() * 180 ) else proj.Transform:SetRotation( angle - math.random() * 180 ) end ----弹道减慢 if proj.Physics then proj.Physics:SetMotorVelOverride(1,0,0) end ----不再具有目标 if proj.components.projectile.target then proj.components.projectile.target = nil end ----如果不是武器类型则加个定时器 if not proj.components.weapon then proj:DoTaskInTime(3, proj.Remove) end end --self.inst:FacePoint(dest) end end --inst.components.locomotor:SetExternalSpeedMultiplier(inst, "zgsabber_speed_mod", 1.25) inst:ListenForEvent("hostileprojectile_for_jws", inst.zgsabber_fn) inst.components.health.absorb = 0 inst.components.health.fire_damage_scale = 1 inst.components.temperature.mintemp = -10 inst.components.temperature.maxtemp = 80 inst.components.freezable.resistance = 180 --回血 inst:DoPeriodicTask(6, function() if not inst.components.health:IsDead() and not inst:HasTag("playerghost") then inst.components.health:DoDelta(TUNING.REGENE, true) --if inst.Light then --inst.Light:Enable(true) --inst.Light:SetRadius(10) --inst.Light:SetFalloff(.5) --inst.Light:SetIntensity(0.9) --inst.Light:SetColour(245/85,85/85,245/85) --end end end) inst:ListenForEvent("attacked", function(inst, data) local attacker = data.attacker if attacker then --点燃攻击者 local v = attacker if v.components.health and not v.components.health:IsDead() and v.components.burnable then if v.xiana_task == nil then v.components.burnable:SpawnFX() v.xiana_task = v:DoPeriodicTask(1, function() v.components.health:DoDelta( -3 * v.components.health.fire_damage_scale * TUNING.SWORD_SKILL ) end) local function cancel(v) if v.xiana_task ~= nil then v.xiana_task:Cancel() v.xiana_task = nil v.components.burnable:KillFX() end end v:DoTaskInTime(2, function() cancel(v) end) v:ListenForEvent("death", function(inst, data) cancel(v) end) end end end end) local function updatedamage(inst, phase) if phase == "day" then inst.components.combat.damagemultiplier = 1 elseif phase == "night" then if TheWorld.state.isfullmoon == true then inst.components.combat.damagemultiplier = 1.5 else inst.components.combat.damagemultiplier = 1.2 end elseif phase == "dusk" then inst.components.combat.damagemultiplier = 1 end end inst:WatchWorldState("phase", updatedamage) updatedamage(inst, TheWorld.state.phase) inst.OnLoad = onload inst.OnNewSpawn = onload endreturn MakePlayerCharacter("yohime", prefabs, assets, common_postinit, master_postinit, start_inv)
1 下一页