Jump to content

How to get Player's Name?


Deathimminent

Recommended Posts

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);
	}
	

}

 

Link to comment
Share on other sites

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

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

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.

  • Like 3
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...