EasyPlayer

Custom Packages that plugins can require for common usages.
Mahi
Senior Member
Posts: 209
Joined: Wed Aug 29, 2012 8:39 pm
Location: Finland

EasyPlayer

Postby Mahi » Tue Jul 07, 2015 12:05 pm

EasyPlayer is an idea of a player class that automates all the player effects without having to worry about other people's plugins interfering with your plugin.
A good example of this are move types: Your plugin gives noclip to someone for 10 seconds (using player.move_type = MoveType.NOCLIP), but 1 second after gaining the noclip, someone else's plugin freezes the player (using player.move_type = MoveType.NONE), and thus removes your beautiful noclip!
What a horrible plugin you've created, only 1 second noclips :(

This was a huge issue when working on my Hero-Wars project, and EasyPlayer is my attempt to fix it. This package is free to use for everyone, as it would most likely be useful for many other plugins too.

EasyPlayer currently implements the following player effects:
  • Noclip
  • Fly
  • Freeze (movement)
  • Paralyze (movement and aim)
  • Burn
  • Godmode

It also implements a restriction system and allows objects to be instantiated directly from an userid using the EasyPlayer.from_userid() classmethod. There's also the @PlayerEffect decorator, if you ever feel like subclassing EasyPlayer and adding your own player effects.
You can read more about it on GitHub, or download the latest version from the releases page.
Mahi
Senior Member
Posts: 209
Joined: Wed Aug 29, 2012 8:39 pm
Location: Finland

Postby Mahi » Sun Jul 12, 2015 5:51 pm

Update 12.7.2015:
You no longer use player.freeze(0) to unfreeze a player, but instead you capture a _PlayerEffect instance and call .cancel() method on it. This way you can even cancel effects with a fixed duration. (Thanks to Ayuto for the suggestion :) )

Here's an example of the new method; burn/unburn a player whenever he jumps.

Syntax: Select all

from easyplayer import EasyPlayer
from events import Event

burn = None

@Event
def player_jump(game_event):
global burn
player = EasyPlayer.from_userid(game_event.get_int('userid'))
if burn is None:
burn = player.burn()
else:
burn.cancel()
burn = None
User avatar
BackRaw
Senior Member
Posts: 413
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany

Postby BackRaw » Sun Jul 12, 2015 10:13 pm

One suggestion: avoid checking for None and handle the effects directly within EasyPlayer:

Syntax: Select all

from easyplayer import EasyPlayer
from events import Event


@Event
def player_jump(game_event):
player = EasyPlayer.from_userid(game_event.get_int('userid'))

burn = player.get_effect('burn')

if burn.is_running():
burn.cancel()

else:
player.start_effect('burn', <duration>)
My Github repositories:

Source.Python: https://github.com/backraw/backraw.sp
Mahi
Senior Member
Posts: 209
Joined: Wed Aug 29, 2012 8:39 pm
Location: Finland

Postby Mahi » Sun Jul 12, 2015 11:17 pm

Thanks for the suggestion! I'm not sure what you mean by this? How's it an improvement over the current style? Avoid checking for None where, I don't think we need to check for None at the moment?

Also, I don't see how your example supports multiple effects of the same type.

EDIT: Ahh, you were referring to the example code I showed :) That's just an example, and 99.9% of the time you won't be having a global variable like that. It might not have been the best example out there.
User avatar
BackRaw
Senior Member
Posts: 413
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany

Postby BackRaw » Tue Jul 14, 2015 12:27 am

Yeah sorry, but you're going good :D
My Github repositories:



Source.Python: https://github.com/backraw/backraw.sp
Mahi
Senior Member
Posts: 209
Joined: Wed Aug 29, 2012 8:39 pm
Location: Finland

Postby Mahi » Sat Aug 01, 2015 8:04 am

Updated: https://github.com/MarkusMeskanen/EasyPlayer/commit/e593e0ac0589fd8bdfe1fc6174d1bd26c0d92c88

Instead of using tick_delays.delay(), I've monkey-patched the events.listener._EventListener.fire_game_event method to call EasyPlayer's events after all other events have been called.
Mahi
Senior Member
Posts: 209
Joined: Wed Aug 29, 2012 8:39 pm
Location: Finland

Postby Mahi » Tue Oct 27, 2015 2:18 pm

Version 1.0 is out, should be stable with the latest SP: https://github.com/MarkusMeskanen/EasyPlayer/releases/tag/v1.0
Mahi
Senior Member
Posts: 209
Joined: Wed Aug 29, 2012 8:39 pm
Location: Finland

Postby Mahi » Sun Nov 01, 2015 8:09 pm

Again new release is out, version 1.1: https://github.com/MarkusMeskanen/EasyPlayer/releases/tag/v1.1

I've switched to useing userIDs for caching instead of the entities' indexes, since userIDs cannot be reused like indexes can. Thanks to Ayuto for pointing this out.
Also, EasyPlayer's method shift_property() now passes the duration properly to the tick_delays.delay() function call.

And this thread should probably be in the Custom Packages forum, which didn't exist back when I made this thread. If so, any admin mind moving it? :)
User avatar
Ayuto
Project Leader
Posts: 1541
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Sun Nov 01, 2015 9:57 pm

Mahi wrote:And this thread should probably be in the Custom Packages forum, which didn't exist back when I made this thread. If so, any admin mind moving it? :)
Done! :)

Return to “Custom Packages”

Who is online

Users browsing this forum: No registered users and 1 guest