Walking man
Revision as of 18:21, 29 May 2023 by Habi (talk | contribs) (Created page with "<poem style="border: 2px solid #d6d2c5; background-color: #f9f4e6; padding: 1em;"> This script uses SetAnim every 100 ms. </poem> <poem style="border: 2px solid #d6d2c5; background-color: #f9f4e6; padding: 1em;"> This script requires modules: LibRPC and z-finder. </poem> <poem style="border: 2px solid #d6d2c5; background-color: #f9f4e6; padding: 1em;"> This script is made as of npcclient version 1.6 beta 4 patch 1. </poem> ==Server Side== 1. In scripts/main.nut...")
This script uses SetAnim every 100 ms.
This script is made as of npcclient version 1.6 beta 4 patch 1.
Server Side
1. In scripts/main.nut, connect our npc using
ConnectNPC("[NPC]apj33", "walking_man.nut", false, "", "rpclib z-finder")
false - console off
"" - host IP, default to 127.0.0.1
rpclib - npc module (to be placed in npcscripts/plugins)
z-finder - another module to get z co-ordinates
Other side
2. Create npcscripts/walking_man.nut and
target<-null;timerid<-null; function WalkToPoint(point) { target=point; if(timerid==null) { timerid=SetTimerEx("step_forward",100,0); //Remotely calling functions 'compilestring' of server. RFC(F("compilestring")("function SetWalkingAnimation(id){if(FindPlayer(id))FindPlayer(id).SetAnim(0,0);}"))(); RFC(F("compilestring")("WalkTimer"+GetMyName()+"<-NewTimer(\"SetWalkingAnimation\",100,0,"+GetMyID()+")"))(); } } function onDestinationReached() { if( GetDistanceFromMeToPoint( Vector(-872.146, -431.502, 11.5288) ) < 2 ) WalkToPoint( Vector( -870.825, -296.79, 11.173) ); else if( GetDistanceFromMeToPoint( Vector(-870.825, -296.79, 11.173) ) < 2 ) { WalkToPoint( Vector( -872.146, -431.502, 11.5288) ); //print something on server console. RFC("print")("npc: i completed one round of patrol"); } } function step_forward() { local newpos=GetMyPos()+(target-GetMyPos()).Normalised()*0.14; newpos.z=FindZFor2DCoord(newpos.x, newpos.y)+1.0425; SetLocalValue(V_POS, newpos); SetLocalValue(F_ANGLE, atan2(-(target.x-GetMyPosX()),target.y-GetMyPosY())); if((target-GetMyPos()).Length()<0.8)//reached destination { if(timerid!=null) KillTimer(timerid); timerid=null; //stop timer of server RFC(F("compilestring")("WalkTimer"+GetMyName()+".Delete()"))(); } else SendOnFootSyncDataLV(); if(timerid==null) onDestinationReached(); } function OnNPCSpawn() { WalkToPoint( Vector(-872.146, -431.502, 11.5288) ); //Acquire weapon RFC(F("compilestring")("FindPlayer("+GetMyID()+").SetWeapon(4,1);"))(); SetTimerEx("SetLocalValue", 1000,1, I_CURWEP, 4); } function OnNPCScriptLoad(params) { if(!MiamiScale_Init("default.map")) { SendChat("My map is not loaded. Bye"); QuitServer(); } } function OnNPCScriptUnload() { MiamiScale_Unload(); }
Notes: The NPC