Diarreamental
Well-Known Member
- Joined
- Jul 6, 2015
- Messages
- 453
- Solutions
- 1
- Reaction score
- 80
Hello
As stated in the title ranged attack are off like gfb , spears or any ranged attack made by monsters
doing a research i found that nostarlius based off tfs 1.2 was having or has this problem too, they have fixed it by changing normal_random to unfirom_random in sources Nostalrius 7.7 (https://otland.net/threads/nostalrius-7-7.262406/page-18)
the code is this:
the other part:
the code is a bit different in tfs 1.5 qnd seems to be "fixed" but it isn't. as i stated in the main title the ranged attacks are very off in comparision with othire or tfs 0.4
here is the code
the other part
can somebody point out what to change or how to?
thank
As stated in the title ranged attack are off like gfb , spears or any ranged attack made by monsters
doing a research i found that nostarlius based off tfs 1.2 was having or has this problem too, they have fixed it by changing normal_random to unfirom_random in sources Nostalrius 7.7 (https://otland.net/threads/nostalrius-7-7.262406/page-18)
the code is this:
Lua:
void Monster::onThinkDefense(uint32_t)
{
for (const spellBlock_t& spellBlock : mType->info.defenseSpells) {
if (uniform_random(0, spellBlock.chance) == 0 && (master || health > mType->info.runAwayHealth || uniform_random(1, 3) == 1)) {
minCombatValue = spellBlock.minCombatValue;
maxCombatValue = spellBlock.maxCombatValue;
spellBlock.spell->castSpell(this, this);
}
}
if (!isSummon() && summons.size() < mType->info.maxSummons && hasFollowPath) {
for (const summonBlock_t& summonBlock : mType->info.summons) {
if (summons.size() >= mType->info.maxSummons) {
continue;
}
uint32_t summonCount = 0;
for (Creature* summon : summons) {
if (summon->getName() == summonBlock.name) {
++summonCount;
}
}
if (summonCount >= summonBlock.max) {
continue;
}
if (uniform_random(0, summonBlock.chance) == 0 && (health > mType->info.runAwayHealth || uniform_random(1, 3) == 1)) {
Monster* summon = Monster::createMonster(summonBlock.name);
if (summon) {
const Position& summonPos = getPosition();
addSummon(summon);
if (!g_game.placeCreature(summon, summonPos, false, summonBlock.force)) {
removeSummon(summon);
} else {
g_game.addMagicEffect(getPosition(), CONST_ME_MAGIC_BLUE);
g_game.addMagicEffect(summon->getPosition(), CONST_ME_TELEPORT);
}
}
}
}
}
}
Code:
void Monster::doAttacking(uint32_t)
{
if (!attackedCreature || (isSummon() && attackedCreature == this)) {
return;
}
const Position& myPos = getPosition();
const Position& targetPos = attackedCreature->getPosition();
bool updateLook = false;
if (OTSYS_TIME() >= earliestAttackTime && !isFleeing()) {
updateLook = true;
if (Combat::closeAttack(this, attackedCreature, FIGHTMODE_BALANCED)) {
egibleToDance = true;
earliestAttackTime = OTSYS_TIME() + 2000;
removeCondition(CONDITION_AGGRESSIVE, true);
}
}
for (spellBlock_t& spellBlock : mType->info.attackSpells) {
if (spellBlock.range != 0 && std::max<uint32_t>(Position::getDistanceX(myPos, targetPos), Position::getDistanceY(myPos, targetPos)) <= spellBlock.range) {
if (uniform_random(0, spellBlock.chance) == 0 && (master || health > mType->info.runAwayHealth || uniform_random(1, 3) == 1)) {
updateLookDirection();
minCombatValue = spellBlock.minCombatValue;
maxCombatValue = spellBlock.maxCombatValue;
spellBlock.spell->castSpell(this, attackedCreature);
egibleToDance = true;
}
}
}
if (updateLook) {
updateLookDirection();
}
}
the code is a bit different in tfs 1.5 qnd seems to be "fixed" but it isn't. as i stated in the main title the ranged attacks are very off in comparision with othire or tfs 0.4
here is the code
Code:
void Monster::doAttacking(uint32_t interval)
{
if (!attackedCreature || (isSummon() && attackedCreature == this)) {
return;
}
bool updateLook = true;
bool resetTicks = interval != 0;
attackTicks += interval;
const Position& myPos = getPosition();
const Position& targetPos = attackedCreature->getPosition();
for (const spellBlock_t& spellBlock : mType->info.attackSpells) {
bool inRange = false;
if (attackedCreature == nullptr) {
break;
}
if (canUseSpell(myPos, targetPos, spellBlock, interval, inRange, resetTicks)) {
if (spellBlock.chance >= static_cast<uint32_t>(uniform_random(1, 100))) {
if (updateLook) {
updateLookDirection();
updateLook = false;
}
minCombatValue = spellBlock.minCombatValue;
maxCombatValue = spellBlock.maxCombatValue;
spellBlock.spell->castSpell(this, attackedCreature);
if (spellBlock.isMelee) {
lastMeleeAttack = OTSYS_TIME();
}
}
}
if (!inRange && spellBlock.isMelee) {
//melee swing out of reach
lastMeleeAttack = 0;
}
}
if (updateLook) {
updateLookDirection();
}
if (resetTicks) {
attackTicks = 0;
}
}
the other part
Code:
void Monster::onThinkDefense(uint32_t interval)
{
bool resetTicks = true;
defenseTicks += interval;
for (const spellBlock_t& spellBlock : mType->info.defenseSpells) {
if (spellBlock.speed > defenseTicks) {
resetTicks = false;
continue;
}
if (defenseTicks % spellBlock.speed >= interval) {
//already used this spell for this round
continue;
}
if ((spellBlock.chance >= static_cast<uint32_t>(uniform_random(1, 100)))) {
minCombatValue = spellBlock.minCombatValue;
maxCombatValue = spellBlock.maxCombatValue;
spellBlock.spell->castSpell(this, this);
}
}
if (!isSummon() && summons.size() < mType->info.maxSummons && hasFollowPath) {
for (const summonBlock_t& summonBlock : mType->info.summons) {
if (summonBlock.speed > defenseTicks) {
resetTicks = false;
continue;
}
if (summons.size() >= mType->info.maxSummons) {
continue;
}
if (defenseTicks % summonBlock.speed >= interval) {
//already used this spell for this round
continue;
}
uint32_t summonCount = 0;
for (Creature* summon : summons) {
if (summon->getName() == summonBlock.name) {
++summonCount;
}
}
if (summonCount >= summonBlock.max) {
continue;
}
if (summonBlock.chance < static_cast<uint32_t>(uniform_random(1, 100))) {
continue;
}
Monster* summon = Monster::createMonster(summonBlock.name);
if (summon) {
if (g_game.placeCreature(summon, getPosition(), false, summonBlock.force)) {
summon->setDropLoot(false);
summon->setSkillLoss(false);
summon->setMaster(this);
g_game.addMagicEffect(getPosition(), CONST_ME_MAGIC_BLUE);
g_game.addMagicEffect(summon->getPosition(), CONST_ME_TELEPORT);
} else {
delete summon;
}
}
}
}
if (resetTicks) {
defenseTicks = 0;
}
}
can somebody point out what to change or how to?
thank