AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [SOLVED] Detect player driving vehicle - for what time? (https://forums.alliedmods.net/showthread.php?t=243749)

Flick3rR 07-09-2014 05:58

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

mottzi 07-09-2014 07:48

Re: Detect player using rally car key for some time
 
Try to play aroung with
RegisterHam(Ham_Use, "func_vehiclecontrols", "eventVehicleControlled", true)

Flick3rR 07-09-2014 08:22

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.

HamletEagle 07-09-2014 08:31

Re: Detect player using rally car key for some time
 
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);
     */ 


mottzi 07-09-2014 08:53

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:


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

Flick3rR 07-09-2014 12:26

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!

Mario AR. 07-09-2014 13:21

Re: Detect player using rally car key for some time
 
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.



Flick3rR 07-09-2014 13:59

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:

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.


All times are GMT -4. The time now is 21:17.

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