• 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!
  • If you're using Gesior 2012 or MyAAC, please review this thread for information about a serious security vulnerability and a fix.

Lua TFS 1.X a nil value

Manigold

Active Member
Joined
Nov 2, 2017
Messages
172
Solutions
8
Reaction score
32
I'm having a problem ,(line 22 :attempt to index local 'conjureItem' <a nil value>)
With this function :

Lua:
function Player:conjureItem(reagentId, conjureId, conjureCount, effect)
    if not conjureCount and conjureId ~= 0 then
        local itemType = ItemType(conjureId)
        if itemType:getId() == 0 then
            return false
        end

        local charges = itemType:getCharges()
        if charges ~= 0 then
            conjureCount = charges
        end
    end

    local conjureItem = self:getItemById(reagentId, true, -1)

    if reagentId ~= 0 and not conjureItem then
        self:sendCancelMessage(RETURNVALUE_YOUNEEDAMAGICITEMTOCASTSPELL)
        self:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    local item = conjureItem:getParent():addItem(conjureId, conjureCount)
    if not item then
        item = self:addItem(conjureId, conjureCount)
        if not item then
            self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
            self:getPosition():sendMagicEffect(CONST_ME_POFF)
            return false
        end
    end

    if item:hasAttribute(ITEM_ATTRIBUTE_DURATION) then
        item:decay()
    end

    conjureItem:remove(1)
    self:getPosition():sendMagicEffect(item:getType():isRune() and CONST_ME_MAGIC_RED or effect)
    return true
end
 
Solution
Same error in line 281.

With this code the items are conjured with the magic effect ,but another error occurs:

View attachment 67417

Send me your Discord through PM. Here it works, don't know why it is not working for you.

---

Edit: Upgrade it to handle with stackable runes.

Lua:
function Player:conjureItem(reagentId, conjureId, conjureCount, effect)
  -- Ensures conjureCount
  if not conjureCount and conjureId ~= 0 then
    local itemType = ItemType(conjureId)
    if itemType:getId() == 0 then
      return false
    end

    local charges = itemType:getCharges()
    if charges ~= 0 then
      conjureCount = charges
    end
  end

  local conjureItem

  -- A reagent id is needed
  if reagentId ~= 0 then
    conjureItem =...

Rexxar

of Unimatrix Zero-One
Joined
Jun 4, 2009
Messages
958
Solutions
3
Reaction score
83
Location
Narnia
Well for one, the line 281 error is because it looks like it's trying to access the data in item on line 273. Which stops existing on line 279 since it's a local.

Line 271 is weird, but it looks like either conjureid or conjurecount is never defined.

Could you post the whole script as it looks like now?
 
OP
OP
Manigold

Manigold

Active Member
Joined
Nov 2, 2017
Messages
172
Solutions
8
Reaction score
32
Well for one, the line 281 error is because it looks like it's trying to access the data in item on line 273. Which stops existing on line 279 since it's a local.

Line 271 is weird, but it looks like either conjureid or conjurecount is never defined.

Could you post the whole script as it looks like now?
The code from Peonso is working ,but its throwing this annoying error.
Lua:
--Pre-made areas

--Waves
AREA_WAVE3 = {
{1, 1, 1},
{1, 1, 1},
{0, 3, 0}
}

AREA_WAVE4 = {
{1, 1, 1, 1, 1},
{0, 1, 1, 1, 0},
{0, 1, 1, 1, 0},
{0, 0, 3, 0, 0}
}

AREA_WAVE6 = {
{0, 0, 0, 0, 0},
{0, 1, 3, 1, 0},
{0, 0, 0, 0, 0}
}

AREA_SQUAREWAVE5 = {
{1, 1, 1},
{1, 1, 1},
{1, 1, 1},
{0, 1, 0},
{0, 3, 0}
}

