• 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 Guild kills

Apoccalypse

New Member
Joined
Apr 15, 2017
Messages
114
Solutions
2
Reaction score
4
Hello guys,
I am trying to make a small reward for the players in the top 5 guilds which has the most kills.
I have two queststions about it:
1.Is it possible to make a script which would find top 5 guild in terms of amount of kills and get them a proper reward?
2.If for first question anserw is yes, then is it posibble to reset amount of kills for each guild once every one week?
I am asking these questions ,bacause i have on my page something like the most powerful guilds where every guild has assigned the proper amount of kills based of its players frags, so I assume that there is probably the way to do it?

Since I have no idea how to get a guild's total kills or is it even possible I decided to get a uniqe storage for every guild.
The problem was/is to establish a uniqe storage for the guilds,so I thought up that the storage would be a guild id.
I thought that the idea is perfect but I've got the error:

Lua:
local config =
{
        killStorageValue = 3943,
        deathStorageValue = 3944, -- moje storage naliczajace zgony i kile
        gid = getPlayerGuildId(cid), -- nie na cid czyli gracza nakladany storage na na gid czyli na gildie
   
        }

 
 
function onKill(cid, target, lastHit)
print("start")

if cid ~= target and isPlayer(target) then
local   levelDiff = getPlayerLevel(target)/getPlayerLevel(cid)
     print("statment 1 passed")
if levelDiff >= 0.75 then
print("diffrence works")

      setGlobalStorageValue((config.gid + 1000),getGlobalStorage((config.gid + 1000),1) + 1)
      doPlayerSendTextMessage(cid, "You gained a kill for your Guild.Congratulation!",21)
       print("config.gid, getGlobalStorage(config.gid,1)")
 
 
 
end

end
return true
end


Code:
[20:36:05.676] [Error - CreatureScript Interface]
[20:36:05.676] data/creaturescripts/scripts/KillTheSameIP.lua:onKill
[20:36:05.694] Description:
[20:36:05.695] data/creaturescripts/scripts/KillTheSameIP.lua:21: attempt to call global 'getGlobalStorage' (a nil value)
[20:36:05.696] stack traceback:
[20:36:05.697]  data/creaturescripts/scripts/KillTheSameIP.lua:21: in function <data/creaturescripts/scripts/KillTheSameIP.lua:11>

Then I realized that a storage has to be a number from 1000 to 80000. (At least I think so)
And since I have no idea what number a guild id could be I decided to increase the guild number id about 1000 to have a number from the interval.


Lua:
local config =
{
        killStorageValue = 3943,
        deathStorageValue = 3944, -- moje storage naliczajace zgony i kile
       gid = getPlayerGuildId(cid) -- nie na cid czyli gracza nakladany storage na na gid czyli na gildie
    
        }
 
  
  
function onKill(cid, target, lastHit)
print("start")


 if cid ~= target and isPlayer(target) then
local   levelDiff = getPlayerLevel(target)/getPlayerLevel(cid)
     print("statment 1 passed")
 if levelDiff >= 0.75 then
 print("diffrence works")

      setGlobalStorageValue((config.gid+1000),getGlobalStorage((config.gid + 1000),1) + 1)
     doPlayerSendTextMessage(cid, "You gained a kill for your Guild.Congratulation!",21)
      print("config.gid, getGlobalStorage(config.gid,1)")
  
  
  
end

end
 return true
end

And the error:

Code:
[20:48:26.247] [Error - CreatureScript Interface]
[20:48:26.247] data/creaturescripts/scripts/KillTheSameIP.lua:onKill
[20:48:26.247] Description:
[20:48:26.247] data/creaturescripts/scripts/KillTheSameIP.lua:21: attempt to perform arithmetic on field 'gid' (a boolean value)
[20:48:26.247] stack traceback:
[20:48:26.247]  data/creaturescripts/scripts/KillTheSameIP.lua:21: in function <data/creaturescripts/scripts/KillTheSameIP.lua:11>

I have to admit that I am a little confused ,because the only explanation for this would be the fact that guild id is not a number but I hardly belive it.
If anyone could take a look on it and explain me why it doesn't want to work in that way that would be great :)
 
Last edited by a moderator:
print your gid, it is most probably false, because you call getPlayerGuildId without cid (there is no cid when config is populated). You need to get guild id inside your onKill function.
 
Lua:
function onKill(cid, target, lastHit)
print("start")

if cid ~= target and isPlayer(target) then
local gid = getPlayerGuildId(cid)
local levelDiff = getPlayerLevel(target)/getPlayerLevel(cid)
     print("statment 1 passed")
if levelDiff >= 0.75 then
print("diffrence works")

      setGlobalStorageValue((gid+1000), getGlobalStorage(gid+1000) + 1)
      doPlayerSendTextMessage(cid, "You gained a kill for your Guild.Congratulation!",21)
       print("gid")
    
    
     
end

end
return true
end

I can not undesrtand why this storage still don't want to work :/

