I
Icy
Guest
So every single command and LUA command doesn't change NPC's health.
All don't work.
/attr works, because it uses the "thingProporties" function:
I guess the specific part that matters is:
So, any idea how I would change this into an LUA function?
Lua:
doCreatureAddHealth
doTargetCombatHealth
setCreatureMaxHealth (lower) -> doCreatureAddHealth (to reset) -> setCreatureMaxHealth (revert)
doAreaCombatHealth
All don't work.
/attr works, because it uses the "thingProporties" function:
Code:
bool TalkAction::thingProporties(Creature* creature, const std::string&, const std::string& param)
{
Player* player = creature->getPlayer();
if(!player)
return false;
const Position& pos = getNextPosition(player->getDirection(), player->getPosition());
Tile* tile = g_game.getTile(pos);
if(!tile)
{
player->sendTextMessage(MSG_STATUS_SMALL, "No tile found.");
g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
return true;
}
Thing* thing = tile->getTopVisibleThing(creature);
if(!thing)
{
player->sendTextMessage(MSG_STATUS_SMALL, "No object found.");
g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
return true;
}
boost::char_separator<char> sep(" ");
tokenizer tokens(param, sep);
std::string invalid;
for(tokenizer::iterator it = tokens.begin(); it != tokens.end();)
{
std::string action = parseParams(it, tokens.end());
toLowerCaseString(action);
if(Item* item = thing->getItem())
{
if(action == "set")
{
std::string type = parseParams(it, tokens.end()), key = parseParams(it,
tokens.end()), value = parseParams(it, tokens.end());
if(type == "integer" || type == "number" || type == "int")
item->setAttribute(key, atoi(value.c_str()));
else if(type == "float" || type == "double")
item->setAttribute(key, (float)atof(value.c_str()));
else if(type == "bool" || type == "boolean")
item->setAttribute(key, booleanString(value));
else
item->setAttribute(key, value);
}
else if(action == "erase" || action == "remove")
item->eraseAttribute(parseParams(it, tokens.end()));
else if(action == "action" || action == "actionid" || action == "aid")
{
int32_t tmp = atoi(parseParams(it, tokens.end()).c_str());
if(tmp > 0)
item->setActionId(tmp);
else
item->resetActionId();
}
else if(action == "unique" || action == "uniqueid" || action == "uid")
{
int32_t tmp = atoi(parseParams(it, tokens.end()).c_str());
if(tmp >= 1000 || tmp <= 0xFFFF)
item->setUniqueId(tmp);
}
else if(action == "destination" || action == "position"
|| action == "pos" || action == "dest") //TODO: doesn't work
{
if(Teleport* teleport = item->getTeleport())
teleport->setDestination(Position(atoi(parseParams(it, tokens.end()).c_str()), atoi(
parseParams(it, tokens.end()).c_str()), atoi(parseParams(it, tokens.end()).c_str())));
}
else
{
std::stringstream s;
s << action << " (" << parseParams(it, tokens.end()) << ")";
invalid += s.str();
break;
}
}
else if(Creature* _creature = thing->getCreature())
{
if(action == "health")
_creature->changeHealth(atoi(parseParams(it, tokens.end()).c_str()));
else if(action == "maxhealth")
_creature->changeMaxHealth(atoi(parseParams(it, tokens.end()).c_str()));
else if(action == "mana")
_creature->changeMana(atoi(parseParams(it, tokens.end()).c_str()));
else if(action == "maxmana")
_creature->changeMaxMana(atoi(parseParams(it, tokens.end()).c_str()));
else if(action == "basespeed")
_creature->setBaseSpeed(atoi(parseParams(it, tokens.end()).c_str()));
else if(action == "droploot")
_creature->setDropLoot((lootDrop_t)atoi(parseParams(it, tokens.end()).c_str()));
else if(action == "lossskill")
_creature->setLossSkill(booleanString(parseParams(it, tokens.end())));
else if(action == "cannotmove")
_creature->setNoMove(booleanString(parseParams(it, tokens.end())));
else if(action == "skull")
{
_creature->setSkull(getSkulls(parseParams(it, tokens.end())));
g_game.updateCreatureSkull(_creature);
}
else if(action == "shield")
{
_creature->setShield(getShields(parseParams(it, tokens.end())));
g_game.updateCreatureShield(_creature);
}
else if(action == "emblem")
{
_creature->setEmblem(getEmblems(parseParams(it, tokens.end())));
g_game.updateCreatureEmblem(_creature);
}
else if(action == "speaktype")
_creature->setSpeakType((SpeakClasses)atoi(parseParams(it, tokens.end()).c_str()));
else if(Player* _player = _creature->getPlayer())
{
if(action == "fyi")
_player->sendFYIBox(parseParams(it, tokens.end()).c_str());
else if(action == "tutorial")
_player->sendTutorial(atoi(parseParams(it, tokens.end()).c_str()));
else if(action == "guildlevel")
_player->setGuildLevel((GuildLevel_t)atoi(parseParams(it, tokens.end()).c_str()));
else if(action == "guildrank")
_player->setRankId(atoi(parseParams(it, tokens.end()).c_str()));
else if(action == "guildnick")
_player->setGuildNick(parseParams(it, tokens.end()).c_str());
else if(action == "group")
_player->setGroupId(atoi(parseParams(it, tokens.end()).c_str()));
else if(action == "vocation")
_player->setVocation(atoi(parseParams(it, tokens.end()).c_str()));
else if(action == "sex" || action == "gender")
_player->setSex(atoi(parseParams(it, tokens.end()).c_str()));
else if(action == "town" || action == "temple")
{
if(Town* town = Towns::getInstance()->getTown(parseParams(it, tokens.end())))
{
_player->setMasterPosition(town->getPosition());
_player->setTown(town->getID());
}
}
else if(action == "marriage" || action == "partner")
_player->marriage = atoi(parseParams(it, tokens.end()).c_str());
else if(action == "balance")
_player->balance = atoi(parseParams(it, tokens.end()).c_str());
else if(action == "rates")
_player->rates[atoi(parseParams(it, tokens.end()).c_str())] = atof(
parseParams(it, tokens.end()).c_str());
else if(action == "idle")
_player->setIdleTime(atoi(parseParams(it, tokens.end()).c_str()));
else if(action == "stamina")
_player->setStaminaMinutes(atoi(parseParams(it, tokens.end()).c_str()));
else if(action == "capacity" || action == "cap")
_player->setCapacity(atoi(parseParams(it, tokens.end()).c_str()));
else if(action == "execute")
g_talkActions->onPlayerSay(_player, atoi(parseParams(it, tokens.end()).c_str()),
parseParams(it, tokens.end()), booleanString(parseParams(it, tokens.end())));
else if(action == "saving" || action == "save")
_player->switchSaving();
else
{
std::stringstream s;
s << action << " (" << parseParams(it, tokens.end()) << ")";
invalid += s.str();
break;
}
}
/*else if(Npc* _npc = _creature->getNpc())
{
}
else if(Monster* _monster = _creature->getMonster())
{
}*/
else
{
std::stringstream s;
s << action << " (" << parseParams(it, tokens.end()) << ")";
invalid += s.str();
break;
}
}
}
const SpectatorVec& list = g_game.getSpectators(pos);
SpectatorVec::const_iterator it;
Player* tmpPlayer = NULL;
for(it = list.begin(); it != list.end(); ++it)
{
if((tmpPlayer = (*it)->getPlayer()))
tmpPlayer->sendUpdateTile(tile, pos);
}
for(it = list.begin(); it != list.end(); ++it)
(*it)->onUpdateTile(tile, pos);
g_game.addMagicEffect(pos, MAGIC_EFFECT_WRAPS_GREEN);
if(invalid.empty())
return true;
std::string tmp = "Following action was invalid: " + invalid;
player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, tmp.c_str());
return true;
}
I guess the specific part that matters is:
Code:
_creature->changeHealth(atoi(parseParams(it, tokens.end()).c_str()));
So, any idea how I would change this into an LUA function?
Last edited by a moderator: