Jump to content

How to properly trade with players?


Recommended Posts

Posted (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 by boxo
Posted

 

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.

Posted (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 by boxo
Posted
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

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...