• 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!

CreatureEvent (SecureMode) PVP System

Fresh

Quack!
Joined
Oct 21, 2009
Messages
1,837
Solutions
18
Reaction score
614
Location
Poland
Hello,
Today i want release an PvP System.


PVP System
036pl1.png



_______________________________
Credits to:
_______________________________
*Cykotitan, for general help
*PhoOwned, for Skull Appear part
*Oskar1121, for C++ part


_______________________________
What this system do?
_______________________________
- If you have securemode off
handoff.png
, you CANNOT attack/target enemy players with melee damage and area/wave spells. If your area spells or wave is near player or falls on him, you DONT receive White Skull & enemy dont receive damage (Spells ignore enemy player).
- If you have securemode on
handon.png
, you CAN attack/target enemy players. Your area/wave spells are dealing damage to players and you receive White Skull.


_______________________________
How I can add this?
Follow this steps:
_______________________________

1) Add this function in C++ : getPlayerSecureMode using this thread: http://otland.net/f35/getplayersecuremode-cid-getplayerfightmode-cid-128276/

2) Now you must add these 2 scripts to CreatureEvents :

- Create in ~\data\creaturescripts\scripts an LUA file called raczka.lua, and paste this script:
Lua:
function onTarget(cid, target)
	if(attacker and isPlayer(attacker) and (type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS) and getPlayerSecureMode(attacker)) then
		return false
	end
	return true
end
 
function onStatsChange(cid, attacker, type, combat, value)
	if(attacker and isPlayer(attacker) and (type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS) and getPlayerSecureMode(attacker)) then
		if combat ~= COMBAT_HEALING then
return false
end 
end
return true
end
 
function onCast(cid, target)
	if(attacker and isPlayer(attacker) and (type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS) and getPlayerSecureMode(attacker)) then
		if combat ~= COMBAT_HEALING then
return false
end 
end
return true
end

- Now, create in ~\data\creaturescripts\scripts an LUA file called raczka1.lua, and paste this script:
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

3) Now you must declare this in creaturescripts.xml:
XML:
	<event type="statschange" name="Raczka" event="script" value="raczka.lua"/>
	<event type="target" name="RaczkaTarget" event="script" value="raczka.lua"/>
	<event type="cast" name="RaczkaCast" event="script" value="raczka.lua"/>
	<event type="combat" name="RaczkaSkull" event="script" value="raczka1.lua"/>


4) You must add/declare the script in login.lua:
[Add before return true]
Lua:
	registerCreatureEvent(cid, "Raczka")
	registerCreatureEvent(cid, "RaczkaTarget")
	registerCreatureEvent(cid, "RaczkaCast")
	registerCreatureEvent(cid, "RaczkaSkull")


That's all. :rolleyes:
Now if you have securemode off you cannot attack other players with melee and area/wave spells (you dont receive skull).
If you have securemode on your spells deal damage to players and you receive skull and you can attack with melee (can target enemy player). :w00t:
 
Last edited:
It's nice, but makes the 'job' of afk cavebotters easier
 
It's nice, but makes the 'job' of afk cavebotters easier
Nope, they cannot turn off pvp. Only attacker (you) is supported there.
If you have secure mode ON and attack with area/wave spells your spells dont attack the other players.
Making good point for experience, if any low level come in your exp place you turn off secure and you dont kill him :).
 
Nope, they cannot turn off pvp. Only attacker (you) is supported there.
If you have secure mode ON and attack with area/wave spells your spells dont attack the other players.
Making good point for experience, if any low level come in your exp place you turn off secure and you dont kill him :).
I said, they won't hit other players and so they won't get skulled if they use UE's while botting :p.
 
I said, they won't hit other players and so they won't get skulled if they use UE's while botting :p.

Yes of course, but if they dont have hand ON (securemode) you can easy kill them if they are botting :)
 
chances are they are going to have it on if there botting, do u think they wanna die? ;o
 
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;
}  
        -->
</mod>
 
Last edited:
@Lessaire
but we are noobzors and we use tfs 0.3, not 0.4..
when you reload for example talkactions, mods that use talkactions don't work [you have to remember to /reload mods] :(
 
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="20110402" 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"><=!=[=C=D=A=T=A=[
registerCreatureEvent(cid, "SecureMode") ; 
registerCreatureEvent(cid, "SecureModeCast") ; 
registerCreatureEvent(cid, "SecureModeSkull") ; 
registerCreatureEvent(cid, "SecureModeTarget") ; 
_result = true ; 
    ]=]=></event>
     <event type="statschange" name="SecureMode"       event="script" ><=!=[=C=D=A=T=A=[
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" ><=!=[=C=D=A=T=A=[
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" ><=!=[=C=D=A=T=A=[
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" ><=!=[=C=D=A=T=A=[
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>

Very, very nice :)
 
@Lessaire
but we are noobzors and we use tfs 0.3, not 0.4..
when you reload for example talkactions, mods that use talkactions don't work [you have to remember to /reload mods] :(

It's been my experience that /reload works just fine, but any changes done to the mods don't actually take, but the code that was loaded before is still resident and works. But either way, the way I see it, is that mods are for 'production ready' code and /reload is for test/development servers. The two should not be intermingling anyway. Also it's not hard to break down a mod back into it's components.
 
nice but meh devs should just right this code to source and add a config setting for it...
 
Any problem by attacking PK in secure mode OFF ? Like spells don't hit.
 
This not working on my tfs 0.3.6 pl, if i have securemode off then i cant attack other player
 
Last edited:
Back
Top