Ramirow
Veteran OT User
- Joined
- Aug 22, 2009
- Messages
- 584
- Solutions
- 15
- Reaction score
- 301
- Location
- Argentina
- YouTube
- ramirogrant
Hello guys, I'm trying to learn lua, I don't want to ask or search for scripts, I want to be able to create them myself..So I was looking at the libraries for functions and stuff. I've created an script from scratch.
Can someone analyze the script and tell me if it was done correctly? I would love some feedback on these subject.
Sorry if the script is bad, It's just..My first time lol
This is supposed to:
- Check for an storage value
- Assign the storage at the end
- Give reward depending on player vocation
- If is knight, it gives a different weapon depending on highest skill
I don't know if I used tables correctly or if a var should be used to shorten a function("voc" = getPlayerVocation(cid).)
Can someone analyze the script and tell me if it was done correctly? I would love some feedback on these subject.
Sorry if the script is bad, It's just..My first time lol
This is supposed to:
- Check for an storage value
- Assign the storage at the end
- Give reward depending on player vocation
- If is knight, it gives a different weapon depending on highest skill
I don't know if I used tables correctly or if a var should be used to shorten a function("voc" = getPlayerVocation(cid).)
Code:
-- Scripted by Ramiro Jesse Grant for Phoenix OTS
local storage = 51222
local voc = getPlayerVocation(cid)
local count = 1
local bag = 2330
local sword = 2
local axe = 3
local club = 1
local items = {
[1] = {7407, 2445, 7455}, -- Knight Items
[2] = {8868, 2122}, -- Druid/Sorcerer Items
[3] = {8858, 2352} -- Paladin Items
}
function onUse(cid, item, frompos, item2, topos)
if getPlayerStorageValue(cid, storage) == -1 then
if voc == 1 or voc == 5 or voc == 9 or voc == 2 or voc == 6 or voc == 10
local m = items[2]
doPlayerAddItem(cid, bag, 1)
doAddContainerItem(bag, m[1], count)
doAddContainerItem(bag, m[2], count)
doPlayerSendTextMessage(cid,22,"Felicidades "..getPlayerName(cid).."! Has encontrado un "..getItemNameById(bag).." que contiene una "..getItemNameById(m[1]).." y un "..getItemNameById(m[2])..".")
end
if voc == 3 or voc == 7 or voc == 11 then
local p = items[3]
doPlayerAddItem(cid, bag, 1)
doAddContainerItem(bag, p[1], count)
doAddContainerItem(bag, p[2], count)
doPlayerSendTextMessage(cid,22,"Felicidades "..getPlayerName(cid).."! Has encontrado una "..getItemNameById(bag).." que contiene un "..getItemNameById(p[1]).." y una "..getItemNameById(p[2])..".")
end
if voc == 4 or voc == 8 or voc == 12 then
local k = items[1]
if getPlayerSkillLevel(cid, sword) > getPlayerSkillLevel(cid, club) and getPlayerSkillLevel(cid, sword) > getPlayerSkillLevel(cid, axe) then
doPlayerAddItem(cid, k[1], count)
doPlayerSendTextMessage(cid,22,"Felicidades "..getPlayerName(cid).."! Has encontrado una .."getItemNameById(k[1])..".")
end
if getPlayerSkillLevel(cid, club) > getPlayerSkillLevel(cid, sword) and getPlayerSkillLevel(cid, club) > getPlayerSkillLevel(cid, axe) then
doPlayerAddItem(cid, k[2], count)
doPlayerSendTextMessage(cid,22,"Felicidades "..getPlayerName(cid).."! Has encontrado una .."getItemNameById(k[2])..".")
elseif getPlayerSkillLevel(cid, axe) > getPlayerSkillLevel(cid, sword) and getPlayerSkillLevel(cid, axe) > getPlayerSkillLevel(cid, club) then
doPlayerAddItem(cid, k[3], count)
doPlayerSendTextMessage(cid,22,"Felicidades "..getPlayerName(cid).."! Has encontrado una .."getItemNameById(k[3])..".")
end
end
setPlayerStorageValue(cid, storage, 1)
end
if(getPlayerStorageValue(cid, storage) > 0) then
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It is empty.")
end
return TRUE
end