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

does not add wing to player tfs 1.5

Mateus Robeerto

Excellent OT User
Joined
Jun 5, 2016
Messages
1,337
Solutions
71
Reaction score
697
Location
ლ(ಠ益ಠლ)
When I click on the item, however the wings are not added to the player. See the script.
Lua:
local config = {
    storage = 5359236,
    effect = CONST_ME_FIREWORK_RED,
    text1 = "You have gained your new wings!",
    text2 = "You already have these wings!",
    wingId = 1
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(config.storage) < 1 then
        if player:getStorageValue(config.storage) == -1 then
            player:addWings(config.wingId)
            player:sendTextMessage(MESSAGE_INFO_DESCR, config.text1)
            player:setStorageValue(config.storage, 1)
            player:getPosition():sendMagicEffect(config.effect)
            item:remove(1)
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, config.text2)
        end
    else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have already used this item.")
    end
    return true
end

XML:
<wing id="1" clientid="1655" name="Wing" speed="20" />
 
Solution
I don't seem to have that addWing or addWings function. I need to add this part in the source in lucasript.cpp and lucasscript.h.

Lua:
Lua Script Error: [Action Interface]
data/actions/scripts/roupa.lua:onUse
data/actions/scripts/roupa.lua:16: attempt to call method 'addWing' (a nil value)
stack traceback:
        [C]: in function 'addWing'
        data/actions/scripts/roupa.lua:16: in function <data/actions/scripts/roupa.lua:1>

