Jump to content

How to properly trade with players?


boxo

Recommended Posts

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
Link to comment
Share on other sites

 

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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