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

Lua Help func remove blesses

gmstrikker

Well-Known Member
Joined
Jul 30, 2014
Messages
458
Solutions
1
Reaction score
50
Thats is how add full bless
Code:
doPlayerAddBlessing(cid, 1)
doPlayerAddBlessing(cid, 2)
doPlayerAddBlessing(cid, 3)
doPlayerAddBlessing(cid, 4)
doPlayerAddBlessing(cid, 5)

Right?

And to remove all blesses?
 
You need to source edit to make this possible. So what you need to do is add the function to player.h and doPlayerRemoveBlessing to luascript.

Code:
void addBlessing(int16_t blessing) {blessings += blessing;}
void removeBlessing(int16_t blessing) {blessings -= blessing;}

Code:
int32_t LuaInterface::luaDoPlayerRemoveBlessing(lua_State* L)
{
//doPlayerRemoveBlessing(cid, blessing)
int16_t blessing = popNumber(L) - 1;
ScriptEnviroment* env = getEnv();
if(Player* player = env->getPlayerByUID(popNumber(L)))
{
if(player->hasBlessing(blessing))
{
player->removeBlessing(1 << blessing);
lua_pushboolean(L, true);
}
else
lua_pushboolean(L, false);
}
else
{
errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
lua_pushboolean(L, false);
}

return 1;
}
 
to add all blessings:
Code:
for i = 1,5 do
    doPlayerAddBlessing(cid, [i])
to remove all blessings, dunno if this works but try it:
Code:
for i = -1,-5 do
    doPlayerAddBlessing(cid, [i])
 
Thats is how add full bless
Code:
doPlayerAddBlessing(cid, 1)
doPlayerAddBlessing(cid, 2)
doPlayerAddBlessing(cid, 3)
doPlayerAddBlessing(cid, 4)
doPlayerAddBlessing(cid, 5)

Right?

And to remove all blesses?

Blessings is a single column in the database, just set it to its default value 0
Code:
`blessings` TINYINT(2) NOT NULL DEFAULT 0,
to add all blessings:
Code:
for i = -1,-5 do
    doPlayerAddBlessing(cid, [i])
This is how you count backwards
Code:
for i = 5, 0, -1 do
    print(i)
end
-- output
5
4
3
2
1
0
Code:
-- default of step is 1
for var = start, stop, step do
 
Blessings is a single column in the database, just set it to its default value 0
Code:
`blessings` TINYINT(2) NOT NULL DEFAULT 0,

This is how you count backwards
Code:
for i = 5, 0, -1 do
    print(i)
end
-- output
5
4
3
2
1
0
Code:
-- default of step is 1
for var = start, stop, step do
I'm genuinely curious though..
When we use
Code:
for i = 1, 5 do
    doPlayerAddBlessing(cid, i)
end
I assume the default step is +1.
However if it's a single column in the database.. how do we alter each value in the column?
When using the command, it changes each of the 5/6 blessing values..?
Code:
doPlayerAddBlessing(cid, 1) (change value in row 1, to 1)
.
.
.
doPlayerAddBlessing(cid, 5) (change value in row 5, to 1)

As far as I know, there is no way to alter this number while the player is online.
When player is offline we can do a database query to alter it directly.. but meh
Maybe I'm wrong though.

-- edit --
We can give them blessings while online, but cannot remove the blessings while online currently.

-- edit 2 --
@OP
You can remove them by killing the player. xD (easy solution)
 
Last edited:
Blessings is a single column in the database, just set it to its default value 0
Code:
`blessings` TINYINT(2) NOT NULL DEFAULT 0,

This is how you count backwards
Code:
for i = 5, 0, -1 do
    print(i)
end
-- output
5
4
3
2
1
0
Code:
-- default of step is 1
for var = start, stop, step do
Ah, didn't know. Thanks for clarifying :)
 
@Xikini
There is no such thing as +1, 1 is always positive, -1 is always negative even when we add 1 + -1 or -1 + 1 always equals 0.
Lets run some tests using the values -1, 1, +1
-1
Code:
local start, stop, step = 5, 0, -1

for var = start, stop, step do
    print(var .. ' + '.. step ..' = '.. (var + step))
end
-- output
5 + -1 = 4
4 + -1 = 3
3 + -1 = 2
2 + -1 = 1
1 + -1 = 0
0 + -1 = -1
1
Code:
local start, stop, step = 0, 5, 1

for var = start, stop, step do
    print(var .. ' + '.. step ..' = '.. (var + step))
end
-- output
0 + 1 = 1
1 + 1 = 2
2 + 1 = 3
3 + 1 = 4
4 + 1 = 5
5 + 1 = 6
+1
Code:
local start, stop, step = 0, 5, +1

