boxo Posted May 27, 2018 Share Posted May 27, 2018 (edited) 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, 2018 by boxo Quote Link to comment Share on other sites More sharing options...
d0zza Posted May 27, 2018 Share Posted May 27, 2018 Are you checking if the player is not null? Quote Link to comment Share on other sites More sharing options...
Team Cape Posted May 27, 2018 Share Posted May 27, 2018 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. Quote Link to comment Share on other sites More sharing options...
boxo Posted May 27, 2018 Author Share Posted May 27, 2018 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. Quote Link to comment Share on other sites More sharing options...
Hel Posted May 27, 2018 Share Posted May 27, 2018 I've always just written player.interact("Trade with") and never had an issue Quote Link to comment Share on other sites More sharing options...
d0zza Posted May 27, 2018 Share Posted May 27, 2018 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. Quote Link to comment Share on other sites More sharing options...
boxo Posted May 27, 2018 Author Share Posted May 27, 2018 (edited) 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, 2018 by boxo Quote Link to comment Share on other sites More sharing options...
d0zza Posted May 27, 2018 Share Posted May 27, 2018 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 Quote Link to comment Share on other sites More sharing options...