Error 502
Intermediate OT User
1.5 Nekiro downgrade.
I don't have much experience in C++. I come to ask how to do an IF function without dying trying xd
I want to know if the way of coding in c++ is correct, especially the storage
Context: how to change the way to display HP and mana according to storage , changing them with talkations. using c++
as in the gif
protocolgame.cpp on void ProtocolGame::AddPlayerStats(NetworkMessage& msg)
HP
MANA
Beta script lua On Server
I don't need help in lua but in c++ I don't know the language, I don't know how to call storages or do if functions
I don't have much experience in C++. I come to ask how to do an IF function without dying trying xd
I want to know if the way of coding in c++ is correct, especially the storage
Context: how to change the way to display HP and mana according to storage , changing them with talkations. using c++
as in the gif
protocolgame.cpp on void ProtocolGame::AddPlayerStats(NetworkMessage& msg)
HP
C++:
void ProtocolGame::AddPlayerStats(NetworkMessage& msg)
{
msg.addByte(0xA0);
//Get storage and IF
std::string value;
getStorage(7999, value);
int32_t check = atoi(value.c_str());
if(check >=1){
// IF storage >=1 then HP in percent
if (player->getMaxHealth() > 0)
{
msg.add<uint16_t>(std::min<int32_t>(player->getHealth() * 100 / player->getMaxHealth(), std::numeric_limits<uint16_t>::max()));
msg.add<uint16_t>(100);
}
else
{
msg.add<uint16_t>(0);
msg.add<uint16_t>(0);
}
}
else
{
// else storage = 0 then HP in Points
msg.add<uint16_t>(std::min<int32_t>(player->getHealth(), std::numeric_limits<uint16_t>::max()));
msg.add<uint16_t>(std::min<int32_t>(player->getMaxHealth(), std::numeric_limits<uint16_t>::max()));
}
MANA
C++:
if(check >=1){
if (player->getMaxMana() > 0)
{
msg.add<uint16_t>(std::min<int32_t>(player->getMana() * 100 / player->getMaxMana(), std::numeric_limits<uint16_t>::max()));
msg.add<uint16_t>(100);
}
else
{
msg.add<uint16_t>(0);
msg.add<uint16_t>(0);
}
}
else
{
msg.add<uint16_t>(std::min<int32_t>(player->getMana(), std::numeric_limits<uint16_t>::max()));
msg.add<uint16_t>(std::min<int32_t>(player->getMaxMana(), std::numeric_limits<uint16_t>::max()));
}
Beta script lua On Server
Lua:
local creatureEvent = CreatureEvent("setStorage")
function creatureEvent.onLogin(player)
if player:getLastLoginSaved() == 0 then
player:setStorageValue(7999, 1)
end
return true
end
creatureEvent:register()
local talkAction = TalkAction("!hp")
function talkAction.onSay(player, words, param, type)
if player:getStorageValue(7999) == 1 then
player:sendTextMessage(MESSAGE_STATUS_SMALL, 'HP/Mana in percentage')
player:setStorageValue(7999, 0)
else
player:sendTextMessage(MESSAGE_STATUS_SMALL, 'HP/Mana in points')
player:setStorageValue(7999, 1)
return false
end
talkAction:register()