This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

Issues with prop_vehicle_driveable


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
NatalyaAF
Senior Member
Join Date: Dec 2008
Old 01-11-2016 , 00:53   Issues with prop_vehicle_driveable
Reply With Quote #1

https://www.youtube.com/watch?v=JRikusmaWMA

You can see what I'm talking about in there.
- View goes left or right as the car itself turns left or right, but twice as fast as it should
- Sometimes when entering or exiting the vehicle you get stuck in the floor
- Animation sometimes glitches (see the steering wheel pop back to centre position if you hold wheel right or left)

Some relevant sections of code follow.

This handles when a client presses "e" on the car:
PHP Code:
public Action:OnPlayerRunCmd(client, &buttons, &impulseFloat:vel[3], Float:angles[3], &weapon)
{
    static 
bool:PressingUse[MAXPLAYERS 1];
    static 
bool:DuckBuffer[MAXPLAYERS 1];
    static 
OldButtons[MAXPLAYERS 1];
    
    if (!(
OldButtons[client] & IN_USE) && (buttons IN_USE))
    {
        if (!
PressingUse[client])
        {
            if (
GetEntPropEnt(clientProp_Send"m_hVehicle") != -1)
            {
                
LeaveVehicle(client);
                
buttons &= ~IN_USE;
                
PressingUse[client] = true;
                
OldButtons[client] = buttons;
                return 
Plugin_Handled;
            }
            else
            {
                
decl Ent;
                
Ent GetClientAimTarget(clientfalse);
                if (
IsValidEdict(Ent))
                {
                    
decl String:ClassName[255];
                    
GetEdictClassname(EntClassName255);

                    
//Valid:
                    
if (StrEqual(ClassName"prop_vehicle_driveable"false))
                    {
                        new 
Float:origin[3];
                        new 
Float:car_origin[3];
                        new 
Float:distance;

                        
GetClientAbsOrigin(clientorigin);    
                        
GetEntPropVector(EntProp_Send"m_vecOrigin"car_origin);
                        
distance GetVectorDistance(origincar_originfalse);
//                        if ((distance <= 80.00) && (!GetEntProp(Ent, Prop_Data, "m_bLocked")))
                    
                        // It is a car.  See if it is locked or not, and if it is in range.
                        
if ((!GetEntProp(EntProp_Data"m_bLocked")) && (distance <= 88.00))
                        {
                            
// Car in range, unlocked.
                            
new Driver GetEntPropEnt(EntProp_Send"m_hPlayer");
                            if (
Driver == -1)
                            {
                                
AcceptEntityInput(Ent"use"client);
//                                buttons &= ~IN_USE;
                                
PressingUse[client] = true;
                                
OldButtons[client] = buttons;
                                return 
Plugin_Handled;
                            }
                            else if (
cars_seats[Ent] > 0)
                            {
                                
// Car has multiple seats, someone already driving
                                
new Passenger = -1;
                                
decl String:ClassName2[255];
                                for ( new 
ic 1;  ic cars_seats[Ent] + 1ic++ )
                                {
                                    
GetEdictClassname(cars_seat_entities[Ent][ic], ClassName2255);
                                    if (
StrEqual(ClassName2"prop_vehicle_driveable"false))
                                    {
                                        
// Is there a passenger in one of the seats?
                                        
Passenger GetEntPropEnt(cars_seat_entities[Ent][ic], Prop_Send"m_hPlayer");
                                        if (
Passenger == -1)
                                        {
                                            new 
chair cars_seat_entities[Ent][ic];
                                            if (
IsValidEntity(chair))
                                            {
                                                new 
cars_type[Ent];
                                                
SetVariantString("");
                                                
AcceptEntityInput(chair"SetParent"chairchair0);                                    
                                                
AcceptEntityInput(chair"use"client);
                                        
                                                new 
String:car_name2[128];
                                                
GetTargetName(Ent,car_name2,sizeof(car_name2));
                    
                                                
SetVariantString(car_name2);
                                                
AcceptEntityInput(chair"SetParent"chairchair0);
                                                
SetVariantString(car_passenger_attachment[t][ic]);
                                                
AcceptEntityInput(chair"SetParentAttachment"chairchair0);                                

                                                break;
                                            }
                                        }
                                    }
                                }
                            }                        
                        }
                        else
                        {
                            
EmitSoundToAll("doors/default_locked.wav"EntSNDCHAN_AUTOSNDLEVEL_NORMAL);
                        }
                    }
                }                            
            }
        }
        
PressingUse[client] = true;
    }
    else
    {
        
PressingUse[client] = false;
    } 
And this is the car's think script (run every frame):
PHP Code:
public OnThink(entity)
{
    new 
Driver GetEntPropEnt(entityProp_Send"m_hPlayer");
    if (
Driver 0)
    {
        new 
car GetEntPropEnt(DriverProp_Send"m_hVehicle");
        if (
car != entity)
        {
            
PrintToChatAll("\x04[Car] ERROR");
            
LeaveVehicle(Driver);
            
SDKUnhook(carSDKHook_ThinkOnThink);
            
SDKHook(carSDKHook_ThinkOnThink); 
            
AcceptEntityInput(car"Use"Driver);
        }
    }
    
decl Float:ang[3];
    if (
IsValidEntity(ViewEnt[entity]))
    {
        if (
Driver 0)
        {
            if(
IsClientInGame(Driver) && IsPlayerAlive(Driver))
            {
                
SetEntProp(entityProp_Data"m_nNextThinkTick"1);
                
SetEntPropFloat(entityProp_Data"m_flTurnOffKeepUpright"1.0);
                
//SetClientViewEntity(Driver, ViewEnt[entity]);
                
Driving[Driver] = true;
                
                new 
cars_type[entity];            
                if (
car_driver_view[t] == 1)
                {
                    if (
Cars_Driver_Prop[entity] == -1)
                    {
                        new 
prop CreateEntityByName("prop_physics_override");
                        if(
IsValidEntity(prop))
                        {
                            new 
String:model[128];
                            
GetClientModel(Drivermodelsizeof(model));
                            
DispatchKeyValue(prop"model"model);
                            
DispatchKeyValue(prop"skin","0");
                            
ActivateEntity(prop);
                            
DispatchSpawn(prop);
                                        
                            new 
enteffects GetEntProp(propProp_Send"m_fEffects");  
                            
enteffects |= 1;
                            
enteffects |= 128;
                            
enteffects |= 512;
                            
SetEntProp(propProp_Send"m_fEffects"enteffects);  
                    
                            new 
String:car_ent_name[128];
                            
GetTargetName(entity,car_ent_name,sizeof(car_ent_name));
                    
                            
SetVariantString(car_ent_name);
                            
AcceptEntityInput(prop"SetParent"propprop0);
                            
SetVariantString("vehicle_driver_eyes");
                            
AcceptEntityInput(prop"SetParentAttachment"propprop0);
                            
Cars_Driver_Prop[entity] = prop;
                            
/*                            new hat = GetClientHatEntity(Driver);
                            if (IsValidEntity(hat))
                            {
                                AcceptEntityInput(hat, "ClearParent", hat, hat, 0);
                                new type = GetClientHat(Driver);
                                SetHatEntityToParent(hat, entity, type);
        
                                SetVariantString(car_ent_name);
                                AcceptEntityInput(hat, "SetParent", hat, hat, 0);
                                SetVariantString("n_head");
                                AcceptEntityInput(hat, "SetParentAttachmentMaintainOffset", hat, hat, 0);
                            } */
                        
}
                    }
                }
                else 
Cars_Driver_Prop[entity] = -1;
            }
        }
    }
    if (
GetEntProp(entityProp_Send"m_bEnterAnimOn") == 1)
    {
        
        
SetEntProp(entityProp_Send"m_nSequence"0);
        
        
CarHorn[Driver] = false;
        
armour[Driver] = GetEntProp(DriverProp_Send"m_ArmorValue"); 
        
SetEntProp(entityProp_Send"m_bEnterAnimOn"0);
        
SetEntProp(entityProp_Send"m_nSequence"0);
        if (
is_chair[entity] <= 1)
        {
            if (
GetConVarInt(g_Cvar_GasUse))
            {
                if (
car_fuel[entity] > 0.0)
                {
                    
AcceptEntityInput(entity"TurnOn");
                    
CarOn[entity] = true;
                }
                else 
PrintToChat(Driver"\x04[Car] %T""No_Gas"Driver);
            }
            else
            {
                
AcceptEntityInput(entity"TurnOn");
                
CarOn[entity] = true;
            }
        }
        else if (
is_chair[entity] == 2)
        {
            
AcceptEntityInput(entity"TurnOff");
            
CarOn[entity] = false;
        }
    
        
decl String:targetName[100];

        
decl Float:sprite_rgb[3];
        
sprite_rgb[0] = 0.0;
        
sprite_rgb[1] = 0.0;
        
sprite_rgb[2] = 0.0;
        
        
GetTargetName(entitytargetNamesizeof(targetName));
    
        new 
sprite CreateEntityByName("env_sprite");
        
        
DispatchKeyValue(sprite"model""materials/sprites/dot.vmt");
        
DispatchKeyValue(sprite"renderamt""0");
        
DispatchKeyValue(sprite"renderamt""0");
        
DispatchKeyValueVector(sprite"rendercolor"sprite_rgb);
        
DispatchSpawn(sprite);

        new 
Float:vec[3];
        
GetClientAbsOrigin(Drivervec);
        
GetClientAbsAngles(Driverang);
        
TeleportEntity(spritevecangNULL_VECTOR);

        
SetClientViewEntity(Driversprite);

        
//SetVariantString(targetName);
        
SetVariantString("!activator");
        
AcceptEntityInput(sprite"SetParent"Driver);
        
SetVariantString(targetName);
        
AcceptEntityInput(Driver"SetParent");

        
SetVariantString("vehicle_driver_eyes");
        
AcceptEntityInput(Driver"SetParentAttachment");
//        SetVariantString("vehicle_driver_eyes");
//        AcceptEntityInput(sprite, "SetParentAttachment");
        
//        SetEntProp(entity, Prop_Send, "m_nSolidType", 2);

        
        
ViewEnt[entity] = sprite;
    }
    if (
Driver 0)
    {
        
EyeFix(Driver);
        
drivers_car[Driver] = entity;
        
Driving[Driver] = true;
        
buttons2 GetClientButtons(Driver);
        
// Brake Lights on or Off

        
if (buttons2 IN_ATTACK)
        {
            if (!
CarHorn[Driver] && (is_chair[entity] <= 1))
            {
                
EmitSoundToAll("vehicles/mustang_horn.mp3"entitySNDCHAN_AUTOSNDLEVEL_AIRCRAFT);
                
CarHorn[Driver] = true;
                new 
Float:delay GetConVarFloat(g_Cvar_DelayH);
                
h_horn CreateTimer(delayHorn_TimeDriver);
            }
        }
        new 
car_index g_CarIndex[entity];    
        new 
max g_CarLightQuantity[car_index];
        if ((
max 0) && (is_chair[entity] == 0))
        {
            
decl light;
            if (
CarOn[entity])
            {
                
light g_CarLights[car_index][2];
                if (
IsValidEntity(light))
                {
                    
AcceptEntityInput(light"ShowSprite");
                    if ((
buttons2 IN_BACK) && !(buttons2 IN_JUMP))
                    {
                        
SetVariantInt(255);
                        
AcceptEntityInput(light"ColorGreenValue");
                        
SetVariantInt(255);
                        
AcceptEntityInput(light"ColorBlueValue");
                    }
                    else
                    {
                        
SetVariantInt(0);
                        
AcceptEntityInput(light"ColorGreenValue");
                        
SetVariantInt(0);
                        
AcceptEntityInput(light"ColorBlueValue");                    
                    }
                }
                
light g_CarLights[car_index][3];
                if (
IsValidEntity(light))
                {
                    
AcceptEntityInput(light"ShowSprite");
                    if ((
buttons2 IN_BACK) && !(buttons2 IN_JUMP))
                    {
                        
SetVariantInt(255);
                        
AcceptEntityInput(light"ColorGreenValue");
                        
SetVariantInt(255);
                        
AcceptEntityInput(light"ColorBlueValue");
                    }
                    else
                    {
                        
SetVariantInt(0);
                        
AcceptEntityInput(light"ColorGreenValue");
                        
SetVariantInt(0);
                        
AcceptEntityInput(light"ColorBlueValue");                    
                    }
                }
            }
            if (
buttons2 IN_JUMP)
            {    
                
light g_CarLights[car_index][0];
                if (
IsValidEntity(light))
                {
                    
AcceptEntityInput(light"ShowSprite");
                }
                
light g_CarLights[car_index][1];
                if (
IsValidEntity(light))
                {
                    
AcceptEntityInput(light"ShowSprite");
                }
            }
            else
            {    
                
light g_CarLights[car_index][0];
                if (
IsValidEntity(light))
                {
                    
AcceptEntityInput(light"HideSprite");
                }
                
light g_CarLights[car_index][1];
                if (
IsValidEntity(light))
                {
                    
AcceptEntityInput(light"HideSprite");
                }
            }
        }
        if (
GetConVarInt(g_Cvar_GasUse))
        {
            
// Car is on so they're burning gas
            // How fast they burn it depends on forewards or reverse or idle
            
if (buttons2 IN_FORWARD)
            {
                
car_fuel[entity] -= (0.001 mpg[entity]); // accelerate
            
}
            else if (
buttons2 IN_BACK)
            {
                
car_fuel[entity] -= (0.0005 mpg[entity]); // reverse
            
}
            else 
car_fuel[entity] -= (0.0001 mpg[entity]); //idle
            
            
if (car_fuel[entity] <= 0.0)
            {
                
car_fuel[entity] = 0.0;
                
AcceptEntityInput(entity"TurnOff");
            }
            
fuel_display[entity] = RoundToCeil(car_fuel[entity]);
            
SetEntData(Driverm_ArmorValue,fuel_display[entity],4,true);
        }
        if (
is_chair[entity] == 0)
        {
            new 
speed GetEntProp(entityProp_Data"m_nSpeed");
            if (
GetConVarInt(g_Cvar_GasUse))
            {
                
PrintHintText(Driver"%T""Speed+Gas"Driverspeedfuel_display[entity]);
            }
            else 
PrintHintText(Driver"%T""Speed"Driverspeed);
        }
/*        new hat = GetClientHatEntity(Driver);
        if (IsValidEntity(hat))
        {
            AcceptEntityInput(hat, "ClearParent", hat, hat, 0);
            new String:car_ent_name[128];
            GetTargetName(entity,car_ent_name,sizeof(car_ent_name));                
            SetVariantString(car_ent_name);
            AcceptEntityInput(hat, "SetParent", hat, hat, 0);
        } */
    
}

A lot of that crap looks like giberish I'm sure. Some of it is to handle seat entities for multiple passengers, and another section in the second block of code handles a view model of the driver. That stuff all works, I'm mostly trying to figure out the view issue and the getting stuck in the floor issue.
__________________
Talk to me on Steam: natalyaaf
See my website for downloads: www.lady-natalya.info

Natalya: killing someone while they make a plugin
Natalya: perfect analogy
Natalya: for the mayan apocalypse
NatalyaAF is offline
NatalyaAF
Senior Member
Join Date: Dec 2008
Old 01-11-2016 , 10:21   Re: Issues with prop_vehicle_driveable
Reply With Quote #2

Bump with some more information:

The way views are handled isn't the same as Garry's Mod. CS:S and CS:GO don't allow for third person, so the workaround is putting an attachment vehicle_driver_eyes inside the car about where the driver's eyes would be. Also, I put another attachment hovering above and behind the vehicle called vehicle_3rd for third person view.

When entering the car the player's eyes get attached to a sprite that is spawned at the vehicle_driver_eyes attachment. When they press crouch SM picks that up and toggles the attachment back and forth between that and vehicle_3rd.

When switching to 3rd person in GMod the player can see a ragdoll of their character in the car that roughly holds the wheel. CS:S and CS:GO don't appear to have that functionality, so I built in a CS:GO skeleton (or a CS:S skeleton for my older cars) and I spawn a prop of the player's player model inside the car and bonemerge it to the car so it holds the wheel and stuff. But if I deactivate all of the sprite shit and don't fuck with the player view entity at all then when the driver accelerates the view sort-of slips backwards and into the view model. If there was a way to make the view model NOT visible to the driver but visible to everyone else then that might solve half the problem, but then I still wouldn't have a mechanism for putting people into a 3rd-person view.

I think part of the problem is the sprite gets parented to !activator and the activator is the driver, so when the car rotates the driver rotates and the rotation doubles up causing the view to turn left or right. If I parent the sprite to the vehicle itself then the view doesn't turn left or right as the vehicle drives, but now the player can't look left or right, they're stuck looking forward.

Oh and for anyone who looked they might have seen EyeFix(Driver) which I forgot to post the code for:

PHP Code:
stock EyeFix(client)
{
    for (new 
players 1players <= MaxClientsplayers++) 
    { 
        if (
IsClientInGame(players) && IsPlayerAlive(players))
        {
            if (
players != client)
            {
                new 
vehicle GetEntPropEnt(playersProp_Send"m_hVehicle");
                if (
vehicle != -1)
                {
                    new 
FloatVehicleAng[3];
                    
VehicleAng[0] *=2;
                    
VehicleAng[1] *=2;
                    
VehicleAng[2] *=2;
                    
GetEntPropVector(vehicleProp_Data"m_angRotation"VehicleAng);
                    
SubtractVectors(CurrentEyeAngle[players], VehicleAngCurrentEyeAngle[players]);
                }
                
TeleportEntity(playersNULL_VECTORCurrentEyeAngle[players], NULL_VECTOR);
            }
        }
    }

That's a stock from blodia's now defunct vehicle mod. It would keep everyone else in the server from getting their view jerked left or right when a client entered a vehicle in CS:S. But maybe some part of this can be used to fix the driver's view problem?

The driver inherits the rotation of the vehicle so the screen turns but then the sprite inherits that rotation from the driver and it turns which turns the driver's view even more. I suspect this rotation stacking might not happen if the sprite was some other entity which never rotated or something, or if there was a way to parent only the position not the angles of the client's view to the sprite or something like that.
__________________
Talk to me on Steam: natalyaaf
See my website for downloads: www.lady-natalya.info

Natalya: killing someone while they make a plugin
Natalya: perfect analogy
Natalya: for the mayan apocalypse

Last edited by NatalyaAF; 01-11-2016 at 10:31.
NatalyaAF is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 01-11-2016 , 12:00   Re: Issues with prop_vehicle_driveable
Reply With Quote #3

So are you trying to make the client turn it's view screen to the direction of the turn?
Mitchell is offline
NatalyaAF
Senior Member
Join Date: Dec 2008
Old 01-11-2016 , 13:33   Re: Issues with prop_vehicle_driveable
Reply With Quote #4

That would be ideal but I would be okay if the client's view didn't turn at all when the car turned. The problem is when the car turns it turns the client's view twice as much as it should. If you watch the video in OP, at the beginning I drive down a hill and the curved invisible wall turns the car 90° to the left but my view ends up turning 180° to the left. I'd like the view to also turn 90° to the left, or for the view to not change at all.
__________________
Talk to me on Steam: natalyaaf
See my website for downloads: www.lady-natalya.info

Natalya: killing someone while they make a plugin
Natalya: perfect analogy
Natalya: for the mayan apocalypse
NatalyaAF is offline
Reply



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 17:57.


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