• 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 Setting skill requirement on items

archer32

Member
Joined
Feb 3, 2011
Messages
88
Solutions
1
Reaction score
9
Hey there,
What I am trying to accomplish is you cannot use a weapon unless you have required skill level.

Example;
Club needs 130 club skill to use
So my code is as follows

Lua:
function onEquip(cid, item, slot)
    local lvl = 130
    local p = Player(cid)
    if p:getId(cid) and p:getSkillLevel(1) < 130 then
        doPlayerSendTextMessage(cid,25,"You need 130.")
    return
 end
return false
end

I also setup this script in movements for onEquipItem.. with the script name

There is no console errors, no message to character, etc..

Any idea?
 
what is this ?? new to my eye :
first you received CID from callback cool! then you created a player pointer which can be cooler ! [p = Player(cid)]


what the hell is this? p:getId(cid) maybe my knowledge is limited if the function getId() acts different if received parameter to check if it is the same player but im pretty sure it won't because you already pointed to it with Player(cid) i believe you need to remove that from the if condition and it will work, i will check the function later no time rn
 
line 6 try change to
Lua:
return false
Did not work sadly, still no errors
Post automatically merged:

what is this ?? new to my eye :
first you received CID from callback cool! then you created a player pointer which can be cooler ! [p = Player(cid)]


what the hell is this? p:getId(cid) maybe my knowledge is limited if the function getId() acts different if received parameter to check if it is the same player but im pretty sure it won't because you already pointed to it with Player(cid) i believe you need to remove that from the if condition and it will work, i will check the function later no time rn
I am new to this, I was browsing through compat.lua and using the function types there... I figured I was doing things correctly since no errors but.. that is not that case :D
 
This message appear? the "You need 130." if not, then ur code is wrong (or this method its wrong). Anyway as shadow noticed change

Lua:
local p = Player(cid)
to
Lua:
local p = cid

and change
Lua:
if p:getId(cid) and p:getSkillLevel(1) < 130 then

to
Lua:
if p:getSkillLevel(1) < 130 then
 
This message appear? the "You need 130." if not, then ur code is wrong (or this method its wrong). Anyway as shadow noticed change

Lua:
local p = Player(cid)
to
Lua:
local p = cid

and change
Lua:
if p:getId(cid) and p:getSkillLevel(1) < 130 then

to
Lua:
if p:getSkillLevel(1) < 130 then
I try his change but give console errors then

With what you say here, I do get (You need 130.) now, but when I equip with player with 130+ it just says "You cannot dress this object here"
Which is odd, because I state in movements slot="hand"
 
change at the end from return false to return true
That did it! Thank you for helping my oversights :)
Still learning

Update code for anybody wondering now

Lua:
function onEquip(cid, item, slot)
    local lvl = 130
    local p = cid
    if p:getId(cid) and p:getSkillLevel(1) < 130 then
        doPlayerSendTextMessage(cid,25,"You need 130.")
    return
 end
return true
end
 
Well, since u wanna learn something so.

you have local lvl = 130, but you are not using this, lets use this variable and remove the getId check which is absolute useless

Lua:
function onEquip(cid, item, slot)
    local lvl = 130
    local p = cid
    if p:getSkillLevel(1) < lvl then
        doPlayerSendTextMessage(cid,25,"You need " .. lvl .. ".")
    return
 end
return true
end
That should work too.
 
Back
Top