Lua Function Restet system TFS 0.4_SVN & TFS 0.3.6

Wazzap

Killing Elite
Joined
Jun 15, 2010
Messages
124
Reaction score
4
Location
London / Poland
After pocketing the appropriate level we go to bp (protection zone).
After typing !reset automatically logs out of our character.
After logging into the form we have reset lvl, exp, and will appear in the same place where you were.
When you click the "Look" is displayed on the player resets the amount taken.

MySQL:
ALTER TABLE `players` ADD `resets` INT(11) NOT NULL DEFAULT "0";
SQLite:
ALTER TABLE players ADD resets INTEGER not null default 0
adding sources
player.h
search for:
uint32_t level;
below, add:
uint32_t resets;
Go to iologindata.cpp
search for:
query << "SELECT `id`, `account_id`, `group_id`, `world_id`, `sex`, `vocation`, `experience`, `level`,"
Change that:
query << "SELECT `id`, `account_id`, `group_id`, `world_id`, `sex`, `vocation`, `experience`, `level`, `resets`, "
Search for:
player->level = std::max((uint32_t)1, (uint32_t)result->getDataInt("level"));
below add:
player->resets = (uint32_t)result->getDataInt("resets");
Search for:
query << "`maglevel` = " << player->magLevel << ", ";
Add below
query << "`resets` = " << player->resets << ", ";
players.cpp
Search for:
s << " (Level " << level << ")";
Change that:
s << " (Level " << level << ") [Reset " << resets << "]";
players.h
Search for:
void setPromotionLevel(uint32_t pLevel);
Add below:
uint32_t getResets() { return resets;}
void setResets(int32_t amount) { resets += amount; if (resets < 0) {resets = 0;} }
TFS 0.3.6


luascript.cpp
Search for:
int32_t LuaScriptInterface::luaDoPlayerSetIdleTime(lua_State* L)
{
//doPlayerSetIdleTime(cid, amount)
int64_t amount = popNumber(L);
ScriptEnviroment* env = getEnv();
if(Player* player = env->getPlayerByUID(popNumber(L)))
{
player->setIdleTime(amount);
lua_pushboolean(L, true);
}
else
{
errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
lua_pushboolean(L, false);
}
return 1;
}
Add below:
int32_t LuaScriptInterface::luaGetResets(lua_State* L)
{
//getResets(cid)
ScriptEnviroment* env = getEnv();
if(Player* player = env->getPlayerByUID(popNumber(L)))
lua_pushnumber(L, player->getResets());
else
{
errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
lua_pushboolean(L, false);
}
return 1;
}

int32_t LuaScriptInterface::luaSetResets(lua_State* L)
{
//setResets(cid, amount)
int32_t amount = popNumber(L);
ScriptEnviroment* env = getEnv();
if(Player* player = env->getPlayerByUID(popNumber(L)))
{
player->setResets(amount);
lua_pushboolean(L, true);
}
else
{
errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
lua_pushboolean(L, false);
}
return 1;
}
Search for:
//doPlayerSetIdleTime(cid, amount)
lua_register(m_luaState, "doPlayerSetIdleTime", LuaInterface::luaDoPlayerSetIdleTime);
add below
//getResets(cid)
lua_register(m_luaState, "getResets", LuaScriptInterface::luaGetResets);

//setResets(cid, amount)
lua_register(m_luaState, "setResets", LuaScriptInterface::luaSetResets);

TFS 0.4_SVN


serch for
int32_t LuaInterface::luaDoPlayerSetIdleTime(lua_State* L)
{
//doPlayerSetIdleTime(cid, amount)
int64_t amount = popNumber(L);
ScriptEnviroment* env = getEnv();
if(Player* player = env->getPlayerByUID(popNumber(L)))
{
player->setIdleTime(amount);
lua_pushboolean(L, true);
}
else
{
errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
lua_pushboolean(L, false);
}

return 1;
}
Add below:
int32_t LuaInterface::luaGetResets(lua_State* L)
{
//getResets(cid)
ScriptEnviroment* env = getEnv();
if(Player* player = env->getPlayerByUID(popNumber(L)))
lua_pushnumber(L, player->getResets());
else
{
errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
lua_pushboolean(L, false);
}
return 1;
}

int32_t LuaInterface::luaSetResets(lua_State* L)
{
//setResets(cid, amount)
int32_t amount = popNumber(L);
ScriptEnviroment* env = getEnv();
if(Player* player = env->getPlayerByUID(popNumber(L)))
{
player->setResets(amount);
lua_pushboolean(L, true);
}
else
{
errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
lua_pushboolean(L, false);
}
return 1;
}
Search for:
//doPlayerSetIdleTime(cid, amount)
lua_register(m_luaState, "doPlayerSetIdleTime", LuaInterface::luaDoPlayerSetIdleTime);
Add below:
//getResets(cid)
lua_register(m_luaState, "getResets", LuaInterface::luaGetResets);

//setResets(cid, amount)
lua_register(m_luaState, "setResets", LuaInterface::luaSetResets);
luascript.h
Search for :
static int32_t luaDoPlayerSetIdleTime(lua_State* L);
Add below:
static int32_t luaGetResets(lua_State* L);
static int32_t luaSetResets(lua_State* L);
talkactions.xml
<talkaction words="!rank;/rank" event="script" value="ranks.lua"/>
<talkaction words="!reset;/reset" script="reset.lua"/>
ranks.lua
function getPlayerNameByGUID2(n)
local c = db.getResult("SELECT `name` FROM `players` WHERE `id` = "..n..";")
if c:getID() == -1 then
return "SQL_ERROR["..n.."]"
end
return c:getDataString("name")
end

