Ledge climb
#1

Hello Scripters, I've been thinking of a feature for my project which i don't think will be that hard to create using the samp default functions and codes and i need your help in creating it.

I'm thinking of creating a function where if a player is grabbing the ledge, He can press the side movement controls to move side by side, I think this can be done with the SetPlayerVelocity, Or if you have a better idea, Please drop it below, Also we're gunna have to detect where the ledge finishes so the player won't get bugged flying somewhere else.
Reply
#2

The setplayervelocity idea is hard to get right, but I have actually done it before. For it to work better players have to get used to spamming the jump key a little bit.

You have to first set the player ~0.05 behind his position and to the direction he is going, then down ~0.05.
After that, set his velocity toward the ledge. If the player was not spamming jump, it may not always grab the ledge. If he was spamming jump, it will most of the time. I don't know how to perfect it, but this is similar to how I did it a long time ago.
Reply
#3

Just wrote this for you. It has been tested but has no code to prevent abuse.

Usage:
- Jump onto a ledge; then press jump again to get put into movement mode.
- Move your character using "Y" (negative x) and "N" (positive x).
- Press jump again to get released from the ledge.

Things to consider:
- You should add a way to figure out when a object ends, so the player can't freely move around the map
- You should add an alternate function to allow players to climb on top / over of ledges.

pawn Код:
new bool: p_ClimbingLedge[MAX_PLAYERS char];

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    new Float: pX, Float: pY, Float: pZ;
    GetPlayerPos(playerid, pX, pY, pZ);

    if(newkeys & KEY_JUMP)
    {
        if(IsPlayerClimbingLedge(playerid))
        {
            if(p_ClimbingLedge{playerid})
            {
                TogglePlayerControllable(playerid, true);
                p_ClimbingLedge{playerid} = false;
               
                return true;
            }
       
            TogglePlayerControllable(playerid, false);
            p_ClimbingLedge{playerid} = true;
           
            ApplyAnimation(playerid, "PED", "CLIMB_idle", 4.1, 0, 1, 1, 1, 0, 1);
        }
    }

    if(newkeys & KEY_YES)
    {
        if(IsPlayerClimbingLedge(playerid) && p_ClimbingLedge{playerid})
        {
            SetPlayerPos(playerid, pX - 1, pY, pZ);
            ApplyAnimation(playerid, "PED", "CLIMB_idle", 4.1, 0, 1, 1, 1, 0, 1);
        }
    }
   
    if(newkeys & KEY_NO)
    {
        if(IsPlayerClimbingLedge(playerid) && p_ClimbingLedge{playerid})
        {
            SetPlayerPos(playerid, pX + 1, pY, pZ);
            ApplyAnimation(playerid, "PED", "CLIMB_idle", 4.1, 0, 1, 1, 1, 0, 1);
        }
    }

    return true;
}

IsPlayerClimbingLedge(playerid)
{
    new const animlist[][] = {
        {"CLIMB_idle"},
        {"CLIMB_jump"},
        {"CLIMB_jump_B"},
        {"CLIMB_Pull"}
    };

    static animlib[32], animname[32];

    GetAnimationName(GetPlayerAnimationIndex(playerid), animlib, sizeof(animlib), animname, sizeof(animname));
   
    for(new i; i < sizeof(animlist); i ++)
    {
        if(strcmp(animname, animlist[i][0], true) == 0)
        {
            return true;
        }
    }
   
    return false;
}
Here's a preview of what it looks like: https://www.youtube.com/watch?v=iXKXTrVlggU
Reply
#4

Quote:
Originally Posted by Mionee
Посмотреть сообщение
Just wrote this for you. It has been tested but has no code to prevent abuse.
Very nice, but there is one slight issue, what if they're not always facing North or South? What happens when you change the facing angle? You end up going straight through buildings or floating off into the air. You should be taking the player's rotation into consideration. As you mentioned, the 'end of the object' is the trickiest part.
Reply
#5

Quote:
Originally Posted by Threshold
Посмотреть сообщение
Very nice, but there is one slight issue, what if they're not always facing North or South? What happens when you change the facing angle? You end up going straight through buildings or floating off into the air. You should be taking the player's rotation into consideration.
I completely overlooked that, thanks for mentioning!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)