Raised This Month: $222 Target: $400
 55% 

Looking for a function thatll set the players current velocity.. NOT MAXSPEED


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
12Toastie
Junior Member
Join Date: Nov 2014
Old 05-05-2021 , 01:52   Looking for a function thatll set the players current velocity.. NOT MAXSPEED
Reply With Quote #1

Allow me to explain.. this is for TFC..

In TFC each class has their own maxspeed, and are allowed to bunnyhop up to 170% of their maxspeed. If they try to bhop over that 170%, itll reset their velocity to their maxspeed.

For example, a Scout has a maxspeed of 400.. and can go as high as 680 and if he tries to bhop while being over 680, his velocity will be reset to 400.

Now there is another thing called a "chop hop"... where a player can actually maintain a high rate of speed past 680 by +duck'ing instead. I want to apply that same mechanic to +duck where if they try it while over 680, itll set them back to 400. Is there a function thatll set their current velocity given these conditions?

Last edited by 12Toastie; 05-05-2021 at 01:53.
12Toastie is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 05-05-2021 , 03:02   Re: Looking for a function thatll set the players current velocity.. NOT MAXSPEED
Reply With Quote #2

pev_velocity?
__________________
HamletEagle is offline
12Toastie
Junior Member
Join Date: Nov 2014
Old 05-05-2021 , 11:25   Re: Looking for a function thatll set the players current velocity.. NOT MAXSPEED
Reply With Quote #3

Hey thank you for your reply! Ya i have been trying to use that. I am a rather novice programmer so I am not sure if there is something I need to do differently, but I am getting an effect of sorts but not the intended affect. Ill psuedo code it and explain what its doing for me..

register(hamduck, chop)

public chop(id)

speed stuff
convert speed to percentage stuff

new float:speedvec[3]
speedvec[0] = maxspeed
speedvec[1] = maxspeed
speedvec[2] = 0.0

if(conditions to cause my player to slowdown){
set_pev(id, pev_velocity, speedvec)
}

I am not getting the intended behavior, which is for it to slow the player down to the maxspeed... it is instead throwing my player backward sometimes or stopping on a dime. I understand its like because of how I am doing that speedvec and assigning it values, but idk what wizardry i gotta do to ensure its always projecting the player in the proper direction. I have also tried entity_set_float(id, EV_VEC_velocity, speedvec) with the same result.

Last edited by 12Toastie; 05-05-2021 at 11:27.
12Toastie is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 05-05-2021 , 12:02   Re: Looking for a function thatll set the players current velocity.. NOT MAXSPEED
Reply With Quote #4

http://www.amxmodx.org/api/fun/set_user_maxspeed
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders

CSGO REMAKE ~ CSGO MOD [STABLE]
Shadows Adi is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 05-05-2021 , 17:35   Re: Looking for a function thatll set the players current velocity.. NOT MAXSPEED
Reply With Quote #5

try this

Code:
limit_velocity(id, value) {     new Float:fvelocity[3]     pev(id, pev_velocity, fvelocity)     new Float:speed = floatsqroot(floatpower(fvelocity[0],2.0) + floatpower(fvelocity[1],2.0))     if(speed > value)     {         new Float:x, Float:y         x = fvelocity[0] / speed         y = fvelocity[1] / speed         fvelocity[0] = x * value         fvelocity[1] = y * value         set_pev(id, pev_velocity, fvelocity)     } }

Last edited by jimaway; 05-05-2021 at 17:35.
jimaway is offline
12Toastie
Junior Member
Join Date: Nov 2014
Old 05-05-2021 , 18:45   Re: Looking for a function thatll set the players current velocity.. NOT MAXSPEED
Reply With Quote #6

Quote:
Originally Posted by Shadows Adi View Post
Thank you for your reply!

For tfc simply setting the user maxspeed wont cut it because users of chophop are not effected by it. I will need to actually alter their velocity as their maxspeed by default is the maxspeed I want to use anyway. I am trying to reset their velocity BACK to their maxspeed. Was actually the first thing i searched up and tried. I really do appreciate the reply though and hope this doesnt come off foul.

Last edited by 12Toastie; 05-05-2021 at 18:46.
12Toastie is offline
12Toastie
Junior Member
Join Date: Nov 2014
Old 05-05-2021 , 18:47   Re: Looking for a function thatll set the players current velocity.. NOT MAXSPEED
Reply With Quote #7

Quote:
Originally Posted by jimaway View Post
try this

Code:
limit_velocity(id, value) {     new Float:fvelocity[3]     pev(id, pev_velocity, fvelocity)     new Float:speed = floatsqroot(floatpower(fvelocity[0],2.0) + floatpower(fvelocity[1],2.0))     if(speed > value)     {         new Float:x, Float:y         x = fvelocity[0] / speed         y = fvelocity[1] / speed         fvelocity[0] = x * value         fvelocity[1] = y * value         set_pev(id, pev_velocity, fvelocity)     } }
damn.. thank you for the pretty much very copy/pastable code hahaha.. i will implement it tonight and let you know how it goes!
12Toastie is offline
12Toastie
Junior Member
Join Date: Nov 2014
Old 05-05-2021 , 20:32   Re: Looking for a function thatll set the players current velocity.. NOT MAXSPEED
Reply With Quote #8

ya unfortunately that seemed to have no affect? i threw it in prethink just to see if it would limit at all without conditions and it didnt.. perhaps im calling it wrong?

limit_velocity(id, 100.0) is how i called it for testing purposes within prethink

Code:
limit_velocity(id, value) {     new Float:fvelocity[3]     pev(id, pev_velocity, fvelocity)     new Float:speed = floatsqroot(floatpower(fvelocity[0],2.0) + floatpower(fvelocity[1],2.0))     //client_print(0, print_chat, "%f", speed);     //client_print(0, print_chat, "%f", value);     if(speed > value)     {         client_print(0, print_chat, "%f", speed);         new Float:x, Float:y         x = fvelocity[0] / speed         y = fvelocity[1] / speed         fvelocity[0] = x * value         fvelocity[1] = y * value         set_pev(id, pev_velocity, fvelocity)         } }

I edited the code to get values.. it gets the speed/value in the function before the statement.. with setting the value at 100.0 and the speed typically being 400.0 at maxspeed it prints out nothing, so for some reason its not getting by that statement.

edit: prints if i hard code to value into the function. checking to see if itll work altogether now.

So its actually launching me forward right now but at least in the intended direction.. so just gotta inverse it somehow.. but progress! thanks!

edit:edit:GOT IT! This is what ended up working for anyone that may be looking for something similar.. thank you for your help!

Code:
limit_velocity(id) {     new Float:fvelocity[3]     pev(id, pev_velocity, fvelocity)     new Float:maxSpeed     pev(id, pev_maxspeed, maxSpeed)     new Float:speed = floatsqroot(floatpower(fvelocity[0],2.0) + floatpower(fvelocity[1],2.0))     //client_print(0, print_chat, "%f", speed);     //client_print(0, print_chat, "%f", value);     if(speed > maxSpeed)     {         //client_print(0, print_chat, "higher");         new Float:x, Float:y         x = fvelocity[0] / speed         y = fvelocity[1] / speed         fvelocity[0] = x * maxSpeed         fvelocity[1] = y * maxSpeed         set_pev(id, pev_velocity, fvelocity)         } }

Last edited by 12Toastie; 05-05-2021 at 20:57.
12Toastie is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 20:41.


Powered by vBulletin®
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Theme made by Freecode