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

Solved Blessing talkaction tfs 1.1

FLE

Member
Joined
Oct 5, 2008
Messages
422
Reaction score
24
Location
Vancouver Canada
So I have this script and I am trying too make it work on tfs 1.1

Code:
local bless = {1, 2, 3, 4, 5}
local cost = 50000
function onSay(cid, words, param)
for i = 1, table.maxn(bless) do
if(getBlessings(cid, bless)) then
doPlayerSendCancel(cid, "You have already all blessings.")
return TRUE
end
end

if(doPlayerRemoveMoney(cid, cost) == TRUE) then
for i = 1, table.maxn(bless) do
doPlayerAddBlessing(cid, bless)
end
doCreatureSay(cid, "You are now blessed!" ,19)
doSendMagicEffect(getPlayerPosition(cid), 49)
else
doPlayerSendCancel(cid, "You don\'t have enough money.")
end
return TRUE
end

If you dont want too spoil it for me, can you atleast tell me where table.maxn(bless) is located?

or tell me what table.maxn(bless) is?

thanks,
-Mj
 
Last edited by a moderator:
The function table.maxn returns the lenght of the array.
So in this case it will return 5.

You can also make it easier by using either
Code:
for i = 1, 5 do

Or this to skip maxn / getn
Code:
for i = 1, #array
 
In the compat.lua you can see how to change TFS 0.2 functions to TFS 1.1 functions.
https://github.com/otland/forgottenserver/blob/1.1/data/lib/compat/compat.lua#L211
https://github.com/otland/forgottenserver/blob/1.1/data/lib/compat/compat.lua#L383
https://github.com/otland/forgottenserver/blob/1.1/data/lib/compat/compat.lua#L354
https://github.com/otland/forgottenserver/blob/1.1/data/lib/compat/compat.lua#L367
https://github.com/otland/forgottenserver/blob/1.1/data/lib/compat/compat.lua#L163
https://github.com/otland/forgottenserver/blob/1.1/data/lib/compat/compat.lua#L569

The first parameter of function onSay is userdata in TFS 1.1.
Code:
function onSay(player, words, param)
So you can just do it like this.
Code:
if player:hasBlessing(bless[i]) then
Also change the 19 in the say function.
Code:
player:say("You are now blessed!", TALKTYPE_MONSTER_SAY)
 
So I have this script and I am trying too make it work on tfs 1.1
have fun this will work good
Code:
function onSay(cid, words, param)
    if getPlayerBlessing(cid, 1) or getPlayerBlessing(cid, 2) or getPlayerBlessing(cid, 3) or getPlayerBlessing(cid, 4) or getPlayerBlessing(cid, 5) then
        doPlayerSendCancel(cid,'You have already got one or more blessings!')
    else

         if doPlayerRemoveItem(cid,2160,5) == TRUE then
            doPlayerAddBlessing(cid, 1)
            doPlayerAddBlessing(cid, 2)
            doPlayerAddBlessing(cid, 3)
            doPlayerAddBlessing(cid, 4)
            doPlayerAddBlessing(cid, 5)
            doSendMagicEffect(getPlayerPosition(cid), 49)
             cid:say("You are now blessed!", TALKTYPE_MONSTER_SAY)
            doPlayerSendTextMessage(cid,MESSAGE_EVENT_ADVANCE,'You have been blessed by the gods!')
        else
            doPlayerSendCancel(cid, "You need 5 crystal coin to get blessed!")
        end
    end

return false
end

i test this too and this work now
Code:
function onSay(cid, words, param)
    for i = 1, 5 do
     if getPlayerBlessing(cid, i) then
       doPlayerSendCancel(cid,'You have already got one or more blessings!')
       else
      if doPlayerRemoveItem(cid,2160,5) == TRUE then
       for i = 1, 5 do
         doPlayerAddBlessing(cid,i)
       end
  doSendMagicEffect(getPlayerPosition(cid), 49)
  cid:say("You are now blessed!", TALKTYPE_MONSTER_SAY)
  doPlayerSendTextMessage(cid,MESSAGE_EVENT_ADVANCE,'You have been blessed by the gods!')
  else
  doPlayerSendCancel(cid, "You need 5 crystal coin to get blessed!")
  end
  end
end
return false
end
 
Last edited:
Hmm,
Thanks guys i now understand what table.maxn does.

@Limos
thanks for the links too the compats, Im still not sure I understand how it all works I looked for the functions used in this script and changed them too the newer ones. Also changed what u said.

Now when i try to use !bless the server crashes, and when i try too use blesschecker tool i also crash...

Lua:
local bless = {1, 2, 3, 4, 5}
local cost = 50000
function onSay(cid, words, param)
for i = 1, table.maxn(bless) do
if player:hasBlessing(bless[i]) then
doPlayerSendCancel(cid, "You have already all blessings.")
return TRUE
end
end

if(doPlayerRemoveMoney(cid, cost) == TRUE) then
for i = 1, table.maxn(bless) do
doPlayerAddBlessing(cid, bless)
end
player:say("You are now blessed!", TALKTYPE_MONSTER_SAY)
doSendMagicEffect(getPlayerPosition(cid), 49)
else
doPlayerSendCancel(cid, "You don\'t have enough money.")
end
return TRUE
end

I dont know how but i complicated things ><'
(im good at that)[/i]
 
@Sir Islam
Thank you friend, I will try your scripts.
I noticed a flaw though, it does playerRemoveItem, it should do playerRemoveMoney? right? what if they dont have crystal coins but platinum!

yey +1 for the noob fle!

Ty all very much for helping me.
1 last question..
is p:hasblessing
p:removemoney
(is this the new style of writing a script)

Should i be learning like this?

like what exactly is the difference between writing it that way or the other way?
 
Last edited by a moderator:
I noticed a flaw though, it does playerRemoveItem, it should do playerRemoveMoney? right? what if they dont have crystal coins but platinum!

u can change this id of item any way u can use

if(doPlayerRemoveMoney(cid,50000) == TRUE) then

Should i be learning like this?
yes will be good
 
Last edited by a moderator:
yes thanks bro, I changed it too the money thing, because i saw that in the compat...

Thanks for your guys help, I feel like I learned something here! GOOD STUFF!
 
Ty all very much for helping me.
1 last question..
is p:hasblessing
p:removemoney
(is this the new style of writing a script)

Should i be learning like this?

like what exactly is the difference between writing it that way or the other way?
It is better to use the TFS 1.1 functions, the functions with cid are functions from TFS 0.2 and they work because they are added to compat.lua which sets/changes them to TFS 1.1 functions.
So it's faster to use the TFS 1.1 functions since you will use less code and don't have to get the userdata again in every function, since it's already defined in the main function.

For example doPlayerSendCancel(cid, text)
https://github.com/otland/forgottenserver/blob/1.1/data/lib/compat/compat.lua#L383
Code:
function doPlayerSendCancel(cid, text) local p = Player(cid) return p ~= nil and p:sendCancelMessage(text) or false end
In this function cid is changed to userdata (this is incase it's a creatureid) and then it's used with the TFS 1.1 function sendCancelMessage.
So you can just use that instead.
Code:
player:sendCancelMessage(text)
In TFS 1.1 the first parameter of main functions (besides globalevent functions) is userdata.
So you can just use do it like this.
~~~~
function onSay(player, words, param)
player:sendCancelMessage("some text")
-- etc​
 
Back
Top