Walking npc

Started by habi2, Oct 29, 2024, 01:28 PM

Previous topic - Next topic

habi2

npcscripts/test.nut

MiamiScale_Init("default.map")
t<-GetTickCount();

lastpos<-Vector(0,0,0);

function Walk()
{
local lastpos=GetMyPos();
local newpos=move2(lastpos,GetMyFacingAngle(), 0.22,0)  //pos,pangle,dis,angle)
local z=FindZFor2DCoord(newpos.x, newpos.y);
if(!z)
{
Stop();
return;
}
else newpos.z=z+ 0.5; //Update z co-ordinate so that npc do not float in air/fall down.

//Check wall, etc.
if(newpos.z-lastpos.z > 0.5)
{
//cannot move forward
Stop();
SendChat("I can't go further");
print("the jump is "+(newpos.z-lastpos.z)+" to "+newpos+" from "+lastpos+"\n");
return
}
SetLocalValue(F_POSX,newpos.x);
SetLocalValue(F_POSY,newpos.y);
SetLocalValue(F_POSZ,newpos.z);
SetLocalValue(I_KEYS, KEY_ONFOOT_FORWARD)
SetLocalValue(V_ONFOOT_SPEED, (newpos-lastpos).Normalised()*0.12688)
SendOnFootSyncDataLV()
}
function Stop()
{
if(timer!=null)
KillTimer(timer)
//Send stationary-npc packet (stop walking)
SetLocalValue(I_KEYS, 0)
SetLocalValue(V_ONFOOT_SPEED, Vector(0,0,0))
SendOnFootSyncDataLV()
}
timer<-null
function MainFunc()
{
if(timer!=null)
KillTimer(timer)
timer<-SetTimerEx("Walk", 50, 0);
}

function OnPlayerText(pid,text)
{
if(text=="run"||text=="walk")MainFunc();
else if(text=="stop")Stop()
else if(text=="come"){Stop();SetMyPos(GetPlayerPos(pid));}
else if(text=="turn around"||text=="ta")SetMyFacingAngle(GetMyFacingAngle()+PI)
else if(text=="update")dofile("npcscripts/test.nut");
}

//Functions used to get the values...
/*
function OnPlayerUpdate(pid, utype)
{
if(utype==PLAYERUPDATE_NORMAL  )
{
local speed=GetPlayerSpeed(pid).Length();
if(speed > 0)
{
local now=GetTickCount();
//print(now-t+" "+speed+"\n");

local pos=GetPlayerPos(pid);
//print(now-t+" "+(pos-lastpos).Length()+"\n");
local s=50*(pos-lastpos).Length()/(now-t);
//print(s+"\n");
t=now;
lastpos=pos;
}
}
}*/
//speed=0.12688, 50 ms, s=0.334, dis 0.22

Command-line
//Assuming current working directory is that of server32.exe as well as npcclient_0471.exe
//Connect to 127.0.0.1 8192
npcclient_0471.exe -n habi0 -c -q z-finder
dofile("npcscripts/test.nut")
Note that we have loaded the npc additional plugin z-finder located in npcscripts/plugins.

Type come in chat and npc teleport to you. Then use walk and it will run straight. stop to stop it. Type ta or turn around and npc change angle by 180 degree.



PSL

#1
Thanks for this tutorial, very useful.
This script allows the NPC to move in a face-facing direction.

PSL

I made a script for NPCS walking freely last December, but it didn't work very well, it used random points and random angles, it was like walking around, it didn't work very well at all.

[TDA]Speed

hey habi can you make a one with path finding or ai something like that?

habi2

Hi [TDA]Speed, we can definitely think about making a path-finding npc. In fact from an IPL file, the path can be found. Ah yes, when given command to go to a location, it will walk through the road making left turn or right turn. it is possible now.

vitovc

it is possible but he wants you to code pathfinding for him xD
actually there is alot of AI-stuff can be done (and needed for DM-gamemods). I feel fear when I imagine how much work should be done to make npc to act like real players in terms of DM.
...::: vice city :::...
Useful things for vcmp: Relative position and finding an angle (in 3d), 3d line (like laser)

[TDA]Speed

Quote from: habi2 on Nov 04, 2024, 05:05 PMHi [TDA]Speed, we can definitely think about making a path-finding npc. In fact from an IPL file, the path can be found. Ah yes, when given command to go to a location, it will walk through the road making left turn or right turn. it is possible now.
i just knew that path finding maybe could be lag but i tried to understand the walking script code of yours what if player gets close exmple npc cop and wanted player if the wanted player near to npc he will start follow him like
this is from npc walking script if( GetDistanceFromMeToPoint( pos ) < 2 ) WalkToPoint( pos );
pos = wanted player.Pos
so would this work ?

[TDA]Speed

Quote from: vitovc on Nov 04, 2024, 06:44 PMit is possible but he wants you to code pathfinding for him xD
actually there is alot of AI-stuff can be done (and needed for DM-gamemods). I feel fear when I imagine how much work should be done to make npc to act like real players in terms of DM.
maybe we can make something more easliy then this like know the nearest pos of npc and walk to it

MEGAMIND

