• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Solved Creaturescript file bug

Ahead

New Member
Joined
Dec 27, 2013
Messages
165
Reaction score
2
I got in my OT a creaturescript that recompense you if you reach X level. Well, it always worked fine but magically (of course, i do not know why if i did not touched anything) it got bugged. I will explain:

Here is the .lua

Code:
function onAdvance(cid, skill, oldlevel, newlevel)
       
            if(getPlayerStorageValue(cid, 99963) ~= 1 and newlevel >= 50) then
                            doPlayerAddItem(cid, 2160, 5)
                            setPlayerStorageValue(cid, 99963, 1)
                            doPlayerSendTextMessage(cid, 22, "You have received 5 Crystal Coins because you reached level 45.")
                            end

            if(getPlayerStorageValue(cid, 99964) ~= 1 and newlevel >= 100) then
                            doPlayerAddItem(cid, 2160, 5)
                            setPlayerStorageValue(cid, 99964, 1)
                            doPlayerSendTextMessage(cid, 22, "You have received 5 Crystal Coins because you reached level 100.")
                            end

            if(getPlayerStorageValue(cid, 99965) ~= 1 and newlevel >= 150) then
                            doPlayerAddItem(cid, 2160, 5)
                            setPlayerStorageValue(cid, 99965, 1)
                            doPlayerSendTextMessage(cid, 22, "You have received 5 Crystal Coins and an Addon Doll because you reached level 150.")
                            end

            if(getPlayerStorageValue(cid, 99966) ~= 1 and newlevel >= 200) then
                            doPlayerAddItem(cid, 2160, 10)
                            doPlayerAddItem(cid, 10064, 1)
                            setPlayerStorageValue(cid, 99966, 1)
                            doPlayerSendTextMessage(cid, 22, "You have received 5 Crystal Coins because you reached level 200.")
                            end

            if(getPlayerStorageValue(cid, 99967) ~= 1 and newlevel >= 250) then
                            doPlayerAddItem(cid, 2160, 10)
                            setPlayerStorageValue(cid, 99967, 1)
                            doPlayerSendTextMessage(cid, 22, "You have received 5 Crystal Coins because you reached level 250.")
                            end

            return TRUE
end

And here the problem:

When i log in with a lvl 8 player and i get ONE level more (to 9, although i get 12 because my server rates) i mysteriously receive 35 crystal coins and this item i put (a doll, doPlayerAddItem(cid, 10064, 1), even when they are for lvl 200). The thing i do not know is WHY now it works like that if before worked propely, you have to reach lvl 50 and incomings...

Thank you all. I hope to be understandable.
 
try my script
it's working perfectly

Code:
function onAdvance(cid, skill, oldlevel, newlevel)

    if getPlayerStorageValue(cid, 50020) == -1 and skill == SKILL_LEVEL and newlevel >= 20 then
        doPlayerAddItem(cid, 2160, 2)
        setPlayerStorageValue(cid, 50020, 1)
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "Congratulations! You won 2 crystal coins to reached level 20.")
    end
  
    if getPlayerStorageValue(cid, 50050) == -1 and skill == SKILL_LEVEL and newlevel >= 50 then
        doPlayerAddItem(cid, 2160, 3)
        setPlayerStorageValue(cid, 50050, 1)
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "Congratulations! You won 3 crystal coins to reached level 50.")
    end

    if getPlayerStorageValue(cid, 50080) == -1 and skill == SKILL_LEVEL and newlevel >= 80 then
        doPlayerAddItem(cid, 2160, 5)
        setPlayerStorageValue(cid, 50080, 1)
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "Congratulations! You won 5 crystal coins to reached level 80.")
    end

    if getPlayerStorageValue(cid, 50100) == -1 and skill == SKILL_LEVEL and newlevel >= 100 then
        doPlayerAddItem(cid, 2160, 10)
        setPlayerStorageValue(cid, 50100, 1)
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "Congratulations! You won 10 crystal coins to reached level 100.")
    end
  
    if getPlayerStorageValue(cid, 50150) == -1 and skill == SKILL_LEVEL and newlevel >= 150 then
        doPlayerAddItem(cid, 2160, 12)
        setPlayerStorageValue(cid, 50150, 1)
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "Congratulations! You won 12 crystal coins to reached level 150.")
    end

return TRUE
end

Dont forget edit the advance messages because your are wrong
 
I had the script like these, but what does "skill == SKILL_LEVEL". I do not want nothing related with skills, or it is just irrelevant?
 
