AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Model doesn't look right (https://forums.alliedmods.net/showthread.php?t=321006)

LordDeath 01-20-2020 02:20

Model doesn't look right
 
Seems that I got tired of trying, the issue is that the model looks wrong in the hologram, but fine once I start the car and drive with it around, is there a way to fix that?
https://i.imgur.com/qlBcNpC.png
Hologram Spawn:
Code:

CreateSavage(id)
{
    static func_breakable_id
 
    if (!func_breakable_id)
        func_breakable_id = engfunc(EngFunc_AllocString, "func_breakable")
 
    new iEntity = engfunc(EngFunc_CreateNamedEntity, func_breakable_id)
 
    if (!pev_valid(iEntity))
        return FM_NULLENT
 
    dllfunc(DLLFunc_Spawn, iEntity)
 
    if (!id)
        return iEntity
 
    set_pev(iEntity, pev_classname, "savage")
    set_pev(iEntity, pev_owner, id)
    set_pev(iEntity, pev_solid, SOLID_NOT)
    set_pev(iEntity, pev_movetype, MOVETYPE_PUSHSTEP)
    set_pev(iEntity, pev_frame, 0)
    set_pev(iEntity, pev_framerate, 0)
    set_pev(iEntity, pev_takedamage, 0.0)
    set_pev(iEntity, pev_renderfx, kRenderFxGlowShell)
    set_pev(iEntity, pev_renderamt, 5.0)
    engfunc(EngFunc_SetModel, iEntity, modelname)
    engfunc(EngFunc_SetSize, iEntity, {-4.0, -4.0, 0.0}, {4.0, 4.0, 4.0})
    new Float:StartAngle[3]
    pev(id, pev_angles, StartAngle)
    set_pev(iEntity, pev_angles, StartAngle)
    CheckEntityPosition(iEntity, id)
    g_iSavageEntity[id] = iEntity
    return iEntity
}

Code:

