16.04.2010, 18:45
Usage:
WalkNPC(playerid, Float, Float:y, Float:z, bool:run);
StopWalkNPC(playerid);
Code:
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);
}