• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TFS 1.X+ C++ doubt about function

jackl90

Member
Joined
Jul 25, 2017
Messages
249
Reaction score
12
I was looking the sources of the forgotten server 1.2

I found in Player.cpp

bool Player::dropCorpse(Creature* lastHitCreature, Creature* mostDamageCreature, bool lastHitUnjustified, bool mostDamageUnjustified)
{
if (getZone() != ZONE_PVP || !Player::lastHitIsPlayer(lastHitCreature)) {
return Creature::dropCorpse(lastHitCreature, mostDamageCreature, lastHitUnjustified, mostDamageUnjustified);
}

setDropLoot(true);
return false;
}

Player.h
bool dropCorpse(Creature* lastHitCreature, Creature* mostDamageCreature, bool lastHitUnjustified, bool mostDamageUnjustified) final;


I tested what this function does, if in case the server have pvp tiles for example and the player die there for players is automatically sent to the temple.

my doubt is... i tested if the player die for monster, and after i tested if player die for field damage. this function don't work


how can i add in function if the player dies for monster or field does it work too?
 
up

this part here
if (getZone() != ZONE_PVP || !Player::lastHitIsPlayer(lastHitCreature)) maybe if i remove of function ---> || !Player::lastHitIsPlayer(lastHitCreature)

function will check only if not is ZONE_PVP? only it in case
 
You could do this in lua via onPrepareDeath. Simply check if the tile is pvp, if it is then teleport to the temple, heal the player, and return false. This would also allow you to teleport the player to a position of your choice outside of the pvp arena which is nicer (imo) than sending to temple and making them walk all the way back to the arena.
 
You could do this in lua via onPrepareDeath. Simply check if the tile is pvp, if it is then teleport to the temple, heal the player, and return false. This would also allow you to teleport the player to a position of your choice outside of the pvp arena which is nicer (imo) than sending to temple and making them walk all the way back to the arena.

good !! i need it :/

someone with Lua knowledge can do this for me?
 
LUA:
local templePosition = Position(1000, 1000, 7)
   
function onPrepareDeath(creature, killer)
    local tile = Tile(creature:getPosition())
    if tile:hasFlag(TILESTATE_PVPZONE) then
        if creature:isPlayer() then
            creature:addHealth(creature:getMaxHealth())      
            creature:teleportTo(templePosition)
        end
    end
    return true
end

remember to register at login.lua and creaturescript.xml
 
I will test now :) thanks
up

this part here
if (getZone() != ZONE_PVP || !Player::lastHitIsPlayer(lastHitCreature)) maybe if i remove of function ---> || !Player::lastHitIsPlayer(lastHitCreature)

function will check only if not is ZONE_PVP? only it in case
first is better i disable this function to check if !=ZONE_PVP? can cause some kind of conflict?
 
I did a script called arena.lua in creaturescripts folder
I put this inside this
LUA:
local templePosition = Position(32372, 31784, 7)
  
function onPrepareDeath(creature, killer)
    local tile = Tile(creature:getPosition())
    if tile:hasFlag(TILESTATE_PVPZONE) then
        if creature:isPlayer() then
            creature:addHealth(creature:getMaxHealth())     
            creature:teleportTo(templePosition)
        end
    end
    return true
end

After i put this player:registerEvent("TestArena") in Login.lua

in creaturescripts.xml
<event type="onPrepareDeath" name="TestArena" script="arena.lua"/>


but i got a error in console
Code:
[Error - CreatureEvent::configureEvent] Invalid type for creature event: TestArena
[Warning - BaseEvents::loadFromXml] Failed to configure event
 
I did a script called arena.lua in creaturescripts folder
I put this inside this
LUA:
local templePosition = Position(32372, 31784, 7)

function onPrepareDeath(creature, killer)
    local tile = Tile(creature:getPosition())
    if tile:hasFlag(TILESTATE_PVPZONE) then
        if creature:isPlayer() then
            creature:addHealth(creature:getMaxHealth())  
            creature:teleportTo(templePosition)
        end
    end
    return true
end

After i put this player:registerEvent("TestArena") in Login.lua

in creaturescripts.xml
<event type="onPrepareDeath" name="TestArena" script="arena.lua"/>


but i got a error in console
Code:
[Error - CreatureEvent::configureEvent] Invalid type for creature event: TestArena
[Warning - BaseEvents::loadFromXml] Failed to configure event
Should be in creaturescripts.xml
XML:
<event type="preparedeath" name="TestArena" script="arena.lua"/>

@roriscrave
 
the script worked now, but my problem continue... if the player pass on a energy field without owner for example and die, the player appear died on
templePosition with a corpse too
 
the script worked now, but my problem continue... if the player pass on a energy field without owner for example and die, the player appear died on
templePosition with a corpse too
There are a number of arena scripts already written why reinvent the wheel? Use the search on this forum to find one even if it isn't for 1.3 you can always upgrade it to 1.3
 
There are a number of arena scripts already written why reinvent the wheel? Use the search on this forum to find one even if it isn't for 1.3 you can always upgrade it to 1.3

Yes, i found many scripts, but my real problem is not the script, is the die method...


Scripts dont work with fields damage in ground.

For example: if a player1 attack player2 with fire field, ok player2 will be teleported normally without die

But, if player1 use a field field in ground and after some time, player2 pass on fire field, player2 die.

I think the problem is (creature, killer)
Because field in ground after some time no have "owner".
 
Back
Top