function titleuse(itemindex, charaindex, toindex, haveitemindex)
	local id = other.atoi(item.getChar(itemindex, "字段"))
	if GetCharNewTitleMode(charaindex,id -1)== 1 then
		char.TalkToCli(charaindex, -1, "您已拥有该称号！", "黄色")
		return
	end
	local titlename = item.getChar(itemindex,"显示名")
	char.DelItem(charaindex, haveitemindex)
	char.setCharNewTitleMode(charaindex,id -1)
--	char.setInt(charaindex, "称号状态2", 0)
---	char.setInt(charaindex, "称号状态3", 0)

	char.TalkToCli(charaindex, -1, "恭喜你获得新称号"..titlename.."！", "黄色")
	char.talkToServer(-1, "[功成名就]恭喜勇者 " .. char.getChar(charaindex, "名字") .. " 获得"..titlename.."称号", "黄色")
	local param = {charaindex}
	other.CallFunction("TitleListSend", "data/ablua/freechartitle.lua", param)
end

function GetCharNewTitleMode(charaindex,id)
	if id< 32 then
		if other.DataAndData(char.getInt(charaindex,"称号状态1"),id)~= 0 then
			return 1
		end
	elseif id< 64 then
		if other.DataAndData(char.getInt(charaindex,"称号状态2"),id-32)~= 0 then
			return 1
		end
	elseif id< 96 then
		if other.DataAndData(char.getInt(charaindex,"称号状态3"),id-64)~= 0 then
			return 1
		end
	end
	return 0
end

function main()
	item.addLUAListFunction( "ITEM_TITLE", "titleuse", "")
end
