local KEY = { LAST_HP_KEY = "T$LAST_HP", LAST_MP_KEY = "T$LAST_MP" } HpMpRecover = {} --记录下血量和蓝量,在进入跨服地图或者登录游戏的时候恢复 function HpMpRecover.record(actor) local hp = getbaseinfo(actor, "hp") local mp = getbaseinfo(actor, "mp") setplaydef(actor, KEY.LAST_HP_KEY, hp) setplaydef(actor, KEY.LAST_MP_KEY, mp) info("记录当前血量和蓝量", "hp",hp, "mp", mp) end --恢复血量和蓝量 function HpMpRecover.recover(actor) intervalcalldelay(actor, 500, 0, 1, "hpmprecover_recover") end function hpmprecover_recover(actor) local lastHp = getplaydef(actor, KEY.LAST_HP_KEY) local lastMp = getplaydef(actor, KEY.LAST_MP_KEY) if not string.isNullOrEmpty(lastHp) then local numLastHp = tonumber(lastHp) local numCurrHp = getbaseinfo(actor, "hp") if numLastHp ~= numCurrHp then sethp(actor,numLastHp) info("恢复当前HP", "之前的HP:", numLastHp, "现在的HP:", numCurrHp) end end if not string.isNullOrEmpty(lastMp) then local numLastMp = tonumber(lastMp) local numCurrMp = getbaseinfo(actor, "mp") if numLastMp ~= numCurrMp then setmp(actor, numLastMp) info("恢复当前MP", "之前的MP:", numLastMp,"现在的MP:", numCurrMp) end end end