Raised This Month: $32 Target: $400
 8% 

Do action after player reaches specfic velocity.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Celty
Junior Member
Join Date: Jun 2015
Old 08-01-2015 , 02:11   Do action after player reaches specfic velocity.
Reply With Quote #1

Is there a way to check if a player is going at or more then a specific velocity, and play a sound when they reach it.

Sorry there is not much context but that's the simplest way i could put it to avoid confusion.

Willing to pay for this to be made.
__________________


Last edited by Celty; 08-02-2015 at 04:25.
Celty is offline
ThatOneGuy
Veteran Member
Join Date: Jul 2012
Location: Oregon, USA
Old 08-01-2015 , 02:42   Re: Do action after player reaches specfic velocity.
Reply With Quote #2

You would have to constantly monitor them. Not to hard to do, but uses a little CPU to monitor all players like that.

You could do something like the following...
Code:
new bool:ga_bSoundPlayed[MAXPLAYERS + 1] = {false, ...};
new g_iTickCount = 1;

public OnGameFrame()
{
	new Float:fVelocity = 0.0;

	if(g_iTickCount > MaxClients)
	{
		g_iTickCount = 1;
	}
	else
	{
		if(g_iTickCount % 1 == 0)
		{
			new client = g_iTickCount / 1;
			if(IsClientInGame(client) && IsPlayerAlive(client))
			{	
				GetEntPropVector(client, Prop_Data, "m_vecVelocity", fVelocity);
				if(fVelocity > 350)
				{
					if(!ga_bSoundPlayed[client])
					{
						EmitSoundToClientAny(client, sSoundPath);
					}
				}
				else
				{
					if(ga_bSoundPlayed[client])
					{
						ga_bSoundPlayed[client] = false;
					}
				}
				
				
			}
		}
		g_iTickCount++;
	}
}
The idea to use the tickcount for filtering out some of the processing is from Inami's macrodox plugin. I'm not sure the point in the dividing and multiplying by one, but I left that there in case there is some significance to it, since I havent tested it without. I really cant think of why that would be there though. Anyways, use a global boolean to check if they have already had the sound played. Make sure you precache the sounds as well and add them to the download table.
__________________

Last edited by ThatOneGuy; 08-01-2015 at 02:57.
ThatOneGuy is offline
Celty
Junior Member
Join Date: Jun 2015
Old 08-02-2015 , 04:25   Re: Do action after player reaches specfic velocity.
Reply With Quote #3

Im looking for anyone who can make this for me, would be willing to pay.
__________________

Celty is offline
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 08-03-2015 , 13:37   Re: Do action after player reaches specfic velocity.
Reply With Quote #4

Quote:
Originally Posted by Celty View Post
Im looking for anyone who can make this for me, would be willing to pay.
Dude, don't pay anything to anyone except to ThatOneGuy who did that code above, this is pretty much everything.

Try this.
__________________
Want to check my plugins ?

Last edited by Arkarr; 08-03-2015 at 15:17.
Arkarr is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 08-03-2015 , 14:14   Re: Do action after player reaches specfic velocity.
Reply With Quote #5

Less CPU burden



*
ThatOneGuy suggest
__________________
Do not Private Message @me

Last edited by Bacardi; 08-04-2015 at 01:17.
Bacardi is offline
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 08-03-2015 , 15:16   Re: Do action after player reaches specfic velocity.
Reply With Quote #6

Quote:
Originally Posted by Bacardi View Post
Your code [...]
Shouldn't you add the flag TIMER_FLAG_NOMAPCHANGE as well ? I think it could be better, so, if the map change, the sound will be still playing.
Or 'OnClientPutInServer' fire when the player join after a map change as well ?
__________________
Want to check my plugins ?

Last edited by Arkarr; 08-03-2015 at 15:18.
Arkarr is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 08-03-2015 , 15:29   Re: Do action after player reaches specfic velocity.
Reply With Quote #7

Quote:
Originally Posted by Arkarr View Post
Shouldn't you add the flag TIMER_FLAG_NOMAPCHANGE as well ? I think it could be better, so, if the map change, the sound will be still playing.
Or 'OnClientPutInServer' fire when the player join after a map change as well ?
Aa aa aa, that's beginner's mistake. Do your home work

3 Passing Data
[css] Native "KillTimer" error
__________________
Do not Private Message @me

Last edited by Bacardi; 08-03-2015 at 15:32. Reason: more!
Bacardi is offline
ThatOneGuy
Veteran Member
Join Date: Jul 2012
Location: Oregon, USA
Old 08-03-2015 , 20:51   Re: Do action after player reaches specfic velocity.
Reply With Quote #8

Alternately, Bacardi, pass the client's userID and when converting back, check if still valid. If not, return Plugin_Stop. This avoids creating a global array of handles that could potentially be leaked if the coder doesnt handle them properly. I usually try to avoid global array handles (excluding ADT arrays and some others), since the code can often be accomplished without them...Just my preference though, since to me it is "cleaner". I used to do it the other way around though (killing timers).

Quote:
Originally Posted by Arkarr View Post
Dude, don't pay anything to anyone except to ThatOneGuy who did that code above, this is pretty much everything.
Meh, no worries. Whoever makes it still needs to make the cvars and add the code to precache the sound and add to DL tbl. So, they're doing part of the work as well. The OP also had some additional requests (trail of flames when they break the speed threshold), that I'm not sure can be done with simplicity. Igniting or even parenting a fire entity would make it right on the client, not trail him, correct? Is there a way to make it more of a "trail" outside of creating a bunch of entities on a repeat timer, TP'ing them to the client, then killing them after X seconds? Hmmmm...one other idea would be to parent say 6 fire entities, each offset slightly more from the player. Then you wouldnt have to kill them, etc. until they lose speed. That might be an even better option, although I imagine it being slightly more "rigid" of a trail than the TP'ing ents.
__________________

Last edited by ThatOneGuy; 08-03-2015 at 21:16.
ThatOneGuy is offline
Reply



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 11:25.


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