石器ABLUA神奇经验丹

石器时代私服里很多服里都会有收集经验丹的功能,这里提一下给大家分析分析一下,写法和语句上可能跟你们所使用的不太一样。但大致都是相同的。

看到freecharexpsave.lua这个LUA,其函数为FreeCharExpSave( charaindex, exp ),参数为玩家索引和获得的经验值。

代码分析如下:

function FreeCharExpSave( charaindex, exp )
	--获取道具栏第一个位置的索引(9是在高版本是道具栏第一个位置)
	--9~23均为道具栏,0~8为装备栏,市面上99.99%的石器时代无论高低版都是按照高版本的方式来。
	--石器1.82版则是按照5~19为道具栏,0~4为装备栏
	itemindex = char.getItemIndex(charaindex, 9)
	--如果存在道具则返回道具索引
	if itemindex > -1 then
		--判断该道具ID,需要参考itemset6.txt,这里22100为神奇经验丹
		if item.getInt(itemindex, "序号") == 22100 then
			--防止出现经验丹叠加导致叠加的经验丹都会收集到经验
		    if item.getInt(itemindex, "堆叠") > 1 then
			    return
		    end
			--定义收集经验的变量,这里是获取该道具的字段,经验存放在这个字段里
		    local itemexp = other.atoi(item.getChar(itemindex, "字段"))
			--这里超过20W亿的经验则返回就不会再经验经验了
		    if itemexp > 2000000000 then
			    return
		    end
			--判断服务器线路,这样可以在不同的线路里获得不同的经验倍数
		    if config.getGameservername() == "石器一线" then
				--把获得的经验写入至字段里,这里要提一下,exp的经验只是1倍的经验,并非最终获得经验,所以根据线路的不同乘不同倍数,再加上经验果的经验。
				--有源码的话可以修改成最终获得的经验,比这种写法要方便多了。石器1.82就是最终人物所获得的经验
			    item.setChar(itemindex, "字段", itemexp + exp * 2 + exp * 4 * (char.getWorkInt(charaindex, "经验加成") / 100))
		    else
			    item.setChar(itemindex, "字段", itemexp + exp * 2 + exp * 6 * (char.getWorkInt(charaindex, "经验加成") / 100))
		    end
			--判断收集的经验数,根据万,亿来写入到说明里
		    if other.atoi(item.getChar(itemindex, "字段")) > 100000000 then
				--这里是超过一亿的时候,则说明改成亿
			    item.setChar(itemindex, "说明", "神奇经验丹已收集到" .. other.atoi(item.getChar(itemindex, "字段")) / 100000000 .. "亿 EXP")
		    elseif other.atoi(item.getChar(itemindex, "字段")) > 10000 then
			    --这里是超过一万的时候,则说明改成万
			    item.setChar(itemindex, "说明", "神奇经验丹已收集到" .. other.atoi(item.getChar(itemindex, "字段")) / 10000 .. "万 EXP")
		    else
			    item.setChar(itemindex, "说明", "神奇经验丹已收集到" .. other.atoi(item.getChar(itemindex, "字段")) .. " EXP")
		    end
			--更新道具说明等显示
		    item.UpdataItemOne(charaindex, itemindex)
		    return
		end
	end
end

注释已经说的很清楚了。相信很容易看懂。


发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。