Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Float: CORRER = 0.0084;
- const Float: COUPE = 0.006;
- const Float: ANDAR = 0.0016;
- const FOOT_RATE = 200;
- const Float: Z_CORRECTION = 0.075;
- const CALL_SYNC = 10;
- native SetNPCVelocity(npc, Float:x, Float:y, Float:z);
- native SetNPCPos(npc, Float:x, Float:y, Float:z);
- native CreateBuild(npc, Float:x, Float:y, Float:z);
- native SaveBuild(npc);
- native SetNPCTime(npc, time);
- native SetNPCKey(npc, key);
- native GetNPCKey(npc);
- native SetNPCArmour(npc, armour);
- native GetNPCArmour(npc);
- native SetNPCWeapon(npc, armour);
- native GetNPCWeapon(npc);
- native SetNPCHealth(npc, health);
- native GetNPCHealth(npc);
- native SetNPCSpecialAction(npc, anime);
- native GetNPCSpecialAction(npc);
- native SetNPCAngle(npc, Float:w, Float:x, Float:y, Float:z);
- #define KEYUP 0x00FF
- #define KEYDOWN 0xFF00
- stock IsNPCConnected[MAX_PLAYERS char];
- native SetNPCUpDownKey(npc,key) ;
- native FinishBuild(npc);
- stock PlayBuild(npc) return SendClientMessage(npc, -1, "L");
- stock StopBuild(npc) return SendClientMessage(npc, -1, "U");
- stock SetNPCRepeat(npc, bool: repeat) return SendClientMessage(npc, -1, repeat ? "R" : "N" );
- stock CreateINPC(npcname[]) {
- static i ;
- for( i = 0; i != MAX_PLAYERS; i++) {
- if(!IsPlayerNPC(i) && !IsPlayerConnected(i) && !IsNPCConnected {i}) {
- IsNPCConnected {i} = 1;
- break;
- }
- }
- ConnectNPC(npcname, "INPC");
- return i;
- }
- stock DestroyINPC(npcid) {
- StopBuild(npc);
- Kick(npc);
- }
- stock bool: IsNPCArmed(npc) return !!GetPlayerWeapon(npc);
- stock SetNPCVirtualWorld(npc, virtual) return SetPlayerVirtualWorld(npc, virtual);
- stock GetNPCVirtualWorld(npc) return GetPlayerVirtualWorld(npc);
- stock SetNPCInterior(npc, inte) return SetPlayerInterior(npc, inte);
- stock GetNPCInterior(npc) return GetPlayerInterior(npc);
- stock GetNPCSkin(npc) return GetPlayerSkin(npc);
- stock IsPlayerNearOfNPC(playerid, npc , Float:dis) {
- static Float:x, Float:y, Float:z;
- GetNPCPos(npc, x , y ,z);
- return IsPlayerInRangeOfPoint(playerid, dis, x ,y ,z );
- }
- stock MoveNPC(npc, Float:toX, Float:toY, Float:toZ, Float: speed) {
- toZ += Z_CORRECTION;
- if(speed < 0.0005) {
- #if defined DEBUG
- printf("Erro: NPC %d está muito lento (vel %f)", npc,speed);
- #endif
- return false;
- }
- static Float: pos[4];
- if(!GetPlayerPos(npc, pos[0] , pos[1] , pos[2])) return false;
- static Float: vel[2], Float: distancia;
- pos[3] = atan2( toY - pos[1], toX - pos[0] );
- vel[0]= (speed * floatcos(pos[3], degrees));
- vel[1]= (speed * floatsin(pos[3], degrees));
- distancia = floatsqroot( (toX - pos[0]) * ( toX - pos[0] ) + ( toY - pos[1] ) * ( toY - pos[1] ) + ( toZ - pos[2] ) * ( toZ - pos[2] ) );
- if(distancia < 1.0) {
- #if defined DEBUG
- printf("Erro: O NPC está muito próximo do destino (%f metros)", npc, distancia);
- #endif
- return false;
- }
- static tempo, blocos;
- tempo = floatround( distancia / speed );
- if(!tempo) {
- #if defined DEBUG
- printf("Erro: NPC %d está demorando muito pouco tempo para chegar no destino (tempo %d)", npc,tempo);
- #endif
- return false;
- }
- blocos= tempo / FOOT_RATE;
- if(!blocos) {
- #if defined DEBUG
- printf("Erro: NPC %d não tem nenhum caminho para ser calculado (%d blocos)", npc,blocos);
- #endif
- return false;
- }
- static Float: parteX, Float: parteY, Float: parteZ, Float: w;
- tempo = tempo / blocos;
- parteX = pos[0];
- parteX = pos[1];
- parteZ = pos[2];
- Euler2Quat( 90 - pos[3] , w, parteX, parteY, parteZ);
- SetNPCAngle(npc, w, parteX, parteY, parteZ);
- parteX = (toX-pos[0])/blocos;
- parteY = (toY-pos[1])/blocos;
- parteZ = (toZ-pos[2])/blocos;
- SetNPCVelocity(npc, vel[0], vel[1], 0.0);
- SetNPCUpDownKey(npc, KEYUP);
- CreateBuild(npc, pos[0], pos[1], pos[2]);
- static i ;
- for( i = 0; i != blocos; ++ i) {
- SetNPCPos(npc, pos[0] + (i * parteX), pos[1] + (i * parteY), (pos[2] + (i * parteZ)));
- SetNPCTime(npc, FOOT_RATE * i);
- SaveBuild(npc);
- }
- SetNPCUpDownKey(npc, 0);
- SetNPCTime(npc, FOOT_RATE * (blocos + 1));
- SetNPCVelocity(npc, 0.0, 0.0, 0.0);
- SaveBuild(npc);
- FinishBuild(npc);
- PlayBuild(npc);
- return true;
- }
- #define IsNPCNearOfPlayer IsPlayerNearOfNPC
- stock SetNPCSkin(npc, skin) return SetPlayerSkin(npc, skin);
- stock SetNPCAngleToXYZ(npc, Float:x2, Float:y2, Float:z2) {
- static Float: x1, Float: y1 , Float: z1, Float: w, Float: a;
- if(!GetPlayerPos(npc, x1 , y1 , z1)) return false;
- a = atan2(y2 - y1 , x2 - x1);
- while(a < 0) a += 360.0;
- while(a > 360) a -= 360.0;
- Euler2Quat( 90.0 - angle, w, x2, y2, z2);
- SetNPCAngle(npc, w, x2, y2, z2);
- return true;
- }
- stock Euler2Quat(Float: angle, &Float:w, &Float:x, &Float:y, &Float:z) {
- static
- Float:s
- ;
- s = (angle *(3.14/180)) / 2;
- z = floatsin(s);
- x *= z;
- y *= z;
- w = floatcos(s);
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement