Nade Prediction

Posts 1–12 of 12 · Page 1 of 1
Granade trajectory code
Does anyone here have or know how to code the granade trajectory code lines?
I thought teamgamerfood internal had these.
Quote Originally Posted by Joplin View Post
I thought teamgamerfood internal had these.
I only need the code part for it though
Next time google it.
Next time GOOGLE it!
php code:
Code:
class CPredictGrenade
{
public:
    CPredictGrenade(Vector InitialPosition, Vector InitialVelocity, C_BaseEntity* pEnt, CDrawing drawing)
    {
        vInitialVelocity = InitialVelocity;
        vInitialPosition = InitialPosition;
        draw = drawing;
        pEntity = pEnt;
    }

    void Draw()
    {
        const float TIMEALIVE = 2.0f;
        const float GRENADE_COEFFICIENT_OF_RESTITUTION = 0.4f;
        float step = 0.1f;//TIMEALIVE / NUMBLOOPS;
        float gravity = 800.0f / TIMEALIVE;
        float friction = 0.8f;
        DWORD ent = (DWORD)pEntity;
        Vector position;
        Vector startpos = vInitialPosition;
        Vector throwvec = vInitialVelocity;
        int collisions = 0;

        for (float timelive = 0.0f; timelive < TIMEALIVE; timelive += step)
        {
            position = startpos + throwvec * step;

            trace_t tr;
            _asm
            {
                mov eax, ent
                lea ecx, tr
                push ecx
                push 6 // push 6 traces through windows
                push eax
                push MASK_SOLID
                lea edx, position
                lea ecx, startpos
                call offys.g_dwTraceLine
                add esp, 0x10
            }
            
            if (tr.DidHit()) // if the trace hits a surface
            {
                //isHit = true;
                float anglez = DotProduct(Vector(0, 0, 1), tr.plane.normal);
                float invanglez = DotProduct(Vector(0, 0, -1), tr.plane.normal);
                float angley = DotProduct(Vector(0, 1, 0), tr.plane.normal);
                float invangley = DotProduct(Vector(0, -1, 0), tr.plane.normal);
                float anglex = DotProduct(Vector(1, 0, 0), tr.plane.normal);
                float invanglex = DotProduct(Vector(-1, 0, 0), tr.plane.normal);
                float scale = math.flGetDistance(tr.endpos, pEntity->GetAbsOrigin()) / 2;
                Color color = Color(0, 0, 255);
                if (anglez > 0.5)
                {
                    tr.endpos.z += 1;
                    Vector startPos = tr.endpos + Vector(-scale, 0, 0);
                    Vector endPos = tr.endpos + Vector(scale, 0, 0);
                    Vector outStart, outEnd;
                    if (draw.WorldToScreen(startPos, outStart) && draw.WorldToScreen(endPos, outEnd))
                        draw.DrawLine(outStart.x, outStart.y, outEnd.x, outEnd.y, color);
            
                    startPos = tr.endpos + Vector(0, -scale, 0);
                    endPos = tr.endpos + Vector(0, scale, 0);
                    if (draw.WorldToScreen(startPos, outStart) && draw.WorldToScreen(endPos, outEnd))
                        draw.DrawLine(outStart.x, outStart.y, outEnd.x, outEnd.y, color);
                }
                else if (invanglez > 0.5)
                {
                    tr.endpos.z += 1;
                    Vector startPos = tr.endpos + Vector(-scale, 0, 0);
                    Vector endPos = tr.endpos + Vector(scale, 0, 0);
                    Vector outStart, outEnd;
                    if (draw.WorldToScreen(startPos, outStart) && draw.WorldToScreen(endPos, outEnd))
                        draw.DrawLine(outStart.x, outStart.y, outEnd.x, outEnd.y, color);
            
                    startPos = tr.endpos + Vector(0, -scale, 0);
                    endPos = tr.endpos + Vector(0, scale, 0);
                    if (draw.WorldToScreen(startPos, outStart) && draw.WorldToScreen(endPos, outEnd))
                        draw.DrawLine(outStart.x, outStart.y, outEnd.x, outEnd.y, color);
                }
                else if (angley > 0.5)
                {
                    tr.endpos.y += 1;
                    Vector startPos = tr.endpos + Vector(0, 0, -scale);
                    Vector endPos = tr.endpos + Vector(0, 0, scale);
                    Vector outStart, outEnd;
                    if (draw.WorldToScreen(startPos, outStart) && draw.WorldToScreen(endPos, outEnd))
                        draw.DrawLine(outStart.x, outStart.y, outEnd.x, outEnd.y, color);
            
                    startPos = tr.endpos + Vector(-scale, 0, 0);
                    endPos = tr.endpos + Vector(scale, 0, 0);
                    if (draw.WorldToScreen(startPos, outStart) && draw.WorldToScreen(endPos, outEnd))
                        draw.DrawLine(outStart.x, outStart.y, outEnd.x, outEnd.y, color);
                }
                else if (invangley > 0.5)
                {
                    tr.endpos.y += 1;
                    Vector startPos = tr.endpos + Vector(0, 0, -scale);
                    Vector endPos = tr.endpos + Vector(0, 0, scale);
                    Vector outStart, outEnd;
                    if (draw.WorldToScreen(startPos, outStart) && draw.WorldToScreen(endPos, outEnd))
                        draw.DrawLine(outStart.x, outStart.y, outEnd.x, outEnd.y, color);
            
                    startPos = tr.endpos + Vector(-scale, 0, 0);
                    endPos = tr.endpos + Vector(scale, 0, 0);
                    if (draw.WorldToScreen(startPos, outStart) && draw.WorldToScreen(endPos, outEnd))
                        draw.DrawLine(outStart.x, outStart.y, outEnd.x, outEnd.y, color);
                }
                else if (anglex > 0.5)
                {
                    tr.endpos.x += 1;
                    Vector startPos = tr.endpos + Vector(0, -scale, 0);
                    Vector endPos = tr.endpos + Vector(0, scale, 0);
                    Vector outStart, outEnd;
                    if (draw.WorldToScreen(startPos, outStart) && draw.WorldToScreen(endPos, outEnd))
                        draw.DrawLine(outStart.x, outStart.y, outEnd.x, outEnd.y, color);
            
                    startPos = tr.endpos + Vector(0, 0, -scale);
                    endPos = tr.endpos + Vector(0, 0, scale);
                    if (draw.WorldToScreen(startPos, outStart) && draw.WorldToScreen(endPos, outEnd))
                        draw.DrawLine(outStart.x, outStart.y, outEnd.x, outEnd.y, color);
                }
                else if (invanglex > 0.5)
                {
                    tr.endpos.x += 1;
                    Vector startPos = tr.endpos + Vector(0, -scale, 0);
                    Vector endPos = tr.endpos + Vector(0, scale, 0);
                    Vector outStart, outEnd;
                    if (draw.WorldToScreen(startPos, outStart) && draw.WorldToScreen(endPos, outEnd))
                        draw.DrawLine(outStart.x, outStart.y, outEnd.x, outEnd.y, color);
            
                    startPos = tr.endpos + Vector(0, 0, -scale);
                    endPos = tr.endpos + Vector(0, 0, scale);
                    if (draw.WorldToScreen(startPos, outStart) && draw.WorldToScreen(endPos, outEnd))
                        draw.DrawLine(outStart.x, outStart.y, outEnd.x, outEnd.y, color);
                }
            
                //float proj = DotProduct(throwvec, tr.plane.normal);
                throwvec = -2.0f * tr.plane.normal * DotProduct(throwvec, tr.plane.normal) + throwvec;
                throwvec *= GRENADE_COEFFICIENT_OF_RESTITUTION;
                collisions++;
                if (collisions > 2)
                    break;
            
                position = startpos + throwvec * tr.fraction * step;
            
                timelive += (step * (1 - tr.fraction));
            } // end of bounce
            
            Vector vOutStart, vOutEnd;
            if (draw.WorldToScreen(startpos, vOutStart), draw.WorldToScreen(position, vOutEnd))
            {
                draw.DrawLine(vOutStart.x, vOutStart.y, vOutEnd.x, vOutEnd.y, Color(0, 255, 0));
            }
            
            startpos = position;
            throwvec.z -= gravity * tr.fraction * step;
        }
    }

private:
    CDrawing draw;
    Vector vInitialVelocity; //the velocity by which you will shoot the projectile
    Vector vInitialPosition;
    C_BaseEntity* pEntity;
};
BTW you didn't say what language...
Quote Originally Posted by HarryMidnight View Post
Next time GOOGLE it!
php code:
Code:
class CPredictGrenade
{
public:
    CPredictGrenade(Vector InitialPosition, Vector InitialVelocity, C_BaseEntity* pEnt, CDrawing drawing)
    {
        vInitialVelocity = InitialVelocity;
        vInitialPosition = InitialPosition;
        draw = drawing;
        pEntity = pEnt;
    }

