[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
#2

Wow! incredible, Sounds Good, Im gonna to Test This , Thanks for this.
Reply
#3

Good one Lorenc.



I'll tell you if there is any errors.
Reply
#4

Nice!
Reply
#5

WOW, I hade the same idea
Reply
#6

Nice one!
Reply
#7

Quote:
Originally Posted by Lorenc_
View Post
Disadvantages
  • Compile-time might take about 0.750 milliseconds due to compilation of YSI.


Other than that, looks pretty good.
Reply
#8

I think you meant 0.75 seconds rather than 0.750 milliseconds
^^
Cheers, good job. A video is critical for this.
Reply
#9

not bad
Reply
#10

I will update my include soon and it will be better than yours. I'm sorry for this.

But yours is good for who don't want streamer. I will put link to this page from my page.
Reply
#11

Do they(NPCs) go through walls?
Reply
#12

Quote:
Originally Posted by Dirkon
View Post
Do they(NPCs) go through walls?
With mapandreas all NPC's will be placed on the ground Z, which avoids that.

Quote:
Originally Posted by wups
View Post
I think you meant 0.75 seconds rather than 0.750 milliseconds
^^
Cheers, good job. A video is critical for this.
They're the same thing I assume lol, thanks for the comment though!
EDIT: I meant, they update at 750 milliseconds (The movement, I'll try see if I shorten the timer speed to have it more efficient)

@erorcun

I don't mind Just wanted to have something rather more simple in the community
No competition!! Just make it for the community rather then competing, things seem to go wrong always with competitions :O

@others

Thanks for the comments.
Reply
#13

This is an epic release. But a video is a must here that will fastly ingrease the downloads. Gonna test it anyway.
Reply
#14

Quote:
Originally Posted by Lorenc_
View Post
They're the same thing I assume lol, thanks for the comment though!
Well, since 0.75 is the same as 0.750 I assume it's not the same.

Looks good ─ you can do quite a few things to optimize some things, though.
Reply
#15

Quote:

I think you meant 0.75 seconds rather than 0.750 milliseconds
1 second = 1000 milliseconds, but I think you know that!
Reply
#16

Quote:
Originally Posted by wups
View Post
1 second = 1000 milliseconds, but I think you know that!
That's what I was actually trying to explain as he assumed they're equal. You misunderstood my sentence.
Reply
#17

Quote:
Originally Posted by RyDeR`
View Post
That's what I was actually trying to explain as he assumed they're equal. You misunderstood my sentence.
Well, they do update each 750 milliseconds, weird reaction but I requested a fix for it on 0.3d. It clearly worked well in 0.3a as said by erorcun :O

Sorry for my fail, 75 = 750 ms, LMAO.

Do you mind telling me some bits where to optimize :O?
Reply
#18

Why my bots spawn in floats: 0.0,0.0,0.0?
Reply
#19

No, i'm sorry, all bots spawn roud this Float: 1958.2336,1344.3185,1100.5126 on the sky.
How i can resolve this? Please з_з
Reply
#20

Quote:
Originally Posted by usersamp
View Post
No, i'm sorry, all bots spawn roud this Float: 1958.2336,1344.3185,1100.5126 on the sky.
How i can resolve this? Please з_з
Look at the Z coordinate: 1100.5126. How do you not expect that it'll be up in the sky if it's 1000 units up :O
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)