#8
Quote from: [TDA]Speed on Nov 10, 2024, 09:30 AM
Quote from: vitovc on Nov 04, 2024, 06:44 PMit is possible but he wants you to code pathfinding for him xD
actually there is alot of AI-stuff can be done (and needed for DM-gamemods). I feel fear when I imagine how much work should be done to make npc to act like real players in terms of DM.
maybe we can make something more easliy then this like know the nearest pos of npc and walk to it

i did it eventaully u can do it too, get the nearest player id from distanceotpoint and walk it there.. an example here it moves twoards the loaction of player where ever it is going

[TDA]Speed

Quote from: MEGAMIND on Nov 10, 2024, 10:30 AM
Quote from: [TDA]Speed on Nov 10, 2024, 09:30 AM
Quote from: vitovc on Nov 04, 2024, 06:44 PMit is possible but he wants you to code pathfinding for him xD
actually there is alot of AI-stuff can be done (and needed for DM-gamemods). I feel fear when I imagine how much work should be done to make npc to act like real players in terms of DM.
maybe we can make something more easliy then this like know the nearest pos of npc and walk to it

i did it eventaully u can do it too, get the nearest player id from distanceotpoint and walk it there.. an example here it moves twoards the loaction of player where ever it is going
Quote from: MEGAMIND on Nov 10, 2024, 10:30 AM
Quote from: [TDA]Speed on Nov 10, 2024, 09:30 AM
Quote from: vitovc on Nov 04, 2024, 06:44 PMit is possible but he wants you to code pathfinding for him xD
actually there is alot of AI-stuff can be done (and needed for DM-gamemods). I feel fear when I imagine how much work should be done to make npc to act like real players in terms of DM.
maybe we can make something more easliy then this like know the nearest pos of npc and walk to it

i did it eventaully u can do it too, get the nearest player id from distanceotpoint and walk it there.. an example here it moves twoards the loaction of player where ever it is going
lool man thats awsome! nick work

MEGAMIND

#10
Quote from: [TDA]Speed on Nov 10, 2024, 04:12 PM
Quote from: MEGAMIND on Nov 10, 2024, 10:30 AM
Quote from: [TDA]Speed on Nov 10, 2024, 09:30 AM
Quote from: vitovc on Nov 04, 2024, 06:44 PMit is possible but he wants you to code pathfinding for him xD
actually there is alot of AI-stuff can be done (and needed for DM-gamemods). I feel fear when I imagine how much work should be done to make npc to act like real players in terms of DM.
maybe we can make something more easliy then this like know the nearest pos of npc and walk to it

i did it eventaully u can do it too, get the nearest player id from distanceotpoint and walk it there.. an example here it moves twoards the loaction of player where ever it is going
Quote from: MEGAMIND on Nov 10, 2024, 10:30 AM
Quote from: [TDA]Speed on Nov 10, 2024, 09:30 AM
Quote from: vitovc on Nov 04, 2024, 06:44 PMit is possible but he wants you to code pathfinding for him xD
actually there is alot of AI-stuff can be done (and needed for DM-gamemods). I feel fear when I imagine how much work should be done to make npc to act like real players in terms of DM.
maybe we can make something more easliy then this like know the nearest pos of npc and walk to it

i did it eventaully u can do it too, get the nearest player id from distanceotpoint and walk it there.. an example here it moves twoards the loaction of player where ever it is going
lool man thats awsome! nick work
u cant test that npc.ai at my server more of that want in depth knowledge ? https://forum.vc-mp.org/index.php?topic=3350.msg54387#new

[TDA]Speed

Quote from: MEGAMIND on Nov 10, 2024, 04:16 PM
Quote from: [TDA]Speed on Nov 10, 2024, 04:12 PM
Quote from: MEGAMIND on Nov 10, 2024, 10:30 AM
Quote from: [TDA]Speed on Nov 10, 2024, 09:30 AM
Quote from: vitovc on Nov 04, 2024, 06:44 PMit is possible but he wants you to code pathfinding for him xD
actually there is alot of AI-stuff can be done (and needed for DM-gamemods). I feel fear when I imagine how much work should be done to make npc to act like real players in terms of DM.
maybe we can make something more easliy then this like know the nearest pos of npc and walk to it

i did it eventaully u can do it too, get the nearest player id from distanceotpoint and walk it there.. an example here it moves twoards the loaction of player where ever it is going
Quote from: MEGAMIND on Nov 10, 2024, 10:30 AM
Quote from: [TDA]Speed on Nov 10, 2024, 09:30 AM
Quote from: vitovc on Nov 04, 2024, 06:44 PMit is possible but he wants you to code pathfinding for him xD
actually there is alot of AI-stuff can be done (and needed for DM-gamemods). I feel fear when I imagine how much work should be done to make npc to act like real players in terms of DM.
maybe we can make something more easliy then this like know the nearest pos of npc and walk to it

i did it eventaully u can do it too, get the nearest player id from distanceotpoint and walk it there.. an example here it moves twoards the loaction of player where ever it is going
lool man thats awsome! nick work
u cant test that npc.ai at my server more of that want in depth knowledge ? https://forum.vc-mp.org/index.php?topic=3350.msg54387#new
okey brother thanks for link, you asking or suggesting? xD

MEGAMIND

#12
Quote from: [TDA]Speed on Nov 12, 2024, 08:27 AMokey brother thanks for link, you asking or suggesting? xD
pls use transltor that i suggested u to that if u want u can test it out.. i dont need to ask anyone