AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   old origin (fall damage) (https://forums.alliedmods.net/showthread.php?t=313185)

CrazY. 12-30-2018 16:40

old origin (fall damage)
 
Hello, I'm trying to save player's origin before of he fell and "teleport" him to this origin if he receive fall damage. Since is there no specific way to do this, what I did then was loop through players each 0.1 seconds, save their origin and teleport they when receive fall damage.

It's working but sometimes the saved origin is the same point from where they fall, so when I teleport them, they stay falling infinitly. Also, I tried to save origin while they climb ladder, but if I teleport them to this origin, same problem happen.

Spoiler

raizo11 12-31-2018 06:00

Re: old origin (fall damage)
 
Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <hamsandwich>
#include <fakemeta>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "raizo"

new his_position[33][3]
new last_position[33][3]

new maxplayers

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)
   
    RegisterHam(Ham_TakeDamage, "player", "Player_TakeDamage", false);

    maxplayers = get_maxplayers();

    set_task(1.0,"update",0,"",0,"b",0)

}

public update()
{
    for(new id;id < maxplayers;id++)
    {
        if(is_user_alive(id))
        {
            check(id)
        }
    }
}

public Player_TakeDamage(id, iInflictor, iAttacker, Float: fDamage, bitsDamageType)
{
    if(!is_user_connected(id))
    {
        return HAM_IGNORED;
    }
   
    if(bitsDamageType & DMG_FALL && fDamage >= pev(id, pev_health))
    {
        move_to_check(id)
        return HAM_SUPERCEDE;
    }
   
    return HAM_IGNORED;
}

stock move_to_check(id)
{
        set_pev(id, pev_origin, his_position[id])
}

public check(id)
{
    if(is_user_alive(id))
    {
        if(!(pev(id, pev_flags) & FL_ONGROUND))
        {
            return PLUGIN_HANDLED;
        }
        last_position[id][0] = his_position[id][0]
        last_position[id][1] = his_position[id][1]
        last_position[id][2] = his_position[id][2]
        pev(id, pev_origin, his_position[id])
        his_position[id][2] += 5
        return PLUGIN_HANDLED;
    }
    return PLUGIN_HANDLED;
}


E1_531G 12-31-2018 10:45

Re: old origin (fall damage)
 
Save only the last position when the player is on the ground.

raizo11 12-31-2018 11:26

Re: old origin (fall damage)
 
Quote:

Originally Posted by CrazY. (Post 2631889)
I'm trying to save player's origin before of he fell and "teleport" him to this origin if he receive fall damage.

Is not that what you wanted? be more explicit

CrazY. 12-31-2018 11:30

Re: old origin (fall damage)
 
Quote:

Originally Posted by E1_531G (Post 2632021)
Save only the last position when the player is on the ground.

That's what I did.

Code:
if (!(pev(pPlayer, pev_flags) & FL_ONGROUND))         continue;


Quote:

Originally Posted by raizo11 (Post 2631972)
Spoiler

It's the exact same way as I did.

shauli 12-31-2018 11:39

Re: old origin (fall damage)
 
You mean that the origin is in the air or it's on the ground but he's falling because he has some velocity?
If it's velocity, just reset it.

Also, there's something similar on this plugin, you might want to take a look:
https://forums.alliedmods.net/showthread.php?p=806220

Black Rose 12-31-2018 15:56

Re: old origin (fall damage)
 
Do a check with traceline if the position is "safe" before saving it.

CrazY. 12-31-2018 17:17

Re: old origin (fall damage)
 
O_o

Are you sure you read the code that I provided? Because all these suggestions are there...

Quote:

Originally Posted by CrazY. (Post 2631889)
Code:
public plugin_init() {     set_task(0.1, "HandleFallDamageTask", TASK_FALLDAMAGE, .flags = "b");     RegisterHam(Ham_TakeDamage, "player", "CBasePlayer_TakeDamage"); } public HandleFallDamageTask(iTaskId) {     new Players[MAX_PLAYERS], iPlayerCount;     get_players(Players, iPlayerCount, "ach");     new Float:vecOrigin[3], Float:vecEnd[3], Float:flFallVelocity, Float:flFraction, i, pPlayer, hTr;     hTr = create_tr2();     for (i = 0; i < iPlayerCount; i++)     {         pPlayer = Players[i];         pev(pPlayer, pev_flFallVelocity, flFallVelocity);         if (flFallVelocity > 0.0)             continue;         if (!(pev(pPlayer, pev_flags) & FL_ONGROUND))             continue;         pev(pPlayer, pev_origin, vecOrigin);         xs_vec_copy(vecOrigin, vecEnd);         if (pev(pPlayer, pev_flags) & FL_DUCKING)             vecEnd[2] -= 36.0;         else             vecEnd[2] -= 74.0;         engfunc(EngFunc_TraceLine, vecOrigin, vecEnd, IGNORE_MONSTERS, pPlayer, hTr);         get_tr2(hTr, TR_flFraction, flFraction);         if (flFraction >= 0.9)             continue;         xs_vec_copy(vecOrigin, g_vecOrigin[pPlayer]);     }     free_tr2(hTr); } public CBasePlayer_TakeDamage(this, pInflictor, pAttacker, Float:flDamage, bitsDamageType) {     if (!(bitsDamageType & DMG_FALL))         return HAM_IGNORED;     set_pev(this, pev_velocity, Float:{0.0, 0.0, 0.0});     set_pev(this, pev_punchangle, Float:{0.0,0.0,0.0});     engfunc(EngFunc_SetOrigin, this, g_vecOrigin[this]);     SetHamReturnInteger(false);     return HAM_SUPERCEDE; }


Black Rose 12-31-2018 18:52

Re: old origin (fall damage)
 
Quote:

Originally Posted by CrazY. (Post 2632088)
O_o

Are you sure you read the code that I provided? Because all these suggestions are there...

I actually didn't, sorry.

Natsheh 12-31-2018 19:21

Re: old origin (fall damage)
 
I really cant think about anything else than using player prethink forward in this.

PHP Code:

#define PLAYER_FATAL_FALL_SPEED 980.0
#define PLAYER_MAX_SAFE_FALL_SPEED 500.0 // ithink this should be 350.0 not sure
#define PLAYER_FALL_PUNCH_THRESHHOLD 250.0

static Float:fSafeOrigin[33][3];

public 
client_prethink(id)
{
       if(!
is_user_alive(id)) return;

       if((
pev(idpev_flags) & FL_ONGROUND))
       {
            
pev(idpev_originfSafeOrigin[id]);
       }
       else {
            static 
Float:fVelocity[3]
            
pev(idpev_velocityfVelocity)

            if( 
fVelocity[2] <  -PLAYER_MAX_SAFE_FALL_SPEED  ) {
                  
set_pev(idpev_originfSafeOrigin[id])
                  
set_pev(idpev_velocityFloat:{0.0,0.0,0.0});
            }
        }




All times are GMT -4. The time now is 07:37.

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