Luascript.cpp
above
Lua:
registerClass("Monster", "Creature", LuaScriptInterface::luaMonsterCreate);
add
Lua:
    registerMethod("Player", "addAura", LuaScriptInterface::luaPlayerAddAura);
    registerMethod("Player", "addWings", LuaScriptInterface::luaPlayerAddWings);
    registerMethod("Player"...
When I click on the item, however the wings are not added to the player. See the script.
Lua:
local config = {
    storage = 5359236,
    effect = CONST_ME_FIREWORK_RED,
    text1 = "You have gained your new wings!",
    text2 = "You already have these wings!",
    wingId = 1
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(config.storage) < 1 then
        if player:getStorageValue(config.storage) == -1 then
            player:addWings(config.wingId)
            player:sendTextMessage(MESSAGE_INFO_DESCR, config.text1)
            player:setStorageValue(config.storage, 1)
            player:getPosition():sendMagicEffect(config.effect)
            item:remove(1)
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, config.text2)
        end
    else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have already used this item.")
    end
    return true
end

XML:
<wing id="1" clientid="1655" name="Wing" speed="20" />
the error may be because you have addWings and it is actually addWing

In any case I will send you as I do



Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getLevel() < 1000 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Necesitas ser nivel 1000 para usar este ítem!")
        return true
    end

    -- Realiza los cambios de atuendo, monturas, alas, aura, etc.
   -- player:removeOutfit(637, 637) -- Agrega el atuendo
   -- player:addOutfit(637, 637) -- Agrega el atuendo
    --player:addOutfit(1634, 1634) -- Agrega el atuendo
   -- player:addOutfit(1326, 1326) -- Agrega el atuendo
   -- player:addOutfit(916, 916) -- Agrega el atuendo
   --  player:addMount(89) -- Agrega la montura
     --player:addMount(45) -- Agrega la montura
    --player:setStorageValue(36043, 1)
     player:addWing(54) -- Agrega las alas
     player:addAura(34) -- Agrega el aura
    -- player:addAura(34) -- Agrega el aura
   --  player:addAura(45) -- Agrega el aura
     --player:addAura(2) -- Agrega el aura
       player:addShader(2) -- Agrega el aura
    --   player:addShader(7) -- Agrega el aura
    -- Realiza otros cambios de atuendo, montura, alas, aura, etc.

    item:remove(1) -- Elimina el ítem usado

    -- Opcional: Envía un mensaje o realiza otras acciones adicionales
    -- player:say('¡GRACIAS POR AYUDAR A QUE EL SERVIDOR SE MANTENGA ONLINE!', TALKTYPE_MONSTER_SAY)
    fromPosition:sendMagicEffect(CONST_ME_GIFT_WRAPS)

    return true
end
 
I don't seem to have that addWing or addWings function. I need to add this part in the source in lucasript.cpp and lucasscript.h.

Lua:
Lua Script Error: [Action Interface]
data/actions/scripts/roupa.lua:onUse
data/actions/scripts/roupa.lua:16: attempt to call method 'addWing' (a nil value)
stack traceback:
        [C]: in function 'addWing'
        data/actions/scripts/roupa.lua:16: in function <data/actions/scripts/roupa.lua:1>
 
I don't seem to have that addWing or addWings function. I need to add this part in the source in lucasript.cpp and lucasscript.h.

Lua:
Lua Script Error: [Action Interface]
data/actions/scripts/roupa.lua:onUse
data/actions/scripts/roupa.lua:16: attempt to call method 'addWing' (a nil value)
stack traceback:
        [C]: in function 'addWing'
        data/actions/scripts/roupa.lua:16: in function <data/actions/scripts/roupa.lua:1>

Luascript.cpp
above
Lua:
registerClass("Monster", "Creature", LuaScriptInterface::luaMonsterCreate);
add
Lua:
    registerMethod("Player", "addAura", LuaScriptInterface::luaPlayerAddAura);
    registerMethod("Player", "addWings", LuaScriptInterface::luaPlayerAddWings);
    registerMethod("Player", "addShader", LuaScriptInterface::luaPlayerAddShader);

above
Lua:
int LuaScriptInterface::luaMonsterCreate(lua_State* L)
add
Lua:
int LuaScriptInterface::luaPlayerAddWings(lua_State* L) {
    // player:addWing(wingId or wingName)
    Player* player = getUserdata<Player>(L, 1);
    if (!player) {
        lua_pushnil(L);
        return 1;
    }

    uint8_t wingId;
    if (isNumber(L, 2)) {
        wingId = getNumber<uint8_t>(L, 2);
    }
    else {
        Wing* wing = g_game.wings.getWingByName(getString(L, 2));
        if (!wing) {
            lua_pushnil(L);
            return 1;
        }
        wingId = wing->id;
    }
    pushBoolean(L, player->addWing(wingId));
    return 1;
}

int LuaScriptInterface::luaPlayerAddAura(lua_State* L) {
    // player:addAura(auraId or auraName)
    Player* player = getUserdata<Player>(L, 1);
    if (!player) {
        lua_pushnil(L);
        return 1;
    }

    uint8_t auraId;
    if (isNumber(L, 2)) {
        auraId = getNumber<uint8_t>(L, 2);
    }
    else {
        Aura* aura = g_game.auras.getAuraByName(getString(L, 2));
        if (!aura) {
            lua_pushnil(L);
            return 1;
        }
        auraId = aura->id;
    }
    pushBoolean(L, player->addAura(auraId));
    return 1;
}

int LuaScriptInterface::luaPlayerAddShader(lua_State* L) {
    // player:addShader(shaderId or shaderName)
    Player* player = getUserdata<Player>(L, 1);
    if (!player) {
        lua_pushnil(L);
        return 1;
    }

    uint8_t shaderId;
    if (isNumber(L, 2)) {
        shaderId = getNumber<uint8_t>(L, 2);
    }
    else {
        Shader* shader = g_game.shaders.getShaderByName(getString(L, 2));
        if (!shader) {
            lua_pushnil(L);
            return 1;
        }
        shaderId = shader->id;
    }
    pushBoolean(L, player->addShader(shaderId));
    return 1;
}


luascript.h
above
Lua:
static int luaMonsterCreate(lua_State* L);
add
Lua:
   static int luaPlayerAddAura(lua_State* L);
        static int luaPlayerAddWings(lua_State* L);
        static int luaPlayerAddShader(lua_State* L);


player.cpp
above
Lua:
bool Player::hasWing(const Wing* wing) const
add
Lua:
bool Player::addWing(uint8_t wingId)
{
    if (!g_game.wings.getWingByID(wingId)) {
        return false;
    }

    const uint8_t tmpWingId = wingId - 1;
    const uint32_t key = PSTRG_WINGS_RANGE_START + (tmpWingId / 31);

    int32_t value;
    if (getStorageValue(key, value)) {
        value |= (1 << (tmpWingId % 31));
    }
    else {
        value = (1 << (tmpWingId % 31));
    }

    addStorageValue(key, value);
    return true;
}

above
Lua:
bool Player::hasAura(const Aura* aura) const
add
Lua:
bool Player::addAura(uint8_t auraId)
{
    if (!g_game.auras.getAuraByID(auraId)) {
        return false;
    }

    const uint8_t tmpAuraId = auraId - 1;
    const uint32_t key = PSTRG_AURAS_RANGE_START + (tmpAuraId / 31);

    int32_t value;
    if (getStorageValue(key, value)) {
        value |= (1 << (tmpAuraId % 31));
    }
    else {
        value = (1 << (tmpAuraId % 31));
    }

    addStorageValue(key, value);
    return true;
}

above
Lua:
bool Player::hasShader(const Shader* shader) const
add
Lua:
bool Player::addShader(uint8_t shaderId)
{
    if (!g_game.shaders.getShaderByID(shaderId)) {
        return false;
    }

    const uint8_t tmpShaderId = shaderId - 1;
    const uint32_t key = PSTRG_SHADERS_RANGE_START + (tmpShaderId / 31);

    int32_t value;
    if (getStorageValue(key, value)) {
        value |= (1 << (tmpShaderId % 31));
    }
    else {
        value = (1 << (tmpShaderId % 31));
    }

    addStorageValue(key, value);
    return true;
}


player.h
above
Lua:
uint8_t getCurrentAura() const;
add
Lua:
bool addWing(uint8_t wingId);

above
Lua:
uint8_t getCurrentWing() const;
add
Lua:
bool addAura(uint8_t auraId);

above
Lua:
void sendFYIBox(const std::string& message) {
add
Lua:
bool addShader(uint8_t shaderId);

Credits goes to @Pox

here a script to give player wings by items

Lua:
local config = {
    [8888] = {wingId = 1, effect = CONST_ME_FIREWORK_RED, storage = 2929}, -- ItemID in [8888]
    [8887] = {wingId = 2, effect = CONST_ME_FIREWORK_RED, storage = 2930},
}

local addWingsSystem = Action()

function addWingsSystem.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local wings = config[item.itemid]
    if not wings then
        return true
    end
    if player:getStorageValue(wings.storage) == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, 'You alredy received those wings!')
        return true
    end
    player:addWings(wings.wingId)
    player:setStorageValue(wings.storage, 1)
    player:getPosition():sendMagicEffect(wings.effect)
    player:sendTextMessage(MESSAGE_INFO_DESCR, 'You received new wings!')
    player:removeItem()
    return true
end

for v, _ in pairs(config) do
    addWingsSystem:id(v)
end
addWingsSystem:register()
 
Last edited:
Solution
Luascript.cpp
above
Lua:
registerClass("Monster", "Creature", LuaScriptInterface::luaMonsterCreate);
add
Lua:
    registerMethod("Player", "addAura", LuaScriptInterface::luaPlayerAddAura);
    registerMethod("Player", "addWings", LuaScriptInterface::luaPlayerAddWings);
    registerMethod("Player", "addShader", LuaScriptInterface::luaPlayerAddShader);

above
Lua:
int LuaScriptInterface::luaMonsterCreate(lua_State* L)
add
Lua:
int LuaScriptInterface::luaPlayerAddWings(lua_State* L) {
    // player:addWing(wingId or wingName)
    Player* player = getUserdata<Player>(L, 1);
    if (!player) {
        lua_pushnil(L);
        return 1;
    }

    uint8_t wingId;
    if (isNumber(L, 2)) {
        wingId = getNumber<uint8_t>(L, 2);
    }
    else {
        Wing* wing = g_game.wings.getWingByName(getString(L, 2));
        if (!wing) {
            lua_pushnil(L);
            return 1;
        }
        wingId = wing->id;
    }
    pushBoolean(L, player->addWing(wingId));
    return 1;
}

int LuaScriptInterface::luaPlayerAddAura(lua_State* L) {
    // player:addAura(auraId or auraName)
    Player* player = getUserdata<Player>(L, 1);
    if (!player) {
        lua_pushnil(L);
        return 1;
    }

    uint8_t auraId;
    if (isNumber(L, 2)) {
        auraId = getNumber<uint8_t>(L, 2);
    }
    else {
        Aura* aura = g_game.auras.getAuraByName(getString(L, 2));
        if (!aura) {
            lua_pushnil(L);
            return 1;
        }
        auraId = aura->id;
    }
    pushBoolean(L, player->addAura(auraId));
    return 1;
}

int LuaScriptInterface::luaPlayerAddShader(lua_State* L) {
    // player:addShader(shaderId or shaderName)
    Player* player = getUserdata<Player>(L, 1);
    if (!player) {
        lua_pushnil(L);
        return 1;
    }

    uint8_t shaderId;
    if (isNumber(L, 2)) {
        shaderId = getNumber<uint8_t>(L, 2);
    }
    else {
        Shader* shader = g_game.shaders.getShaderByName(getString(L, 2));
        if (!shader) {
            lua_pushnil(L);
            return 1;
        }
        shaderId = shader->id;
    }
    pushBoolean(L, player->addShader(shaderId));
    return 1;
}


luascript.h
above
Lua:
static int luaMonsterCreate(lua_State* L);
add
Lua:
   static int luaPlayerAddAura(lua_State* L);
        static int luaPlayerAddWings(lua_State* L);
        static int luaPlayerAddShader(lua_State* L);


player.cpp
above
Lua:
bool Player::hasWing(const Wing* wing) const
add
Lua:
bool Player::addWing(uint8_t wingId)
{
    if (!g_game.wings.getWingByID(wingId)) {
        return false;
    }

    const uint8_t tmpWingId = wingId - 1;
    const uint32_t key = PSTRG_WINGS_RANGE_START + (tmpWingId / 31);

    int32_t value;
    if (getStorageValue(key, value)) {
        value |= (1 << (tmpWingId % 31));
    }
    else {
        value = (1 << (tmpWingId % 31));
    }

    addStorageValue(key, value);
    return true;
}

above
Lua:
bool Player::hasAura(const Aura* aura) const
add
Lua:
bool Player::addAura(uint8_t auraId)
{
    if (!g_game.auras.getAuraByID(auraId)) {
        return false;
    }

    const uint8_t tmpAuraId = auraId - 1;
    const uint32_t key = PSTRG_AURAS_RANGE_START + (tmpAuraId / 31);

    int32_t value;
    if (getStorageValue(key, value)) {
        value |= (1 << (tmpAuraId % 31));
    }
    else {
        value = (1 << (tmpAuraId % 31));
    }

    addStorageValue(key, value);
    return true;
}

above
Lua:
bool Player::hasShader(const Shader* shader) const
add
Lua:
bool Player::addShader(uint8_t shaderId)
{
    if (!g_game.shaders.getShaderByID(shaderId)) {
        return false;
    }

    const uint8_t tmpShaderId = shaderId - 1;
    const uint32_t key = PSTRG_SHADERS_RANGE_START + (tmpShaderId / 31);

    int32_t value;
    if (getStorageValue(key, value)) {
        value |= (1 << (tmpShaderId % 31));
    }
    else {
        value = (1 << (tmpShaderId % 31));
    }

    addStorageValue(key, value);
    return true;
}


player.h
above
Lua:
uint8_t getCurrentAura() const;
add
Lua:
bool addWing(uint8_t wingId);

above
Lua:
uint8_t getCurrentWing() const;
add
Lua:
bool addAura(uint8_t auraId);

above
Lua:
void sendFYIBox(const std::string& message) {
add
Lua:
bool addShader(uint8_t shaderId);

Credits goes to @Pox

here a script to give player wings by items

Lua:
local config = {
    [8888] = {wingId = 1, effect = CONST_ME_FIREWORK_RED, storage = 2929}, -- ItemID in [8888]
    [8887] = {wingId = 2, effect = CONST_ME_FIREWORK_RED, storage = 2930},
}

local addWingsSystem = Action()

function addWingsSystem.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local wings = config[item.itemid]
    if not wings then
        return true
    end
    if player:getStorageValue(wings.storage) == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, 'You alredy received those wings!')
        return true
    end
    player:addWings(wings.wingId)
    player:setStorageValue(wings.storage, 1)
    player:getPosition():sendMagicEffect(wings.effect)
    player:sendTextMessage(MESSAGE_INFO_DESCR, 'You received new wings!')
    player:removeItem()
    return true
end

for v, _ in pairs(config) do
    addWingsSystem:id(v)
end
addWingsSystem:register()
Very well, perfectly functional! Thanks a lot... I tested the script I posted, but it didn't work, and I also tested the other guy's and it didn't work either. The one you posted I tested and it worked perfectly. Thank you very much from the heart!
 
Very well, perfectly functional! Thanks a lot... I tested the script I posted, but it didn't work, and I also tested the other guy's and it didn't work either. The one you posted I tested and it worked perfectly. Thank you very much from the heart!
No Problem
Have fun
Mark it as solution
 
use newer tfs and then u will find it :D

Sad Spongebob Squarepants GIF
 
use newer tfs and then u will find it :D
this script use in action??

Lua:
local config = {
    [8888] = {wingId = 1, effect = CONST_ME_FIREWORK_RED, storage = 2929}, -- ItemID in [8888]
    [8887] = {wingId = 2, effect = CONST_ME_FIREWORK_RED, storage = 2930},
}

local addWingsSystem = Action()

function addWingsSystem.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local wings = config[item.itemid]
    if not wings then
        return true
    end
    if player:getStorageValue(wings.storage) == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, 'You alredy received those wings!')
        return true
    end
    player:addWings(wings.wingId)
    player:setStorageValue(wings.storage, 1)
    player:getPosition():sendMagicEffect(wings.effect)
    player:sendTextMessage(MESSAGE_INFO_DESCR, 'You received new wings!')
    player:removeItem()
    return true