for var = start, stop, step do
    print(var .. ' + '.. step ..' = '.. (var + step))
end
-- output
 unexpected symbol near '+'
See :)
 
@Xikini
There is no such thing as +1, 1 is always positive, -1 is always negative even when we add 1 + -1 or -1 + 1 always equals 0.
Lets run some tests using the values -1, 1, +1
-1
Code:
local start, stop, step = 5, 0, -1

for var = start, stop, step do
    print(var .. ' + '.. step ..' = '.. (var + step))
end
-- output
5 + -1 = 4
4 + -1 = 3
3 + -1 = 2
2 + -1 = 1
1 + -1 = 0
0 + -1 = -1
1
Code:
local start, stop, step = 0, 5, 1

for var = start, stop, step do
    print(var .. ' + '.. step ..' = '.. (var + step))
end
-- output
0 + 1 = 1
1 + 1 = 2
2 + 1 = 3
3 + 1 = 4
4 + 1 = 5
5 + 1 = 6
+1
Code:
local start, stop, step = 0, 5, +1

for var = start, stop, step do
    print(var .. ' + '.. step ..' = '.. (var + step))
end
-- output
unexpected symbol near '+'
See :)
Right, I know how to count as well.
1,2,3,4,5,4,3,2,1,0,-1,-2,-3,-4,-5,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5
However, we aren't counting right now.
Code:
doPlayerAddBlessing(cid, 1)
doPlayerAddBlessing(cid, 2)
doPlayerAddBlessing(cid, 3)
doPlayerAddBlessing(cid, 4)
doPlayerAddBlessing(cid, 5)
This is not counting.
There is 5 different blessings.
If you use only..
Code:
doPlayerAddBlessing(cid, 5)
It will not work.
Your only giving the player blessing number 5.
Change Blessing 5 to '1' or 'enable'.
You are not adding 5 blessings.
 
Right, I know how to count as well.
1,2,3,4,5,4,3,2,1,0,-1,-2,-3,-4,-5,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5
However, we aren't counting right now.
Code:
doPlayerAddBlessing(cid, 1)
doPlayerAddBlessing(cid, 2)
doPlayerAddBlessing(cid, 3)
doPlayerAddBlessing(cid, 4)
doPlayerAddBlessing(cid, 5)
This is not counting.
There is 5 different blessings.
If you use only..
Code:
doPlayerAddBlessing(cid, 5)
It will not work.
Your only giving the player blessing number 5.
Change Blessing 5 to '1' or 'enable'.
You are not adding 5 blessings.
I know you know how to count, i was just giving you an example of the step of a for loop :)

The c++ source of doPlayerAddBlessing, I do understand some of it but not enough to translate to english, so I won't even reference the source, lets just keep it simple :p
 
Guys sorry to my dumb, but is my first time editng sources...

I have this erros when i test what i have tried:
Code:
[8:38:53.360] [Error - TalkAction Interface]
[8:38:53.360] data/talkactions/scripts/removebless.lua:onSay
[8:38:53.360] Description:
[8:38:53.360] data/talkactions/scripts/removebless.lua:13: attempt to call global 'doPlayerRemoveBlessing' (a nil value)
[8:38:53.360] stack traceback:
[8:38:53.360]    data/talkactions/scripts/removebless.lua:13: in function <data/talkactions/scripts/removebless.lua:2>

I have tried:
My !rbless
removebless.lua
Code:
local bless = {1, 2, 3, 4, 5}
function onSay(cid, words, param)
local cost = getPlayerLevel(cid) * 1500

   if isPremium(cid) == FALSE then
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Purchase at the NPC, only VIP players can use this command!")
    return TRUE
   end

   for i = 1, table.maxn(bless) do
     if(getPlayerBlessing(cid, bless[i])) then
       for i = 1, table.maxn(bless) do
         doPlayerRemoveBlessing(cid, bless[i])
       end
       doCreatureSay(cid, "REMOVED BLESSES" ,19)
       doSendMagicEffect(getPlayerPosition(cid), 29)
     else
       doPlayerSendCancel(cid, "You dont have all blesses.")
     end
   end
  
   return TRUE
end


Sources changes:
luascript.h
http://pastebin.com/rmjsRbbv

luascript.cpp
http://pastebin.com/UpAQBdMG

players.h
http://pastebin.com/KBnUdqyD
 
Just curious, why do you want to remove a player's blessings?

I need remove blesses to RPG history =)

After you edit your sources, you have to recompile.

I made it =)
I didn't made nothing worng on my pastbin links?

Its my first time, i just do what i think it need, but i think i making something mistake
 
Back
Top