Push a player to a given point

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Push a player to a given point

Postby Kami » Sat Dec 02, 2017 8:13 am

Hey guys, I've been trying to recreate the old est_pushto effect but I got strange behavior.

This is what I tried:

Syntax: Select all

@ServerCommand('pushto')
def pushto(command):
userid = int(command[1])
x1 = float(command[2])
y1 = float(command[3])
z1 = float(command[4])
vec = Vector(x1,y1,z1)
player = Player(index_from_userid(userid))
player.set_property_vector('m_vecBaseVelocity', Vector(x1,y1,z1))


The problem I encounter is, that the point I'm getting pushed to seems to stay the same most of the time, only changing for reasons unknown to me.

Maybe you guys have a better insight what I'm doing wrong. Thank you :)
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: Push a player to a given point

Postby iPlayer » Sat Dec 02, 2017 8:36 am

Hey, Kami

The main issue here is that your code doesn't push player towards any particular location. Instead it treats your coordinates as a vector to add to the player velocity.

See, if you use type pushto 2 0 0 1000 (2 is my userid), your code will just add the vector (0, 0, 1000) to player's current velocity. That means that if a player was standing still, he'd get pushed straightly upwards, and his initial speed will be 1000. The point of the map located at (0, 0, 1000) doesn't play any role in your implementation.

Try this:

Syntax: Select all

from commands.typed import TypedSayCommand
from mathlib import Vector
from players.entity import Player


@TypedSayCommand('!pushme')
def say_pushme(command_info, x:float, y:float, z:float):
player = Player(command_info.index)
player.teleport(None, None, Vector(x, y, z) - player.origin)


Usage:
!pushme 0 0 0 (chat command)

This will push the player towards point at (0, 0, 0). Depending on how far that point is from the player, pushing velocity will vary.

I use player.teleport to set velocity to players. Its arguments are new location, new angle and new velocity. I don't need to change player's location or angle, so I just pass None.

But be aware that player.base_velocity (that's a shortcut for what you use in your code) will add the velocity; player.teleport sets the new velocity. So in my code it doesn't matter what the player velocity was before they typed the command.

If you need their old velocity to be taken into account, you can do it this way:

Syntax: Select all

player.teleport(None, None, player.velocity + Vector(x, y, z) - player.origin)
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Re: Push a player to a given point

Postby Kami » Sat Dec 02, 2017 8:54 am

This works just as I want it to, thank you very much!
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Push a player to a given point

Postby Ayuto » Sat Dec 02, 2017 8:59 am

I prefer calling the teleport function like this:

Syntax: Select all

player.teleport(velocity=Vector(x, y, z) - player.origin)

It's a little bit easier to read.
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: Push a player to a given point

Postby iPlayer » Sat Dec 02, 2017 9:01 am

Oh yeah, I forgot that it's wrapped now.
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Push a player to a given point

Postby L'In20Cible » Sat Dec 02, 2017 9:33 am

I would rather recommend using Player.base_velocity which applies the given Vector and doesn't requires a dynamic call.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 33 guests