So yeah, nothing official but I use this for my server. I'm sure you guys can fix this up if it seems hacky >.> / Here you go Jimmy ;)
If I missed something or if anything doesn't work just reply and we'll fix it. it's worked fine for me though, no lagg or w.e.
Map.cpp in the ::Walk( function, where ever you see fit to add it;
if(this->GetSpec(target_x, target_y) == Map_Tile::Spikes2 || this->GetSpec(target_x, target_y) == Map_Tile::Spikes3)
{
from->PlaySound(72); // Spike Sound ;)
if(from->Damage(from->maxhp/7) <= 0) // This is what I set it to, nothing official.
{
return false; // not gonna want to walk if you're dead right ;)
}
}
Character.cpp where ever you want to add it;
int Character::Damage(int amount)
{
amount = std::max(amount, 0);
int limitamount = std::min(amount, int(this->hp));
if (this->world->config["LimitDamage"])
{
amount = limitamount;
}
this->hp -= limitamount;
if (this->party)
{
this->party->UpdateHP(this);
}
//int rechp = int(this->maxhp * static_cast<double>(this->map->world->config["DeathRecover"]));
PacketBuilder builder(PACKET_AVATAR, PACKET_REPLY, 10);
builder.AddShort(0);
builder.AddShort(this->player->id);
builder.AddThree(amount);
builder.AddChar(this->direction);
builder.AddChar(int(double(this->hp) / double(this->maxhp) * 100.0));
builder.AddChar(this->hp == 0);
UTIL_FOREACH(this->map->characters, character)
{
if (!character->InRange(this))
{
continue;
}
character->Send(builder);
}
PacketBuilder builderr(PACKET_RECOVER, PACKET_PLAYER, 6);
builderr.AddShort(this->hp);
builderr.AddShort(this->tp);
builderr.AddShort(0); // ?
this->Send(builderr);
if(this->hp <= 0)
{
++this->deaths;
int rechp = int(this->maxhp * static_cast<double>(this->world->config["DeathRecover"]));
this->hp = rechp;
if (this->map->world->config["Deadly"])
{
this->DropAll(0);
}
this->map->Leave(this, WARP_ANIMATION_NONE, true);
this->nowhere = true;
this->mapid = this->SpawnMap();
this->map = this->world->GetMap(this->SpawnMap());
this->x = this->SpawnX();
this->y = this->SpawnY();
PacketReader reader("");
this->player->client->queue.AddAction(PacketReader(std::array<char, 2>{
{char(PACKET_INTERNAL_NULL), char(PACKET_INTERNAL)}
}.data()), 1.5);
this->player->client->queue.AddAction(PacketReader(std::array<char, 2>{
{char(PACKET_INTERNAL_WARP), char(PACKET_INTERNAL)}
}.data()), 0.0);
}
return amount;
}
Character.HPP;
int Damage(int amount = 100);