AREA_SQUAREWAVE6 = {
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
{0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
{0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
{0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
{0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
{0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
{0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
{0,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1, 0, 0, 0},
{0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0},
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
{1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1},
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
{0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0},
{0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0},
{0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0}
}

--Squares
AREA_SQUARE1X1 = {
{1, 1, 1},
{1, 3, 1},
{1, 1, 1}
}

-- Walls
AREA_WALLFIELD = {
{1, 1, 3, 1, 1}
}

AREADIAGONAL_WALLFIELD = {
{0, 0, 0, 0, 1},
{0, 0, 0, 1, 1},
{0, 1, 3, 1, 0},
{1, 1, 0, 0, 0},
{1, 0, 0, 0, 0},
}

-- Spells-only arrays

--This HUGE array contains all corpses of the game, until protocol 8.0
-- It is used on animate dead rune and on undead legion spell. No unmoveable corpses are there.
CORPSES = {
2806,2807,2808,2809,2810,2811,2812,2813,2814,2815,2816,2817,2818,2819,2820,2821,2822,2823,
2824,2825,2826,2827,2828,2829,2830,2831,2832,2833,2834,2835,2836,2837,2838,2839,2840,2841,
2842,2843,2844,2845,2846,2847,2848,2849,2850,2851,2852,2853,2854,2855,2856,2857,2858,2859,
2879,2880,2881,2882,2883,2884,2885,2886,2887,2888,2889,2890,2891,2892,2893,2894,2895,2896,
2897,2898,2899,2900,2901,2902,2903,2904,2905,2906,2907,2908,2909,2910,2911,2912,2913,2914,
2915,2916,2917,2918,2919,2920,2921,2922,2923,2924,2925,2926,2927,2928,2929,2930,2931,2932,
2933,2934,2935,2936,2937,2938,2939,2940,2941,2942,2943,2944,2945,2946,2947,2948,2949,2950,
2951,2952,2953,2954,2955,2956,2957,2958,2959,2960,2961,2962,2963,2964,2965,2966,2967,2968,
2969,2970,2971,2972,2973,2974,2975,2976,2977,2978,2979,2980,2981,2982,2983,2984,2985,2986,
2987,2988,2989,2990,2991,2992,2993,2994,2995,2996,2997,2998,2999,3000,3001,3002,3003,3004,
3005,3006,3007,3008,3009,3010,3011,3012,3013,3014,3015,3016,3017,3018,3019,3020,3021,3022,
3023,3024,3025,3026,3027,3028,3029,3030,3031,3032,3033,3034,3035,3036,3037,3038,3039,3040,
3041,3042,3043,3044,3045,3046,3047,3048,3049,3050,3051,3052,3053,3054,3055,3056,3057,3058,
3059,3060,3061,3062,3063,3064,3065,3066,3067,3068,3069,3070,3071,3072,3073,3074,3075,3076,
3077,3078,3079,3080,3081,3082,3083,3084,3085,3086,3087,3088,3089,3090,3091,3092,3093,3094,
3095,3096,3097,3098,3099,3100,3101,3102,3103,3104,3105,3106,3107,3108,3109,3110,3111,3112,
3113,3114,3115,3116,3117,3118,3119,3120,3121,3128,3129,3130,3131,3132,3133,3134,4252,4253,
4254,4255,4256,4257,4258,4259,4260,4261,4262,4263,4264,4265,4266,4267,4268,4269,4270,4271,
4272,4273,4274,4275,4276,4277,4278,4279,4280,4281,4282,4283,4284,4285,4286,4287,4288,4289,
4290,4291,4292,4293,4294,4295,4296,4297,4298,4299,4300,4301,4302,4303,4304,4305,4306,4307,
4308,4309,4310,4311,4312,4313,4314,4315,4316,4317,4318,4319,4320,4321,4322,4323,4324,4325,
4326,4327,5522,5523,5524,5525,5526,5527,5528,5529,5530,5531,5532,5533,5534,5535,5536,5537,
5538,5540,5541,5542,5565,5566,5567,5568,5625,5626,5627,5628,5629,5630,5666,5667,5668,5688,
5689,5690,5727,5728,5729,5762,5765,5766,5767,5931,5932,5933,5934,5935,5936,5965,6022,6082,
6083,6084,6303,6304,6305,6307,6308,6309,6310,6313,6314,6315,6317,6318,6319,6321,6322,6323,
6325,6326,6327,6328,6329,6330,6333,6334,6335,6337,6338,6339,6341,6342,6343,6345,6346,6347,
6349,6350,6351,6355,6365,6366,6367,6520,6521,6522,6560,7092,7093,7094,7256,7257,7258,7283,
7284,7285,7317,7318,7319,7321,7322,7323,7325,7326,7328,7329,7331,7332,7333,7335,7336,7337,
7339,7340,7341,7345,7346,7347,7623,7624,7625,7626,7627,7629,7630,7631,7638,7639,7640,7741,
7742,7743,7848,7849,7908,7927,7928,7929,7931,7970,7971,8272}

-- This array contains all destroyable field items
FIELDS = {1487,1488,1489,1490,1491,1492,1493,1494,1495,1496,1500,1501,1502,1503,1504}

function Player:conjureItem(reagentId, conjureId, conjureCount, effect)
    if not conjureCount and conjureId ~= 0 then
        local itemType = ItemType(conjureId)
        if itemType:getId() == 0 then
            return false
        end

        local charges = itemType:getCharges()
        if charges ~= 0 then
            conjureCount = charges
        end
    end

    local conjureItem = self:getItemById(reagentId, true, -1)
    if reagentId ~= 0 and not conjureItem then
        self:sendCancelMessage(RETURNVALUE_YOUNEEDAMAGICITEMTOCASTSPELL)
        self:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    elseif reagentId ~= 0 and conjureItem then
        self:getItemById(reagentId, true, -1):transform(conjureId, conjureCount)
    else
        local item = self:addItem(conjureId, conjureCount)
        if not item then
            self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
            self:getPosition():sendMagicEffect(CONST_ME_POFF)
            return false
        end
    end

    if item:hasAttribute(ITEM_ATTRIBUTE_DURATION) then
        item:decay()
    end

    conjureItem:remove(1)
    self:getPosition():sendMagicEffect(item:getType():isRune() and CONST_ME_MAGIC_RED or effect)
    return true
end
 

Rexxar

of Unimatrix Zero-One
Joined
Jun 4, 2009
Messages
958
Solutions
3
Reaction score
83
Location
Narnia
Lua:
function onCastSpell(creature, variant)
    return creature:conjureItem(0, 2260, 1)
end

Yeah definitely not passing an effect value.
I don't know how LUA handles not being passed expected values, but you could try changing it to

Lua:
function onCastSpell(creature, variant)
    return creature:conjureItem(0, 2260, 1, CONST_ME_MAGIC_GREEN)
end
 

River KA

Veteran OT User
Joined
Feb 1, 2010
Messages
512
Solutions
26
Reaction score
310
The code from Peonso is working ,but its throwing this annoying error.
Lua:
--Pre-made areas

--Waves
AREA_WAVE3 = {
{1, 1, 1},
{1, 1, 1},
{0, 3, 0}
}

AREA_WAVE4 = {
{1, 1, 1, 1, 1},
{0, 1, 1, 1, 0},
{0, 1, 1, 1, 0},
{0, 0, 3, 0, 0}
}

AREA_WAVE6 = {
{0, 0, 0, 0, 0},
{0, 1, 3, 1, 0},
{0, 0, 0, 0, 0}
}

AREA_SQUAREWAVE5 = {
{1, 1, 1},
{1, 1, 1},
{1, 1, 1},
{0, 1, 0},
{0, 3, 0}
}

AREA_SQUAREWAVE6 = {
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
{0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
{0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
{0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
{0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
{0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
{0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0}
}

AREA_SQUAREWAVE7 = {
{0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
{0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
{0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
{0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
{0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
{0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
{0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0}
}

--Diagonal waves
AREADIAGONAL_WAVE4 = {
{0, 0, 0, 0, 1, 0},
{0, 0, 0, 1, 1, 0},
{0, 0, 1, 1, 1, 0},
{0, 1, 1, 1, 1, 0},
{1, 1, 1, 1, 1, 0},
{0, 0, 0, 0, 0, 3}
}

AREADIAGONAL_SQUAREWAVE5 = {
{1, 1, 1, 0, 0},
{1, 1, 1, 0, 0},
{1, 1, 1, 0, 0},
{0, 0, 0, 1, 0},
{0, 0, 0, 0, 3}
}

AREADIAGONAL_WAVE6 = {
{0, 0, 1},
{0, 3, 0},
{1, 0, 0}
}

--Beams
AREA_BEAM1 = {
{3}
}

AREA_BEAM5 = {
{1},
{1},
{1},
{1},
{3}
}

AREA_BEAM7 = {
{1},
{1},
{1},
{1},
{1},
{1},
{3}
}

AREA_BEAM8 = {
{1},
{1},
{1},
{1},
{1},
{1},
{1},
{3}
}

--Diagonal Beams
AREADIAGONAL_BEAM5 = {
{1, 0, 0, 0, 0},
{0, 1, 0, 0, 0},
{0, 0, 1, 0, 0},
{0, 0, 0, 1, 0},
{0, 0, 0, 0, 3}
}

AREADIAGONAL_BEAM7 = {
{1, 0, 0, 0, 0, 0, 0},
{0, 1, 0, 0, 0, 0, 0},
{0, 0, 1, 0, 0, 0, 0},
{0, 0, 0, 1, 0, 0, 0},
{0, 0, 0, 0, 1, 0, 0},
{0, 0, 0, 0, 0, 1, 0},
{0, 0, 0, 0, 0, 0, 3}
}

--Circles
AREA_CIRCLE2X2 = {
{0, 1, 1, 1, 0},
{1, 1, 1, 1, 1},
{1, 1, 3, 1, 1},
{1, 1, 1, 1, 1},
{0, 1, 1, 1, 0}
}

AREA_CIRCLE3X3 = {
{0, 0, 1,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, 1, 1, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0}
}

--Squares
AREA_SQUARE1X1 = {
{1, 1, 1},
{1, 3, 1},
{1, 1, 1}
}

-- Walls
AREA_WALLFIELD = {
{1, 1, 3, 1, 1}
}

AREADIAGONAL_WALLFIELD = {
{0, 0, 0, 0, 1},
{0, 0, 0, 1, 1},
{0, 1, 3, 1, 0},
{1, 1, 0, 0, 0},
{1, 0, 0, 0, 0},
}

-- Spells-only arrays

--This HUGE array contains all corpses of the game, until protocol 8.0
-- It is used on animate dead rune and on undead legion spell. No unmoveable corpses are there.
CORPSES = {
2806,2807,2808,2809,2810,2811,2812,2813,2814,2815,2816,2817,2818,2819,2820,2821,2822,2823,
2824,2825,2826,2827,2828,2829,2830,2831,2832,2833,2834,2835,2836,2837,2838,2839,2840,2841,
2842,2843,2844,2845,2846,2847,2848,2849,2850,2851,2852,2853,2854,2855,2856,2857,2858,2859,
2879,2880,2881,2882,2883,2884,2885,2886,2887,2888,2889,2890,2891,2892,2893,2894,2895,2896,
2897,2898,2899,2900,2901,2902,2903,2904,2905,2906,2907,2908,2909,2910,2911,2912,2913,2914,
2915,2916,2917,2918,2919,2920,2921,2922,2923,2924,2925,2926,2927,2928,2929,2930,2931,2932,
2933,2934,2935,2936,2937,2938,2939,2940,2941,2942,2943,2944,2945,2946,2947,2948,2949,2950,
2951,2952,2953,2954,2955,2956,2957,2958,2959,2960,2961,2962,2963,2964,2965,2966,2967,2968,
2969,2970,2971,2972,2973,2974,2975,2976,2977,2978,2979,2980,2981,2982,2983,2984,2985,2986,
2987,2988,2989,2990,2991,2992,2993,2994,2995,2996,2997,2998,2999,3000,3001,3002,3003,3004,
3005,3006,3007,3008,3009,3010,3011,3012,3013,3014,3015,3016,3017,3018,3019,3020,3021,3022,
3023,3024,3025,3026,3027,3028,3029,3030,3031,3032,3033,3034,3035,3036,3037,3038,3039,3040,
3041,3042,3043,3044,3045,3046,3047,3048,3049,3050,3051,3052,3053,3054,3055,3056,3057,3058,
3059,3060,3061,3062,3063,3064,3065,3066,3067,3068,3069,3070,3071,3072,3073,3074,3075,3076,
3077,3078,3079,3080,3081,3082,3083,3084,3085,3086,3087,3088,3089,3090,3091,3092,3093,3094,
3095,3096,3097,3098,3099,3100,3101,3102,3103,3104,3105,3106,3107,3108,3109,3110,3111,3112,
3113,3114,3115,3116,3117,3118,3119,3120,3121,3128,3129,3130,3131,3132,3133,3134,4252,4253,
4254,4255,4256,4257,4258,4259,4260,4261,4262,4263,4264,4265,4266,4267,4268,4269,4270,4271,
4272,4273,4274,4275,4276,4277,4278,4279,4280,4281,4282,4283,4284,4285,4286,4287,4288,4289,
4290,4291,4292,4293,4294,4295,4296,4297,4298,4299,4300,4301,4302,4303,4304,4305,4306,4307,
4308,4309,4310,4311,4312,4313,4314,4315,4316,4317,4318,4319,4320,4321,4322,4323,4324,4325,
4326,4327,5522,5523,5524,5525,5526,5527,5528,5529,5530,5531,5532,5533,5534,5535,5536,5537,
5538,5540,5541,5542,5565,5566,5567,5568,5625,5626,5627,5628,5629,5630,5666,5667,5668,5688,
5689,5690,5727,5728,5729,5762,5765,5766,5767,5931,5932,5933,5934,5935,5936,5965,6022,6082,
6083,6084,6303,6304,6305,6307,6308,6309,6310,6313,6314,6315,6317,6318,6319,6321,6322,6323,
6325,6326,6327,6328,6329,6330,6333,6334,6335,6337,6338,6339,6341,6342,6343,6345,6346,6347,
6349,6350,6351,6355,6365,6366,6367,6520,6521,6522,6560,7092,7093,7094,7256,7257,7258,7283,
7284,7285,7317,7318,7319,7321,7322,7323,7325,7326,7328,7329,7331,7332,7333,7335,7336,7337,
7339,7340,7341,7345,7346,7347,7623,7624,7625,7626,7627,7629,7630,7631,7638,7639,7640,7741,
7742,7743,7848,7849,7908,7927,7928,7929,7931,7970,7971,8272}

-- This array contains all destroyable field items
FIELDS = {1487,1488,1489,1490,1491,1492,1493,1494,1495,1496,1500,1501,1502,1503,1504}

function Player:conjureItem(reagentId, conjureId, conjureCount, effect)
    if not conjureCount and conjureId ~= 0 then
        local itemType = ItemType(conjureId)
        if itemType:getId() == 0 then
            return false
        end

        local charges = itemType:getCharges()
        if charges ~= 0 then
            conjureCount = charges
        end
    end

    local conjureItem = self:getItemById(reagentId, true, -1)
    if reagentId ~= 0 and not conjureItem then
        self:sendCancelMessage(RETURNVALUE_YOUNEEDAMAGICITEMTOCASTSPELL)
        self:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    elseif reagentId ~= 0 and conjureItem then
        self:getItemById(reagentId, true, -1):transform(conjureId, conjureCount)
    else
        local item = self:addItem(conjureId, conjureCount)
        if not item then
            self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
            self:getPosition():sendMagicEffect(CONST_ME_POFF)
            return false
        end
    end

    if item:hasAttribute(ITEM_ATTRIBUTE_DURATION) then
        item:decay()
    end

    conjureItem:remove(1)
    self:getPosition():sendMagicEffect(item:getType():isRune() and CONST_ME_MAGIC_RED or effect)
    return true
end

Lua:
function Player:conjureItem(reagentId, conjureId, conjureCount, effect)
  -- Ensures conjureCount
  if not conjureCount and conjureId ~= 0 then
    local itemType = ItemType(conjureId)
    if itemType:getId() == 0 then
      return false
    end

    local charges = itemType:getCharges()
    if charges ~= 0 then
      conjureCount = charges
    end
  end

  local conjureItem

  -- A reagent id is needed
  if reagentId ~= 0 then
    conjureItem = self:getItemById(reagentId, true, -1)

    -- Needed reagent item not found
    if not conjureItem then
      self:sendCancelMessage(RETURNVALUE_YOUNEEDAMAGICITEMTOCASTSPELL)
      self:getPosition():sendMagicEffect(CONST_ME_POFF)
      return false
    end

    -- Transform
    conjureItem = conjureItem:transform(conjureId, conjureCount)

  -- A reagent id is not needed
  else
    -- Add item
    conjureItem = self:addItem(conjureId, conjureCount)
  end

  -- Could not transform/add conjure item
  if not conjureItem then
    self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
    self:getPosition():sendMagicEffect(CONST_ME_POFF)
    return false
  end

  -- If has duration attribute, start decaying
  if conjureItem:hasAttribute(ITEM_ATTRIBUTE_DURATION) then
    conjureItem:decay()
  end

  -- Send magic effect

  effect = conjureItem:getType():isRune() and CONST_ME_MAGIC_RED or effect
  if effect then
    self:getPosition():sendMagicEffect(effect)
  end

  return true
end
 
OP
OP
Manigold

Manigold

Active Member
Joined
Nov 2, 2017
Messages
172
Solutions
8
Reaction score
32
Yeah definitely not passing an effect value.
I don't know how LUA handles not being passed expected values, but you could try changing it to

Lua:
function onCastSpell(creature, variant)
    return creature:conjureItem(0, 2260, 1, CONST_ME_MAGIC_GREEN)
end
Same error in line 281.
Lua:
function Player:conjureItem(reagentId, conjureId, conjureCount, effect)
  -- Ensures conjureCount
  if not conjureCount and conjureId ~= 0 then
    local itemType = ItemType(conjureId)
    if itemType:getId() == 0 then
      return false
    end

    local charges = itemType:getCharges()
    if charges ~= 0 then
      conjureCount = charges
    end
  end

  local conjureItem

  -- A reagent id is needed
  if reagentId ~= 0 then
    conjureItem = self:getItemById(reagentId, true, -1)

    -- Needed reagent item not found
    if not conjureItem then
      self:sendCancelMessage(RETURNVALUE_YOUNEEDAMAGICITEMTOCASTSPELL)
      self:getPosition():sendMagicEffect(CONST_ME_POFF)
      return false
    end

    -- Transform
    conjureItem = conjureItem:transform(conjureId, conjureCount)

  -- A reagent id is not needed
  else
    -- Add item
    conjureItem = self:addItem(conjureId, conjureCount)
  end

  -- Could not transform/add conjure item
  if not conjureItem then
    self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
    self:getPosition():sendMagicEffect(CONST_ME_POFF)
    return false
  end

  -- If has duration attribute, start decaying
  if conjureItem:hasAttribute(ITEM_ATTRIBUTE_DURATION) then
    conjureItem:decay()
  end

  -- Send magic effect

  effect = conjureItem:getType():isRune() and CONST_ME_MAGIC_RED or effect
  if effect then
    self:getPosition():sendMagicEffect(effect)
  end

  return true
end
With this code the items are conjured with the magic effect ,but another error occurs:

boolean value.png
 

River KA

Veteran OT User
Joined
Feb 1, 2010
Messages
512
Solutions
26
Reaction score
310
Same error in line 281.

With this code the items are conjured with the magic effect ,but another error occurs:

View attachment 67417

Send me your Discord through PM. Here it works, don't know why it is not working for you.

---

Edit: Upgrade it to handle with stackable runes.

Lua:
function Player:conjureItem(reagentId, conjureId, conjureCount, effect)
  -- Ensures conjureCount
  if not conjureCount and conjureId ~= 0 then
    local itemType = ItemType(conjureId)
    if itemType:getId() == 0 then
      return false
    end

    local charges = itemType:getCharges()
    if charges ~= 0 then
      conjureCount = charges
    end
  end

  local conjureItem

  -- A reagent id is needed
  if reagentId ~= 0 then
    conjureItem = self:getItemById(reagentId, true, -1)

    -- Needed reagent item not found
    if not conjureItem then
      self:sendCancelMessage(RETURNVALUE_YOUNEEDAMAGICITEMTOCASTSPELL)
      self:getPosition():sendMagicEffect(CONST_ME_POFF)
      return false
    end

    local itemParent = conjureItem:getParent()

    -- Parent not found; or parent is not player and not item; or cannot remove reagent item
    if not itemParent or (not itemParent:isPlayer() and not itemParent:isItem()) or not conjureItem:remove(1) then
      self:sendCancelMessage(RETURNVALUE_YOUNEEDAMAGICITEMTOCASTSPELL)
      self:getPosition():sendMagicEffect(CONST_ME_POFF)
      return false
    end

    -- itemParent is player, then try add to player
    if itemParent:isPlayer() then
      conjureItem = self:addItem(conjureId, conjureCount)

    -- itemParent is container item
    else
      -- Have available space within, then try add to this container
      if itemParent:getCapacity() - itemParent:getSize() > 0 then
        conjureItem = itemParent:addItem(conjureId, conjureCount)

      -- Have no space within, then try add to player
      else
        conjureItem = self:addItem(conjureId, conjureCount)
      end
    end

  -- A reagent id is not needed
  else
    -- Add item
    conjureItem = self:addItem(conjureId, conjureCount)
  end

  -- Could not transform/add conjure item
  if not conjureItem then
    self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
    self:getPosition():sendMagicEffect(CONST_ME_POFF)
    return false
  end

  -- If has duration attribute, start decaying
  if conjureItem:hasAttribute(ITEM_ATTRIBUTE_DURATION) then
    conjureItem:decay()
  end

  -- Send magic effect

  effect = conjureItem:getType():isRune() and CONST_ME_MAGIC_RED or effect
  if effect then
    self:getPosition():sendMagicEffect(effect)
  end

  return true
end

@Manigold
 
Last edited:
Solution
OP
OP
Manigold

Manigold

Active Member
Joined
Nov 2, 2017
Messages
172
Solutions
8
Reaction score
32
Send me your Discord through PM. Here it works, don't know why it is not working for you.

---

Edit: Upgrade it to handle with stackable runes.

Lua:
function Player:conjureItem(reagentId, conjureId, conjureCount, effect)
  -- Ensures conjureCount
  if not conjureCount and conjureId ~= 0 then
    local itemType = ItemType(conjureId)
    if itemType:getId() == 0 then
      return false
    end

    local charges = itemType:getCharges()
    if charges ~= 0 then
      conjureCount = charges
    end
  end

  local conjureItem

  -- A reagent id is needed
  if reagentId ~= 0 then
    conjureItem = self:getItemById(reagentId, true, -1)

    -- Needed reagent item not found
    if not conjureItem then
      self:sendCancelMessage(RETURNVALUE_YOUNEEDAMAGICITEMTOCASTSPELL)
      self:getPosition():sendMagicEffect(CONST_ME_POFF)
      return false
    end

    local itemParent = conjureItem:getParent()

    -- Parent not found; or parent is not player and not item; or cannot remove reagent item
    if not itemParent or (not itemParent:isPlayer() and not itemParent:isItem()) or not conjureItem:remove(1) then
      self:sendCancelMessage(RETURNVALUE_YOUNEEDAMAGICITEMTOCASTSPELL)
      self:getPosition():sendMagicEffect(CONST_ME_POFF)
      return false
    end

    -- itemParent is player, then try add to player
    if itemParent:isPlayer() then
      conjureItem = self:addItem(conjureId, conjureCount)

    -- itemParent is container item
    else
      -- Have available space within, then try add to this container
      if itemParent:getCapacity() - itemParent:getSize() > 0 then
        conjureItem = itemParent:addItem(conjureId, conjureCount)

      -- Have no space within, then try add to player
      else
        conjureItem = self:addItem(conjureId, conjureCount)
      end
    end

  -- A reagent id is not needed
  else
    -- Add item
    conjureItem = self:addItem(conjureId, conjureCount)
  end

  -- Could not transform/add conjure item
  if not conjureItem then
    self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
    self:getPosition():sendMagicEffect(CONST_ME_POFF)
    return false
  end

  -- If has duration attribute, start decaying
  if conjureItem:hasAttribute(ITEM_ATTRIBUTE_DURATION) then
    conjureItem:decay()
  end

  -- Send magic effect

  effect = conjureItem:getType():isRune() and CONST_ME_MAGIC_RED or effect
  if effect then
    self:getPosition():sendMagicEffect(effect)
  end

  return true
end

@Manigold
Thank you very much , works like a charm, you are the best.
 
Top