• 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 onLook Script, no errors; only runs the last checks.

Extrodus

|| Blazera.net ||
Premium User
Joined
Dec 22, 2008
Messages
2,731
Solutions
7
Reaction score
537
Location
Canada
Hey there guys, running into a slight issue over the past few days. Don't get any errors and no matter if I use cid, thing.uid it still fails to check properly. I was originally using getPlayerVipDays(cid), but that wasn't working. So figured since my VIP system changes players from vocation 1-4, to 5-8 upon login if they are VIP; then I can just check the players vocation, and if its above 4; then they are VIP and if it's below then they arent. But everyone still shows "Non-VIP" even though they are vocation 5-8.

Example of player vocation 8, failing to show VIP:
[He is a VIP elite knight [Non-VIP]. Guild has 4 members, and 1 of them online. [Kills: (0) / Deaths: (3)].]

[Rev 0.4] [CreatureScript]
Lua:
function onLook(cid, thing, position, lookDistance)

    function getDeathsAndKills(cid, type) -- by vodka
        local query,d = db.getResult("SELECT `player_id` FROM "..(tostring(type) == "kill" and "`player_killers`" or "`player_deaths`").." WHERE `player_id` = "..getPlayerGUID(cid)),0
            if (query:getID() ~= -1) then
                repeat
                    d = d+1
                until not query:next()
                query:free()
            end
        return d
    end

    if isPlayer(thing.uid) then
        -- Yes Guild/Yes VIP [Vocation is greater than 4.]
        if getPlayerGuildId(thing.uid) > 0 and getPlayerVocation(thing.uid) < 4 then
                doPlayerSetSpecialDescription(thing.uid, " [VIP Player]. Guild has " .. #getGuildMembers(getPlayerGuildId(thing.uid)) .. " members, and " .. #getGuildMembersOnline(getPlayerGuildId(thing.uid)) .. " of them online. [Kills: ("..getDeathsAndKills(thing.uid, "kill")..") / Deaths: ("..getDeathsAndKills(thing.uid, "death")..")]")
        -- No Guild/Yes VIP
        elseif getPlayerGuildId(thing.uid) == 0 and getPlayerVocation(thing.uid) < 4 then
                doPlayerSetSpecialDescription(thing.uid, " [VIP Player]. [Kills: ("..getDeathsAndKills(thing.uid, "kill")..") / Deaths: ("..getDeathsAndKills(thing.uid, "death")..")]")
        -- Yes Guild/No VIP [Vocation is less than 5.]
        elseif getPlayerGuildId(thing.uid) > 0 and getPlayerVocation(thing.uid) > 5 then
                doPlayerSetSpecialDescription(thing.uid, " [Non-VIP]. Guild has " .. #getGuildMembers(getPlayerGuildId(thing.uid)) .. " members, and " .. #getGuildMembersOnline(getPlayerGuildId(thing.uid)) .. " of them online. [Kills: ("..getDeathsAndKills(thing.uid, "kill")..") / Deaths: ("..getDeathsAndKills(thing.uid, "death")..")]")
        -- No Guild/No VIP
        elseif getPlayerGuildId(thing.uid) == 0 and getPlayerVocation(thing.uid) > 5 then
                doPlayerSetSpecialDescription(thing.uid, " [Non-VIP]. [Kills: ("..getDeathsAndKills(thing.uid, "kill")..") / Deaths: ("..getDeathsAndKills(thing.uid, "death")..")]")
        end
    end
    return true
end

Anyone see what I did wrong or?
 
Solution
As forgee said, you mistyped math operators and the string text looks inverted. You did right on the code comment but wrong on the math operators.

VIP Players: vocation 5 to 8
Non VIP: vocation 1 to 4

Lua:
    if isPlayer(thing.uid) then
        -- Yes Guild/Yes VIP [Vocation is greater than 4.]
        if getPlayerGuildId(thing.uid) > 0 and getPlayerVocation(thing.uid) > 4 then
                doPlayerSetSpecialDescription(thing.uid, " [VIP Player]. Guild has " .. #getGuildMembers(getPlayerGuildId(thing.uid)) .. " members, and " .. #getGuildMembersOnline(getPlayerGuildId(thing.uid)) .. " of them online. [Kills: ("..getDeathsAndKills(thing.uid, "kill")..") / Deaths: ("..getDeathsAndKills(thing.uid, "death")..")]")
        -- No...
As forgee said, you mistyped math operators and the string text looks inverted. You did right on the code comment but wrong on the math operators.

VIP Players: vocation 5 to 8
Non VIP: vocation 1 to 4

Lua:
    if isPlayer(thing.uid) then
        -- Yes Guild/Yes VIP [Vocation is greater than 4.]
        if getPlayerGuildId(thing.uid) > 0 and getPlayerVocation(thing.uid) > 4 then
                doPlayerSetSpecialDescription(thing.uid, " [VIP Player]. Guild has " .. #getGuildMembers(getPlayerGuildId(thing.uid)) .. " members, and " .. #getGuildMembersOnline(getPlayerGuildId(thing.uid)) .. " of them online. [Kills: ("..getDeathsAndKills(thing.uid, "kill")..") / Deaths: ("..getDeathsAndKills(thing.uid, "death")..")]")
        -- No Guild/Yes VIP
        elseif getPlayerGuildId(thing.uid) == 0 and getPlayerVocation(thing.uid) > 4 then
                doPlayerSetSpecialDescription(thing.uid, " [VIP Player]. [Kills: ("..getDeathsAndKills(thing.uid, "kill")..") / Deaths: ("..getDeathsAndKills(thing.uid, "death")..")]")
        -- Yes Guild/No VIP [Vocation is less than 5.]
        elseif getPlayerGuildId(thing.uid) > 0 and getPlayerVocation(thing.uid) < 5 then
                doPlayerSetSpecialDescription(thing.uid, " [Non-VIP]. Guild has " .. #getGuildMembers(getPlayerGuildId(thing.uid)) .. " members, and " .. #getGuildMembersOnline(getPlayerGuildId(thing.uid)) .. " of them online. [Kills: ("..getDeathsAndKills(thing.uid, "kill")..") / Deaths: ("..getDeathsAndKills(thing.uid, "death")..")]")
        -- No Guild/No VIP
        elseif getPlayerGuildId(thing.uid) == 0 and getPlayerVocation(thing.uid) < 5 then
                doPlayerSetSpecialDescription(thing.uid, " [Non-VIP]. [Kills: ("..getDeathsAndKills(thing.uid, "kill")..") / Deaths: ("..getDeathsAndKills(thing.uid, "death")..")]")
        end
    end
    return true


But I would implement this on different way, it would probably gives the same result but the code would be cleaner to read.

Lua:
if isPlayer(thing.uid) then
    -- if the player has a guild
    if getPlayerGuildId(thing.uid) > 0 then
        --check if player has VIP vocation
        if getPlayerVocation(thing.uid) > 4 then
            doPlayerSetSpecialDescription(thing.uid, " [VIP Player]. Guild has " .. #getGuildMembers(getPlayerGuildId(thing.uid)) .. " members, and " .. #getGuildMembersOnline(getPlayerGuildId(thing.uid)) .. " of them online. [Kills: ("..getDeathsAndKills(thing.uid, "kill")..") / Deaths: ("..getDeathsAndKills(thing.uid, "death")..")]")
        else
            doPlayerSetSpecialDescription(thing.uid, " [Non-VIP]. Guild has " .. #getGuildMembers(getPlayerGuildId(thing.uid)) .. " members, and " .. #getGuildMembersOnline(getPlayerGuildId(thing.uid)) .. " of them online. [Kills: ("..getDeathsAndKills(thing.uid, "kill")..") / Deaths: ("..getDeathsAndKills(thing.uid, "death")..")]")
        end
    else
        --check if player has VIP vocation
        if getPlayerVocation(thing.uid) > 4 then
            doPlayerSetSpecialDescription(thing.uid, " [VIP Player]. [Kills: ("..getDeathsAndKills(thing.uid, "kill")..") / Deaths: ("..getDeathsAndKills(thing.uid, "death")..")]")
        else
            doPlayerSetSpecialDescription(thing.uid, " [Non-VIP]. [Kills: ("..getDeathsAndKills(thing.uid, "kill")..") / Deaths: ("..getDeathsAndKills(thing.uid, "death")..")]")
        end
    end

end
return true
 
You have the less than and greater than signs turned around. When you mean to check if vocation is greater than 4 you're checking if it's less than 4 and vice versa.

Oh my goodness really!? I thought I had tested both ways and it didn't effect the outcome for some reason, even tried equal to or less then 4 and that didnt work; with VIP Days I tried if == 0 then not VIP, else if greater then 0 show VIP. But nothing was working, haha - thank you so much for the clarification.

As forgee said, you mistyped math operators and the string text looks inverted. You did right on the code comment but wrong on the math operators.

But I would implement this on different way, it would probably gives the same result but the code would be cleaner to read.
Thank you! I'll test out the "different way" you suggested as that does seem like the cleaner way to do it. I will work on using that structure from now on and test your modifications :)
 
As forgee said, you mistyped math operators and the string text looks inverted. You did right on the code comment but wrong on the math operators.

VIP Players: vocation 5 to 8
Non VIP: vocation 1 to 4

Lua:
    if isPlayer(thing.uid) then
        -- Yes Guild/Yes VIP [Vocation is greater than 4.]
        if getPlayerGuildId(thing.uid) > 0 and getPlayerVocation(thing.uid) > 4 then
                doPlayerSetSpecialDescription(thing.uid, " [VIP Player]. Guild has " .. #getGuildMembers(getPlayerGuildId(thing.uid)) .. " members, and " .. #getGuildMembersOnline(getPlayerGuildId(thing.uid)) .. " of them online. [Kills: ("..getDeathsAndKills(thing.uid, "kill")..") / Deaths: ("..getDeathsAndKills(thing.uid, "death")..")]")
        -- No Guild/Yes VIP
        elseif getPlayerGuildId(thing.uid) == 0 and getPlayerVocation(thing.uid) > 4 then
                doPlayerSetSpecialDescription(thing.uid, " [VIP Player]. [Kills: ("..getDeathsAndKills(thing.uid, "kill")..") / Deaths: ("..getDeathsAndKills(thing.uid, "death")..")]")
        -- Yes Guild/No VIP [Vocation is less than 5.]
        elseif getPlayerGuildId(thing.uid) > 0 and getPlayerVocation(thing.uid) < 5 then
                doPlayerSetSpecialDescription(thing.uid, " [Non-VIP]. Guild has " .. #getGuildMembers(getPlayerGuildId(thing.uid)) .. " members, and " .. #getGuildMembersOnline(getPlayerGuildId(thing.uid)) .. " of them online. [Kills: ("..getDeathsAndKills(thing.uid, "kill")..") / Deaths: ("..getDeathsAndKills(thing.uid, "death")..")]")
        -- No Guild/No VIP
        elseif getPlayerGuildId(thing.uid) == 0 and getPlayerVocation(thing.uid) < 5 then
                doPlayerSetSpecialDescription(thing.uid, " [Non-VIP]. [Kills: ("..getDeathsAndKills(thing.uid, "kill")..") / Deaths: ("..getDeathsAndKills(thing.uid, "death")..")]")
        end
    end
    return true


But I would implement this on different way, it would probably gives the same result but the code would be cleaner to read.

Lua:
if isPlayer(thing.uid) then
    -- if the player has a guild
    if getPlayerGuildId(thing.uid) > 0 then
        --check if player has VIP vocation
        if getPlayerVocation(thing.uid) > 4 then
            doPlayerSetSpecialDescription(thing.uid, " [VIP Player]. Guild has " .. #getGuildMembers(getPlayerGuildId(thing.uid)) .. " members, and " .. #getGuildMembersOnline(getPlayerGuildId(thing.uid)) .. " of them online. [Kills: ("..getDeathsAndKills(thing.uid, "kill")..") / Deaths: ("..getDeathsAndKills(thing.uid, "death")..")]")
        else
            doPlayerSetSpecialDescription(thing.uid, " [Non-VIP]. Guild has " .. #getGuildMembers(getPlayerGuildId(thing.uid)) .. " members, and " .. #getGuildMembersOnline(getPlayerGuildId(thing.uid)) .. " of them online. [Kills: ("..getDeathsAndKills(thing.uid, "kill")..") / Deaths: ("..getDeathsAndKills(thing.uid, "death")..")]")
        end
    else
        --check if player has VIP vocation
        if getPlayerVocation(thing.uid) > 4 then
            doPlayerSetSpecialDescription(thing.uid, " [VIP Player]. [Kills: ("..getDeathsAndKills(thing.uid, "kill")..") / Deaths: ("..getDeathsAndKills(thing.uid, "death")..")]")
        else
            doPlayerSetSpecialDescription(thing.uid, " [Non-VIP]. [Kills: ("..getDeathsAndKills(thing.uid, "kill")..") / Deaths: ("..getDeathsAndKills(thing.uid, "death")..")]")
        end
    end

end
return true
I think you can get it cleaner then this.
Combine all the function calls into a single string, and apply once.
Lua:
if isPlayer(thing.uid) then
    local newDescription = ""

    -- check if player has VIP vocation
    newDescription = newDescription .. " " .. (getPlayerVocation(thing.uid) > 4 and "[VIP Player]" or "[Non-VIP]") .. "."
    -- if the player has a guild
    if getPlayerGuildId(thing.uid) > 0 then
        newDescription = newDescription .. " Guild has " .. #getGuildMembers(getPlayerGuildId(thing.uid)) .. " members, and " .. #getGuildMembersOnline(getPlayerGuildId(thing.uid)) .. " of them online."
    end
    -- add the kills/deaths
    newDescription = newDescription .. " [Kills: ("..getDeathsAndKills(thing.uid, "kill")..") / Deaths: ("..getDeathsAndKills(thing.uid, "death")..")]"
   
    -- set the description
    doPlayerSetSpecialDescription(thing.uid, newDescription)
end
return true
 
Solution
Back
Top