Hey, hi, hello.

Spoiler for Orignal post:
For those of you who are interested:
Spoiler for My Story:

I first started playing around with private servers back in 2009/2010, I never really learnt much except a few things about variables and conditional statements.
Every two or 3 years, i stumble across some private server and all the feelings rush back and before I know it, I've downloaded eclipse again and I'm digging through some random ass server I leached from the download section..
Just to fill it with a bunch of tuts from the snippet section before giving up at some kind of brick wall that I run into..
Never really learning much in the process.

My final nail in the coffin for me and private servers were about 3 years ago (or so I thought..) when I found Unity.
Boy did I fall in love, after months of experimenting with unity and C# I was actually learning a few things and getting a grasp on gaming concepts.
Looking through Unity tutorials on YouTube I stumbled across a unreal engine tutorial and decided to stick it out.
Before the video was finished, I already had unreal engine downloaded and was playing around with an example template..

After using Unreal's visual scripting "Blueprints" I gained a tight grasp on all the fundamentals of unreal engine even basic usage of programming features such as; arrays, all types of variables, enums, different classes, connecting them all together and much more.
So I began to look into the C++ side of it, another Six months later I would say I've tuned my programming skills a bit, (too the point where I'm actually making C++ code plugins to sell on the official unreal engine marketplace) but I'm far from amazing because I still lack a lot of basic knowledge.
Especially when its a networked game, with the power of unreal engine if your making a single player game, things can pretty much be "sellotaped" and "blue tacked" together, as long as the user experiences a smooth experience.

With this whole covid-19 shit I've got a lot of time on my hands and decided to dive back into rsps and just have a little play around while I'm burnt out from making my current zombie survival based project for steam.


It's been a while since I've played around with java or rsps's so I'm a little bit rusty here.
I'm using anguish as a base, I like the whole teleport tab idea. But I didn't like the fact the you could use it anywhere at anytime for free.
So I decided to change that.

I stumbled across the "Config.java" file and found it's just basically a list of variables grouped together so It's easy to quickly change values without digging around and changing things too much, Happy days I wanted to add individual prices for each teleport that could possibly change in the future.
So this file would be great!

For testing purposes I thought I'd start with the one teleport first, get everything working and copy pasta to each one after.

so in config I added this variable:

Spoiler for config var:
Code:
public static final int ANCIENT_CAVERN = 5000;


I found the button id and traced it back to the file "TeleportTabTeleHandler.java"
In which I found that it teleport's dependant on the tabs selected:

Spoiler for Button ID:
Code:
case 185248://2
				//player.sendMessage("teletabsel "  + player.teleTabSelected);
				if (!teleportCheck(player))
					return;
				if (player.teleTabSelected == 0) { // Monsters
					player.getPA().startTeleport(3011, 3151, 0, "modern", false);
				} else if (player.teleTabSelected == 1) { // Minigames
					player.getPA().startTeleport(3365, 3266, 0, "modern", false);
				} else if (player.teleTabSelected == 2) { // Skilling
					player.getPA().startTeleport(2933, 3290, 0, "modern", false);
				} else if (player.teleTabSelected == 3) { // Bosses
					player.getPA().startTeleport(2968, 4383, 2, "modern", false);
				} else if (player.teleTabSelected == 4) { // Wilderness
					player.getPA().startTeleport(2539, 4716, 0, "modern", false);
				} else if (player.teleTabSelected == 5) { // Cities
					player.getPA().startTeleport(2662, 3306, 0, "modern", false);
				}
				break;


Okay, easy enough.
So to simply charge you for the teleport I found you can get your inventory (which I assume is an array) and then check If it has an Item using playerHasItem();
If that then returns true I can execute the teleport as normal and remove the coins with deleteItem();, if not return a message like this:

Spoiler for Charge for teleport:
Code:
if (c.getItems().playerHasItem(995, Config.ANCIENT_CAVERN))
{
	player.getPA().startTeleport(3565, 3316, 0, "modern", false); // change
	c.getItems().deleteItem(995, 1000);
	player.sendMessage("You paid @[email protected] + Config.ANCIENT_CAVERN+ @[email protected] for the teleport!");
}
else
{
	player.sendMessage("You Don't have enough @[email protected]@[email protected] for this teleport!");
}


