[Include] Controllable NPC
#1



A controllable NPC script using the default NPC natives.
Why? What? Why'd you make this?

1st. I was inspired by erorcun's controllable NPC script though had a lot of issues with that so I wanted to create my own using some of his ideas in the creation of this include. This include is MUCH easier to use, hardly anything will error if you do all the requested inside the thread correctly. This is stated down.

2nd. Erorcun's probably has more functions though soon, this include will reach more functions by each version which I'm willing to update and support. The major thing about this version is that it uses up-to-date methods. It's faster than his I assume!

3rd. I'm a fan of NPC's and love playing with them while no-ones around

What this version uses:
  • y_ini - The fastest reader/writer
  • Mapandreas - RyDeR`'s one, I can make a version for users using the plugin if needed!
  • y_hooks - One single include contains all the features and some callbacks required hooking.
  • No filterscripts or so many files! Just 1 npcmode file and a scriptfile folder to be created!
  • Up-to-date and organised!
  • Easy as pie to use!
  • Has a fix towards duplicates of a NPC name!
Functions
pawn Code:
/*
    native CreateCNPC(name[24], skin, Float: X, Float: Y, Float: Z)
    native SetNpcMoveTo(nID, Float: X, Float: Y, Float: Z, bool: run = false)
    native GetNPCPlayerID(nID)
    native GetDistanceBetweenPlayerAndNPC(playerid, nID)
    native GetClosestNPC(playerid)
    native GetNpcIDFromPlayerID(playerid)
    native StopCNPC(npcid)
    native GetCNPCTotalCount()
    native ReturnNpcName(npcid)
    native SetNPCPos(npcid, Float: X, Float: Y, Float: Z)
    native ApplyAnimationToNPC(npcid, animlib[], animname[], Float: fDelta, loop, lockx, locky, freeze, time, forcesync = 0)
    native SetNPCFacingAngle(npcid, Float: Angle)
    native GiveNPCWeapon(npcid, weaponid, ammo)
    native ResetNPCWeapons(npcid)
   
    native SetPlayerFacePoint(playerid, Float: fX, Float: fY, Float: offset = 0.0)
    native strmatch(const str1[], const str2[])
    native strreplacechar(string[], oldchar, newchar)
   
*/
There is more however, those are used within the functions so I'd call this function list a list containing useful ones.

Example Gamemode
pawn Code:
/*
    *
    *   CNPC - Gamemode Example.
    *
    *
    *
    *
    *
    *
*/



#include                            <a_samp>
#include                            <a_cnpc>
#include                            <zcmd>

/* ** NPC DATA ** */
new
    Npc:    PornhubUser,
    szTmpstring                     [128] // I'm being a bit careless about strings now. Haha.
;

main(){}
public OnGameModeInit()
{
    SetGameModeText("CNPC 0.1a");
    AddPlayerClass(0, 0.0, 0.0, 5.0, 270.0, 0, 0, 0, 0, 0, 0);
    CreateCNPC("Jackie", 119, 5, 0, 5);
    CreateCNPC("Troll", 289, 0, 5, 5);
    PornhubUser = CreateCNPC("Porn Hub User", 5, 5, 5, 5);
    CreateCNPC("Porn Hub User", 5, 5, 5, 5);
    CreateCNPC("Porn Hub User", 5, 5, 5, 5);
    return 1;
}

public OnGameModeExit() return 1;

public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
    return 1;
}

public OnNpcCreated(npcid)
{
    printf("%s(%d) created!", ReturnNpcName(npcid), npcid);
    return 1;
}

public OnNpcConnected(npcid)
{
    printf("%s(%d) connected!", ReturnNpcName(npcid), npcid);
    return 1;
}

public OnNpcFinishedMoving(npcid)
{
    printf("%s(%d) finished moving!", ReturnNpcName(npcid), npcid);
    return 1;
}

public OnNpcDestroyed(npcid)
{
    printf("%s(%d) destroyed!", ReturnNpcName(npcid), npcid);
    return 1;
}

CMD:closest(playerid, params[])
{
    new Npc: nTmp = GetClosestNPC(playerid);
    format(szTmpstring, 128, "Closest: %d", _: nTmp);
    SendClientMessage(playerid, -1, szTmpstring);
    return 1;
}

CMD:distance(playerid, params[])
{
    if(!IsNPCConnected(strval(params))) return 0;
    new Float: fTmp = GetDistanceBetweenPlayerAndNPC(playerid, Npc:strval(params));
    format(szTmpstring, 128, "Distance: %f", fTmp);
    SendClientMessage(playerid, -1, szTmpstring);
    return 1;
}

CMD:walk(playerid, params[])
{
    new Float: X, Float: Y, Float: Z;
    GetPlayerPos(playerid, X, Y,Z);
    SetNpcMoveTo(PornhubUser, X, Y, Z, false);
    return 1;
}

CMD:run(playerid, params[])
{
    new Float: X, Float: Y, Float: Z;
    GetPlayerPos(playerid, X, Y,Z);
    SetNpcMoveTo(PornhubUser, X, Y, Z, true);
    return 1;
}

CMD:runall(playerid, params[])
{
    new Float: X, Float: Y, Float: Z;
    GetPlayerPos(playerid, X, Y,Z);
    foreachcnpc(i)
    {
        SetNpcMoveTo(i, X, Y, Z, true);
    }
    return 1;
}
Media

If anyone could make a video, PM me the link of the video and I'll clip it on the the thread. I CBF doing so.

Disadvantages
  • Sloppy walking/running, takes approx 1 second to update movement.
  • Compile-time might take about 0.750 milliseconds due to compilation of YSI. (y_hooks especially, use v0.2a to have this situation cured!
  • Doesn't stream NPC's (might soon)
  • SetPlayerVelocity fails, don't msg me about it.
Advantages
  • Fast and up-to-date.
  • Works on Linux (Pretty sure, since it's using the natives)
  • No plugins required!
  • Very easy to use
  • ETC. (Look at "Why? What? Why'd you make this?" to see some more stuff)
Download
[0.2.2a] Latest (v)
[0.2.2a] Recommended build via pastebin!

[0.1a] Download (Not recommended, stick with the latest.)

Includes the scriptfiles/npcmodes/includes/examples. ( All Versions )

Notifications

Code:
[0.2a] This version hooks all callbacks itself! No y_hooks meaning no long compilation time :)
[0.2a] Cool functions added.
[0.2.2a] Major bug fix with NPC's not spawning to their location.
[0.2.2a] New call back "OnNpcSpawn"..
Questions

How can I make something like Zombies?
Look here. That link describes what it takes to create such a thing though indeed, you need a bit of experience.

Where do I place the .inc file?
Inside your server directory, click on "pawno" then click again on "include"

Why is the walking/running so sloppy?
You need to read through this again. DERP.

Where do I create a NPC?
Look at the example.

On some functions I get "Tag mismatch", how can I prevent this?
I'm not sure where you'll get that but if you do, you can use "Convert.ToNPC(param)" to prevent it.

Credits
Lorenc_ - Created this.
RyDeR` - Mapandreas include.
erorcun - Ideas/solutions.
y_less - y_ini.
Reply


