From SA-MP Wiki
(Difference between revisions)
Revision as of 17:22, 3 July 2012
This page explains the functions provided by the RNPC plugin by User:Mauzen
RNPC (Recordfree NPCs) is a server plugin. Its purpose is to create the NPC record files in runtime, so they dont need to be recorded manually.
This way the NPCs can be controlled dynamically from the script-side.
It can be found in this forum thread: http://forum.sa-mp.com/showthread.php?t=355849
| Important Note: RNPC does not support vehicles yet, but therefore allows complete control over OnFoot-NPCs.
|
Scripting functions
General
RNPC_ConnectRNPC
Connects a new RNPC to the server. This, or at least using the RNPC npcscript is needed for any other functions.
Parameters:(name[])
| Returns | ID of the connected NPC |
RNPC_MoveRNPC
Simply moves the NPC to the given position. This works without entering build mode first.
Parameters:(npcid, Float:x, Float:y, Float:z, Float:speed)
| npcid | ID of the NPC to move. |
| speed | Movement speed. For OnFoot-Running 0.006 is a good value. |
| Returns | 1 on success, 0 on fail |
Record generation
RNPC_CreateBuild
Use this function to enter "build mode".
It creates the record file for the given NPC and so allows the other function to write to it.
Parameters:(npcid, type, slot)
| npcid | The ID of the NPC who should be controlled. |
| type | The recording type, either PLAYER_RECORDING_TYPE_ONFOOT or PLAYER_RECORDING_TYPE_VEHICLE |
| slot | The recording slot that should be created. Every slot got its own file, so you can keep multiple recordings for a NPC at once, and later choose which one should be played back. Default value is 0 |
| Returns | 1 on success, 0 if build mode is already active. |
RNPC_FinishBuild
Finishes the currently active build and ends the "build mode". This is needed before playing the generated record back.
Parameters:(clear)
| npcid | Determines if a last segment should be added at the end to clear things like velocity and movement, so the NPC just stands still after the playback. Default value is 1 |
| Returns | 1 on success, 0 if there is no active build. |
RNPC_AddMovement
Appends a movement from (x1,y1,z1) to (x2,y2,z2) to the current build.
Parameters:(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2, Float:speed)
| x1,y1,z1 | The coordinates where the NPC should start to move. |
| x1,y1,z1 | The target coordinates. |
| speed | Movement speed. For OnFoot-Running 0.006 is a good value. |
| Returns | 1 on success, 0 on fail |
RNPC_ConcatMovement
Appends a movement from the NPCs last position to (x,y,z) to the current build.
| Important Note: Use this only after using AddMovement at least once, or movement will be bugged, as the last position is unknown.
|
Parameters:(Float:x, Float:y, Float:z, Float:speed)
| x,y,z | The target coordinates. |
| speed | Movement speed. For OnFoot-Running 0.006 is a good value. |
| Returns | 1 on success, 0 on fail |
RNPC_AddPause
Adds a pause to the current build. The NPC wont move, but continue with his current attributes (e.g. keeps shooting).
Parameters:(Ftime)
| Returns | 1 on success, 0 on fail |
Playback control
RNPC_StartBuildPlayback
Starts playing a preciously generated recording.
Parameters:(npcid, slot)
| npcid | The ID of the NPC who should play his recording. |
| slot | The slot of the build that should be played back. Default value is 0 |
| Returns | This function doesn't return a specific value |
RNPC_StartPlayback
Makes the NPC play back any recording file in the npcmodes directory.
Parameters:(npcid, rec[])
| npcid | The ID of the NPC who should play the recording. |
| slot | The name of the recording that should be played. |
| Returns | This function doesn't return a specific value |
RNPC_StopPlayback
Stops any running playback for the given NPC.
Parameters:(npcid)
| npcid | The ID of the NPC who should stop. |
| Returns | This function doesn't return a specific value |
RNPC_SetAutorepeat
Sets wether the NPC should restart his playback after finishing it.
Parameters:(npcid, repeat)
| npcid | The ID of the NPC to control |
| repeat | 1/0 to set repeating. |
| Returns | This function doesn't return a specific value |
Attribute setters
Theres a whole bunch of simple setter functions. They are meant to be used in build mode, and affect all following actions of the NPC until changed again.
They should be quite self-explaining, so heres just a plain list of all OnFoot-Setters:
native RNPC_SetLRKeys(lr);
native RNPC_SetUDKeys(ud);
native RNPC_SetKeys(keys);
native RNPC_SetQuat1(Float:w); // Better use SetAngleQuats than this
native RNPC_SetQuat2(Float:x);
native RNPC_SetQuat3(Float:y);
native RNPC_SetQuat4(Float:z);
native RNPC_SetHealth(hp);
native RNPC_SetArmour(arm);
native RNPC_SetSpecialAction(sp);
native RNPC_SetWeaponID(weaponid);
native RNPC_SetAnimID(anim);
native RNPC_SetAnimParams(params); // Not sure how the params work yet
native RNPC_SetAngleQuats(Float:a, Float:h, Float:b); // a, h and b are degree angles, where h is the facing angle
native RNPC_SetUpdateRate(rate); // The interval in ms in which segments are written. Default of 100ms should be fine.
Example code
The "build mode-thingy" might be hard to understand just from explaining the single functions.
So heres some example code that should make it more clear.
Walk a bit and rage-shoot
SetPlayerPos(npcid, 0.0, 0.0, 0.0);
RNPC_CreateBuild(npcid, PLAYER_RECORDING_ONFOOT); // start build mode
RNPC_SetWeaponID(32); // Set weapon
RNPC_AddPause(500); // wait a bit
RNPC_AddMovement(0.0, 0.0, 0.0, 20.0, 20.0, 0.0); // start moving
RNPC_ConcatMovement(0.0, 20.0, 0.0); // Continue walking
RNPC_AddPause(200); // wait a bit again
RNPC_SetKeys(128); // aim straight forward
RNPC_AddPause(500);
RNPC_SetKeys(128 + 4); // Start shooting straight forward
RNPC_AddPause(500);
for (new i = 0; i < 360; i+=20) {
// Makes the NPC rotate slowly
RNPC_SetAngleQuats(0.0, i, 0.0);
RNPC_AddPause(150);
}
RNPC_SetKeys(128); // stop shooting
RNPC_AddPause(500);
RNPC_SetKeys(0); // stop aiming
RNPC_FinishBuild(); // end the build mode and finish the build
RNPC_StartBuildPlayback(npcid); // start playback
Simple following script
stock FollowPlayer(npcid, targetid)
{
SetTimerEx("Follower", 500, 1, "ii", npcid, targetid);
}
public Follower(npcid, targetid)
{
new Float:x, Float:y, Float:z;
GetPlayerPos(targetid, x, y, z);
RNPC_MoveRNPC(npcid, x, y, z, 0.006);
}