Right, so everything's working as intended.
Now, I was thinking well, you don't want to charge staff right? what if they need to get somewhere quick don't have any P on them? Well, that's easy lewis.
Just make it so staff can use it for free!

So back digging I go, and find out the rights system is made using a enum, while digging I also found out that I can get my rights by using getRights(), Awesome!

That means I can do something like this to make it free for staff:

Spoiler for free for staff:
Code:
					if (player.getRights().getPrimary() == Right.OWNER)  
					{
						player.getPA().startTeleport(3565, 3316, 0, "modern", false); // change
						player.sendMessage("Your teleport was @[email protected]");
					}
					else
					{
						if (c.getItems().playerHasItem(995, 1000))
						{
							player.getPA().startTeleport(3565, 3316, 0, "modern", false); // change
							c.getItems().deleteItem(995, 1000);
							player.sendMessage("You paid @[email protected]@[email protected] for the teleport!");
						}
						else
						{
							player.sendMessage("You Don't have enough @[email protected]@[email protected] for this teleport!");
						}
					}


Everything works as intended, Go Lewis!
But now, If I want to add other ranks I could just do the old school way and use || and add a new argument like this:

Spoiler for Free for Multi-rights:
Code:
					if (player.getRights().getPrimary() == Right.OWNER || player.getRights().getPrimary() == Right.ADMIN || player.getRights().getPrimary() == Right.MOD)  
					{
						player.getPA().startTeleport(3565, 3316, 0, "modern", false); // change
						player.sendMessage("Your teleport was @[email protected]");
					}
					else
					{
						if (c.getItems().playerHasItem(995, 1000))
						{
							player.getPA().startTeleport(3565, 3316, 0, "modern", false); // change
							c.getItems().deleteItem(995, 1000);
							player.sendMessage("You paid @[email protected]@[email protected] for the teleport!");
						}
						else
						{
							player.sendMessage("You Don't have enough @[email protected]@[email protected] for this teleport!");
						}
					}


But once again, me being me.
I may wanna change it, and it'll be a pain in the ass to remove it from over 20 teleport's..

Back to the "Config.java" file we go!
I added in a set of enums that would be allowed to use the teleport's for free like this:

Spoiler for list of accepted rights:
Code:
Set<Rights> freetp = EnumSet.of(Right.OWNER, Right.ADMIN, Right.MOD, Right.SUPPORT, Right.SPONSORS


Great, Now I have a list of rights that would be accepted!
So naturally when want to check this list I'd have to run it through a loop like this:

Spoiler for for loop:
Code:
for (Rights i : Config.freetp)
{
	if(i != player.getRights().getPrimary())
	{
		if (c.getItems().playerHasItem(995, Config.ANCIENT_CAVERN))
		{
			player.getPA().startTeleport(1773, 5336, 0, "modern", true);
			c.getItems().deleteItem(995, 1000);
			player.sendMessage("You paid @[email protected]" + Config.ANCIENT_CAVERN + "@[email protected] for the teleport!");
			break;
		}
		else
		{
			player.sendMessage("You Don't have enough @[email protected]@[email protected] for this teleport!");
			break;
		}
}
else
{
	player.getPA().startTeleport(1773, 5336, 0, "modern", true);
	player.sendMessage("Your teleport was @[email protected]");
	break;
}


Once again, everything works as expected!

But here's the thing, every time a person clicks the teleport it's gunna run through that loop. on a single player game, which I'm used to making, that's not going to make much of an impact of computer resources if one person clicks it every now and again.
However from a multiplayer game such as a rsps, if you have say 100 players and 30 of them decided to teleport at the same time It could be a bit resource heavy i assume right?

So overall my question(s) is... Is this a bad way to handle it? Are there other ways? Am I overthinking it? Will It cause lagg on a hosted server?

Many thanks for taking the time to read this!


I was 100% overthinking it and found an even easier way to do it that doesn't invole a loop, Thanks anyway