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

[SUPPORT] onLogin function

Michael Orsino

Premium User
Premium User
Support Team
Joined
Nov 15, 2007
Messages
864
Solutions
10
Reaction score
451
Location
Western Australia
Currently creating a war server, am trying to write a script that will give all players an appropriate magic level and skills for their vocation when they first log in, and not let it drop below this value. I am unsure of the syntax of the doplayeraddskill function. The script I have written does not work, but maybe it will help whoever can write it. I do not know what is wrong with the script, I am far from good at lua.

Script needs to work in CD0.3.5pl1 - my war server will be released to the public once I have completed it. It is not an especially advanced war server, but I (and the community who currently play it) believe it is good and fun.

Code:
function onLogin(cid)

local playerVoc = getPlayerVocation(cid)
local magLevel = getPlayerMagLevel(cid, true)
local playerDist = getPlayerSkillLevel(cid, distance)
local playerSword = getPlayerSkillLevel(cid, sword)

if playerVoc == 5 and magLevel < 50 then
doPlayerAddMagLevel(cid,50)

elseif playerVoc == 6 and magLevel < 50 then
doPlayerAddMagLevel(cid,50)

elseif playerVoc == 7 and magLevel < 15 and playerDist < 70 then
doPlayerAddSkill(cid, distance, 70)
doPlayerAddMagLevel(cid,15)

elseif playerVoc == 8 and magLevel < 8 and playerSword < 70 then
doPlayerAddSkill(cid, axe, 60)
doPlayerAddSkill(cid, sword, 60)
doPlayerAddSkill(cid, club, 60)
doPlayerAddSkill(cid, shielding, 60)
doPlayerAddMagLevel(cid,8)

end
return TRUE
end
 
Fixed version..
LUA:
function onLogin(cid)
local playerVoc = getPlayerVocation(cid)
local magLevel = getPlayerMagLevel(cid)
local playerDist = getPlayerSkillLevel(cid, SKILL_DISTANCE)
local playerSword = getPlayerSkillLevel(cid, SKILL_SWORD)

if playerVoc == 5 and magLevel < 50 then
doPlayerAddMagLevel(cid, 50)

elseif playerVoc == 6 and magLevel < 50 then
doPlayerAddMagLevel(cid,50)

elseif playerVoc == 7 and magLevel < 15 and playerDist < 70 then
doPlayerAddSkill(cid, SKILL_DISTANCE, 70)
doPlayerAddMagLevel(cid,15)

elseif playerVoc == 8 and magLevel < 8 and playerSword < 70 then
doPlayerAddSkill(cid, SKILL_AXE, 60)
doPlayerAddSkill(cid, SKILL_SWORD, 60)
doPlayerAddSkill(cid, SKILL_CLUB, 60)
doPlayerAddSkill(cid, SKILL_SHIELD, 60)
doPlayerAddMagLevel(cid, 8)
end
return TRUE
end
 
Ah thank you very much
This script works, but it does not do what I was hoping for.

For magic level this works perfectly, for axe/sword/club it will only give the one level on each.

Maybe a calculation using
getPlayerRequiredSkillTries(cid, skillId, skillLevel)
and doPlayerAddSkillTry(cid, skillid, n)
to add the appropriate skilltry's when the skill is added?

I am really not sure, I think it's getting too complicated for me =(
 
Could do it by injection if it was a one off change to the entire server how ever I need it to be recurring and executed at the onLogin stage on a character by character basis.
Not to mention editing skills (not magic level) via injection is pretty horrible.
 
I hate bumping threads, but I simply cant get any further with this script myself. Will take a look at the actual function doPlayerAddSkill, maybe it is broken.
 
Then try
LUA:
function onLogin(cid)
local playerVoc = getPlayerVocation(cid)
local magLevel = getPlayerMagLevel(cid)
local playerDist = getPlayerSkillLevel(cid, SKILL_DISTANCE)
local playerSword = getPlayerSkillLevel(cid, SKILL_SWORD)
local reqTries = getPlayerRequiredSkillTries

if playerVoc == 5 and magLevel < 50 then
doPlayerAddMagLevel(cid, 50)

