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

OTClient player:getVocation() return always 0

roriscrave

Advanced OT User
Joined
Dec 7, 2011
Messages
1,188
Solutions
34
Reaction score
200
Hello, im using this code in otclient in modules/client/client.lua:
Lua:
function onGameStart()
  local player = g_game.getLocalPlayer()
  if not player then return end
  g_window.setTitle(g_app.getName() .. " - " .. player:getName()) 
  print(player:getName(), player:getVocation())
end

and it print:
Roris 0
Player Test 0

It return 0, for all vocations, how can i correct it? In tfs getVocation() works fine, but in OTclient dont work.
 
Last edited:
OTCv8 Github search for "getVocation()"

Should be fine. Are you sure the test players have a vocation? xDD
all my codes are equal that codes you sended.
Yes player have vocation, because if i put in server game (data/creaturescripts/login.lua)
print(player:getVocation()) -- its ok
the problem is in OTClient
Post automatically merged:

HOW can i send player:getVocation in protocol?
 
Last edited:
The vocation is sent in protocolgameparse.cpp

Code:
void ProtocolGame::parsePlayerInfo(const InputMessagePtr& msg)
{
    bool premium = msg->getU8(); // premium
    if(g_game.getFeature(Otc::GamePremiumExpiration))
        msg->getU32(); // premium expiration used for premium advertisement
    int vocation = msg->getU8(); // vocation

    int spellCount = msg->getU16();
    std::vector<int> spells;
    for(int i=0;i<spellCount;++i)
        spells.push_back(msg->getU8()); // spell id

    m_localPlayer->setPremium(premium);
    m_localPlayer->setVocation(vocation); // here
    m_localPlayer->setSpells(spells);
}

So there may be some code missing in your sources that's responsible for that.

The other idea, might be, that you are checking to early. Maybe the vocation is not sent yet at the time you check it in function onGameStart()?

Try putting log in other functions, like in scripts, that executes later after the player has logged into game.
 
Its client id, not server id, check your vocations.xml, its not id but clientid that is sent.
No problem with my vocations.xml, in tfs funcion getVocation() works fine. The problem is in cliente side.

Lua:
<vocation id="1" name="Attacker" description="a attacker" needpremium="0" gaincap="10" gainhp="100" gainmana="50" gainhpticks="1" gainhpamount="20" gainmanaticks="1" gainmanaamount="10" manamultiplier="1.1" attackspeed="1200" basespeed="250" soulmax="200" gainsoulticks="60" corpseId="2813" fromvoc="1">
        <formula meleeDamage="1.0" distDamage="1.0" defense="1.0" armor="1.0"/>
        <skill id="0" multiplier="1.1" />
        <skill id="1" multiplier="1.1" />
        <skill id="2" multiplier="1.2" />
        <skill id="3" multiplier="1.2" />
        <skill id="4" multiplier="1.2" />
        <skill id="5" multiplier="1.1" />
        <skill id="6" multiplier="1.1" />
    </vocation>
 
No problem with my vocations.xml, in tfs funcion getVocation() works fine. The problem is in cliente side.

Lua:
<vocation id="1" name="Attacker" description="a attacker" needpremium="0" gaincap="10" gainhp="100" gainmana="50" gainhpticks="1" gainhpamount="20" gainmanaticks="1" gainmanaamount="10" manamultiplier="1.1" attackspeed="1200" basespeed="250" soulmax="200" gainsoulticks="60" corpseId="2813" fromvoc="1">
        <formula meleeDamage="1.0" distDamage="1.0" defense="1.0" armor="1.0"/>
        <skill id="0" multiplier="1.1" />
        <skill id="1" multiplier="1.1" />
        <skill id="2" multiplier="1.2" />
        <skill id="3" multiplier="1.2" />
        <skill id="4" multiplier="1.2" />
        <skill id="5" multiplier="1.1" />
        <skill id="6" multiplier="1.1" />
    </vocation>
No... read my post again. Its not fine. You are missing clientId which defaults to 0.
 
Changed to:
Lua:
<vocation id="1" clientid="1"
and tried change to:
Code:
<vocation id="1" clientId="1"

And used this code in client side (OTClient):
Lua:
    local player = g_game.getLocalPlayer()
    print(player:getName(), player:getVocation())

And it printed:
Roris 0
Player Test 0

Either player are in vocation ID = 1. How can i know it? I put in tfs (data/creaturescripts/login.lua)
Lua:
print(player:getVocation():getId())

And it print 1.

The error persist
 
hmmm my source dont have this code, have only
Lua:
void ProtocolGame::sendStats()
, maybe the problem are there.
you recommend add this two functions or only sendBasicData

Code:
sendClientFeatures
sendBasicData
 
Back
Top