function doPlayerAddAchievement(cid, achie) -- 'achie' may be an achievement ID or achievement NAME
if type(achie) == "string" then -- name
--if not getPlayerAchievementByName(cid, achie) then
-- doCreatureSetStorage(cid, getAchievementStorageIdByName(achie), getAchievementStorageValueByName(achie))
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, getAchievementMessageByName(achie))
--end
elseif type(achie) == "number" then-- id
--if not getPlayerAchievement(cid, achie) then
-- doCreatureSetStorage(cid, getAchievementStorageId(achie), getAchievementStorageValue(achie))
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, getAchievementMessage(achie))
--end
end
return true
end
CREATE TABLE `player_achievements`
(
`player_id` INT NOT NULL DEFAULT 0,
`id` INT NOT NULL DEFAULT 0,
`grade` INT NOT NULL DEFAULT 0,
`points` INT NOT NULL DEFAULT 0,
`secret` BOOLEAN NOT NULL DEFAULT FALSE,
KEY (`player_id`), UNIQUE (`player_id`, `id`),
FOREIGN KEY (`player_id`) REFERENCES `players`(`id`) ON DELETE CASCADE
) ENGINE = InnoDB;
db.executeQuery("INSERT INTO `player_achievements` WHERE `player_id` = cid VALUES (" .. id .. ", " .. info.grade .. ", " .. info.points .. ", " .. info.secret .. ");")
db.executeQuery("INSERT INTO `player_achievements` VALUES (" .. getPlayerGUID(cid) .. ", " .. id .. ", " .. info.grade .. ", " .. info.points .. ", " .. info.secret .. ");"
return getCreatureStorage(cid, getAchievementStorageId(id)) >= getAchievementStorageValue(id);
return tonumber(getCreatureStorage(cid, getAchievementStorageId(id))) >= tonumber(getAchievementStorageValue(id));
old_doCreatureSetStorage = doCreatureSetStorage
function doCreatureSetStorage(cid, sid, value)
if(isPlayer(cid)) then
if sid >= ACHIEVEMENT_FIRST and sid <= ACHIEVEMENT_LAST then
local id = sid - ACHIEVEMENT_BASE
if getAchievementStorageValue(id) >= value and getCreatureStorage(cid, sid) >= getAchievementStorageValue(id) then
doPlayerAddAchievement(cid, id, true);
end
end
end
return old_doCreatureSetStorage(cid, sid, value)
end
function doPlayerGiveAchievement(cid, achievementid)
doCreatureSetStorage(cid, getAchievementStorageId(achievementid), getCreatureStorage(cid, getAchievementStorageId(achievementid)) + 1)
end
doCreatureSetStorage(cid, getAchievementStorageId(30), getCreatureStorage(cid, getAchievementStorageId(30)) + 1)