Senior Member
|
01-11-2016
, 00:53
Issues with prop_vehicle_driveable
|
#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, &impulse, Float: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(client, Prop_Send, "m_hVehicle") != -1) { LeaveVehicle(client); buttons &= ~IN_USE; PressingUse[client] = true; OldButtons[client] = buttons; return Plugin_Handled; } else { decl Ent; Ent = GetClientAimTarget(client, false); if (IsValidEdict(Ent)) { decl String:ClassName[255]; GetEdictClassname(Ent, ClassName, 255);
//Valid: if (StrEqual(ClassName, "prop_vehicle_driveable", false)) { new Float:origin[3]; new Float:car_origin[3]; new Float:distance;
GetClientAbsOrigin(client, origin); GetEntPropVector(Ent, Prop_Send, "m_vecOrigin", car_origin); distance = GetVectorDistance(origin, car_origin, false); // 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(Ent, Prop_Data, "m_bLocked")) && (distance <= 88.00)) { // Car in range, unlocked. new Driver = GetEntPropEnt(Ent, Prop_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] + 1; ic++ ) { GetEdictClassname(cars_seat_entities[Ent][ic], ClassName2, 255); 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 t = cars_type[Ent]; SetVariantString(""); AcceptEntityInput(chair, "SetParent", chair, chair, 0); AcceptEntityInput(chair, "use", client); new String:car_name2[128]; GetTargetName(Ent,car_name2,sizeof(car_name2)); SetVariantString(car_name2); AcceptEntityInput(chair, "SetParent", chair, chair, 0); SetVariantString(car_passenger_attachment[t][ic]); AcceptEntityInput(chair, "SetParentAttachment", chair, chair, 0);
break; } } } } } } else { EmitSoundToAll("doors/default_locked.wav", Ent, SNDCHAN_AUTO, SNDLEVEL_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(entity, Prop_Send, "m_hPlayer"); if (Driver > 0) { new car = GetEntPropEnt(Driver, Prop_Send, "m_hVehicle"); if (car != entity) { PrintToChatAll("\x04[Car] ERROR"); LeaveVehicle(Driver); SDKUnhook(car, SDKHook_Think, OnThink); SDKHook(car, SDKHook_Think, OnThink); AcceptEntityInput(car, "Use", Driver); } } decl Float:ang[3]; if (IsValidEntity(ViewEnt[entity])) { if (Driver > 0) { if(IsClientInGame(Driver) && IsPlayerAlive(Driver)) { SetEntProp(entity, Prop_Data, "m_nNextThinkTick", 1); SetEntPropFloat(entity, Prop_Data, "m_flTurnOffKeepUpright", 1.0); //SetClientViewEntity(Driver, ViewEnt[entity]); Driving[Driver] = true; new t = 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(Driver, model, sizeof(model)); DispatchKeyValue(prop, "model", model); DispatchKeyValue(prop, "skin","0"); ActivateEntity(prop); DispatchSpawn(prop); new enteffects = GetEntProp(prop, Prop_Send, "m_fEffects"); enteffects |= 1; enteffects |= 128; enteffects |= 512; SetEntProp(prop, Prop_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", prop, prop, 0); SetVariantString("vehicle_driver_eyes"); AcceptEntityInput(prop, "SetParentAttachment", prop, prop, 0); 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(entity, Prop_Send, "m_bEnterAnimOn") == 1) { SetEntProp(entity, Prop_Send, "m_nSequence", 0); CarHorn[Driver] = false; armour[Driver] = GetEntProp(Driver, Prop_Send, "m_ArmorValue"); SetEntProp(entity, Prop_Send, "m_bEnterAnimOn", 0); SetEntProp(entity, Prop_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(entity, targetName, sizeof(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(Driver, vec); GetClientAbsAngles(Driver, ang); TeleportEntity(sprite, vec, ang, NULL_VECTOR);
SetClientViewEntity(Driver, sprite);
//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", entity, SNDCHAN_AUTO, SNDLEVEL_AIRCRAFT); CarHorn[Driver] = true; new Float:delay = GetConVarFloat(g_Cvar_DelayH); h_horn = CreateTimer(delay, Horn_Time, Driver); } } 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(Driver, m_ArmorValue,fuel_display[entity],4,true); } if (is_chair[entity] == 0) { new speed = GetEntProp(entity, Prop_Data, "m_nSpeed"); if (GetConVarInt(g_Cvar_GasUse)) { PrintHintText(Driver, "%T", "Speed+Gas", Driver, speed, fuel_display[entity]); } else PrintHintText(Driver, "%T", "Speed", Driver, speed); } /* 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
|
|