Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* stunt.inc
- Info:
- Detects when a player is doing a wheele or stoppie, so you can handle it.
- Useful if you want give rewards to the players that did it.
- Soon:
- Two-wheels detection, and maybe insane stunt
- More acurrate in detection.
- */
- /* Vars */
- static const gValidModelForStunt[212] =
- {
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1,
- 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 2, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 2, 2, 2, 0, 0, 1, 1, 2, 0, 1, 2/*quad*/, 0, 0, 1, 1,
- 0, 1, 1, 1, 1, 2, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 0, 0, 0,
- 1, 1, 1, 1, 1, 0, 0, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1,
- 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 2, 1, 1, 1,
- 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0
- };
- enum stunt_pInfo_enum
- {
- stunt_ID,
- stunt_Time,
- Float:stunt_fX,
- Float:stunt_fY,
- Float:stunt_fZ,
- Float:stunt_Health
- };
- static stunt_pInfo[MAX_PLAYERS][stunt_pInfo_enum];
- /* Macros */
- #define STUNT_NONE 0
- #define STUNT_WHEELIE 1
- #define STUNT_STOPPIE 2
- #define STUNT_TWO_WHEELS 3 // deprecated
- #define VEHICLE_TYPE_NONE 0 // Boats, airplanes, trailers or RC vehicles can't do stunts.
- #define VEHICLE_TYPE_CAR 1 // Can do two-weels.
- #define VEHICLE_TYPE_BIKE 2 // Can do wheelie or stoppie.
- #define GetPlayerCurrentStunt(%1,%2) stunt_pInfo[%1][stunt_ID]
- /* Functions */
- public OnPlayerUpdate(playerid)
- {
- static vehicleid, Float:quat[4], time;
- if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
- {
- if(gValidModelForStunt[GetVehicleModel(GetPlayerVehicleID(playerid)) - 400] == VEHICLE_TYPE_BIKE)
- {
- vehicleid = GetPlayerVehicleID(playerid);
- time = (GetTickCount() - stunt_pInfo[playerid][stunt_Time]);
- GetVehicleRotationQuat(vehicleid, quat[0], quat[1], quat[2], quat[3]);
- if(stunt_pInfo[playerid][stunt_ID] != STUNT_NONE) // Is stunting
- {
- static Float:Health;
- GetVehicleHealth(vehicleid, Health);
- if(Health != stunt_pInfo[playerid][stunt_Health]) // Failed stunt!
- {
- new Float:Pos[3];
- GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
- new const Float:dist = VectorSize(stunt_pInfo[playerid][stunt_fX] - Pos[0], stunt_pInfo[playerid][stunt_fY] - Pos[1], stunt_pInfo[playerid][stunt_fZ] - Pos[2]);
- CallLocalFunction("OnPlayerFinishStunt", "ddifb", playerid, stunt_pInfo[playerid][stunt_ID], time, dist, false);
- stunt_pInfo[playerid][stunt_ID] = STUNT_NONE;
- return 1;
- }
- new Float:Pos[3];
- GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
- CallLocalFunction("OnPlayerUpdateStunt", "ddif", playerid, stunt_pInfo[playerid][stunt_ID], GetTickCount() - stunt_pInfo[playerid][stunt_Time], VectorSize(stunt_pInfo[playerid][stunt_fX] - Pos[0], stunt_pInfo[playerid][stunt_fY] - Pos[1], stunt_pInfo[playerid][stunt_fZ] - Pos[2]));
- }
- if(quat[1] < -0.15) // Wheelie
- {
- if(stunt_pInfo[playerid][stunt_ID] == STUNT_NONE)
- {
- stunt_pInfo[playerid][stunt_ID] = STUNT_WHEELIE;
- stunt_pInfo[playerid][stunt_Time] = GetTickCount();
- GetPlayerPos(playerid, stunt_pInfo[playerid][stunt_fX], stunt_pInfo[playerid][stunt_fY], stunt_pInfo[playerid][stunt_fZ]);
- CallLocalFunction("OnPlayerStartStunt", "dd", playerid, STUNT_WHEELIE);
- GetVehicleHealth(vehicleid, stunt_pInfo[playerid][stunt_Health]);
- }
- return 1;
- }
- if(quat[1] > 0.15) // Stoppie
- {
- if(stunt_pInfo[playerid][stunt_ID] == STUNT_NONE)
- {
- stunt_pInfo[playerid][stunt_ID] = STUNT_STOPPIE;
- stunt_pInfo[playerid][stunt_Time] = GetTickCount();
- GetPlayerPos(playerid, stunt_pInfo[playerid][stunt_fX], stunt_pInfo[playerid][stunt_fY], stunt_pInfo[playerid][stunt_fZ]);
- CallLocalFunction("OnPlayerStartStunt", "dd", playerid, STUNT_STOPPIE);
- GetVehicleHealth(vehicleid, stunt_pInfo[playerid][stunt_Health]);
- }
- return 1;
- }
- if(stunt_pInfo[playerid][stunt_ID] != STUNT_NONE)
- {
- new Float:Pos[3];
- GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
- new const Float:dist = VectorSize(stunt_pInfo[playerid][stunt_fX] - Pos[0], stunt_pInfo[playerid][stunt_fY] - Pos[1], stunt_pInfo[playerid][stunt_fZ] - Pos[2]);
- CallLocalFunction("OnPlayerFinishStunt", "ddifb", playerid, stunt_pInfo[playerid][stunt_ID], time, dist, true);
- stunt_pInfo[playerid][stunt_ID] = STUNT_NONE;
- }
- }
- }
- return 1;
- }
- public OnPlayerStateChange(playerid, newstate, oldstate)
- {
- if(oldstate == PLAYER_STATE_DRIVER && stunt_pInfo[playerid][stunt_ID] != STUNT_NONE)
- {
- new Float:Pos[3];
- GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
- new const Float:dist = VectorSize(stunt_pInfo[playerid][stunt_fX] - Pos[0], stunt_pInfo[playerid][stunt_fY] - Pos[1], stunt_pInfo[playerid][stunt_fZ] - Pos[2]);
- new const time = (GetTickCount() - stunt_pInfo[playerid][stunt_Time]);
- CallLocalFunction("OnPlayerFinishStunt", "ddifb", playerid, stunt_pInfo[playerid][stunt_ID], time, dist, false);
- stunt_pInfo[playerid][stunt_ID] = STUNT_NONE;
- }
- return 1;
- }
- /* Forwards */
- forward OnPlayerStartStunt(playerid, stuntid);
- forward OnPlayerUpdateStunt(playerid, stuntid, time, Float:dist);
- forward OnPlayerFinishStunt(playerid, stuntid, time, Float:dist, bool:success);
- // "time" in miliseconds!
- /* Hook functions */
- #if defined _ALS_OnPlayerUpdate
- #undef OnPlayerUpdate
- #else
- #define _ALS_OnPlayerUpdate
- #endif
- #define OnPlayerUpdate stunt_OnPlayerUpdate
- forward stunt_OnPlayerUpdate(playerid);
- #if defined _ALS_OnPlayerStateChange
- #undef OnPlayerStateChange
- #else
- #define _ALS_OnPlayerStateChange
- #endif
- #define OnPlayerStateChange stunt_OnPlayerStateChange
- forward stunt_OnPlayerStateChange(playerid, newstate, oldstate);
Advertisement
Add Comment
Please, Sign In to add comment