• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

CreatureEvent (SecureMode) PVP System

[26/07/2013 13:35:16] [Error - CreatureScript Interface]
[26/07/2013 13:35:16] data/creaturescripts/scripts/raczka1.lua:onCombat
[26/07/2013 13:35:16] Description:
[26/07/2013 13:35:16] data/creaturescripts/scripts/raczka1.lua:2: attempt to call global 'getPlayerSecureMode' (a nil value)
[26/07/2013 13:35:16] stack traceback:
[26/07/2013 13:35:16] data/creaturescripts/scripts/raczka1.lua:2: in function <data/creaturescripts/scripts/raczka1.lua:1>
 
[26/07/2013 13:35:16] [Error - CreatureScript Interface]
[26/07/2013 13:35:16] data/creaturescripts/scripts/raczka1.lua:onCombat
[26/07/2013 13:35:16] Description:
[26/07/2013 13:35:16] data/creaturescripts/scripts/raczka1.lua:2: attempt to call global 'getPlayerSecureMode' (a nil value)
[26/07/2013 13:35:16] stack traceback:
[26/07/2013 13:35:16] data/creaturescripts/scripts/raczka1.lua:2: in function <data/creaturescripts/scripts/raczka1.lua:1>

http://otland.net/f35/getplayersecuremode-cid-getplayerfightmode-cid-128276/
 