Messages In This Thread
Controllable NPC - by Lorenc_ - 04.12.2011, 06:06
Respuesta: Controllable NPC - by [Nikk] - 04.12.2011, 06:14
Re: Controllable NPC - by [HiC]TheKiller - 04.12.2011, 06:17
Re: Controllable NPC - by Rudy_ - 04.12.2011, 06:19
Re: Controllable NPC - by System64 - 04.12.2011, 07:02
Re: Controllable NPC - by fiki574 - 04.12.2011, 07:32
Re: Controllable NPC - by Hiddos - 04.12.2011, 10:03
Re: Controllable NPC - by wups - 04.12.2011, 10:26
Re: Controllable NPC - by iPeanut - 04.12.2011, 10:54
Re: Controllable NPC - by erorcun - 04.12.2011, 11:26
Re: Controllable NPC - by Dirkon - 04.12.2011, 12:06
Re: Controllable NPC - by Lorenc_ - 04.12.2011, 19:52
Re: Controllable NPC - by TheArcher - 04.12.2011, 21:52
Re: Controllable NPC - by RyDeR` - 05.12.2011, 15:25
Re: Controllable NPC - by wups - 05.12.2011, 15:36
Re: Controllable NPC - by RyDeR` - 05.12.2011, 15:40
Re: Controllable NPC - by Lorenc_ - 05.12.2011, 20:13
Re: Controllable NPC - by usersamp - 16.01.2012, 19:37
Re: Controllable NPC - by usersamp - 16.01.2012, 21:40
Re: Controllable NPC - by Lorenc_ - 17.01.2012, 00:09
Re: Controllable NPC - by Brian_G - 17.01.2012, 00:13
Re: Controllable NPC - by Deskoft - 17.01.2012, 00:53
Re: Controllable NPC - by Scenario - 17.01.2012, 01:38
Re: Controllable NPC - by SoUrAv - 17.01.2012, 04:13
Re: Controllable NPC - by Lorenc_ - 17.01.2012, 06:10
Re: Controllable NPC - by usersamp - 17.01.2012, 06:37
Re: Controllable NPC - by usersamp - 17.01.2012, 07:06
Re: Controllable NPC - by Niko_boy - 17.01.2012, 08:33
Re: Controllable NPC - by Lorenc_ - 17.01.2012, 08:52
Re: Controllable NPC - by Lorenc_ - 02.04.2012, 13:12
Re: Controllable NPC - by clavador - 02.04.2012, 16:48
Re: Controllable NPC - by [T]HeLLBoY - 02.04.2012, 17:33
Re: Controllable NPC - by Snipa - 29.04.2012, 23:34
Respuesta: Controllable NPC - by [Vector] - 30.04.2012, 05:25
Re: Respuesta: Controllable NPC - by TheArcher - 30.04.2012, 09:42
Re: Controllable NPC - by Juninho_Oakley - 30.04.2012, 15:13
Re: Respuesta: Controllable NPC - by mprofitt - 30.04.2012, 20:15
Re: Respuesta: Controllable NPC - by TheArcher - 30.04.2012, 21:45
Re: Controllable NPC - by Lorenc_ - 30.04.2012, 22:05
Re: Controllable NPC - by Manowar - 09.07.2012, 18:35
Re: Controllable NPC - by TheArcher - 09.07.2012, 18:38
Re: Controllable NPC - by Scarface34 - 24.08.2012, 12:49
Re: Controllable NPC - by Lordzy - 08.12.2012, 08:17
Re: Controllable NPC - by Sasino97 - 08.12.2012, 17:36
Re: Controllable NPC - by Sasino97 - 10.12.2012, 12:42
Re: Controllable NPC - by burnfire - 03.05.2013, 11:27
Respuesta: Controllable NPC - by Swedky - 03.10.2013, 16:22
Re: Controllable NPC - by xF4Life - 06.10.2013, 15:26
Re: Controllable NPC - by iBeast - 06.10.2013, 15:35
Re: Controllable NPC - by Weponz - 02.06.2014, 04:17
Re: Controllable NPC - by Inn0cent - 02.06.2014, 06:08

Forum Jump:


Users browsing this thread: 2 Guest(s)