Code:
[21:27:07.677] [Error - CreatureScript Interface]
[21:27:07.677] data/creaturescripts/scripts/KillTheSameIP.lua:onKill
[21:27:07.677] Description:
[21:27:07.677] data/creaturescripts/scripts/KillTheSameIP.lua:22: attempt to call global 'getGlobalStorage' (a nil value)
[21:27:07.677] stack traceback:
[21:27:07.677]  data/creaturescripts/scripts/KillTheSameIP.lua:22: in function <data/creaturescripts/scripts/KillTheSameIP.lua:11>
 
What TFS is that? Shouldn't you be using getGlobalStorageValue in line 22? If this is the script in KillTheSameIP.lua, since there's no line 22 in script you posted.
 
I added tag with tfs version. I've just removed unneed config before I posted the script.
Hmm ,I changed to getGlobalStorageValue and I get no errors but clients crahes after scipt is execuded and console print:

Code:
start
statment 1 passed
diffrence works
gid

hmm,I assume that the problem is that gid is just a gid, not a number and I have no idea why.

Lua:
function onKill(cid, target, lastHit)
print("start")

if cid ~= target and isPlayer(target) then
local gid = getPlayerGuildId(cid)
print("gid")
local levelDiff = getPlayerLevel(target)/getPlayerLevel(cid)
     print("statment 1 passed")
if levelDiff >= 0.75 then
print("diffrence works")

      setGlobalStorageValue((gid+1000), getGlobalStorageValue(gid+1000) + 1)
      doPlayerSendTextMessage(cid, "You gained a kill for your Guild.Congratulation!",21)
 


 
end

end

return true
end

Code:
start
gid
statment 1 passed
diffrence works

Do I make something wrong or the gid is actually not a number but for some reasons just gid?

@Edit. The line doPlayerSendTextMessage from some reasons causes the crash but the question still is actual, why console print gid just like a gid ,not as a number?
 
Last edited by a moderator:
I added tag with tfs version. I've just removed unneed config before I posted the script.
Hmm ,I changed to getGlobalStorageValue and I get no errors but clients crahes after scipt is execuded and console print:

Code:
start
statment 1 passed
diffrence works
gid

hmm,I assume that the problem is that gid is just a gid, not a number and I have no idea why.

Lua:
function onKill(cid, target, lastHit)
print("start")

if cid ~= target and isPlayer(target) then
local gid = getPlayerGuildId(cid)
print("gid")
local levelDiff = getPlayerLevel(target)/getPlayerLevel(cid)
     print("statment 1 passed")
if levelDiff >= 0.75 then
print("diffrence works")

      setGlobalStorageValue((gid+1000), getGlobalStorageValue(gid+1000) + 1)
      doPlayerSendTextMessage(cid, "You gained a kill for your Guild.Congratulation!",21)
 


 
end

end

return true
end

Code:
start
gid
statment 1 passed
diffrence works

Do I make something wrong or the gid is actually not a number but for some reasons just gid?

@Edit. The line doPlayerSendTextMessage from some reasons causes the crash but the question still is actual, why console print gid just like a gid ,not as a number?

Please read the rules; Rules for the Support board
#2

You should write what TFS version you are using, if you wanna add a tag thats fine but still write it out.
Always tab your scripts, it will make it a billion times easier to find the problems.
Always use the const variables, not the integers, (21 => MESSAGE_STATUS_SMALL) - why? Well if Cipsoft changes the numbers you only have to change the value of MESSAGE_STATUS_SMALL, insted of all the scripts.
As stated above, gid is a variable, so print it as a variable not a string.

Lua:
function onKill(cid, target, lastHit)
    print("start")
    if cid ~= target and isPlayer(target) then
        local gid = getPlayerGuildId(cid)
        print(gid)

        local levelDiff = getPlayerLevel(target) / getPlayerLevel(cid)
        if levelDiff >= 0.75 then
            print("diffrence works")
            setGlobalStorageValue((gid + 1000), getGlobalStorageValue(gid+1000) + 1)
            doPlayerSendTextMessage(cid, "You gained a kill for your Guild.Congratulation!", MESSAGE_STATUS_SMALL)
        end
    end

    return true
end
 
Lua:
function onKill(cid, target, lastHit)
print("start")

if cid ~= target and isPlayer(target) then
local gid = getPlayerGuildId(cid) + 50000
print(gid)
local levelDiff = getPlayerLevel(target)/getPlayerLevel(cid)
     print("statment 1 passed")
if levelDiff >= 0.75 then
print("diffrence works")

      setGlobalStorageValue(gid, getGlobalStorageValue(gid) + 1)
     
      print (setGlobalStorageValue(gid, getGlobalStorageValue(gid) + 1))
    
     
      if (getGlobalStorageValue(gid) >= 2) then
      print("5")
    
     end

end

end
print (getGlobalStorageValue(gid) + 1)
return true

end

Code:
start
50002
statment 1 passed
diffrence works

2

I can not do it, print(getGlobalStorageValue(gid) + 1) always prints 2 and even if i make setGlobalStorageValue(gid,1) it prints just nothing.It is just so simple thing and for some reasons storage always is 1 and it doesn't want to increase. I have complately no idea why.
 
Back
Top