Jump to content

How to check item???


bookkc

Recommended Posts

I Try to do this,
 

 
function OnCastSpell(event, player, item, bag, slot)
	if (Player:EquipItem(34470, 12)) then
	print "Has Item"
	end
end

RegisterPlayerEvent(29, OnCastSpell)

but have error
 

 
2018-04-11 09:33:56 ERROR Eluna: lua_scripts/aaa.lua:3: calling 'EquipItem' on bad self (bad argument : Player expected, got table)


Whats wrong???

Link to comment
Share on other sites

so, i do this, but..

local itemid = 34470
local function Timed(event, player, item, bag, slot)
    if(item:IsEquipped(itemid)) then
    print "Has Item"
    else
    print "NO Has Item"
    end
end


function OnCastSpell(event, player, item, bag, slot)
    player:RegisterEvent(Timed, 1000, 5)
end

RegisterPlayerEvent(29, OnCastSpell)

2018-04-11 11:10:05 ERROR Eluna: lua_scripts/aaa.lua:2: attempt to index local 'item' (a number value)
2018-04-11 11:10:06 ERROR Eluna: lua_scripts/aaa.lua:2: attempt to index local 'item' (a number value)
2018-04-11 11:10:07 ERROR Eluna: lua_scripts/aaa.lua:2: attempt to index local 'item' (a number value)
2018-04-11 11:10:08 ERROR Eluna: lua_scripts/aaa.lua:2: attempt to index local 'item' (a number value)
2018-04-11 11:10:09 ERROR Eluna: lua_scripts/aaa.lua:2: attempt to index local 'item' (a number value)

Link to comment
Share on other sites

1 hour ago, bookkc said:

I Try to do this,


function OnCastSpell(event, player, item, bag, slot)
    if (Player:EquipItem(34470, 12)) then
        print "Has Item"
    end
end

RegisterPlayerEvent(29, OnCastSpell)

but have error
2018-04-11 09:33:56 ERROR Eluna: lua_scripts/aaa.lua:3: calling 'EquipItem' on bad self (bad argument : Player expected, got table)

Whats wrong???

2

First you use player and then you use Player. They should be exactly the same (lowercase). So you are using wrong variables.

 

 

30 minutes ago, bookkc said:

so, i do this, but..


local itemid = 34470
local function Timed(event, player, item, bag, slot)
    if(item:IsEquipped(itemid)) then
        print "Has Item"
    else
        print "NO Has Item"
    end
end


function OnCastSpell(event, player, item, bag, slot)
    player:RegisterEvent(Timed, 1000, 5)
end

RegisterPlayerEvent(29, OnCastSpell)

2018-04-11 11:10:05 ERROR Eluna: lua_scripts/aaa.lua:2: attempt to index local 'item' (a number value)
2018-04-11 11:10:06 ERROR Eluna: lua_scripts/aaa.lua:2: attempt to index local 'item' (a number value)
2018-04-11 11:10:07 ERROR Eluna: lua_scripts/aaa.lua:2: attempt to index local 'item' (a number value)
2018-04-11 11:10:08 ERROR Eluna: lua_scripts/aaa.lua:2: attempt to index local 'item' (a number value)
2018-04-11 11:10:09 ERROR Eluna: lua_scripts/aaa.lua:2: attempt to index local 'item' (a number value)

 

As you can see from here: http://www.elunaengine.com/WorldObject/RegisterEvent.html
The parameters in your Timed function are wrong. You have named repeats as item

To access the item in a timed event you need to do something like this:
 

local itemid = 34470

local function Timed(player, itemguid)
    local item = player:GetItemByGUID(itemguid)
    if item and item:IsEquipped(itemid) then
        print "Has item and it is equipped"
    else
        print "Has no item or it is not equipped"
    end
end

local function OnCastSpell(event, player, item, bag, slot)
    local itemguid = item:GetGUID()
    -- We create a function that calls Timed with the player from the timed function and the item guid
    -- The item cannot be directly passed because it could have been deleted before Timed function is called.
    -- The player we get from the parameters passed to the timed function so it must be valid.
    local function Dummy(_,_,_,plr)
        Timed(plr, itemguid)
    end
    player:RegisterEvent(Dummy, 1000, 5)
end

RegisterPlayerEvent(29, OnCastSpell)

 

Link to comment
Share on other sites

i try to make this

 

function CheckOnEquipped(event, player, item, bag, slot)
local entry = item:GetEntry(34470)
    if(player:EquipItem(entry, 12)) then
        print "Has Item"
    else
        print "NO Has Item"
    end
  
end
RegisterPlayerEvent(29, CheckOnEquipped)

 

Link to comment
Share on other sites

Try this:

function CheckOnEquipped(event, player, item, bag, slot)
  local entry = item:GetEntry()
  if entry == 34470 and player:EquipItem(34470, 12) then
  	print "Has Item"
  else
  	print "NO Has Item"
  end
end
RegisterPlayerEvent(29, CheckOnEquipped)

 

Link to comment
Share on other sites

3 minutes ago, bookkc said:

no... its not work... i has 

 


print "NO Has Item"

if  34470 item in 12 slot

Can you explain what it is exactly that you try to do?
It seems the code does not match what you try to do, so trying to fix it in some way will not result in what you want.

The EquipItem function does not check if an item is equipped. It tries to equip an item. So of course if you have an item in slot 12 it will fail causing "No Has Item" to be printed.
If you were looking for a function to get an item from a specific slot, then use http://www.elunaengine.com/Player/GetItemByPos.html

For any further help, I request that you explain what it is that you try to do.

Link to comment
Share on other sites

function CheckOnEquipped(event, player, item, bag, slot)
  local entry = item:GetEntry()
  if (player:GetItemByPos(255, 12) == 34470) then
      print "Has Item"
  else
      print "NO Has Item"
  end
end
RegisterPlayerEvent(29, CheckOnEquipped)

this, not work too(

Link to comment
Share on other sites

local item = player:GetItemByPos(255, 12) -- get item equipped in slot 12
if item and item:GetEntry() == 34470 then -- if item exists and the entry of it is 34470
	print "Has Item"
else
	print "NO Has Item"
end

"i need to check item 34470 in slot 12 its Trinket"

This code does exactly that.
The main reason the code you posted above does not work is that GetItemByPos does not return a number, so it will never equal to 34470.
As you can see in this code I use GetEntry to get the entry number and then compare that to the expected number.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use