welll im using this lua code in creatuevents folders the idea is to disable mounts for certain outfits
but it isn't working.... could someone convert this code for me into cc++ pls?
outfitcheck.lua
mounts.cpp
but it isn't working.... could someone convert this code for me into cc++ pls?
outfitcheck.lua
Code:
local outfit_ids = {387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 28, 29, 30, 31}
function onOutfit(cid, old, current)
local mount_not_allowed = false
if current.lookMount > 0 then
for i = 1, #outfit_ids do
if current.lookType == outfit_ids[i] then
mount_not_allowed = true
break
end
end
end
if mount_not_allowed == true then
current.lookMount = 0
doPlayerSetMounted(cid, false)
doCreatureChangeOutfit(cid, current)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, "Mount disabled on this outfit.")
end
return true
end
mounts.cpp
Code:
////////////////////////////////////////////////////////////////////////
// OpenTibia - an opensource roleplaying game
////////////////////////////////////////////////////////////////////////
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
////////////////////////////////////////////////////////////////////////
#include "otpch.h"
#include "mounts.h"
bool Mount::isTamed(Player* player) const
{
if(!player)
return false;
if(player->hasCustomFlag(PlayerCustomFlag_CanUseAllMounts))
return true;
if(premium && !player->isPremium())
return false;
uint8_t tmpId = id - 1;
std::string value;
int32_t key = PSTRG_MOUNTS_RANGE_START + (tmpId / 31);
if(player->getStorage(asString(key), value))
{
int32_t tmp = (int32_t)std::pow(2., tmpId % 31);
return (tmp & atoi(value.c_str())) == tmp;
}
if(storageId.empty())
return false;
player->getStorage(storageId, value);
if(value == storageValue)
return true;
int32_t intValue = atoi(value.c_str());
if(!intValue && value != "0")
return false;
int32_t tmp = atoi(storageValue.c_str());
if(!tmp && storageValue != "0")
return false;
return intValue >= tmp;
}
void Mount::addAttributes(Player* player)
{
if(invisible)
{
Condition* condition = Condition::createCondition(CONDITIONID_MOUNT, CONDITION_INVISIBLE, -1, 0);
player->addCondition(condition);
}
if(manaShield)
{
Condition* condition = Condition::createCondition(CONDITIONID_MOUNT, CONDITION_MANASHIELD, -1, 0);
player->addCondition(condition);
}
if(conditionSuppressions)
{
player->setConditionSuppressions(conditionSuppressions, false);
player->sendIcons();
}
if(regeneration)
{
Condition* condition = Condition::createCondition(CONDITIONID_MOUNT, CONDITION_REGENERATION, -1, 0);
if(healthGain)
condition->setParam(CONDITIONPARAM_HEALTHGAIN, healthGain);
if(healthTicks)
condition->setParam(CONDITIONPARAM_HEALTHTICKS, healthTicks);
if(manaGain)
condition->setParam(CONDITIONPARAM_MANAGAIN, manaGain);
if(manaTicks)
condition->setParam(CONDITIONPARAM_MANATICKS, manaTicks);
player->addCondition(condition);
}
bool needUpdateSkills = false;
for(uint32_t i = SKILL_FIRST; i <= SKILL_LAST; ++i)
{
if(skills[i])
{
needUpdateSkills = true;
player->setVarSkill((skills_t)i, skills[i]);
}
if(skillsPercent[i])
{
needUpdateSkills = true;
player->setVarSkill((skills_t)i, (int32_t)(player->getSkill((skills_t)i, SKILL_LEVEL) * ((skillsPercent[i] - 100) / 100.f)));
}
}
if(needUpdateSkills)
player->sendSkills();
bool needUpdateStats = false;
for(uint32_t s = STAT_FIRST; s <= STAT_LAST; ++s)
{
if(stats[s])
{
needUpdateStats = true;
player->setVarStats((stats_t)s, stats[s]);
}
if(statsPercent[s])
{
needUpdateStats = true;
player->setVarStats((stats_t)s, (int32_t)(player->getDefaultStats((stats_t)s) * ((statsPercent[s] - 100) / 100.f)));
}
}
if(needUpdateStats)
player->sendStats();
}
void Mount::removeAttributes(Player* player)
{
if(invisible)
player->removeCondition(CONDITION_INVISIBLE, CONDITIONID_MOUNT);
if(manaShield)
player->removeCondition(CONDITION_MANASHIELD, CONDITIONID_MOUNT);
if(conditionSuppressions)
{
player->setConditionSuppressions(conditionSuppressions, true);
player->sendIcons();
}
if(regeneration)
player->removeCondition(CONDITION_REGENERATION, CONDITIONID_MOUNT);
bool needUpdateSkills = false;
for(uint32_t i = SKILL_FIRST; i <= SKILL_LAST; ++i)
{
if(skills[i])
{
needUpdateSkills = true;
player->setVarSkill((skills_t)i, -skills[i]);
}
if(skillsPercent[i])
{
needUpdateSkills = true;
player->setVarSkill((skills_t)i, -(int32_t)(player->getSkill((skills_t)i, SKILL_LEVEL) * ((skillsPercent[i] - 100) / 100.f)));
}
}
if(needUpdateSkills)
player->sendSkills();
bool needUpdateStats = false;
for(uint32_t s = STAT_FIRST; s <= STAT_LAST; ++s)
{
if(stats[s])
{
needUpdateStats = true;
player->setVarStats((stats_t)s, -stats[s]);
}
if(statsPercent[s])
{
needUpdateStats = true;
player->setVarStats((stats_t)s, -(int32_t)(player->getDefaultStats((stats_t)s) * ((statsPercent[s] - 100) / 100.f)));
}
}
if(needUpdateStats)
player->sendStats();
}
void Mounts::clear()
{
for(MountList::iterator it = mounts.begin(); it != mounts.end(); ++it)
delete *it;
mounts.clear();
}
bool Mounts::reload()
{
clear();
return loadFromXml();
}
bool Mounts::loadFromXml()
{
xmlDocPtr doc = xmlParseFile(getFilePath(FILE_TYPE_XML, "mounts.xml").c_str());
if(!doc)
{
std::clog << "[Warning - Mounts::loadFromXml] Cannot load mounts file." << std::endl;
std::clog << getLastXMLError() << std::endl;
return false;
}
xmlNodePtr root = xmlDocGetRootElement(doc);
if(xmlStrcmp(root->name, (const xmlChar*)"mounts"))
{
std::clog << "[Error - Mounts::loadFromXml] Malformed mounts file." << std::endl;
xmlFreeDoc(doc);
return false;
}
for(xmlNodePtr p = root->children; p; p = p->next)
parseMountNode(p);
xmlFreeDoc(doc);
return true;
}
bool Mounts::parseMountNode(xmlNodePtr p)
{
if(xmlStrcmp(p->name, (const xmlChar*)"mount"))
return false;
int32_t intValue;
std::string strValue;
uint8_t mountId = 0;
if(readXMLInteger(p, "id", intValue))
mountId = intValue;
std::string name;
if(readXMLString(p, "name", strValue))
name = strValue;
uint16_t clientId = 0;
if(readXMLInteger(p, "clientid", intValue) || readXMLInteger(p, "clientId", intValue) || readXMLInteger(p, "cid", intValue))
clientId = intValue;
int32_t speed = 0;
if(readXMLInteger(p, "speed", intValue))
speed = intValue;
int32_t attackSpeed = 0;
if(readXMLInteger(p, "attackspeed", intValue) || readXMLInteger(p, "attackSpeed", intValue))
attackSpeed = intValue;
bool premium = true;
if(readXMLString(p, "premium", strValue))
premium = booleanString(strValue);
std::string storageId, storageValue;
if(readXMLString(p, "quest", strValue))
{
storageId = strValue;
storageValue = "1";
}
else
{
if(readXMLString(p, "storageId", strValue))
storageId = strValue;
if(readXMLString(p, "storageValue", strValue))
storageValue = strValue;
}
if(!mountId)
{
std::clog << "[Error - Mounts::parseMountNode] Entry without mountId" << std::endl;
return false;
}
if(!clientId)
{
std::clog << "[Error - Mounts::parseMountNode] Entry without clientId" << std::endl;
return false;
}
Mount* mount = new Mount(name, mountId, clientId,
speed, attackSpeed, premium, storageId, storageValue);
if(!mount)
return false;
if(readXMLString(p, "manaShield", strValue))
mount->manaShield = booleanString(strValue);
if(readXMLString(p, "invisible", strValue))
mount->invisible = booleanString(strValue);
if(readXMLInteger(p, "healthGain", intValue))
{
mount->healthGain = intValue;
mount->regeneration = true;
}
if(readXMLInteger(p, "healthTicks", intValue))
{
mount->healthTicks = intValue;
mount->regeneration = true;
}
if(readXMLInteger(p, "manaGain", intValue))
{
mount->manaGain = intValue;
mount->regeneration = true;
}
if(readXMLInteger(p, "manaTicks", intValue))
{
mount->manaTicks = intValue;
mount->regeneration = true;
}
for(xmlNodePtr configNode = p->children; configNode != NULL; configNode = configNode->next)
{
if(!xmlStrcmp(configNode->name, (const xmlChar*)"reflect"))
{
if(readXMLInteger(configNode, "percentAll", intValue))
{
for(uint32_t i = (COMBAT_FIRST + 1); i <= COMBAT_LAST; i <<= 1)
mount->reflect[REFLECT_PERCENT][i] += intValue;
}
if(readXMLInteger(configNode, "percentElements", intValue))
{
mount->reflect[REFLECT_PERCENT][COMBAT_ENERGYDAMAGE] += intValue;
mount->reflect[REFLECT_PERCENT][COMBAT_FIREDAMAGE] += intValue;
mount->reflect[REFLECT_PERCENT][COMBAT_EARTHDAMAGE] += intValue;
mount->reflect[REFLECT_PERCENT][COMBAT_ICEDAMAGE] += intValue;
}
if(readXMLInteger(configNode, "percentMagic", intValue))
{
mount->reflect[REFLECT_PERCENT][COMBAT_ENERGYDAMAGE] += intValue;
mount->reflect[REFLECT_PERCENT][COMBAT_FIREDAMAGE] += intValue;
mount->reflect[REFLECT_PERCENT][COMBAT_EARTHDAMAGE] += intValue;
mount->reflect[REFLECT_PERCENT][COMBAT_ICEDAMAGE] += intValue;
mount->reflect[REFLECT_PERCENT][COMBAT_HOLYDAMAGE] += intValue;
mount->reflect[REFLECT_PERCENT][COMBAT_DEATHDAMAGE] += intValue;
}