Create item functions with Lua

Joined
Sep 19, 2009
Messages
921
Reaction score
194
Location
Germany
Hello,
since I "finished" the lua add-on. Im still writing some functions etc but its time to make a tutorial now.
The compiled server files with lua will be released soon.


What do you need?
You only need Lua experience.
no c++ or anything else is needed!

How do I write new functions for items?
Nothing easier than that.
Example:
Code:
function ItemUse_XXXX ( role )
end

role = unique char id.
XXXX <-- is the function ID from the item.
So you have to search in the item-list which I give you for "Use_Item_Tblidx" and there you'll have unique numbers (maybe some duplicate so they will share the same function)

then you just write

Code:
function ItemUse_8001 ( role )
end

8001 = Use_Item_Tblidx from (id)18001 - (name)Senzu Beans

now we go forward and do this:

Code:
function ItemUse_8001 ( role )
    local hp = [COLOR=#333333]g_test:[/COLOR]GetChaAttr(role, ATTR_HP) 
end

hp is now the current life.

now we add a easy check:
Code:
function ItemUse_8001 ( role )
    local hp = g_test:GetChaAttr(role, ATTR_HP)
    if hp <= 0 then -- Check if char is dead 
    end 
end

time to go further and do more checks
Code:
function ItemUse_8001 ( role )    local hp = g_test:GetChaAttr(role, ATTR_HP)
    if hp <= 0 then -- Check if char is dead 
    end 
    
    hp_resume = 20 -- how many life to heal?
    hp = hp + hp_resume 
    mxhp = g_test:GetChaAttr(role,ATTR_MXHP) -- get max life
    
    if hp > mxhp then --Add check that player wont get more life than he has
        hp = mxhp -- set life = max life
    end
end

now the final:
Code:
function ItemUse_8001 ( role )    local hp = g_test:GetChaAttr(role, ATTR_HP)
    if hp <= 0 then -- Check if char is dead 
    end 
    
    hp_resume = 20 -- how many life to heal?
    hp = hp + hp_resume 
    mxhp = g_test:GetChaAttr(role,ATTR_MXHP) -- get max life
    
    if hp > mxhp then --Add check that player wont get more life than he has
        hp = mxhp
    end
    
    g_test:SetCharaAttr(hp, role, ATTR_HP) 
end

g_test:SetCharaAttr(hp, role, ATTR_HP)
update the life from the player

now you finished writing a function which recovers 20 life points

Itemlist:
 
Last edited:
@Daneos can your spear me the .exe for dbo, i got the server but when i train to use it on the client it keeps crashing, others say thats it might be the server codes but i know your codes don't lie so it the .exe for sure. so can you upload the .exe for dbo and maybe the server files because dont be too sure and i dont wanna be annoying you while your focused :*:
 
Yep trying to work on a server as well need Use_Item_Tblidx so i can start setting that up ..or how to get the info directly.
 
Use_Item_Tblidx? For what? With TBLIDX u are fine, but I really don't know what are u trying to do, he use the TBLIDX

function ItemUse_XXXX

xxxx = TBLIDX of item
 
The Table id numbers is what i need the identification numbers for the items ..
Was wondering if anyone has the item identification numbers..
 
._. Really? No one can think? It's easy, THINK, how the code do... is obviusly isn't your code, for search the data of SKILL in the DateBase, how with one TBLIDX u can get all the data of that SKILL, with the TBLIDX 200351 i can know is SSJ, cost 440 ep... etc, etc.

If u want I explain that to you, the server have maps who contains all the data of the tables, if u use one for where i = map.begin() and i != map.end(); i++) and there u can put this, printf("ItemID: %d\n", i->tblidx); then on the screen you are going to see all the IDS of items. If you search in google is one way to create .txt, u can save all data in one .txt and make it like your one DB and see all what have the DB.
 
You see your not listening seems like you getting mad to help. But it is simple "TBLIDX 200351" 200351 Is what i have been asking for but i need all the item id's Dont need the explanation i need the id numbers. unlike you haven't helped with this project at all not sure where to get all the item id numbers and Mission id's the whole reason i am here asking. I see and understand the command you are talking but where do you do it at where is this implemented how do i get id's print to a .txt if you can explain this, maybe i can do it instead of asking the same question over and over again it seems a language barrier is making this.. I just need the ids simple and plain and not as great as the rest of you here still learning thus why i am asking. i Just need the number data for the Korea version of the game so i can experiment get better on my own.
 
Try to do what I said about for of the maps and put all on the .txt and you can get all the ids

Or

 
Thanks for the Help i have the Translations didn't look in there for a while but all the names ids are there Thanks alot. Now i can do what i wanted i located all Item ids and mob and quest. Now what you were talking about earlier was making the map print out all of it on a .txt where do i initiate the code for instance if i wanted to make a addon that did that at any time then where would initiate the code if that makes sense.
 
Back