[SOLVED] Detect player driving vehicle - for what time?
Hey, guys! I have a little problem, whose solution I couldn't find anywhere. Okay, it's about detecting whether the player is using specific key to drive a rally car. I don't know how exactly to detect if it's car, but maybe if there is a way to detect if the entity (which button is used?) is able to move. My goal is to make a plugin, which counts how many time a driver has drived a car (and if it's above 120 seconds, to forbid driving for him). That's all I need, but I couldn't find a way to do it...
|
Re: Detect player using rally car key for some time
Try to play aroung with
RegisterHam(Ham_Use, "func_vehiclecontrols", "eventVehicleControlled", true) |
Re: Detect player using rally car key for some time
Ahh, that keyword "vehicle". It's pretty useful to search. And the func_ that should be used is "func_vehicle".
Anyways, I still can't understand how to calculate the time that player has used the vehicle. Like I am searching for function which will be called all the time while the player holds the button and drives. And is this ham such a function? Or it's called on the first pressing of the button. I need that info, too, and then I could fix my problem. |
Re: Detect player using rally car key for some time
PHP Code:
|
Re: Detect player using rally car key for some time
Assuming that Ham_Use will be called both when the player started and stopped driving, I thought of something like this:
PHP Code:
Check this out: https://forums.alliedmods.net/showpo...61&postcount=7 |
Re: Detect player using rally car key for some time
Okay. I found a half-solution of the problem. It was about a question for Ham_Use with func_vehicle. The problem is, that it's calling for the time WHILE the player is using the vehicle (driving it to somewhere). And assuming to the fact that I want to count the time user has drived - I reached to Ham_OnControls. It was pretty good way to detect when the player STARTED to drive and put that ham as a first point to count the time. Okay, now one thing left - I have to detect when he has stopped using the vehicle (the final of driving). That's the one thing left to understand. Thanks!
|
Re: Detect player using rally car key for some time
Maybe when the ent velocity is 0...
PHP Code:
|
Re: Detect player using rally car key for some time
It appears this is not the best solution, since the vehicle continues moving after you release the button!
Okay, the great news - Solution was found! The actual solution appears to be one message, which is sent when the HUD with the speed of the vehicle disappears. It's the "Train" event. I didn't find much info about it on the internet, examples neither, but successfully used it thanks to @Black Rose. He explained everything to me good enough to understand the use of the event! Some more info about it is here - https://wiki.alliedmods.net/Half-lif...e_events#Train . The parameters are in the description. You can simply register this message ID as a normal event, using the parameters above. So, this one line was the solution of my problem (detecting when player get off the vehicle): PHP Code:
You have to know, that this event is not using only for that purpose, so you will have to put some conditions and exeptions to detect exactly what you need. Thanks to everyone and especially - Black Rose. |
| All times are GMT -4. The time now is 21:17. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.