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