Raised This Month: $ Target: $400
 0% 

[SOLVED] Detect player driving vehicle - for what time?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 07-09-2014 , 05:58   [SOLVED] Detect player driving vehicle - for what time?
Reply With Quote #1

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...
__________________

Last edited by Flick3rR; 07-09-2014 at 14:05.
Flick3rR is offline
Send a message via Skype™ to Flick3rR
mottzi
Veteran Member
Join Date: May 2010
Location: Switzerland
Old 07-09-2014 , 07:48   Re: Detect player using rally car key for some time
Reply With Quote #2

Try to play aroung with
RegisterHam(Ham_Use, "func_vehiclecontrols", "eventVehicleControlled", true)
mottzi is offline
Send a message via MSN to mottzi
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 07-09-2014 , 08:22   Re: Detect player using rally car key for some time
Reply With Quote #3

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.
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 07-09-2014 , 08:31   Re: Detect player using rally car key for some time
Reply With Quote #4

PHP Code:
/**
     * Description:        Called whenver one entity uses another.
     * Forward params:    function(this, idcaller, idactivator, use_type, Float:value)
     * Return type:        None.
     * Execute params:    ExecuteHam(Ham_Use, this, idcaller, idactivator, use_type, Float:value);
     */ 
HamletEagle is offline
mottzi
Veteran Member
Join Date: May 2010
Location: Switzerland
Old 07-09-2014 , 08:53   Re: Detect player using rally car key for some time
Reply With Quote #5

Assuming that Ham_Use will be called both when the player started and stopped driving, I thought of something like this:
PHP Code:

new g_timesUsed[33]
new 
g_tempTime[33]
new 
g_secondsDriving[33]

public 
plugin_init()
{
    
RegisterHam(Ham_Use"func_vehicle""eventVehicleUsed"true)
}

public 
eventVehicleUsed(thisididactivatoruse_typeFloat:value)
{
    
g_timesUsed[id]++

    
// started driving
    
if(g_timesUsed[id] % 2)
    {
        
g_tempTime[id] = get_systime()
    }
    
// stopped driving
    
else
    {
        
g_secondsDriving += get_systime() - g_tempTime[id]
    }


Check this out:
https://forums.alliedmods.net/showpo...61&postcount=7

Last edited by mottzi; 07-09-2014 at 09:03.
mottzi is offline
Send a message via MSN to mottzi
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 07-09-2014 , 12:26   Re: Detect player using rally car key for some time
Reply With Quote #6

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!
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
Mario AR.
Senior Member
Join Date: May 2011
Location: Lima, Perú
Old 07-09-2014 , 13:21   Re: Detect player using rally car key for some time
Reply With Quote #7

Maybe when the ent velocity is 0...
PHP Code:
new Float:velocity[3];
pev(vehicle_entpev_velocityvelocity);
if (
velocity[0] + velocity[1] + velocity[2] < 1)
{
    
// Not moving.
}
else
{
    
// Is moving.

Mario AR. is offline
Old 07-09-2014, 13:24
Flick3rR
This message has been deleted by Flick3rR. Reason: Wrong.
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 07-09-2014 , 13:59   Re: Detect player using rally car key for some time
Reply With Quote #9

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:
register_event("Train""onTrainResetVehicle""b""1=0"
. I used parameter 0 to detect disappearing of the HUD -> player gets off.
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.
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
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 21:17.


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