May 27, 20187 yr I had previously tried to use the code below but it kept giving me null pointer exception. getPlayers().closest("Name").interact("Trade with"); I did find this to work, however the index does change with a logout, and I'm not sure of how to update the index upon player login. getPlayers().getLocalPlayer(325).interact("Trade with"); Edited May 27, 20187 yr by boxo
May 27, 20187 yr 43 minutes ago, d0zza said: Are you checking if the player is not null? ^ this. if the player is not around, closest() will return null, and because you're calling a method on that null, you'll get an NPE.
May 27, 20187 yr Author I did not perform a null check to see if the player i want to trade is around, however the player I wanted to trade with was in the same exact bank I was in.
May 27, 20187 yr 11 minutes ago, Slut said: I've always just written player.interact("Trade with") and never had an issue He's doing the same thing, just not storing the player he wants to interact with. 15 minutes ago, boxo said: I did not perform a null check to see if the player i want to trade is around, however the player I wanted to trade with was in the same exact bank I was in. Perform the null check anyway because I'm 99.9% sure that's the issue. If it still happens let me know.
May 27, 20187 yr Author So I tested the following code with a different name than the one I was using originally, which I obviously made sure was spelt correctly about 10 different times, and it worked.... for future reference my account name was something similar to "big slap head". With one space after the first and second word, I'm not sure why it wasn't properly working with an account name that had two spaces like mine but it was working on other accounts. Thanks for the help. if (getPlayers().closest("name")!=null) { getPlayers().closest("name").interact("Trade with"); } Edited May 27, 20187 yr by boxo
May 27, 20187 yr 48 minutes ago, boxo said: So I tested the following code with a different name than the one I was using originally, which I obviously made sure was spelt correctly about 10 different times, and it worked.... for future reference my account name was something similar to "big slap head". With one space after the first and second word, I'm not sure why it wasn't properly working with an account name that had two spaces like mine but it was working on other accounts. Thanks for the help. if (getPlayers().closest("name")!=null) { getPlayers().closest("name").interact("Trade with"); } For accounts with spaces in their names you'll need to replace the space character with another character, see the second post in this thread
Create an account or sign in to comment