WalkNPC Function.
#1

Usage:

WalkNPC(playerid, Float, Float:y, Float:z, bool:run);
StopWalkNPC(playerid);

Code:

pawn Код:
new walkobject[MAX_PLAYERS];
new naber[MAX_PLAYERS];

forward WalkNPC(playerid,Float:x,Float:y,Float:z,bool:run);
public WalkNPC(playerid,Float:x,Float:y,Float:z,bool:run)
{
    if(IsPlayerNPC(playerid))
    {
        new Float:xe,Float:ye,Float:ze;
        ApplyAnimation(playerid,"ped","null",0.0,0,0,0,0,0);
        KillTimer(naber[playerid]);
        if(IsValidPlayerObject(playerid,walkobject[playerid]))
        {
            DestroyPlayerObject(playerid,walkobject[playerid]);
        }
        SetPlayerLookAt(playerid,x,y);
        GetPlayerPos(playerid,xe,ye,ze);
        walkobject[playerid] = CreatePlayerObject(playerid, 1248, xe, ye, ze-100, 0, 0, 0 );
        if (run)
        {
            ApplyAnimation(playerid,"ped","run_player",4.1,1,1,1,1,1);
            MovePlayerObject(playerid,walkobject[playerid],x,y,z-100,5.0);
        }
        else
        {
            ApplyAnimation(playerid,"ped","WALK_player",4.1,1,1,1,1,1);
            MovePlayerObject(playerid,walkobject[playerid],x,y,z-100,1.5);
        }
        naber[playerid] = SetTimerEx("Walk",10,true,"i",playerid);
        return 1;
    }
    return 0;
}

forward Walk(playerid);
public Walk(playerid)
{
new Float:xe,Float:ye,Float:ze;
GetPlayerObjectPos(playerid,walkobject[playerid],xe,ye,ze);
SetPlayerPos(playerid,xe,ye,ze+100);
return 1;
}

forward StopWalkNPC(playerid);
public StopWalkNPC(playerid)
{
KillTimer(naber[playerid]);
ApplyAnimation(playerid, "CARRY", "crry_prtial", 4.0, 0, 0, 0, 0, 0);
DestroyPlayerObject(playerid,walkobject[playerid]);
return 1;
}

public OnPlayerObjectMoved(playerid,objectid)
{
    if (objectid == walkobject[playerid])
    {
        StopWalkNPC(playerid);
    }
    return 1;
}

stock SetPlayerLookAt(playerid, Float:x, Float:y)
{
    new Float:Px, Float:Py, Float: Pa;
    GetPlayerPos(playerid, Px, Py, Pa);
    Pa = floatabs(atan((y-Py)/(x-Px)));
    if (x <= Px && y >= Py) Pa = floatsub(180, Pa);
    else if (x < Px && y < Py) Pa = floatadd(Pa, 180);
    else if (x >= Px && y <= Py) Pa = floatsub(360.0, Pa);
    Pa = floatsub(Pa, 90.0);
    if (Pa >= 360.0) Pa = floatsub(Pa, 360.0);
    SetPlayerFacingAngle(playerid, Pa);
}
Reply
#2

More info and some screen shots ?
Reply
#3

By looking at the code it makes the NPC walk in different style.
Reply
#4

Quote:
Originally Posted by ineoncore
By looking at the code it makes the NPC walk in different style.
Experienced scripters can understand that, but the newbie scripters will have difficulties.
Reply
#5

This function can be added gm or fs.

After this, NPC can walk with this function. Not required record file.
Reply
#6

This is more a snippet.. You should post this to 'Usefull Snippets'
http://forum.sa-mp.com/index.php?topic=12197.0
Reply
#7

could be done way easier by setting a walk animation that doesn't reset pos on anim termination, and just end the anim when the NPC stops walkin (apply carry anim ), so no timer or stuff, just 2 checks and an animation.

Also your WalkNPC can pass through walls, animation one doesn't...


Altho gratz for trying.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)