[Help] OnPlayerInteractVehicle
#1

So, I have these functions just below, to repair a vehicle, where the "enter" key is pressed, thus activating a HoldingaAction of a certain time, at the end of it, the car should be repaired (damage restored), but none of this happens, I press "enter" in the right place but the HoldingAction starts and stops instantly.

However, it executes the "StartFixing" function because ActionText appears on the screen, which is inbuilt in it, but HoldingAction does not work, so it does not give proceeding to the code.


On Top of include
PHP код:
static
        
fix_TargetVehicle[MAX_PLAYERS],
Float:    fix_Progress[MAX_PLAYERS];
hook OnPlayerConnect(playerid)
{
    
fix_TargetVehicle[playerid] = INVALID_VEHICLE_ID;

Principal:
PHP код:
public OnPlayerInteractVehicle(playeridvehicleidFloat:angle)
{
    if(
angle 25.0 || angle 335.0)
    {
        new
            
Float:vehiclehealth,
            
ItemType:itemtype;
        
GetVehicleHealth(vehicleidvehiclehealth);
        
itemtype GetItemType(GetPlayerItem(playerid));
        if(
itemtype == item_Spanner)
        {
            if(
CLASSEmecanico[playerid] == true)
            {
                
CancelPlayerMovement(playerid);
                
StartFixing(playeridvehicleid);
            }
            else
            {
                
SendClientMessage(playeridRED"[ > ] Vocк nгo tem capacidade para realizar esta aзгo.");
                return 
1;
            }
        }
    }
    return 
CallLocalFunction("rep_OnPlayerInteractVehicle""ddf"playeridvehicleidFloat:angle);
}
#if defined _ALS_OnPlayerInteractVehicle
    #undef OnPlayerInteractVehicle
#else
    #define _ALS_OnPlayerInteractVehicle
#endif
#define OnPlayerInteractVehicle rep_OnPlayerInteractVehicle
forward rep_OnPlayerInteractVehicle(playeridvehicleidFloat:angle); 
My Functions:
PHP код:
StartFixing(playeridvehicleid)
{
    
ApplyAnimation(playerid"INT_SHOP""SHOP_CASHIER"4.0100001);
    
StartHoldAction(playerid5000);
    
ShowActionText(playeridsprintf("Consertando..."));
    
fix_TargetVehicle[playerid] = vehicleid;
    return 
1;
}
StopFixing(playerid)
{
    if(
fix_TargetVehicle[playerid] == INVALID_VEHICLE_ID)
        return 
0;
    
StopHoldAction(playerid);
    
ClearAnimations(playerid);
    
HideActionText(playerid);
    
fix_TargetVehicle[playerid] = INVALID_VEHICLE_ID;
    return 
1;

My OnHoldActionFinish
PHP код:
public OnHoldActionFinish(playerid)
{
    if(
fix_TargetVehicle[playerid] != INVALID_VEHICLE_ID)
    {
        new
        
itemid,
        
ItemType:itemtype;
        
itemid GetPlayerItem(playerid);
        
itemtype GetItemType(itemid);
        if(
itemtype == item_Spanner)
        {
            
SetVehicleHealth(fix_TargetVehicle[playerid], 990.0);
        }
        
        return 
1;
    }
    
#if defined repair_OnHoldActionFinish
        
return repair_OnHoldActionFinish(playerid);
    
#else
        
return 0;
    
#endif
}
#if defined _ALS_OnHoldActionFinish
    #undef OnHoldActionFinish
#else
    #define _ALS_OnHoldActionFinish
#endif
#define OnHoldActionFinish repair_OnHoldActionFinish
#if defined repair_OnHoldActionFinish
    
forward repair_OnHoldActionFinish(playerid);
#endif 
My KeyStateChange hook:
PHP код:
hook OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    if(
oldkeys 16)
    {
        
StopFixing(playerid);
    }

I know it's a lot, but I'm lost and I do not know what to do, if anyone can help me, I'd be grateful
Reply
#2

Are you trying to repair the vehicle when the player enter's the vehicle? Or are you doing a type of pay and spray where you are at a specific location, press enter and then it repairs the vehicle?
Reply
#3

Quote:
Originally Posted by ItsRobinson
Посмотреть сообщение
Are you trying to repair the vehicle when the player enter's the vehicle? Or are you doing a type of pay and spray where you are at a specific location, press enter and then it repairs the vehicle?
No, in my GM you need to have a tool, then just press "enter" in front of the vehicle he performs and fix, but that's not happening
Reply
#4

Just seen you're trying to do some sort of mechanic thing.

I would just use something like this, but you'd have to change the interaction key from Enter, to avoid the player getting in the vehicle.

PHP код:
public OnPlayerKeyStateChange(playeridnewkeysoldkeys) {
        if((
newkeys KEY_LOOK_LEFT)) //press Q
    
{
        
//Search or make some code to grab the nearest vehicle ID (very easy to find/do)
        
StartFixing(playerid/*Returned closest vehID*/);
    }
    if((
oldkeys KEY_LOOK_LEFT)) //releases Q
    
{
        
StopFixing(playerid);
    } 
Not tested, but should work with a bit of tweaking by yourself.
Reply
#5

I thought of something similar, but then I would face other problems, such as the item that the player must be holding (a specific item is needed) and the position, the right thing would be to fix the vehicle in front of the hood, but in codes like this showed, the player could stay anywhere, and that would not make sense.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)