• TibiaFace

    Tibiaface | Una comunidad Open Tibia donde encontras : mapas, scripts, Otserver, npc y amigos etc ...

    .
    demo menumenu

    Afiliados



    Votar:

    Guia Basica De Action lua

    Compartir:

    Ver el tema anterior Ver el tema siguiente Ir abajo  Mensaje (Página 1 de 1.)

    1default Guia Basica De Action lua el Dom Dic 20, 2015 11:16 pm

    Krapula

    avatar
    Miembro
    Miembro
    Basic

    All action scripts work with the main function onUse, which means all actions scripts are activated when clicking use on items.

    Código:
    function onUse(cid, item, fromPosition, itemEx, toPosition)

    In actions.xml, you add the lua script so it will be loaded by the server.
    You can add it in 3 different ways: uniqueid, actionid or itemid.
    Example:
    Código:
    <action uniqueid="5000" event="script" value="other/name.lua"/>
    <action actionid="5000" event="script" value="other/name.lua"/>
    <action itemid="5000" event="script" value="other/name.lua"/>

    Note: If you use TFS 0.2/1.0, use script instead of event and value, so use script="other/name.lua" instead of event="script" value="other/name.lua".

    Which one you choose depens on what kind of script it is.
    With scripts that should always work with certain itemids like potions, use itemid.
    Uniqueid or actionid depends on what you add to the item.
    The main difference between those ids is that uniqueid makes an item not moveable and can only be used 1x, actionids have no effect on the items and can be used as many times as you want.


    ~~~~~~


    Other actions.xml options
    There are also have more options you can add in the xml lines

    - allowfaruse

    Código:
    <action itemid="2580" event="script" value="tools/fishing.lua" allowfaruse="1"/>

    This can only be used for items with a "use with" option, so you can use it on something else with no limits from where you are.

    - blockwalls
    Defines if item will ignore walls and other blocking items.
    Only for items with "use with" option.

    - fromid, toid (TFS 0.3/0.4 only)
    This can be used to register a whole range of ids in actions.xml, instead of adding different lines for each of them.

    Código:
    <action fromid="2666" toid="2691" event="script" value="other/food.lua"/>
    <action fromuid="4000" touid="4020" event="script" value="other/name.lua"/>
    <action fromaid="4000" toaid="4020" event="script" value="other/name.lua"/>

    You can also do it like this.
    Código:
    <action itemid="7588-7591;8472-8473;7618;7620;8704" event="script" value="liquids/potions.lua"/>

    ~~~~~~


    Lua

    Actions scripts only have 1 main function, function onUse.
    When this function return false, the player gets a cancel message "You cannot use this object".
    If you don't add return true in the script, it will return false, so that's why you always have to add return true.
    Código:
    function onUse(cid, item, fromPosition, itemEx, toPosition)
      -- what the script should do
      return true
    end

    Function onUse has 4 parameters: cid, item, fromPosition, itemEx, toPosition

    - cid
    Creatureid of the player that clicks use on the item.
    Example:

    Código:
    getPlayerLevel(cid)

    This will get the level of the player that clicks use on the item.

    - item
    The item the player clicks use on.
    This can be used in 3 different ways.

    Código:
    item.uid -- uniqueid of the item
    item.actionid -- actionid of the item
    item.itemid -- itemid of the item

    Items already have uniqueids, that's why you can always use item.uid even if you don't add it in the map editor.
    For example to remove the item.

    Código:
    doRemoveItem(item.uid, 1)

    Only difference if you add an uniqueid, it will have a specific uniqueid.

    - fromPosition
    The position where the player clicks use on the item.

    Código:
    doSendMagicEffect(fromPosition, CONST_ME_POFF)

    - itemEx
    This parameter is used for items with a "use with" option, itemEx will be the item/player players use the item on.
    For example a shovel on a hole. The shovel will be the item, the hole will be the itemEx.
    Also this can be used in 3 different ways.


    Código:
    itemEx.uid -- uniqueid of the itemEx
    itemEx.actionid -- actionid of the itemEx
    itemEx.itemid -- itemid of the itemEx

    - toPosition
    The position where the player clicks on the itemEx, if the item doesn't have a "use with" option, it will be the position of the item.

    Código:
    doSendMagicEffect(toPosition, CONST_ME_POFF)

    Copy y paste

    Agradecimiento a
    Zonnebloem

    Ver perfil de usuario https://www.facebook.com

    2default Re: Guia Basica De Action lua el Lun Dic 21, 2015 6:17 pm

    [Admin] God Maya

    avatar
    Administrador
    Administrador
    buen aporte +1 :(MG):



    Ver perfil de usuario http://www.tibiaface.com

    Ver el tema anterior Ver el tema siguiente Volver arriba  Mensaje (Página 1 de 1.)

    Permisos de este foro:
    No puedes responder a temas en este foro.

     

    BienvenidosTibiaFace es una comunidad de Open Tibia. Para participar debes estar registrado (click para Regístrate).