public savage_think(SavEnt)
{
    new SavID = pev(SavEnt, pev_owner)
 
    if (!is_user_alive(SavID) || zp_core_is_zombie(SavID))
    {
        RemoveSavages(SavID)
        return
    }
     
    new Float:FrameTime = (halflife_time() - fSavages[SavID][eLastTime])
    fSavages[SavID][eLastTime] = halflife_time()
     
    new Float:vOrigin[3]
    pev(SavEnt, pev_origin, vOrigin)
 
    // Health handling
    if (pev(SavEnt, pev_health) < 0.0)
    {
        DestroySavage(SavID, true)
        client_print(SavID, print_center, "Your Car got destroyed")
        //zp_grenade_frost_set(SavID, false)
        return
    }
 
    new Float:vVelocity[3]
    pev(SavEnt, pev_velocity, vVelocity)
 
    // That stupid collision box gets stuck behind every little bump , so force it to keep moving
    vVelocity[0] = fSavages[SavID][eVelocity_x] * 0.8 + vVelocity[0] * 0.2
    vVelocity[1] = fSavages[SavID][eVelocity_y] * 0.8 + vVelocity[1] * 0.2
 
    // Input handling
    new buttonpress = 0
    if (g_iSavageCamEntity[SavID] && g_iSavageEntity[SavID])
        buttonpress = pev(SavID, pev_button)
 
    new Float:EngineForce = fSavages[SavID][eEngineForce]
    new Float:TurnAngle = fSavages[SavID][eTurnAngle]
    new Float:BrakeForce = 0.0
    new Float:JumpForce = fSavages[SavID][eJumpForce]
 
    if (buttonpress & IN_ATTACK2 && JumpForce > -1.0)  // Jump
    {
        JumpForce += 5.0 * FrameTime 
        if (JumpForce > 3.0)    JumpForce = 3.0
    }
 
    if (buttonpress & IN_JUMP)  // Break
    {
        EngineForce = 0.0
        BrakeForce = MaxGrip
    }
 
    else if (buttonpress & IN_FORWARD)  // Forward
    {
        EngineForce += Accel * FrameTime
        if (EngineForce > MaxForce)
            EngineForce = MaxForce
    }
    else if (buttonpress & IN_BACK) // Back
    {
        EngineForce -= Accel * FrameTime
        if (EngineForce < MaxForce * -0.7)
            EngineForce = MaxForce * -0.7
    }
    else
        EngineForce = 0.0
 
    if (buttonpress & IN_MOVELEFT)  // Left
    {
        TurnAngle += 1.5 * FrameTime
        if (TurnAngle > 0.5)
            TurnAngle = 0.5
    }
    else if (buttonpress & IN_MOVERIGHT)    // Right
    {
        TurnAngle -= 1.5 * FrameTime
        if (TurnAngle < -0.5)
        TurnAngle = -0.5
    }
    else
    {
        if (floatabs(TurnAngle) < 0.2)
            TurnAngle = 0.0
        else if (TurnAngle > 0.0)
            TurnAngle -= 1.5 * FrameTime
        else if (TurnAngle < 0.0)
            TurnAngle += 1.5 * FrameTime
    }
 
    // dynamics handling 
    new Float:vAngles[3]
    pev(SavEnt, pev_angles, vAngles)
    new Float:Angle = vAngles[1] / 180 * M_PI
 
    new Float:Speed = floatsqroot( vVelocity[0]*vVelocity[0] +vVelocity[1]*vVelocity[1] )
    new Float:VelocityAngle = floatatan2( vVelocity[1], vVelocity[0], radian )
 
    new Float:Grip = 0.0
 
    new Float:Accel_x = -1 * Drag * vVelocity[0]
    new Float:Accel_y = -1 * Drag * vVelocity[1]
 
    new Float:vAVelocity[3]
    pev(SavEnt, pev_avelocity, vAVelocity)
 
    if (!pev(SavEnt, pev_flags))
    {
        // Set angle startpoint for stunts calculations
        if (JumpForce > -1.0 && !(buttonpress & IN_ATTACK2))
        {
            set_pev(SavEnt, pev_startpos, vAngles)
            JumpForce = -1.0
        }
     
        set_pev(SavEnt, pev_endpos, vAngles)
     
        if (buttonpress & IN_FORWARD)
        {
            vAVelocity[0] += 800.0 * FrameTime
            if (vAVelocity[0] > 500.0)
                vAVelocity[0] = 500.0
        }
        else if (buttonpress & IN_BACK)
        {
            vAVelocity[0] -= 800.0 * FrameTime
            if (vAVelocity[0] < -500.0)
            vAVelocity[0] = -500.0
        }
        else
        {
            if (floatabs(vAVelocity[0]) < 80.0)
                vAVelocity[0] = 0.0
            else if (vAVelocity[0] > 0.0)
                vAVelocity[0] -= 800.0 * FrameTime
            else if (vAVelocity[0] < 0.0)
                vAVelocity[0] += 800.0 * FrameTime
        }
 
        if (buttonpress & IN_MOVELEFT)
        {
            vAVelocity[1] += 800.0 * FrameTime * dSavages[SavID][eDirection]
            if (vAVelocity[1] > 500.0)
                vAVelocity[1] = 500.0
        }
        else if (buttonpress & IN_MOVERIGHT)
        {
            vAVelocity[1] -= 800.0 * FrameTime * dSavages[SavID][eDirection]
            if (vAVelocity[1] < -500.0)
                vAVelocity[1] = -500.0
        }
        else
        {
            if (floatabs(vAVelocity[1]) < 80.0)
                vAVelocity[1] = 0.0
            else if (vAVelocity[1] > 0.0)
                vAVelocity[1] -= 800.0 * FrameTime
            else if (vAVelocity[1] < 0.0)
                vAVelocity[1] += 800.0 * FrameTime
        }
    }
    else if ((pev(SavEnt, pev_flags) & FL_INWATER) && (engfunc(EngFunc_PointContents, vOrigin) == CONTENTS_SKY))
    {
        new Float:vBump[3]
        vBump[0] = vOrigin[0] - vVelocity[0] * FrameTime
        vBump[1] = vOrigin[1] - vVelocity[1] * FrameTime
        vBump[2] = vOrigin[2] - vVelocity[2] * FrameTime
        set_pev(SavEnt, pev_origin, vBump)
     
        vVelocity[0] *= -0.5
        vVelocity[1] *= -0.5
        vVelocity[2] *= -0.5
        set_pev(SavEnt, pev_velocity, vVelocity)
    }
    else
    {
        if (floatcos(vAngles[0], degrees) < -0.1)  // Upside down in the ground, so crashed
        {
            TakeSavageBack(SavID)
            client_print(SavID, print_center, "Your car was almost crashed, write /rc to spawn it again")
            return
        }
     
        // Just landed, check stunts
        if (JumpForce < 0.0)
            JumpForce = 0.0
     
        if (Speed > 0.1)
            Grip = floatsin(Angle - VelocityAngle)
 
        new Float:TireGrip = Grip
        if (TireGrip < MaxGrip*-1.0) TireGrip = MaxGrip*-1.0
        else if (TireGrip > MaxGrip) TireGrip = MaxGrip
 
        // 3-speed gearbox
        if (Speed > MaxForce * 1.1)
        {
            if(fSavages[SavID][eGear] < 1.5)
                EngineForce *= 0.5
            fSavages[SavID][eGear] = 1.6
            TireGrip *= 0.6
        }
        else if (Speed > MaxForce * 0.7 && Speed < MaxForce * 0.9)
        {         
            if (fSavages[SavID][eGear] < 1.2 || fSavages[SavID][eGear] > 1.4 )
                EngineForce *= 0.5
            fSavages[SavID][eGear] = 1.3 
            TireGrip *= 0.8
        }
        else if (Speed < MaxForce * 0.5)
            fSavages[SavID][eGear] = 1.0
 
        // Check direction the car is going
        if (floatcos(Angle - VelocityAngle) > 0.0)
            dSavages[SavID][eDirection] = 1
        else
            dSavages[SavID][eDirection] = -1
     
        //Acceleration
        Accel_x += floatcos(Angle) * EngineForce * fSavages[SavID][eGear]
        Accel_y += floatsin(Angle) * EngineForce * fSavages[SavID][eGear]
     
        //Braking
        Accel_x -= floatcos(Angle) * BrakeForce * Speed * dSavages[SavID][eDirection]
        Accel_y -= floatsin(Angle) * BrakeForce * Speed * dSavages[SavID][eDirection]
     
        //Sideways friction ( drifting)
        Accel_x -= floatcos( Angle - M_PI/2 ) * TireGrip * Speed * 10  // Cheap but working tracktion
        Accel_y -= floatsin( Angle - M_PI/2 ) * TireGrip * Speed * 10
     
        new Float:vNewAngle[3]
        vector_to_angle(vVelocity, vNewAngle) 
        vAngles[0] = vNewAngle[0] * dSavages[SavID][eDirection]
     
        vVelocity[0] += Accel_x * FrameTime// * floatcos(CurAng[1], degrees)
        vVelocity[1] += Accel_y * FrameTime// * floatcos(CurAng[1], degrees)
     
        // Rotational force doesn't excists, but i got it right here :)
        vAVelocity[0] = 0.0
        vAVelocity[1] = Speed * floatsin(TurnAngle) * (1-floatabs(Grip)) * dSavages[SavID][eDirection]
        vAVelocity[2] = 0.0
     
        if (!(buttonpress & IN_ATTACK2) && JumpForce > 0.0)
        {
            vVelocity[2] += JumpForce * 100
            JumpForce = 0.0
            entity_set_byte(SavEnt, EV_BYTE_controller1, 127)
            entity_set_byte(SavEnt, EV_BYTE_controller2, 127)
        }
        else
            vVelocity[2] -= Gravity * FrameTime // To stop him from riding up the wall, almost
         
        set_pev(SavEnt, pev_velocity, vVelocity)
        entity_set_byte(SavEnt, EV_BYTE_controller1, floatround((EngineForce-Speed*0.1)/MaxForce *-32)+127)
        entity_set_byte(SavEnt, EV_BYTE_controller2, floatround(TireGrip*(Speed/MaxForce)*32)+127)
    }
 
    entity_set_byte(SavEnt, EV_BYTE_controller3, floatround(TurnAngle*192)+127)
    set_pev(SavEnt, pev_framerate, dSavages[SavID][eDirection]*Speed/100)
 
    vAngles[0] += vAVelocity[0] * FrameTime
    vAngles[1] += vAVelocity[1] * FrameTime
    vAngles[2] += vAVelocity[2] * FrameTime
    set_pev(SavEnt, pev_angles, vAngles)
    set_pev(SavEnt, pev_avelocity, vAVelocity)
 
    fSavages[SavID][eEngineForce] = EngineForce
    fSavages[SavID][eTurnAngle] = TurnAngle
    fSavages[SavID][eVelocity_x] = vVelocity[0]
    fSavages[SavID][eVelocity_y] = vVelocity[1]
    fSavages[SavID][eVelocity_z] = vVelocity[2]
    fSavages[SavID][eJumpForce] = JumpForce
 
    // sound
    new Float:pitch = floatabs(EngineForce/MaxForce) + Speed/1000
    if (fSavages[SavID][eNextSoundTime] < halflife_time())
    {
        emit_sound(SavEnt, CHAN_VOICE, "shmod/savage_engine.wav", VOL_NORM, ATTN_NORM, 0, 80+floatround(pitch*50) )
        fSavages[SavID][eNextSoundTime] = halflife_time() + 0.5
    }
    else if(fSavages[SavID][eNextPitchTime] < halflife_time())
    {
        emit_sound(SavEnt, CHAN_VOICE, "shmod/savage_engine.wav", VOL_NORM, ATTN_NORM, SND_CHANGE_PITCH, 80+floatround(pitch*50) )
        fSavages[SavID][eNextPitchTime] = halflife_time() + 0.1
    }
 
    set_pev(SavEnt, pev_nextthink, halflife_time() + 0.04)
}
 
