[Include] drift-detection.inc - drifting gamemodes or minigames with ease!
#6

Quote:
Originally Posted by RogueDrifter
Посмотреть сообщение
You deleted it lmao, you seriously gonna deny that?
What did you even update? I see no changes from the older thread that was about a year ago.
This is an entire different include, the old one was released in 2016 which was poorly written and I don't want to support it anymore, thus a new thread.

Changes:

drift-detection.inc:

PHP код:
public OnPlayerUpdate(playerid)
{
    if(
g_DriftFlags DRIFT_CHECK_ENABLED && g_DriftPlayers[playerid][playerFlags] & DRIFT_CHECK_ENABLED)
    {
        if(
GetTickCount() > g_DriftPlayers[playerid][lastTimestamp])
        {
            new 
vehicleID GetPlayerVehicleID(playerid);
            if(
vehicleID && GetPlayerState(playerid) == PLAYER_STATE_DRIVER && IsModelACar(GetVehicleModel(vehicleID)))
            {
                new 
FloatvXFloatvYFloatvZ;
                
GetVehicleVelocity(vehicleIDvXvYvZ);
                new 
Floatangle;
                
GetVehicleZAngle(vehicleIDangle);
                new 
Floatspeed;
                
speed floatsqroot(vX*vX vY*vY vZ*vZ) * 180.0;
                
                new 
Floatdirection;
                
direction atan2(vYvX);
                
direction -= 90.0;
        
                if(
direction 0direction += 360.0;
                new 
FloatdriftAngle;
                
driftAngle angle floatabs(direction);
                if(
driftAngle 270.0driftAngle -= 270.0;
                if(
driftAngle < -270.0driftAngle += 270.0;
                
driftAngle floatabs(driftAngle);
            
                switch(
g_DriftPlayers[playerid][driftState])
                {
                    case 
DRIFT_STATE_NONE:
                    {
                        if(
MIN_DRIFT_ANGLE <= driftAngle <= MAX_DRIFT_ANGLE && speed >= MIN_DRIFT_SPEED)
                        {                        
                            
g_DriftPlayers[playerid][driftState] = DRIFT_STATE_DRIFTING;
                            
g_DriftPlayers[playerid][startTimestamp] = GetTickCount();
                            
GetVehicleHealth(vehicleIDg_DriftPlayers[playerid][vHealth]);
                            
GetPlayerPos(playeridg_DriftPlayers[playerid][startPosX], g_DriftPlayers[playerid][startPosY], g_DriftPlayers[playerid][startPosZ]);
                            
                            
#if defined OnPlayerDriftStart
                                
OnPlayerDriftStart(playerid);
                            
#endif
                        
}
                    }
                    case 
DRIFT_STATE_DRIFTING:
                    {
                        if(
g_DriftFlags DAMAGE_CHECK_ENABLED && g_DriftPlayers[playerid][playerFlags] & DAMAGE_CHECK_ENABLED)
                        {
                            new 
FloatvehicleHealth;
                            
GetVehicleHealth(vehicleIDvehicleHealth);
                            if(
vehicleHealth g_DriftPlayers[playerid][vHealth])
                            {
                                
GetPlayerPos(playeridvXvYvZ);
                                
g_DriftPlayers[playerid][driftState] = DRIFT_STATE_NONE;
                                
g_DriftPlayers[playerid][timeoutTicks] = 0;
                                
#if defined OnPlayerDriftEnd
                                    
new Floatdistance;
                                    
distance GetPlayerDistanceFromPoint(playeridg_DriftPlayers[playerid][startPosX], g_DriftPlayers[playerid][startPosY], g_DriftPlayers[playerid][startPosZ]);
                                    
OnPlayerDriftEnd(playeridDRIFT_END_REASON_DAMAGEDdistanceGetTickCount() - g_DriftPlayers[playerid][startTimestamp]);
                                
#endif
                            
}
                        }
                        else if(
MIN_DRIFT_ANGLE <= driftAngle <= MAX_DRIFT_ANGLE && speed >= MIN_DRIFT_SPEED)
                        {
                            
g_DriftPlayers[playerid][timeoutTicks] = 0;
                            
                            
#if defined OnPlayerDriftUpdate
                                
OnPlayerDriftUpdate(playeriddriftAnglespeed);
                            
#endif
                        
}
                        else
                        {
                            
g_DriftPlayers[playerid][timeoutTicks]++;
                            if(
g_DriftPlayers[playerid][timeoutTicks] >= DRIFT_TIMEOUT_INTERVAL)
                            {
                                
GetPlayerPos(playeridvXvYvZ);
                                
                                
g_DriftPlayers[playerid][driftState] = DRIFT_STATE_NONE;
                                
g_DriftPlayers[playerid][timeoutTicks] = 0;
                                
#if defined OnPlayerDriftEnd
                                    
new Floatdistance;
                                    
distance GetPlayerDistanceFromPoint(playeridg_DriftPlayers[playerid][startPosX], g_DriftPlayers[playerid][startPosY], g_DriftPlayers[playerid][startPosZ]);
                                    
OnPlayerDriftEnd(playeridDRIFT_END_REASON_TIMEOUTdistanceGetTickCount() - g_DriftPlayers[playerid][startTimestamp]);
                                
#endif
                            
}
                        }
                    }
                }
            }
            
g_DriftPlayers[playerid][lastTimestamp] = GetTickCount() + DRIFT_PROCESS_INTERVAL;
        }
    }
    
#if defined Drift_OnPlayerUpdate
        
return Drift_OnPlayerUpdate(playerid);
    
#else
        
return true;
    
#endif

drift.inc: (2016)

PHP код:
public OnPlayerUpdate(playerid) {
    if(
GetTickCount() > P_DATA[playerid][T_TICK])
    {
        new 
vehicleid;
        if( (
vehicleid GetPlayerVehicleID(playerid)) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER )
        {
            if(
__IsModelACar(GetVehicleModel(vehicleid)))
            {
                new 
Float:xFloat:yFloat:zFloat:aFloat:dFloat:sFloat:drift_angle;
                
GetVehicleVelocity(vehicleidxyz);
                
GetVehicleZAngle(vehicleida);
                
floatround(floatsqrootx*y*z*z) * 180);
                
atan2(yx);
                
floatsub(d90.0);
                if(
0.0floatadd(d360.0);
                
drift_angle d;
                if(
drift_angle 270.0drift_angle -= 270.0;
                if(
drift_angle < -270.0drift_angle += 270.0;
                
drift_angle floatabs(drift_angle);
                switch (
P_DATA[playerid][P_DRIFTING])
                {
                    case 
0:
                    {
                        if(
MIN_DRIFT_ANGLE <= drift_angle <= MAX_DRIFT_ANGLE && >= MIN_DRIFT_SPEED && !__IsVehicleDrivingBackwards(xya))
                        {
                            
P_DATA[playerid][P_DRIFTING] = true;
                            
P_DATA[playerid][D_STARTTICK] = GetTickCount();
                            
GetVehicleHealth(vehicleidP_DATA[playerid][V_HEALTH]);
                            
GetPlayerPos(playeridP_DATA[playerid][P_STARTX], P_DATA[playerid][P_STARTY], x);
                            
CallLocalFunction("OnDriftStart""i"playerid);
                        }
                    }
                    case 
1:
                    {
                        new 
Float:vhealthFloat:_xFloat:_yFloat:_z;
                        
GetVehicleHealth(vehicleidvhealth);
                        
GetPlayerPos(playerid_x_y_z);
                        if(
vhealth P_DATA[playerid][V_HEALTH]) 
                        {
                            
CallLocalFunction("OnDriftEnd""iifi"playeridDRIFT_END_REASON_CRASH__GetPointDistanceToPoint(P_DATA[playerid][P_STARTX],  P_DATA[playerid][P_STARTY], _x_y),  GetTickCount() - P_DATA[playerid][D_STARTTICK]);
                            
P_DATA[playerid] = R_DATA;
                        }
                        else if(
__IsVehicleDrivingBackwards(xya) || MIN_DRIFT_SPEED)
                        {
                            
CallLocalFunction("OnDriftEnd""iifi"playeridDRIFT_END_REASON_OTHER__GetPointDistanceToPoint(P_DATA[playerid][P_STARTX],  P_DATA[playerid][P_STARTY], _x_y),  GetTickCount() - P_DATA[playerid][D_STARTTICK]);
                            
P_DATA[playerid] = R_DATA;
                        }
                        else if(
MIN_DRIFT_ANGLE <= drift_angle <= MAX_DRIFT_ANGLE && >= MIN_DRIFT_SPEED)
                        {
                            
P_DATA[playerid][T_TIMEOUT] = 0;
                            
CallLocalFunction("OnDriftUpdate""iff"playeriddrift_angles);
                        }
                        else 
                        {
                            
P_DATA[playerid][T_TIMEOUT]++;
                            if(
P_DATA[playerid][T_TIMEOUT] >= DRIFT_TIMEOUT_INTERVAL)
                            {
                                
CallLocalFunction("OnDriftEnd""iifi"playeridDRIFT_END_REASON_TIMEOUT__GetPointDistanceToPoint(P_DATA[playerid][P_STARTX],  P_DATA[playerid][P_STARTY], _x_y),  GetTickCount() - P_DATA[playerid][D_STARTTICK]);
                                
P_DATA[playerid] = R_DATA;
                            }
                        }
                    }
                }
            }
        }
        
P_DATA[playerid][T_TICK] = GetTickCount() + PROCESS_INTERVAL;
    }
    
#if defined D_OnPlayerUpdate
        
return D_OnPlayerUpdate(playerid);
    
#else
        
return true;
    
#endif

Reply


Messages In This Thread
drift-detection.inc - drifting gamemodes or minigames with ease! - by iKarim - 15.02.2018, 14:08
Re: drift-detection.inc - drifting gamemodes or minigames with ease! - by rfr - 15.02.2018, 14:13
Re: drift-detection.inc - drifting gamemodes or minigames with ease! - by RogueDrifter - 15.02.2018, 14:19
Re: drift-detection.inc - drifting gamemodes or minigames with ease! - by iKarim - 15.02.2018, 14:22
Re: drift-detection.inc - drifting gamemodes or minigames with ease! - by RogueDrifter - 15.02.2018, 14:23
Re: drift-detection.inc - drifting gamemodes or minigames with ease! - by iKarim - 15.02.2018, 14:30
Re: drift-detection.inc - drifting gamemodes or minigames with ease! - by RogueDrifter - 15.02.2018, 14:41
Re: drift-detection.inc - drifting gamemodes or minigames with ease! - by iKarim - 15.02.2018, 14:47
Re: drift-detection.inc - drifting gamemodes or minigames with ease! - by RogueDrifter - 15.02.2018, 14:48
Re: drift-detection.inc - drifting gamemodes or minigames with ease! - by iKarim - 15.02.2018, 14:52
Re: drift-detection.inc - drifting gamemodes or minigames with ease! - by RogueDrifter - 15.02.2018, 14:59
Re: drift-detection.inc - drifting gamemodes or minigames with ease! - by iKarim - 15.02.2018, 15:04
Re: drift-detection.inc - drifting gamemodes or minigames with ease! - by RogueDrifter - 15.02.2018, 15:22
Re: drift-detection.inc - drifting gamemodes or minigames with ease! - by iKarim - 15.02.2018, 15:38
Re: drift-detection.inc - drifting gamemodes or minigames with ease! - by RogueDrifter - 15.02.2018, 15:40
Re: drift-detection.inc - drifting gamemodes or minigames with ease! - by iKarim - 15.02.2018, 15:42
Re: drift-detection.inc - drifting gamemodes or minigames with ease! - by RogueDrifter - 15.02.2018, 15:45
Re: drift-detection.inc - drifting gamemodes or minigames with ease! - by iKarim - 16.02.2018, 08:55
Re: drift-detection.inc - drifting gamemodes or minigames with ease! - by RogueDrifter - 16.02.2018, 08:58
Re: drift-detection.inc - drifting gamemodes or minigames with ease! - by iKarim - 16.02.2018, 09:06

Forum Jump:


Users browsing this thread: 3 Guest(s)