this is a var of global.lua to indicate the skill type advanced.

Code:
in global.lua

SKILL_FIST = 0
SKILL_CLUB = 1
SKILL_SWORD = 2
SKILL_AXE = 3
SKILL_DISTANCE = 4
SKILL_SHIELD = 5
SKILL_FISHING = 6
SKILL_MAGLEVEL = 7
SKILL_LEVEL = 8


Code:
in the luascript.cpp

int32_t LuaScriptInterface::luaPlayerGetSkillLevel(lua_State* L)
{
    // player:getSkillLevel(skillType)
    skills_t skillType = static_cast<skills_t>(getNumber<int64_t>(L, 2));
    Player* player = getUserdata<Player>(L, 1);
    if (player && skillType <= SKILL_LAST) {
        pushNumber(L, player->skills[skillType][SKILL_LEVEL]);
    } else {
        pushNil(L);
    }
    return 1;
}
 
I want it just for the level, not for skills.

Anyways i tried the old archive (the same as yours) and it is not working, LOL?!.
 
000-constant.lua TFS 0.3.
Code:
SKILL_FIST = 0
SKILL_CLUB = 1
SKILL_SWORD = 2
SKILL_AXE = 3
SKILL_DISTANCE = 4
SKILL_SHIELD = 5
SKILL_FISHING = 6
SKILL__MAGLEVEL = 7
SKILL__LEVEL = 8

TFS 0.3 uses SKILL__LEVEL instead of SKILL_LEVEL.
You should check for SKILL__LEVEL, else it will also happen if you advance on other skills.
 
Forget that skill shit, i dont want it hahaha. I want another with just level.

