SA-MP Forums Archive
[Include] Controllable NPC - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] Controllable NPC (/showthread.php?tid=301370)

Pages: 1 2 3


Controllable NPC - Lorenc_ - 04.12.2011



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: 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 Advantages 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.


Respuesta: Controllable NPC - [Nikk] - 04.12.2011

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


Re: Controllable NPC - [HiC]TheKiller - 04.12.2011

Good one Lorenc.



I'll tell you if there is any errors.


Re: Controllable NPC - Rudy_ - 04.12.2011

Nice!


Re: Controllable NPC - System64 - 04.12.2011

WOW, I hade the same idea


Re: Controllable NPC - fiki574 - 04.12.2011

Nice one!


Re: Controllable NPC - Hiddos - 04.12.2011

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.


Re: Controllable NPC - wups - 04.12.2011

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


Re: Controllable NPC - iPeanut - 04.12.2011

not bad


Re: Controllable NPC - erorcun - 04.12.2011

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.


Re: Controllable NPC - Dirkon - 04.12.2011

Do they(NPCs) go through walls?


Re: Controllable NPC - Lorenc_ - 04.12.2011

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.


Re: Controllable NPC - TheArcher - 04.12.2011

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


Re: Controllable NPC - RyDeR` - 05.12.2011

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.


Re: Controllable NPC - wups - 05.12.2011

Quote:

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


Re: Controllable NPC - RyDeR` - 05.12.2011

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.


Re: Controllable NPC - Lorenc_ - 05.12.2011

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?


Re: Controllable NPC - usersamp - 16.01.2012

Why my bots spawn in floats: 0.0,0.0,0.0?


Re: Controllable NPC - usersamp - 16.01.2012

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 з_з


Re: Controllable NPC - Lorenc_ - 17.01.2012

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