CreatureEvent (SecureMode) PVP System

Fresh

Quack!
Joined
Oct 21, 2009
Messages
1,537
Reaction score
129
Location
Poland
Hello,
Today i want release an PvP System.


PVP System



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


_______________________________
What this system do?
_______________________________
- If you have securemode off
, 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
, 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:

Cykotitan

Experienced G'
Joined
Nov 4, 2008
Messages
16,897
Reaction score
805
It's nice, but makes the 'job' of afk cavebotters easier
 
OP
Fresh

Fresh

Quack!
Joined
Oct 21, 2009
Messages
1,537
Reaction score
129
Location
Poland
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 :).
 

Cykotitan

Experienced G'
Joined
Nov 4, 2008
Messages
16,897
Reaction score
805
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.
 
OP
Fresh

Fresh

Quack!
Joined
Oct 21, 2009
Messages
1,537
Reaction score
129
Location
Poland
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 :)
 

owned

Veteran OT User
Joined
Nov 9, 2008
Messages
1,977
Reaction score
500
Location
New York
chances are they are going to have it on if there botting, do u think they wanna die? ;o
 

Lessaire

Omniscient Hypervisor
Joined
Dec 29, 2009
Messages
610
Reaction score
39
Location
Clackamas County, OR
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:

PhoOwned

^_^
Joined
Nov 11, 2010
Messages
375
Reaction score
63
@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] :(
 
OP
Fresh

Fresh

Quack!
Joined
Oct 21, 2009
Messages
1,537
Reaction score
129
Location
Poland
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

Omniscient Hypervisor
Joined
Dec 29, 2009
Messages
610
Reaction score
39
Location
Clackamas County, OR
@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.
 

BeniS

Intermediate OT User
Joined
Aug 8, 2009
Messages
1,850
Reaction score
180
Location
New Zealand
nice but meh devs should just right this code to source and add a config setting for it...
 

Sir Knighter

ArchlightOnline.com
Premium User
Joined
Jun 29, 2009
Messages
3,993
Reaction score
1,079
Location
Canada
So wait people with securemode cant be attacked either?
 

tigerx2

Member
Joined
Apr 5, 2010
Messages
104
Reaction score
2
Any problem by attacking PK in secure mode OFF ? Like spells don't hit.
 
OP
Fresh

Fresh

Quack!
Joined
Oct 21, 2009
Messages
1,537
Reaction score
129
Location
Poland
This isn't bug.
That is to be (read first post.)
 

Burczyk

Member
Joined
Oct 10, 2011
Messages
94
Reaction score
3
This not working on my tfs 0.3.6 pl, if i have securemode off then i cant attack other player
 
Last edited:
Top