• 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+ Secure Mode - PVP by hand open/close.

Svira

Banned User
Joined
Jan 27, 2008
Messages
361
Solutions
13
Reaction score
106
Hello dear audience, I have the following problem on src tfs 1.2 and protocol 8.6

"Punching" redskull with a player was very popular, so I decided on optional PVP with Hand open/close support, the code works well, you can mark atas when the hand is closed but:

the problem occurs with AOE spells, then despite the open hand the player gets a skull.



LUA:
if self and self:isPlayer() and target:isPlayer() then
            if self:hasSecureMode() then
                return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
            end
        end

I checked all available topics but none of them solve my problem.
 
Solution
Added to luascript.cpp
C++:
    registerMethod("Player", "hasSecureMode", LuaScriptInterface::luaPlayerHasSecureMode);
and
C++:
int LuaScriptInterface::luaPlayerHasSecureMode(lua_State* L)
{
    // player:hasSecureMode()
    Player* player = getUserdata<Player>(L, 1);
    if (player) {
        pushBoolean(L, player->secureMode);
    } else {
        lua_pushnil(L);
    }
    return 1;
}
next in luascript.h
C++:
        static int luaPlayerHasSecureMode(lua_State* L);

all working fine. Thx.
Do you talk about this right?
1720013185172.png1720013191405.png

if yes you can try this:

LUA:
local ec = EventCallback

ec.onTargetCombat = function(self, target)
    if self and self:isMonster() then
        return true
    end
    if self and self:hasSecureMode() then
        if target:isPlayer() then
            return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE
        end
    end

    return RETURNVALUE_NOERROR
end

ec:register()
 
Do you talk about this right?
View attachment 85812View attachment 85813

if yes you can try this:

LUA:
local ec = EventCallback

ec.onTargetCombat = function(self, target)
    if self and self:isMonster() then
        return true
    end
    if self and self:hasSecureMode() then
        if target:isPlayer() then
            return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE
        end
    end

    return RETURNVALUE_NOERROR
end

ec:register()
I think I clearly wrote that it's about TFS 1.2
These sources don't have callback or revsys
#edit:
furthermore your code is no different except the order...
 
Yes, full function:

LUA:
function Creature:onTargetCombat(target)
target:registerEvent("criticalHitSystemXHP")
    if not self then
               return stat_onTargetCombat(self, target)
    end
        if target:getName() == "Stamina Regenerator" then
        target:registerEvent("EventDPS")
        end

    if target:isPlayer() then
        if self:isMonster() then
            local protectionStorage = target:getStorageValue(Storage.combatProtectionStorage)

            if target:getIp() == 0 then -- If player is disconnected, monster shall ignore to attack the player
                if protectionStorage <= 0 then
                    addEvent(removeCombatProtection, 30 * 1000, target.uid)
                    target:setStorageValue(Storage.combatProtectionStorage, 1)
                elseif protectionStorage == 1 then
                    self:searchTarget()
                    return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
                end

                return true
            end

            if protectionStorage >= os.time() then
                return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
            end
        end
    end
if self:isPlayer() then
        if target and target:getName() == staminaBonus.target then
            local name = self:getName()
            if not staminaBonus.events[name] then
                staminaBonus.events[name] = addEvent(addStamina, staminaBonus.period, name)
            end
        end
       end
       if ADVANCED_SECURE_MODE ~= 0 then
        if self and self:isPlayer() and target:isPlayer() then
            if self:hasSecureMode() then
                return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
            end
        end
    end
    
   return stat_onTargetCombat(self, target)
end
 
LUA:
    if self and self:hasSecureMode() then
        if target:isPlayer() then
            return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
        end
    end

Try to add this right under the function
 
LUA:
    if self and self:hasSecureMode() then
        if target:isPlayer() then
            return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
        end
    end

Try to add this right under the function
When i change my:
LUA:
if ADVANCED_SECURE_MODE ~= 0 then
        if self and self:isPlayer() and target:isPlayer() then
            if self:hasSecureMode() then
                return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
            end
        end
    end
for your code I have an error:

Code:
Lua Script Error: [Event Interface]
data/events/scripts/creature.lua:Creature@onTargetCombat
data/events/scripts/creature.lua:101: attempt to call method 'hasSecureMode' (a nil value)
 
When i change my:
LUA:
if ADVANCED_SECURE_MODE ~= 0 then
        if self and self:isPlayer() and target:isPlayer() then
            if self:hasSecureMode() then
                return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
            end
        end
    end
for your code I have an error:

Code:
Lua Script Error: [Event Interface]
data/events/scripts/creature.lua:Creature@onTargetCombat
data/events/scripts/creature.lua:101: attempt to call method 'hasSecureMode' (a nil value)

Are you sure that you got the function?
TFS 1.2 default doesn't have it in luascript.cpp

Try this and if its not working then idk xD

LUA:
if self and self:isPlayer() and self:hasSecureMode() then
    if target:isPlayer() then
        return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
    end
end
 
Last edited:
Are you sure that you got the function?
TFS 1.2 default doesn't have it

Try this and if its not working then idk xD

LUA:
if self and self:isPlayer() and self:hasSecureMode() then
    if target:isPlayer() then
        return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
    end
end
Yes I have "hasSecureMode" in:
combat.cpp
player.h
spells.cpp
if it is available in the sources it must be, moreover the code I used works fine except for AOE spells
 
Yes I have "hasSecureMode" in:
combat.cpp
player.h
spells.cpp
if it is available in the sources it must be, moreover the code I used works fine except for AOE spells
But is it in luascript.cpp, specifically under the lua Player class: Player:hasSecureMode()?
 
Last edited by a moderator:
But is it in luascript.cpp, specifically under the lua Player class: Player:hasSecureMode()?
Only:
LUA:
registerEnum(RETURNVALUE_TURNSECUREMODETOATTACKUNMARKEDPLAYERS)
#edit:
just a question why does my code work outside of AOE attacks? xD
 
Only:
LUA:
registerEnum(RETURNVALUE_TURNSECUREMODETOATTACKUNMARKEDPLAYERS)
#edit:
just a question why does my code work outside of AOE attacks? xD
LUA:
if ADVANCED_SECURE_MODE ~= 0 then
^ This enum probably doesn't exist or is always 0, therefore I doubt your code block that calls hasSecureMode() is ever executed. You can't get any runtime errors if the code is never ran in the first place...

Once you replaced it, the code now executes and now gives the error for an undefined Lua class method.

Just add hasSecureMode as a Lua Player class method.
 
Last edited by a moderator:
Added to luascript.cpp
C++:
    registerMethod("Player", "hasSecureMode", LuaScriptInterface::luaPlayerHasSecureMode);
and
C++:
int LuaScriptInterface::luaPlayerHasSecureMode(lua_State* L)
{
    // player:hasSecureMode()
    Player* player = getUserdata<Player>(L, 1);
    if (player) {
        pushBoolean(L, player->secureMode);
    } else {
        lua_pushnil(L);
    }
    return 1;
}
next in luascript.h
C++:
        static int luaPlayerHasSecureMode(lua_State* L);

all working fine. Thx.
 
Solution
Back
Top