Rnpc

From SA-MP Wiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 14:37, 3 July 2012
Mauzen (Talk | contribs)

← Previous diff
Revision as of 14:44, 3 July 2012
Mauzen (Talk | contribs)

Next diff →
Line 12: Line 12:
=== RNPC_MoveRNPC === === RNPC_MoveRNPC ===
-{{Description|Simply moves the NPC to the given position. This works without entering edit mode first.}}+{{Description|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}} {{Parameters|npcid, Float:x, Float:y, Float:z, Float:speed}}
{{Param|npcid|ID of the NPC to move.}} {{Param|npcid|ID of the NPC to move.}}
Line 22: Line 22:
=== RNPC_CreateBuild === === RNPC_CreateBuild ===
-{{Description|Use this function to enter "edit mode".+{{Description|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. }} It creates the record file for the given NPC and so allows the other function to write to it. }}
{{Parameters|npcid, type, slot}} {{Parameters|npcid, type, slot}}
Line 28: Line 28:
{{Param|type|The recording type, either PLAYER_RECORDING_TYPE_ONFOOT or PLAYER_RECORDING_TYPE_VEHICLE}} {{Param|type|The recording type, either PLAYER_RECORDING_TYPE_ONFOOT or PLAYER_RECORDING_TYPE_VEHICLE}}
{{Param|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}} {{Param|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 edit mode is already active.}}+{{Returns|1 on success, 0 if build mode is already active.}}
=== RNPC_FinishBuild === === RNPC_FinishBuild ===
-{{Description|Finishes the currently active build and ends the "edit mode". This is needed before playing the generated record back.}}+{{Description|Finishes the currently active build and ends the "build mode". This is needed before playing the generated record back.}}
{{Parameters|clear}} {{Parameters|clear}}
{{Param|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}} {{Param|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}}
Line 89: Line 89:
== Attribute setters == == Attribute setters ==
-Theres a whole bunch of simple setter functions. They are meant to be used in edit mode, and affect all following actions of the NPC until changed again.+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: They should be quite self-explaining, so heres just a plain list of all OnFoot-Setters:
<pawn>native RNPC_SetLRKeys(lr); <pawn>native RNPC_SetLRKeys(lr);
Line 108: Line 108:
= Example code = = Example code =
-The "edit mode-thingy" might be hard to understand just from explaining the single functions.+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. So heres some example code that should make it more clear.
== Walk a bit and rage-shoot == == Walk a bit and rage-shoot ==
<pawn> <pawn>
SetPlayerPos(npcid, 0.0, 0.0, 0.0); SetPlayerPos(npcid, 0.0, 0.0, 0.0);
-RNPC_CreateBuild(npcid, PLAYER_RECORDING_ONFOOT); // start edit mode+RNPC_CreateBuild(npcid, PLAYER_RECORDING_ONFOOT); // start build mode
RNPC_SetWeaponID(32); // Set weapon RNPC_SetWeaponID(32); // Set weapon
RNPC_AddPause(500); // wait a bit RNPC_AddPause(500); // wait a bit
Line 131: Line 131:
RNPC_AddPause(500); RNPC_AddPause(500);
RNPC_SetKeys(0); // stop aiming RNPC_SetKeys(0); // stop aiming
-RNPC_FinishBuild(); // end the edit mode and finish the build+RNPC_FinishBuild(); // end the build mode and finish the build
RNPC_StartBuildPlayback(npcid); // start playback RNPC_StartBuildPlayback(npcid); // start playback

Revision as of 14:44, 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.

Image:32px-Circle-style-warning.png Important Note: RNPC does not support vehicles yet, but therefore allows complete control over OnFoot-NPCs.


Contents

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[])
name[]Name of the NPC.
ReturnsID of the connected NPC (seems bugged atm)

MoveRNPC(npcid, Float:x, Float:y, Float:z, Float:speed)

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)
npcidID of the NPC to move.
x,y,zTarget coordinates.
speedMovement speed. For OnFoot-Running 0.006 is a good value.
Returns1 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)
npcidThe ID of the NPC who should be controlled.
typeThe recording type, either PLAYER_RECORDING_TYPE_ONFOOT or PLAYER_RECORDING_TYPE_VEHICLE
slotThe 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
Returns1 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)
npcidDetermines 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
Returns1 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,z1The coordinates where the NPC should start to move.
x1,y1,z1The target coordinates.
speedMovement speed. For OnFoot-Running 0.006 is a good value.
Returns1 on success, 0 on fail


RNPC_ConcatMovement

Appends a movement from the NPCs last position to (x,y,z) to the current build.


Image:32px-Circle-style-warning.png 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,zThe target coordinates.
speedMovement speed. For OnFoot-Running 0.006 is a good value.
Returns1 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)
timeTime [ms] to pause.
Returns1 on success, 0 on fail


Playback control

RNPC_StartBuildPlayback

Starts playing a preciously generated recording.
Parameters:
(npcid, slot)
npcidThe ID of the NPC who should play his recording.
slotThe slot of the build that should be played back. Default value is 0
ReturnsThis function doesn't return a specific value


RNPC_StartPlayback

Makes the NPC play back any recording file in the npcmodes directory.
Parameters:
(npcid, rec[])
npcidThe ID of the NPC who should play the recording.
slotThe name of the recording that should be played.
ReturnsThis function doesn't return a specific value


RNPC_StopPlayback

Stops any running playback for the given NPC.
Parameters:
(npcid)
npcidThe ID of the NPC who should stop.
ReturnsThis function doesn't return a specific value


RNPC_SetAutorepeat

Sets wether the NPC should restart his playback after finishing it.


Parameters:
(npcid, repeat)
npcidThe ID of the NPC to control
repeat1/0 to set repeating.
ReturnsThis 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

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);
}
Personal tools