hello,
what I have to do, becouse this system not working on my tfs 0.3.6 pl :(
this is my log:
XML:
[03/02/2015 01:01:53] [Error - CreatureScript Interface] 
[03/02/2015 01:01:53] data/creaturescripts/scripts/securemode/raczka1.lua:onCombat
[03/02/2015 01:01:53] Description: 
[03/02/2015 01:01:53] data/creaturescripts/scripts/securemode/raczka1.lua:2: attempt to call global 'getPlayerSecureMode' (a nil value)
[03/02/2015 01:01:53] stack traceback:
[03/02/2015 01:01:53]     data/creaturescripts/scripts/securemode/raczka1.lua:2: in function <data/creaturescripts/scripts/securemode/raczka1.lua:1>

please help me.
 
making it a talkaction?

example: a player says !secure on, then the same player enters Secure Mode
 
Error :/
LUA:
[03/02/2015 01:01:53] [Error - CreatureScript Interface]
[03/02/2015 01:01:53] data/creaturescripts/scripts/securemode/raczka1.lua:onCombat
[03/02/2015 01:01:53] Description:
[03/02/2015 01:01:53] data/creaturescripts/scripts/securemode/raczka1.lua:2: attempt to call global 'getPlayerSecureMode' (a nil value)
[03/02/2015 01:01:53] stack traceback:
[03/02/2015 01:01:53] data/creaturescripts/scripts/securemode/raczka1.lua:2: in function <data/creaturescripts/scripts/securemode/raczka1.lua:1>
 
Error :/
LUA:
[03/02/2015 01:01:53] [Error - CreatureScript Interface]
[03/02/2015 01:01:53] data/creaturescripts/scripts/securemode/raczka1.lua:onCombat
[03/02/2015 01:01:53] Description:
[03/02/2015 01:01:53] data/creaturescripts/scripts/securemode/raczka1.lua:2: attempt to call global 'getPlayerSecureMode' (a nil value)
[03/02/2015 01:01:53] stack traceback:
[03/02/2015 01:01:53] data/creaturescripts/scripts/securemode/raczka1.lua:2: in function <data/creaturescripts/scripts/securemode/raczka1.lua:1>

BUMP
 
Of course
LUA:
function onCombat(cid, target)
    if(target and isPlayer(target) and getPlayerSecureMode(cid)) then
        doPlayerSendCancel(cid, "Turn secure mode off if you really want to attack unmarked players.")
        return false
    end
    return true
end

BUMP!!

BUMP, help someone pls

Error :/
LUA:
[03/02/2015 01:01:53] [Error - CreatureScript Interface]
[03/02/2015 01:01:53] data/creaturescripts/scripts/securemode/raczka1.lua:onCombat
[03/02/2015 01:01:53] Description:
[03/02/2015 01:01:53] data/creaturescripts/scripts/securemode/raczka1.lua:2: attempt to call global 'getPlayerSecureMode' (a nil value)
[03/02/2015 01:01:53] stack traceback:
[03/02/2015 01:01:53] data/creaturescripts/scripts/securemode/raczka1.lua:2: in function <data/creaturescripts/scripts/securemode/raczka1.lua:1>

Someone know what to do?
 
Last edited by a moderator:
It's possible to make it with tfs [1.X] ? or add events type's ? (cast,target,combat,statschange).

If u have any solution's share it plx :D
 
Solution for TFS [1.X]

add in /events/scripts/creature.lua :

--SECURE MODE AOE PROTECTION
function Creature:eek:nTargetCombat(target)
if self:isPlayer() and target:isPlayer() then
if self:hasSecureMode()== true then

return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
end
end
return true
end


and in /src/luascript.cpp :


int LuaScriptInterface::luaCreatureHasSecureMode(lua_State* L)
{
// creature:hasSecureMode()
Creature* creature = getUserdata<Creature>(L, 1);
if (creature) {
pushBoolean(L, creature->secureMode);
} else {
lua_pushnil(L);
}
return 1;
}
 
I think a nice single code box is always so much nicer.

Also... unless I'm mistaken attacker is not an intrinsic or global variable, so I replaced all occurrences to target.

Code:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="SecureMode" version="20110522" author="Xaekai" contact="OtLand.net" enabled="yes">
    <description> SecureMode PVP System    </description>
    <!--
    Original Author: Fresh @ otland.net forums
    Credits for the luascript.cpp functions goes to Oskar1121.
    I merely converted this. Any request for support or enhancement should be directed to the original author.
    -->
    <event type="login"       name="SecureModeLogin"  event="buffer"><![CDATA[
registerCreatureEvent(cid, "SecureMode") ; 
registerCreatureEvent(cid, "SecureModeCast") ; 
registerCreatureEvent(cid, "SecureModeSkull") ; 
registerCreatureEvent(cid, "SecureModeTarget") ; 
_result = true ; 
    ]]></event>
     <event type="statschange" name="SecureMode"       event="script" ><![CDATA[
function onStatsChange(cid, target, type, combat, value)
    if(target and isPlayer(target) and (type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS) and getPlayerSecureMode(target)) then
        if combat ~= COMBAT_HEALING then return false ; end ; 
    end ; 
    return true ; 
end ; 
    ]]></event>
     <event type="cast"        name="SecureModeCast"   event="script" ><![CDATA[
function onCast(cid, target)
    if(target and isPlayer(target) and (type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS) and getPlayerSecureMode(target)) then
        if combat ~= COMBAT_HEALING then return false ; end ; 
    end ; 
    return true ; 
end ; 
    ]]></event>
    <event type="combat"      name="SecureModeSkull"  event="script" ><![CDATA[
function onCombat(cid, target) 
    if(target and isPlayer(target) and getPlayerSecureMode(cid)) then 
        return doPlayerSendCancel(cid, "Turn secure mode off if you really want to attack unmarked players.") ; 
    end ;
    return true ; 
end ; 
    ]]></event>
    <event type="target"      name="SecureModeTarget" event="script" ><![CDATA[
function onTarget(cid, target)
    if(target and isPlayer(target) and (type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS) and getPlayerSecureMode(target)) then
        return false ; 
    end ; 
    return true ; 
end ; 
    ]]></event>

        <!-- luascript.h additions
    //getPlayerSecureMode(cid)
    lua_register(m_luaState, "getPlayerSecureMode", LuaScriptInterface::luaGetPlayerSecureMode);  
    //getPlayerFightMode(cid)
    lua_register(m_luaState, "getPlayerFightMode", LuaScriptInterface::luaGetPlayerFightMode);  
        -->

        <!-- luascript.cpp additions
int32_t LuaScriptInterface::luaGetPlayerSecureMode(lua_State* L)
{
    //getPlayerSecureMode(cid)
    ScriptEnviroment* env = getEnv();
    Player* player = env->getPlayerByUID((uint32_t)popNumber(L));
    if(!player)
    {
        errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
        lua_pushboolean(L, false);
    }
    else
        lua_pushnumber(L, player->getSecureMode());

    return 1;
}  

int32_t LuaScriptInterface::luaGetPlayerFightMode(lua_State* L)
{
    //getPlayerFightMode(cid)
    ScriptEnviroment* env = getEnv();
    Player* player = env->getPlayerByUID((uint32_t)popNumber(L));
    if(!player)
    {
        errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
        lua_pushboolean(L, false);
    }
    else
        lua_pushnumber(L, player->getAttackFactor());

    return 1;
}  
        -->[QUOTE="Lessaire, post: 1253228, member: 71608"]
[FONT=Lucida Console]I think a nice single code box is always so much nicer.

Also... unless I'm mistaken [COLOR=red]attacker[/COLOR] is not an intrinsic or global variable, so I replaced all occurrences to [COLOR=red]target[/COLOR].

[CODE]
<?xml version="1.0" encoding="UTF-8"?>
<mod name="SecureMode" version="20110522" author="Xaekai" contact="OtLand.net" enabled="yes">
    <description> SecureMode PVP System    </description>
    <!--
    Original Author: Fresh @ otland.net forums
    Credits for the luascript.cpp functions goes to Oskar1121.
    I merely converted this. Any request for support or enhancement should be directed to the original author.
    -->
    <event type="login"       name="SecureModeLogin"  event="buffer"><![CDATA[
registerCreatureEvent(cid, "SecureMode") ; 
registerCreatureEvent(cid, "SecureModeCast") ; 
registerCreatureEvent(cid, "SecureModeSkull") ; 
registerCreatureEvent(cid, "SecureModeTarget") ; 
_result = true ; 
    ]]></event>
     <event type="statschange" name="SecureMode"       event="script" ><![CDATA[
function onStatsChange(cid, target, type, combat, value)
    if(target and isPlayer(target) and (type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS) and getPlayerSecureMode(target)) then
        if combat ~= COMBAT_HEALING then return false ; end ; 
    end ; 
    return true ; 
end ; 
    ]]></event>
     <event type="cast"        name="SecureModeCast"   event="script" ><![CDATA[
function onCast(cid, target)
    if(target and isPlayer(target) and (type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS) and getPlayerSecureMode(target)) then
        if combat ~= COMBAT_HEALING then return false ; end ; 
    end ; 
    return true ; 
end ; 
    ]]></event>
    <event type="combat"      name="SecureModeSkull"  event="script" ><![CDATA[
function onCombat(cid, target) 
    if(target and isPlayer(target) and getPlayerSecureMode(cid)) then 
        return doPlayerSendCancel(cid, "Turn secure mode off if you really want to attack unmarked players.") ; 
    end ;
    return true ; 
end ; 
    ]]></event>
    <event type="target"      name="SecureModeTarget" event="script" ><![CDATA[
function onTarget(cid, target)
    if(target and isPlayer(target) and (type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS) and getPlayerSecureMode(target)) then
        return false ; 
    end ; 
    return true ; 
end ; 
    ]]></event>

        <!-- luascript.h additions
    //getPlayerSecureMode(cid)
    lua_register(m_luaState, "getPlayerSecureMode", LuaScriptInterface::luaGetPlayerSecureMode);  
    //getPlayerFightMode(cid)
    lua_register(m_luaState, "getPlayerFightMode", LuaScriptInterface::luaGetPlayerFightMode);  
        -->

        <!-- luascript.cpp additions
int32_t LuaScriptInterface::luaGetPlayerSecureMode(lua_State* L)
{
    //getPlayerSecureMode(cid)
    ScriptEnviroment* env = getEnv();
    Player* player = env->getPlayerByUID((uint32_t)popNumber(L));
    if(!player)
    {
        errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
        lua_pushboolean(L, false);
    }
    else
        lua_pushnumber(L, player->getSecureMode());

    return 1;
}  

int32_t LuaScriptInterface::luaGetPlayerFightMode(lua_State* L)
{
    //getPlayerFightMode(cid)
    ScriptEnviroment* env = getEnv();
    Player* player = env->getPlayerByUID((uint32_t)popNumber(L));
    if(!player)
    {
        errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
        lua_pushboolean(L, false);
    }
    else
        lua_pushnumber(L, player->getAttackFactor());

    return 1;
}  
        -->
</mod>

Apparently the mod works, I don't get a skull when attacking but I get this error in the console

[Error - CreatureScript Interface]
buffer:onCombat
Description:
[string "loadBuffer"]:2: attempt to call global 'getPlayerSecureMode' (a nil value)
stack traceback:
[string "loadBuffer"]:2: in function <[string "loadBuffer"]:1>


Does anyone know what could be happening? I still have the problem.
 
Back
Top