elseif playerVoc == 6 and magLevel < 50 then
doPlayerAddMagLevel(cid,50)

elseif playerVoc == 7 and magLevel < 15 and playerDist < 70 then
doPlayerAddSkillTry(cid, SKILL_DISTANCE, reqTries(cid, SKILL_DISTANCE, 70))
doPlayerAddMagLevel(cid,15)

elseif playerVoc == 8 and magLevel < 8 and playerSword < 70 then
doPlayerAddSkillTry(cid, SKILL_AXE, reqTries(cid, SKILL_AXE, 60))
doPlayerAddSkillTry(cid, SKILL_AXE, reqTries(cid, SKILL_SWORD, 60))
doPlayerAddSkillTry(cid, SKILL_AXE, reqTries(cid, SKILL_CLUB, 60))
doPlayerAddSkillTry(cid, SKILL_AXE, reqTries(cid, SKILL_SHIELD, 60))
doPlayerAddMagLevel(cid, 8)
end
return TRUE
end
 
The script is for a war server, I want it for several reasons.
1.) When players log in, they are given a magic level and skills that allow them to PVP immediately.
2.) I can use the base code of the script to make another that stops players from dropping below certain skills / magic level so that players can always PVP.
3.) I can use the base code of the script to make another that onLogin once-off 'rebalances' everyones skills to a more appropriate level so that important server changes (skill/magic level rate) can be lowered to suit the server that is becoming more advanced.

But dont you people worry about the other scripts, all I need is the script to give players skills when they first log in. I'll deal with the rest.

I will try that script shortly and let you know.


Edit:
Script did not work exactly how you would expect it to, but it has gotten me to where I need it, its dodge as all hell - but it does what I want it to in the end, and thats what matters. Credits to Kekox for the script will be given when the server is released.

Code:
function onLogin(cid)
local playerVoc = getPlayerVocation(cid)
local reqTries = getPlayerRequiredSkillTries
local skillStor = 56364
local gotSkills = getPlayerStorageValue(cid, 56364)


if playerVoc == 5 and gotSkills == -1 then
doPlayerAddSpentMana(cid, (getPlayerRequiredMana(cid,55)))
setPlayerStorageValue(cid, skillStor, 1)

elseif playerVoc == 6 and gotSkills == -1 then
doPlayerAddSpentMana(cid, (getPlayerRequiredMana(cid,55)))
setPlayerStorageValue(cid, skillStor, 1)

elseif playerVoc == 7 and gotSkills == -1 then
doPlayerAddSkillTry(cid, SKILL_DISTANCE, reqTries(cid, SKILL_DISTANCE, 60))
doPlayerAddSkillTry(cid, SKILL_SHIELD, reqTries(cid, SKILL_SHIELD, 60))
doPlayerAddSpentMana(cid, (getPlayerRequiredMana(cid,10)))
setPlayerStorageValue(cid, skillStor, 1)

elseif playerVoc == 8 and gotSkills == -1 then
doPlayerAddSkillTry(cid, SKILL_AXE, reqTries(cid, SKILL_AXE, 60))
doPlayerAddSkillTry(cid, SKILL_SWORD, reqTries(cid, SKILL_SWORD, 60))
doPlayerAddSkillTry(cid, SKILL_CLUB, reqTries(cid, SKILL_CLUB, 60))
doPlayerAddSkillTry(cid, SKILL_SHIELD, reqTries(cid, SKILL_SHIELD, 60))
doPlayerAddMagLevel(cid, 8)
setPlayerStorageValue(cid, skillStor, 1)

end
return TRUE
end
***Scripts notes:
doPlayerAddMagLevel stopped working properly for vocations 5, 6 and 7.
Replaced it with doplayeraddmanaspent, however this adds an extra 5 magic levels on. No idea why.
the doPlayerAddSkillTry lines add an extra 20+ skills on top of the desired 60, 10 of thoes can be accounted by the 10 skill you start with. No clue where the other 10 come from.

Other than that it's all sweet. Its now set to how I need it, it is just dodge. One day I might get around to fixing it but for now thats fine. No doubt it wont work next server update though.
 
Last edited:
Back
Top