public camera_think(CamEnt)
{
    new SavID = pev(CamEnt, pev_owner)
 
    if (!is_valid_ent(SavID)) return
 
    new Float:TargetOrigin[3], Float:CameraOrigin[3], Float:CameraAngles[3]
    pev(g_iSavageEntity[SavID], pev_origin, TargetOrigin)
    pev(CamEnt, pev_origin, CameraOrigin)
    pev(CamEnt, pev_angles, CameraAngles)
 
    new Float:Direction[3], Float:Angles[3]
    Direction[0] = (TargetOrigin[0] - CameraOrigin[0])
    Direction[1] = (TargetOrigin[1] - CameraOrigin[1])
    Direction[2] = (CameraOrigin[2] - TargetOrigin[2])
 
    vector_to_angle(Direction, Angles)
    Angles[0] -= CameraAngles[0]
    Angles[1] -= CameraAngles[1]
 
    Angles[0] = floatsin(Angles[0], degrees) * 500
    Angles[1] = floatsin(Angles[1], degrees) * 500
 
    set_pev(CamEnt, pev_avelocity, Angles)
 
    new Float:Distance = (vector_distance(TargetOrigin, CameraOrigin) - 100) / 50
    Direction[0] *= Distance
    Direction[1] *= Distance
    Direction[2] = (TargetOrigin[2] - CameraOrigin[2] + 50) * Distance
    set_pev(CamEnt, pev_velocity, Direction)
 
    if (g_iSavageCamEntity[SavID] && g_iSavageEntity[SavID])
        set_pev(CamEnt, pev_nextthink, halflife_time() + 0.1)
}

