Author Topic: How to display the item name in a player's slot?  (Read 2111 times)

/title

I'd like to know how to display the item's name in a certain player's slot. For example, if I could change it to display someone's item in a slot, like the first or second.

%client.player.tool[%a].uiName
« Last Edit: March 09, 2015, 06:25:37 PM by Aoki¹ »

%client.player.tool[%b].uiName
not much of a coder, but how do I change it to display another slot name?

not much of a coder, but how do I change it to display another slot name?
%b is the slot

%client.player.tool[4] = .........

%b is the slot

%client.player.tool[4] = .........
thanks!

thanks!
Also keep in mind that the index is 0-based, which means that 0 is the first slot, 1 is the second, 2 is the third, etc.

Another question:

How can I make it display it in an announcement? Here's what I tried:
Code: [Select]
announce("%1's items were: \c3 "@ %client.player.tool[0].uiName @" | \c3 "@ %client.player.tool[1].uiName() @" | \c3 "@ %client.player.tool[2].uiName() @" | \c3 "@ %client.player.tool[3].uiName() @");

Another question:

How can I make it display it in an announcement? Here's what I tried:
Code: [Select]
announce("%1's items were: \c3 "@ %client.player.tool[0].uiName @" | \c3 "@ %client.player.tool[1].uiName() @" | \c3 "@ %client.player.tool[2].uiName() @" | \c3 "@ %client.player.tool[3].uiName() @");
you're using uiName as a function but it's a variable; lose the () on uiName
« Last Edit: March 09, 2015, 06:26:12 PM by Aoki¹ »

%client.player.tool[%a].getID().uiName works better
Why would this work better? It gives you the same result.

Why would this work better? It gives you the same result.
clearly i was mistaken then; sorry about that

You should be making sure that %client.player exists, and that %client.player.tool[%x] exists, before doing anything with it.

if(isObject(%player = %client.player) && isObject(%tool = %player.tool[%x])) {
//announce code using %tool.uiName
}


Assigning the variables as you check them is a good way to save a bit of processing time (instead of accessing %client.player multiple times), and it keeps it in one line, and it works in an if statement, however it can be harder to follow for newer coders. Still, its very convenient.
« Last Edit: March 10, 2015, 11:40:14 AM by boodals 2 »

If you're going to worry about processing time like that, note that there's literally no reason to check %client.player as well in that case.

if (%tool = %client.player.tool[%i]) {
    ...
}

Okay, me and port just talked a bit on steam, you can do that in this case, but if you are using a method to get the second object (in this case the tool), you should use a seperate condition (as in my post), else it will throw a missing function error.

eg
isObject(%player = %client.player) is fine.
isObject(%tool = %client.player.tool[%x]) is fine.
isObject(%tool = %client.player.getTool(%x)) is not fine (assuming Player::getTool(%x) is defined), as if %client.player does not exist, then it will attempt to call 0.getTool(%x) (or similar), which will throw an error.
isObject(%player = %client.player) && isObject(%tool = %player.getTool(%x)) is the correct way to do it.

You could also remove the isObject calls if you know the function will return 0 or an empty string if the object does not exist. However, its much easier to read, more reliable, and closer to how its done in other languages, if you use isObject(%b = %a.b) && isObject(%c = %b.c)

If you're going to worry about processing time like that, note that there's literally no reason to check %client.player as well in that case.

if (%tool = %client.player.tool[%i]) {
    ...
}

May not want to cut out the isObject. If some add-on decides to clear the tool by setting the slot to -1 it'll mess up.

I don't think he cares anymore. I made the add-on for him.