    void Draw()
    {
        const float TIMEALIVE = 2.0f;
        const float GRENADE_COEFFICIENT_OF_RESTITUTION = 0.4f;
        float step = 0.1f;//TIMEALIVE / NUMBLOOPS;
        float gravity = 800.0f / TIMEALIVE;
        float friction = 0.8f;
        DWORD ent = (DWORD)pEntity;
        Vector position;
        Vector startpos = vInitialPosition;
        Vector throwvec = vInitialVelocity;
        int collisions = 0;

        for (float timelive = 0.0f; timelive < TIMEALIVE; timelive += step)
        {
            position = startpos + throwvec * step;

            trace_t tr;
            _asm
            {
                mov eax, ent
                lea ecx, tr
                push ecx
                push 6 // push 6 traces through windows
                push eax
                push MASK_SOLID
                lea edx, position
                lea ecx, startpos
                call offys.g_dwTraceLine
                add esp, 0x10
            }
            
            if (tr.DidHit()) // if the trace hits a surface
            {
                //isHit = true;
                float anglez = DotProduct(Vector(0, 0, 1), tr.plane.normal);
                float invanglez = DotProduct(Vector(0, 0, -1), tr.plane.normal);
                float angley = DotProduct(Vector(0, 1, 0), tr.plane.normal);
                float invangley = DotProduct(Vector(0, -1, 0), tr.plane.normal);
                float anglex = DotProduct(Vector(1, 0, 0), tr.plane.normal);
                float invanglex = DotProduct(Vector(-1, 0, 0), tr.plane.normal);
                float scale = math.flGetDistance(tr.endpos, pEntity->GetAbsOrigin()) / 2;
                Color color = Color(0, 0, 255);
                if (anglez > 0.5)
                {
                    tr.endpos.z += 1;
                    Vector startPos = tr.endpos + Vector(-scale, 0, 0);
                    Vector endPos = tr.endpos + Vector(scale, 0, 0);
                    Vector outStart, outEnd;
                    if (draw.WorldToScreen(startPos, outStart) && draw.WorldToScreen(endPos, outEnd))
                        draw.DrawLine(outStart.x, outStart.y, outEnd.x, outEnd.y, color);
            
                    startPos = tr.endpos + Vector(0, -scale, 0);
                    endPos = tr.endpos + Vector(0, scale, 0);
                    if (draw.WorldToScreen(startPos, outStart) && draw.WorldToScreen(endPos, outEnd))
                        draw.DrawLine(outStart.x, outStart.y, outEnd.x, outEnd.y, color);
                }
                else if (invanglez > 0.5)
                {
                    tr.endpos.z += 1;
                    Vector startPos = tr.endpos + Vector(-scale, 0, 0);
                    Vector endPos = tr.endpos + Vector(scale, 0, 0);
                    Vector outStart, outEnd;
                    if (draw.WorldToScreen(startPos, outStart) && draw.WorldToScreen(endPos, outEnd))
                        draw.DrawLine(outStart.x, outStart.y, outEnd.x, outEnd.y, color);
            
                    startPos = tr.endpos + Vector(0, -scale, 0);
                    endPos = tr.endpos + Vector(0, scale, 0);
                    if (draw.WorldToScreen(startPos, outStart) && draw.WorldToScreen(endPos, outEnd))
                        draw.DrawLine(outStart.x, outStart.y, outEnd.x, outEnd.y, color);
                }
                else if (angley > 0.5)
                {
                    tr.endpos.y += 1;
                    Vector startPos = tr.endpos + Vector(0, 0, -scale);
                    Vector endPos = tr.endpos + Vector(0, 0, scale);
                    Vector outStart, outEnd;
                    if (draw.WorldToScreen(startPos, outStart) && draw.WorldToScreen(endPos, outEnd))
                        draw.DrawLine(outStart.x, outStart.y, outEnd.x, outEnd.y, color);
            
                    startPos = tr.endpos + Vector(-scale, 0, 0);
                    endPos = tr.endpos + Vector(scale, 0, 0);
                    if (draw.WorldToScreen(startPos, outStart) && draw.WorldToScreen(endPos, outEnd))
                        draw.DrawLine(outStart.x, outStart.y, outEnd.x, outEnd.y, color);
                }
                else if (invangley > 0.5)
                {
                    tr.endpos.y += 1;
                    Vector startPos = tr.endpos + Vector(0, 0, -scale);
                    Vector endPos = tr.endpos + Vector(0, 0, scale);
                    Vector outStart, outEnd;
                    if (draw.WorldToScreen(startPos, outStart) && draw.WorldToScreen(endPos, outEnd))
                        draw.DrawLine(outStart.x, outStart.y, outEnd.x, outEnd.y, color);
            
                    startPos = tr.endpos + Vector(-scale, 0, 0);
                    endPos = tr.endpos + Vector(scale, 0, 0);
                    if (draw.WorldToScreen(startPos, outStart) && draw.WorldToScreen(endPos, outEnd))
                        draw.DrawLine(outStart.x, outStart.y, outEnd.x, outEnd.y, color);
                }
                else if (anglex > 0.5)
                {
                    tr.endpos.x += 1;
                    Vector startPos = tr.endpos + Vector(0, -scale, 0);
                    Vector endPos = tr.endpos + Vector(0, scale, 0);
                    Vector outStart, outEnd;
                    if (draw.WorldToScreen(startPos, outStart) && draw.WorldToScreen(endPos, outEnd))
                        draw.DrawLine(outStart.x, outStart.y, outEnd.x, outEnd.y, color);
            
                    startPos = tr.endpos + Vector(0, 0, -scale);
                    endPos = tr.endpos + Vector(0, 0, scale);
                    if (draw.WorldToScreen(startPos, outStart) && draw.WorldToScreen(endPos, outEnd))
                        draw.DrawLine(outStart.x, outStart.y, outEnd.x, outEnd.y, color);
                }
                else if (invanglex > 0.5)
                {
                    tr.endpos.x += 1;
                    Vector startPos = tr.endpos + Vector(0, -scale, 0);
                    Vector endPos = tr.endpos + Vector(0, scale, 0);
                    Vector outStart, outEnd;
                    if (draw.WorldToScreen(startPos, outStart) && draw.WorldToScreen(endPos, outEnd))
                        draw.DrawLine(outStart.x, outStart.y, outEnd.x, outEnd.y, color);
            
                    startPos = tr.endpos + Vector(0, 0, -scale);
                    endPos = tr.endpos + Vector(0, 0, scale);
                    if (draw.WorldToScreen(startPos, outStart) && draw.WorldToScreen(endPos, outEnd))
                        draw.DrawLine(outStart.x, outStart.y, outEnd.x, outEnd.y, color);
                }
            
                //float proj = DotProduct(throwvec, tr.plane.normal);
                throwvec = -2.0f * tr.plane.normal * DotProduct(throwvec, tr.plane.normal) + throwvec;
                throwvec *= GRENADE_COEFFICIENT_OF_RESTITUTION;
                collisions++;
                if (collisions > 2)
                    break;
            
                position = startpos + throwvec * tr.fraction * step;
            
                timelive += (step * (1 - tr.fraction));
            } // end of bounce
            
            Vector vOutStart, vOutEnd;
            if (draw.WorldToScreen(startpos, vOutStart), draw.WorldToScreen(position, vOutEnd))
            {
                draw.DrawLine(vOutStart.x, vOutStart.y, vOutEnd.x, vOutEnd.y, Color(0, 255, 0));
            }
            
            startpos = position;
            throwvec.z -= gravity * tr.fraction * step;
        }
    }

private:
    CDrawing draw;
    Vector vInitialVelocity; //the velocity by which you will shoot the projectile
    Vector vInitialPosition;
    C_BaseEntity* pEntity;
};
BTW you didn't say what language...
i have googled it and only found outdated codes
Quote Originally Posted by GemDG View Post
i have googled it and only found outdated codes
I just sent you the first result that came up... Also, why are you making a paste? Just use the code I shared to learn from not to copy. It is way better! Make your own... Be a good coder pls. don't be a paste maker.
Quote Originally Posted by HarryMidnight View Post


