Search

open.mp forum

RegisterLogin

Discussion

General
Chat
Tech
Life
Art
Programming
open.mp
Development Updates
Questions and Suggestions
SA-MP
General Discussions
Videos and Screenshots
Support
Pawn Scripting
Tutorials
Releases
Plugins
Libraries
Filterscripts
Gamemodes
Maps
Advertisements
Other languages
Spanish/Espa?ol
Programaci?n
Discusi?n GTA SA Multijugador
Mods
Offtopic
Juegos
Portuguese/Portugu?s
Russian/???????
Italian/Italiano
Dutch/Nederlands
German/Deutsch
Romanian/Rom?na
Ex-Yu
Polish/Polski
Og?lne
Serwery
Skryptowanie
Filmiki i zdjecia
Lithuanian/Lietuvi?kas
French/Fran?ais
Hungarian/Magyar
Hindi/Urdu
Turkish
Other
Internal
Team
Hidden
Archived

Library

 Collections Links Members Roles

Pathfinding with ColAndreas and FCNPC

I'm trying both to make npcs move around randomly and follow a player, yet there are 2 main problems.

ID
d6ouivfilegovhg7be90
author
sf-kan3's avatar

[SF]kAn3

@sf-kan3


View profile
Copy link
  Report member
started
Dec 23, 2019
replies
0
participating
No

scroll to top

powered by storyden

Login
Discussion
Pawn Scripting
Pathfinding with ColAndreas and FCNPC
sf-kan3's avatar

[SF]kAn3

@sf-kan3


View profile
Copy link
  Report member
• 6y
Pawn Scripting

Pathfinding with ColAndreas and FCNPC

pawn

I'm trying both to make npcs move around randomly and follow a player, yet there are 2 main problems.



1 - While randomly moving, npcs sometimes fall a bit under the ground surface, and then they start going up and down the surface real fast, making severe eye damage if you look at them

2 - When following someone, they will climb any object that is on their way, regardless of its height. For example, if there's a tree between me and the npc, he won't avoid the tree so you will see it going from the ground to the top of the tree while walking. Same thing happens for any other object.



Randomly move around:





GoRandom(npcid){

?? ?if(!FCNPC_IsValid(npcid)){

?? ??? ?printf(" Invalid NPC: %d", npcid);

?? ??? ?return;

?? ?}

??? if(FCNPC_IsMoving(npcid)){

?? ??? ?return;

?? ?}

?? ?if(FCNPC_IsDead(npcid)){

?? ??? ?return;

?? ?}

? ? if(FCNPC_IsAttacking(npcid)){

? ? ?? return;

? ? }

??? new Float: startX, Float: startY, Float: startZ, Float: nx, Float: ny, Float: nz, Float: rx, Float: ry, Float: rz, chance = random(2), bool: positivecoord;

?? ?FCNPC_GetPosition(npcid, startX, startY, startZ);

?? ?positivecoord = (chance == 0) ? true : false;

?? ?startX = (positivecoord == true) ? startX  random(20)  15 : startX - random(20)  15;

?? ?startY = (positivecoord == true) ? startY  random(20)  15 : startY - random(20)  15;

?? ?FCNPC_GetPosition(npcid, nx, ny, nz);

?? ?CA_FindZ_For2DCoord(startX, startY, startZ);

?? ?CA_FindZ_For2DCoord(nx, ny, nz);



?? ?if(CA_RayCastLine(startX, startY, startZ, nx, ny, nz, rx, ry, rz) == 0){

?? ??? ?FCNPC_GoTo(npcid, startX, startY, startZ, FCNPC_MOVE_TYPE_WALK, FCNPC_MOVE_SPEED_AUTO, true);

?? ??? ?FCNPC_ApplyAnimation(npcid, "PED", "WALK_DRUNK", 4.1, 1, 1, 1, 0, 0);

?? ?}



?? ?return;

}





Follow the player:





if(IsPlayerInRangeOfPoint(npcid,45.0,xa,ya,za) && CA_RayCastLine(xa, ya, za, nx, ny, nz, rx, ry, rz) == 0){ // if is near player and there's no object between them

??? FCNPC_GoTo(npcid,xa,ya,za,MOVE_TYPE_RUN,0.4, true);

? ? return 1;

}





Am I doing it wrong, there already is a pathfinding method in FCNPC or CA or anything similar? Also I found Dijkstra (https://pastebin.com/RwQZ1PWy) is it obsolete?

Any help will be appreciated.

0 likes0 replies

    Please sign up or log in to reply