Why this is not working? :(

Code:
function onAdvance(cid, skill, oldlevel, newlevel)

if(getPlayerStorageValue(cid, 99963) == 1 and newlevel >= 50) then
doPlayerAddItem(cid, 2160, 5)
setPlayerStorageValue(cid, 99963, 1)
doPlayerSendTextMessage(cid, 22, "You have received 5 Crystal Coins because you reached level 45.")
end

if(getPlayerStorageValue(cid, 99964) == 1 and newlevel >= 100) then
doPlayerAddItem(cid, 2160, 5)
setPlayerStorageValue(cid, 99964, 1)
doPlayerSendTextMessage(cid, 22, "You have received 5 Crystal Coins because you reached level 100.")
end

if(getPlayerStorageValue(cid, 99965) == 1 and newlevel >= 150) then
doPlayerAddItem(cid, 2160, 5)
setPlayerStorageValue(cid, 99965, 1)
doPlayerSendTextMessage(cid, 22, "You have received 5 Crystal Coins and an Addon Doll because you reached level 150.")
end

if(getPlayerStorageValue(cid, 99966) == 1 and newlevel >= 200) then
doPlayerAddItem(cid, 2160, 10)
doPlayerAddItem(cid, 10064, 1)
setPlayerStorageValue(cid, 99966, 1)
doPlayerSendTextMessage(cid, 22, "You have received 5 Crystal Coins because you reached level 200.")
end

if(getPlayerStorageValue(cid, 99967) == 1 and newlevel >= 250) then
doPlayerAddItem(cid, 2160, 10)
setPlayerStorageValue(cid, 99967, 1)
doPlayerSendTextMessage(cid, 22, "You have received 5 Crystal Coins because you reached level 250.")
end

return TRUE
end
 
Code:
function onAdvance(cid, skill, oldlevel, newlevel)
    if skill ~= SKILL_LEVEL then return true end
   
    if(getPlayerStorageValue(cid, 99963) == -1 and newlevel >= 50) then
        doPlayerAddItem(cid, 2160, 5)
        setPlayerStorageValue(cid, 99963, 1)
        doPlayerSendTextMessage(cid, 22, "You have received 5 Crystal Coins because you reached level 45.")
    end

    if(getPlayerStorageValue(cid, 99964) == -1 and newlevel >= 100) then
        doPlayerAddItem(cid, 2160, 5)
        setPlayerStorageValue(cid, 99964, 1)
        doPlayerSendTextMessage(cid, 22, "You have received 5 Crystal Coins because you reached level 100.")
    end

    if(getPlayerStorageValue(cid, 99965) == -1 and newlevel >= 150) then
        doPlayerAddItem(cid, 2160, 5)
        setPlayerStorageValue(cid, 99965, 1)
        doPlayerSendTextMessage(cid, 22, "You have received 5 Crystal Coins and an Addon Doll because you reached level 150.")
    end

    if(getPlayerStorageValue(cid, 99966) == -1 and newlevel >= 200) then
        doPlayerAddItem(cid, 2160, 10)
        doPlayerAddItem(cid, 10064, 1)
        setPlayerStorageValue(cid, 99966, 1)
        doPlayerSendTextMessage(cid, 22, "You have received 5 Crystal Coins because you reached level 200.")
    end

    if(getPlayerStorageValue(cid, 99967) == -1 and newlevel >= 250) then
        doPlayerAddItem(cid, 2160, 10)
        setPlayerStorageValue(cid, 99967, 1)
        doPlayerSendTextMessage(cid, 22, "You have received 5 Crystal Coins because you reached level 250.")
    end
   
return true
end

Hmm?
 
No sorry Dantez.

Oh my fucking god, i was being rewarded with 5 rewards in 1 row:

22:01 You have received 5 Crystal Coins because you reached level 9.
22:01 You have received 5 Crystal Coins because you reached level 100.
22:01 You have received 5 Crystal Coins and an Addon Doll because you reached level 150.
22:01 You have received 5 Crystal Coins because you reached level 200.
22:01 You have received 5 Crystal Coins because you reached level 250.

By the way, which is the difference between "1" and "-1"?
 
Last edited:
No, below it.

Btw. still on 8 lvl character?

Lvl 8 what?.

Now is a little bit strange, my character level up, receive the items, experience, etc. So the first code is run correctly but suddenly appears the another codes:

22:14 You have received 5 Crystal Coins because you reached level 9.
22:14 You advanced from Level 8 to Level 12.
22:14 You gained 18000 experience points.
22:14 You have received 5 Crystal Coins because you reached level 100.
22:14 You have received 5 Crystal Coins and an Addon Doll because you reached level 150.
22:14 You have received 5 Crystal Coins because you reached level 200.
22:14 You have received 5 Crystal Coins because you reached level 250.

It is like if they come a little bit "lagged".

And in the console appears.... what....

Code:
nil
5
nil
11
nil
8
8
nil
9
4200

WTF
 
Change:
Code:
onAdvance(cid, oldlevel, newlevel)
to:
Code:
function onAdvance(cid, skill, oldlevel, newlevel)

And then add:
Code:
print("Skill: " .. skill .. ", Old: " .. oldlevel .. ", New: " .. newlevel)

I hope it will be more clearer.
 
OMG, man, SKILL__LEVEL is for LEVEL, dont weapon skills...

LOL i almost fall from the chair due to fucking laugh HAHAHAHAHAHAHA. I thought it was any skill level as "16 distance fighting" AHAHAHAHAHAHA.

OK guys, thanks you all for the answers, i solved it, i am using the code which was included with the folder.

This:

Code:
            if(getPlayerStorageValue(cid, 99963) ~= 1 and skill == SKILL__LEVEL and newlevel >= 9) then

Regards.
 
Code:
if skill ~= SKILL_LEVEL then return true end
I am a little bit confused cause my script had it and it didn't work for him. Wut?
 
Code:
if skill ~= SKILL_LEVEL then return true end
I am a little bit confused cause my script had it and it didn't work for him. Wut?
Do u need specify in each advance and need to be "==" not "~="
Another note is, in TFS 1.0 use just ONE UNDERLINE: "SKILL_LEVEL", and in the him version use TWO UNDERLINES: "SKILL__LEVEL"... i think :D


EDIT: i've tested here again, u can use too like this:

Code:
function onAdvance(cid, skill, oldlevel, newlevel)
if skill == SKILL_LEVEL then -------- OPEN HERE

    if getPlayerStorageValue(cid, 50020) == -1 and newlevel >= 20 then
        doPlayerAddItem(cid, 2160, 2)
        setPlayerStorageValue(cid, 50020, 1)
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "Congratulations! You won 2 crystal coins to reached level 20.")
    end
  
    if getPlayerStorageValue(cid, 50050) == -1 and newlevel >= 50 then
        doPlayerAddItem(cid, 2160, 3)
        setPlayerStorageValue(cid, 50050, 1)
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "Congratulations! You won 3 crystal coins to reached level 50.")
    end

end ----------- CLOSE HERE

return TRUE
end

Only at the beginning, and closing at the end of all events
 
Last edited:
Back
Top