end

for v, _ in pairs(config) do
    addWingsSystem:id(v)
end
addWingsSystem:register()
 
this script use in action??

Lua:
local config = {
    [8888] = {wingId = 1, effect = CONST_ME_FIREWORK_RED, storage = 2929}, -- ItemID in [8888]
    [8887] = {wingId = 2, effect = CONST_ME_FIREWORK_RED, storage = 2930},
}

local addWingsSystem = Action()

function addWingsSystem.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local wings = config[item.itemid]
    if not wings then
        return true
    end
    if player:getStorageValue(wings.storage) == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, 'You alredy received those wings!')
        return true
    end
    player:addWings(wings.wingId)
    player:setStorageValue(wings.storage, 1)
    player:getPosition():sendMagicEffect(wings.effect)
    player:sendTextMessage(MESSAGE_INFO_DESCR, 'You received new wings!')
    player:removeItem()
    return true
end

for v, _ in pairs(config) do
    addWingsSystem:id(v)
end
addWingsSystem:register()

data/scripts and somewhere there where ever u want
Make sure u added the function to your source aswell
 
This one knows SabrehavenServer
There are no revscripts, I'm not mistaken.

Ahh well in that case
@tibera

remove:
Lua:
local addWingsSystem = Action()

change this:
Lua:
function addWingsSystem.onUse(player, item, fromPosition, target, toPosition, isHotkey)
to
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)

remove
Lua:
for v, _ in pairs(config) do
    addWingsSystem:id(v)
end
addWingsSystem:register()

Add the script then in actions/scripts
and regist it on xml aswell
if u got as example itemID 8888 and itemID 9832 then it must look like this
XML:
    <action itemid="8888" script="yourScriptName.lua" />
    <action itemid="9832" script="yourScriptName.lua" />
 
Back
Top