savage think (when the car starts moving around) ^ above
The car spawn:
Code:

SpawnSavage(id)
{
    if (!is_user_alive(id) || zp_core_is_zombie(id))
        return PLUGIN_CONTINUE
 
    new SavEnt = g_iSavageEntity[id]
 
    if (!pev_valid(SavEnt))
        return PLUGIN_HANDLED
 
    if (!pev(SavEnt, pev_iuser2))
    {
        engfunc(EngFunc_RemoveEntity, SavEnt)
        zp_colored_print(id, "!tYou can't place Remote car here.")
    //    SpawnFakeSavage(id)       
        set_task(2.0,"OpenSavageMenu", id)
        return PLUGIN_HANDLED
    }
 
  // set_pev(SavEnt, pev_framerate, 0.0)
    set_pev(SavEnt, pev_solid, SOLID_SLIDEBOX)
    set_pev(SavEnt, pev_movetype, MOVETYPE_PUSHSTEP)
    set_pev(SavEnt, pev_friction, 0.0000001)
    set_pev(SavEnt, pev_takedamage, 1.0)
    set_pev(SavEnt, pev_health, get_pcvar_float(g_pCvarSavageCarHP))
    set_pev(SavEnt, pev_sequence, 1)
//    set_pev(SavEnt, pev_framerate, 0)
    set_pev(SavEnt, pev_framerate, 20.0)
    set_pev(SavEnt, pev_body, 3)
    g_iHasSavage[id] -= 1
    g_bHasSpawned[id] = true
    g_bIsSpawningCar[id] = false
 
    RegisterHamFromEntity(Ham_TakeDamage, SavEnt, "Ham_SavageTakeDamage_Pre", false)
    RegisterHamFromEntity(Ham_TakeDamage, SavEnt, "Ham_SavageTakeDamage_Post", true)
 
    new Float:StartAngle[3]
    pev(id, pev_angles, StartAngle)
    //StartAngle[1] = 270.0
    //StartAngle[0] = 90.0 //get_pcvar_float(g_pcvarSavageAngel)
    set_pev(SavEnt, pev_angles, StartAngle)
    set_pev(SavEnt, pev_nextthink, halflife_time() + 0.01)
 
    if (get_pcvar_num(g_pCvarChaseCam))
    {
        new CamEnt = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
 
        if (!pev_valid(CamEnt))
            return PLUGIN_HANDLED
 
        g_iSavageCamEntity[id] = CamEnt
     
        set_pev(CamEnt, pev_classname, "camera")
        set_pev(CamEnt, pev_owner, id)
        set_pev(CamEnt, pev_rendermode, kRenderTransColor)
        engfunc(EngFunc_SetModel, CamEnt, "models/rpgrocket.mdl")
        set_pev(CamEnt, pev_solid, SOLID_NOT)
        set_pev(CamEnt, pev_movetype, MOVETYPE_NOCLIP)
        set_pev(CamEnt, pev_angles, StartAngle)
 
        new Float:StartOrigin[3], Float:Angle = StartAngle[1] / 180 * M_PI
        pev(id, pev_origin, StartOrigin)
        StartOrigin[0] -= floatcos(Angle) * 110
        StartOrigin[1] -= floatsin(Angle) * 110
        StartOrigin[2] += 50
        set_pev(CamEnt, pev_origin, StartOrigin)
        set_pev(CamEnt, pev_nextthink, halflife_time() + 0.05)
        attach_view(id, CamEnt)
    }
 
    new Float:time = halflife_time()
    fSavages[id][eLastTime] = time
    fSavages[id][eNextSoundTime] = time
    fSavages[id][eNextPitchTime] = time
 
    Accel = get_pcvar_float(g_pCvarAccel)
    MaxForce = get_pcvar_float(g_pCvarMaxForce)
    MaxGrip = get_pcvar_float(g_pCvarMaxGrip)
    MaxGrip *= MaxGrip
    Drag = get_pcvar_float(g_pCvarDrag)
    if (MaxGrip > 1.0)  MaxGrip = 1.0
    if (Drag > 1.0) Drag = 1.0
 
    //Gravity = get_cvar_num("sv_gravity")
    //set_user_maxspeed(id, 0.1)
    zp_grenade_frost_set(id, true)
    set_rendering(SavEnt)
    //g_bHasSpawned[id] = true
    new szName[32]
    get_user_name(id, szName, charsmax(szName))
    ColorChat(0,GREEN,"^03 %s ^01 Spawned a ^04 Race Car", szName)
    return PLUGIN_HANDLED
}


georgik57 01-21-2020 17:33

Re: Model doesn't look right
 
not sure, but it looks like it's using some other animation. try forcing the animation you use when "driving" it after you spawn it.


All times are GMT -4. The time now is 02:40.

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