function onSay(cid, words, param)
local max = 10
local letters_to_next = 20

local skills = {
['fist'] = 0,
['club'] = 1,
['sword'] = 2,
['axe'] = 3,
['distance'] = 4,
['shielding'] = 5,
['fishing'] = 6,
['dist'] = 4,
['shield'] = 5,
['fish'] = 6,
}
local name_now
local name = "Highscore for level\n"
local rkn = 0
local no_break = 0
param = string.lower(param)
dofile('config.lua')
if param == "" or param == "level" and ( param ~= "magic" and param == "ml") and skills[param] == nil then
name = name.."\n"
name = name.."Rank Level - Nome do Jogador\n"
local v = db.getResult("SELECT `name`, `level`, `experience` FROM `players` WHERE `group_id` <= 2 ORDER BY `experience` DESC LIMIT 0,"..(max)..";")
repeat
no_break = no_break +1
if v:getID() == -1 then
break
end
rkn = rkn+1
name_now, l = v:getDataString("name"), string.len(v:getDataString("name"))
space = ""
for i=1, letters_to_next-l do
space = space.." "
end
name = name..rkn..". "..v:getDataInt("level") .." - "..name_now..space.." ".."\n"
if no_break >= 20 then
break
end
until v:next() == false

elseif param == "magic" or param == "ml" then
name = name.."\n"
name = name.."Rank Magic - Nome do Jogador\n"
local v = db.getResult("SELECT `name`, `level`, `maglevel` FROM `players` WHERE `group_id` <= 2 ORDER BY `maglevel` DESC LIMIT 0,"..(max)..";")
repeat
if v:getID() == -1 then
break
end
rkn = rkn+1
name_now, l = v:getDataString("name"), string.len(v:getDataString("name"))
space = ""
for i=1, letters_to_next-l do
space = space.." "
end
name = name..rkn..". "..v:getDataInt("maglevel").." - "..name_now..space.." ".." ".."".."\n"
until v:next() == false

elseif param == "reset" or param == "resets" then
name = name.."Rank Reset - Nome do Jogador\n"
local v = db.getResult("SELECT `player_id`, `value` FROM `player_storage` WHERE `key` = 1020 ORDER BY cast(value as INTEGER) DESC;")
local kk = 0

repeat
if kk == max or v:getID() == -1 then
break
end
kk = kk+1
name_now, l = getPlayerNameByGUID2(v:getDataInt("player_id")), string.len(getPlayerNameByGUID2(v:getDataInt("player_id")))
space = ""
for i=1, letters_to_next-l do
space = space.." "
end
if name_now == nil then
name_now = 'sql error['..v:getDataInt("player_id")..']'
end
name = name..kk..". "..v:getDataInt("value").." - "..name_now..space.." ".." ".."".."\n"
until v:next() == false

elseif skills[param] ~= nil then
name = name.."\n"
name = name.."Rank "..param.." fighting - Nome do Jogador\n"
local v = db.getResult("SELECT `player_id`, `value` FROM `player_skills` WHERE `skillid` = "..skills[param].." ORDER BY `value` DESC;")
local kk = 0

repeat
if kk == max or v:getID() == -1 then
break
end
kk = kk+1
name_now, l = getPlayerNameByGUID2(v:getDataInt("player_id")), string.len(getPlayerNameByGUID2(v:getDataInt("player_id")))
space = ""
for i=1, letters_to_next-l do
space = space.." "
end
if name_now == nil then
name_now = 'sql error['..v:getDataInt("player_id")..']'
end
name = name..kk..". "..v:getDataInt("value").." - "..name_now..space.." \n"
until v:next() == false
end
if name ~= "Highscore\n" then
doPlayerPopupFYI(cid, name)
end
return true
end
reset.lua
config = {
RemainingLvl = 8,
exp = 4200,
redskull = true,
battle = true,
pz = true
}

stages = {
{resets = 299, level =100}
}
function onSay(cid, words, param)
local pid = getPlayerGUID(cid)
if(config.redskull) and (getCreatureSkullType(cid) == 4) then
return doPlayerSendTextMessage(cid, 22, "Tylko gracz bez czaszki moze zresetowac.")
end

if(config.pz) and (not getTilePzInfo(getCreaturePosition(cid))) then
return doPlayerSendTextMessage(cid, 22, "Musisz byc w strefie ochrony aby sie zresetowac .")
end

if(config.battle) and (getCreatureCondition(cid, CONDITION_INFIGHT)) then
return doPlayerSendTextMessage(cid, 22, "nie mozesz walczyc by siezresetowac .")
end

for _, stage in ipairs(stages) do
if getResets(cid) <= stage.resets then
if getPlayerLevel(cid) >= stage.level then
setResets(cid, 1)
doRemoveCreature(cid, true)
db.executeQuery("UPDATE `players` SET `level` = "..config.RemainingLvl..", `experience` = "..config.exp.." WHERE `id` = "..pid)
else
doPlayerSendCancel(cid, "musisz miec poziom "..stage.level.." by sie zresetowac.")
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
end
end
end
return true
end
 

desalib

Member
Joined
Jul 4, 2010
Messages
30
Reaction score
0
If you you use doplayerremoveexp instead of dqquery you may do a reset system without having to log back : /
If you want to keep the hp just get it before removing exp and adding it after !
 
Top