Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

How to get Player's Name?

Featured Replies

I am trying to retrieve my player's name and print it to the screen. Why doesn't this work? I try to start the script and nothing happens.

 

import java.awt.Graphics2D;

import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(author = "Death", info = "", logo = "", name = "GetPlayerName", version = 0)
public class GetPlayerName extends Script {

	String myName = myPlayer().getName();
	
	@Override
	public int onLoop() throws InterruptedException {
		
		return random(400,800);
	}
	
	@Override
	public void onPaint(Graphics2D g) {
		g.drawString("My Name: " + myName, 11, 280);
	}
	

}

 

  • Author

Figured it out. myPlayer() can only be called from one of the overriden methods. Assuming that's the case for all methods inherited from MethodProvider? When do the objects from MethodProvider get created? During onStart()?

46 minutes ago, Deathiminent said:

Figured it out. myPlayer() can only be called from one of the overriden methods. Assuming that's the case for all methods inherited from MethodProvider? When do the objects from MethodProvider get created? During onStart()?

Any calls to MethodProvider need to happen in or after onStart(). Also, your player will need to be logged in to retrieve myPlayer() if I'm not mistaken.

 

Edit: This thread belongs in Script Help. Please make it there next time :)

Edited by Imateamcape

10 hours ago, Alek said:

You seemed to find out the random method pretty quickly.

Well duh, he would get banned in 10 seconds without it!

I'm going to spoon feed you, but teach you.

 

g.drawString("My Name: " + myName, 11, 280); // This is your code

 

 

g.drawString("My Name: " + myPlayer().getName(), 11, 280); // This is my code

 

myPlayer() is a call to a method that returns an object of the Player type. It's method signature looks like public Player myPlayer() { return thisObject; } 

You now have a reference to your player object, which contains methods and variables.

Using dot notation, you call a method defined in the Player class. 

getName() is a call to a String returning method in the Player class.. public String getName() { return nameVariable; } 

 

To experiment with the methods, go to the osbot api, and find the Player class, and check out the methods you can use. You can then call those methods like this -> myPlayer().methodName()

** Note methods may or may not require parameters.

 

Anyways this was more than enough help, please give me a thanks if you found this helpful! - Doflamingo

Edited by Doflamingo

55 minutes ago, Doflamingo said:

I'm going to spoon feed you, but teach you.

 


g.drawString("My Name: " + myName, 11, 280); // This is your code

 

 


g.drawString("My Name: " + myPlayer().getName(), 11, 280); // This is my code

 

myPlayer() is a call to a method that returns an object of the Player type. It's method signature looks like public Player myPlayer() { return thisObject; } 

You now have a reference to your player object, which contains methods and variables.

Using dot notation, you call a method defined in the Player class. 

getName() is a call to a String returning method in the Player class.. public String getName() { return nameVariable; } 

 

To experiment with the methods, go to the osbot api, and find the Player class, and check out the methods you can use. You can then call those methods like this -> myPlayer().methodName()

** Note methods may or may not require parameters.

 

Anyways this was more than enough help, please give me a thanks if you found this helpful! - Doflamingo

 

I don't see how any of that was relevant to OP's original question, and his question was already answered correctly 3 days ago.

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.