May 6, 20196 yr Working on my first ever script, got it complete after about 24 hours but I'm stuck on the very last step which is to trade a player the items I've acquired. The `if` statement is failing every time, even when I'm less than 5 squares from the player. It's as if the player is invisible from the bot. This is what I'm doing: private boolean tradePlayer() { Player player = getPlayers().closest(PLAYER_NAME); if (player != null && player.interact("Trade with")) { Sleep.sleepUntil(() -> getTrade().isCurrentlyTrading(), 60000, random(100, 200)); getTrade().offerAll(ITEM_ID); getTrade().acceptTrade(); Sleep.sleepUntil(() -> getTrade().isSecondInterfaceOpen(), 60000, random(100, 200)); getTrade().acceptTrade(); Sleep.sleepUntil(() -> getTrade().didOtherAcceptTrade(), 60000, random(100, 200)); return true; } return false; } Any idea why this script function isn't trading the player? Edited May 6, 20196 yr by Lansana Camara
May 6, 20196 yr It works for me, have you remembered to click refresh on osbot? also try adding log() s to see where its getting to. also have you made sure the username is spelt correctly Edited May 6, 20196 yr by FuryShark
May 6, 20196 yr 1 hour ago, Lansana Camara said: Working on my first ever script, got it complete after about 24 hours but I'm stuck on the very last step which is to trade a player the items I've acquired. The `if` statement is failing every time, even when I'm less than 5 squares from the player. It's as if the player is invisible from the bot. This is what I'm doing: private boolean tradePlayer() { Player player = getPlayers().closest(PLAYER_NAME); if (player != null && player.interact("Trade with")) { Sleep.sleepUntil(() -> getTrade().isCurrentlyTrading(), 60000, random(100, 200)); getTrade().offerAll(ITEM_ID); getTrade().acceptTrade(); Sleep.sleepUntil(() -> getTrade().isSecondInterfaceOpen(), 60000, random(100, 200)); getTrade().acceptTrade(); Sleep.sleepUntil(() -> getTrade().didOtherAcceptTrade(), 60000, random(100, 200)); return true; } return false; } Any idea why this script function isn't trading the player? You should never check != null with anything else. Nest them. Player player = getPlayers().closest(PLAYER_NAME); if (player != null){ if(player.interact("Trade with")) { } }
May 6, 20196 yr Author 1 hour ago, Naked said: You should never check != null with anything else. Nest them. Player player = getPlayers().closest(PLAYER_NAME); if (player != null){ if(player.interact("Trade with")) { } } Why is this? I come from a GoLang/JavaScript/PHP background, and this is allowed in those C-based languages, so I wasn't aware one shouldn't do this in Java. By the way, not sure if that was a tip or a solution but it didn't fix the issue. Thanks, though.
May 6, 20196 yr 3 hours ago, Naked said: You should never check != null with anything else. Nest them. Player player = getPlayers().closest(PLAYER_NAME); if (player != null){ if(player.interact("Trade with")) { } } Why not? I don't see anything wrong with having them on the same line. -Apa @Lansana Camara Does the player name have a space in it? The names for players may include non-breaking spaces so you may need to account for this. Edited May 6, 20196 yr by Apaec
May 6, 20196 yr Author 5 hours ago, FuryShark said: It works for me, have you remembered to click refresh on osbot? also try adding log() s to see where its getting to. also have you made sure the username is spelt correctly Yeah it doesn't work, I tried all that. When I log, it seems that the code stops running at the point that I log because the log never appears in that function, but it appears in logic right before the function. So strange. I'm using the following to do my logs since `log()` doesn't log to the OSBot debugger: getBot().getLogger().debug("..."); Also, If it makes any difference, the characters aren't in a "normal" area. They are at a runecrafting altar...perhaps that somehow messes with the OSBot API's and makes it so that the characters can't be seen? Edited May 6, 20196 yr by Lansana Camara
May 6, 20196 yr Author 44 minutes ago, Apaec said: Why not? I don't see anything wrong with having them on the same line. -Apa @Lansana Camara Does the player name have a space in it? The names for players may include non-breaking spaces so you may need to account for this. Thanks! The issue was dealing with space. Fixed by converting white spaces to nonbreaking spaces.
March 20, 20214 yr On 5/6/2019 at 11:14 AM, Sana said: Thanks! The issue was dealing with space. Fixed by converting white spaces to nonbreaking spaces. May I asked how you did this?
March 20, 20214 yr 34 minutes ago, Psychotechno said: May I asked how you did this? I ran into a similar issue recently. If you have some names you want to compare to player names in-game, you need to replace any spaces in your names with non-breaking spaces like this: String friend = "slayerguy 117"; friend = friend.replace(' ', '\u00A0'); Now if you make a comparison to names pulled from api.players methods your Strings should properly match with the names returned by player.getName().
March 22, 20214 yr On 3/20/2021 at 10:46 PM, Delision said: I ran into a similar issue recently. If you have some names you want to compare to player names in-game, you need to replace any spaces in your names with non-breaking spaces like this: String friend = "slayerguy 117"; friend = friend.replace(' ', '\u00A0'); Now if you make a comparison to names pulled from api.players methods your Strings should properly match with the names returned by player.getName(). I thank you!
Create an account or sign in to comment