Jump to content

Social environment snippet


Botre

Recommended Posts

Social environment snippet

 

Could potentially reduce bans caused by player reports.

 

If you have any other ideas / methods I'll gladly write them in if they are worth it.

 

Cheers!

public class SocialEnvironment {

	/**
	 * @author Botrepreneur 
	 * @Version: 00.14
	 */
	
	public static int getNumberOfOtherPlayers(Script script) {
		return script.getPlayers().getAll().size() - 1;
	}
	
	public static boolean isMyPlayerAlone(Script script) {
		return getNumberOfOtherPlayers(script) == 0;
	}

	public static boolean didSomeoneTalk(Message message) {
		return message != null && message.getType().equals(Message.MessageType.PLAYER);
	}
	
	public static boolean isPlayerInteractingWithMe(Script script, Player player) {
		return player!= null && player.exists() && player.getInteracting() != null && player.getInteracting().getName().equals(script.myPlayer().getName());
	}
	
	public static boolean isSomePlayerInteractingWithMe(Script script) {
		if (!isMyPlayerAlone(script)) {
			List<Player> players = script.getPlayers().getAll();
			for (Player player : players) {
				if (isPlayerInteractingWithMe(script, player)) {
					return true;
				}
			}
			
		}
		return false;
	}
	
	public static boolean isSomePlayerInteractingWithMe(Script script, int radius) {
		if (!isMyPlayerAlone(script)) {
			List<Player> players = script.getPlayers().getAll();
			for (Player player : players) {
				if (script.map.distance(player) <= radius && isPlayerInteractingWithMe(script, player)) {
					return true;
				}
			}
			
		}
		return false;
	}
	
	public static boolean isTradeRequested(Message message) {
		return message != null && message.getType().equals(Message.MessageType.RECEIVE_TRADE);
	}
	
	public static boolean doesModExist(Script script) {
		if (!isMyPlayerAlone(script)) {
			for (Player p : script.getPlayers().getAll()) {
				if (p.getName().toLowerCase().startsWith("mod ")) {
					return true;
				}
			}
		}
		return false;
	}

}
Edited by Botrepreneur
Link to comment
Share on other sites

public static boolean isMyPlayerAlone(Script script) {
        return script.getPlayers().getAll().size() > 1;

    }
 

Is checking if your player isn't alone.

 

Iterating through every local player to see if one is interacting with you is overkill. Why not search in a certain radius?

I think there a method that creates an area around an entity. You could use that, and loop through everybody in the area to see if they are interacting with you.

Also it should be smaller or equal to one

Link to comment
Share on other sites

public static boolean isMyPlayerAlone(Script script) {
        return script.getPlayers().getAll().size() > 1;

    }

Is checking if your player isn't alone.

 

Iterating through every local player to see if one is interacting with you is overkill. Why not search in a certain radius?

 

 

Fixed, thanks.

To check whether or not a player is in a certain radius you'd still have to iterate through all players, I added a second method that accepts a radius argument though, but I'm not sure checking for distance is less expensive than checking for interaction.

I might just add a method that accepts a custom filter (so you could filter for room, distance, combat level and anything else you can think off)

 

I think there a method that creates an area around an entity. You could use that, and loop through everybody in the area to see if they are interacting with you.

 

You'd still have to iterate through all entities to check if they are in that area. Do you think this would be less expensive?

 

 

Thanks for the replies biggrin.png

Edited by Botrepreneur
Link to comment
Share on other sites

Fixed, thanks.

To check whether or not a player is in a certain radius you'd still have to iterate through all players, I added a second method that accepts a radius argument though, but I'm not sure checking for distance is less expensive than checking for interaction.

I might just add a method that accepts a custom filter (so you could filter for room, distance, combat level and anything else you can think off)

 

 

You'd still have to iterate through all entities to check if they are in that area. Do you think this would be less expensive?

 

 

Thanks for the replies biggrin.png

its better because even though you iterating through all players. You not consistently checking to see if that player is interacting with you especially with people that are like 10 tiles away. Also i was talking about this method

		script.myPlayer().getArea(radius);

Edited by josedpay
Link to comment
Share on other sites

 

its better because even though you iterating through all players. You not consistently checking to see if that player is interacting with you especially with people that are like 10 tiles away. Also i was talking about this method

		script.myPlayer().getArea(radius);

 

But you would still need to check constantly if they are in the radius considering they could move, I'll do some performance tests ^^

 

Get monster position

Check if generated area contains that position

If check returns positive then check for interaction

 

versus

 

Check for interaction

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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