I just sent you the first result that came up... Also, why are you making a paste? Just use the code I shared to learn from not to copy. It is way better! Make your own... Be a good coder pls. don't be a paste maker.
Well i'm not even a coder a friend of mine is but he doesn't want to make the code for a hack
Quote Originally Posted by GemDG View Post
Well i'm not even a coder a friend of mine is but he doesn't want to make the code for a hack
Then just use something like DDX, Quecheat, KateBot or HookTronic...
You are just going to get your self vac baned if you don't know what you are doing.
Quote Originally Posted by HarryMidnight View Post


Then just use something like DDX, Quecheat, KateBot or HookTronic...
You are just going to get your self vac baned if you don't know what you are doing.
Who says this code is for me i clearly said that i can't code and that the code is not for me but a friend of mine who does know what he's doing
Quote Originally Posted by GemDG View Post
Who says this code is for me i clearly said that i can't code and that the code is not for me but a friend of mine who does know what he's doing
If your friend knew what he was doing why would he have to paste?
Quote Originally Posted by GemDG View Post
Who says this code is for me i clearly said that i can't code and that the code is not for me but a friend of mine who does know what he's doing
Ok, but my point is stil valid. Also your fend needs to learn how not to paste, but it is slightly acceptable to paste at the beginning... Almost everyone does that when they develop their very first hack (paste).
so google again and find a better and more precise code in the same exact thread. its not outdated by the way.
Posts 1–12 of 12 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us