[Tutorial] How to make a driving vehicle NPC
#1

This guide was originaly made to help a friend to make an NPC, and while I where looping through my server files, I found it and tough somebody else could get use for it. Most people already know how to make an NPC, and somebody may have a greater tutorial than me, but its still worth sharing as some people may find it useful.

I did not include onfoot NPCs as I havent touched this since I made it for my friend, and he only needed to learn how to make an NPC that drives a vehicle. I have also not included how to record an NPC, so you will need to get a NPC record by your own

The tutorial/guide or what you want to call it, is in a .pwn file, so I wont explain any further here

If there is showing up problems with this, please contact me so I can help you with the problem

Ways to see the guide:
Pastebin: http://pastebin.com/ZmuieEbM

Download (PAWN only): http://solidfiles.com/d/afe1/

Dirrect download (Recommended): http://solidfiles.com/d/afe1/download/

pawn Code:
/*
                                NPC Help by Sayaron
                               
                               
This is a small guide that helps you to make NPCs in vehicles

What is required for it to work?:
-A NPC record (Use the filterscript npc_record wich is included in the sa-mp folder at download. The file will be in "npcmodes" > "recordings")
-A npcmode that reefers to the NPC record (Look in the folder "npcmodes" to see how its done)

*/

#include <a_samp>

new YourVehicle; // The name of your vehicle


public OnGameModeInit()
{
    ConnectNPC("YourNPC","RecordName"); // The name of your NPC and the record. The record need to match an record with the same name. The NPC name can be anything

    YourVehicle = AddStaticVehicle(448,2076.4067,2227.7834,10.4165,178.8465,6,6); // Creating your vehicle, this can be done ingame by typing /save. Then go to your SA-MP folder and find the folder "savedpositions"

    return 1;
}
public OnPlayerSpawn(playerid)
{
    if(!IsPlayerNPC(playerid)) return 0; // If the player is not a NPC, nothing will happend

    new playername[64]; //Player String
    GetPlayerName(playerid,playername,64); //This is to get the NPC's name

    if(!strcmp(playername, "YourNPC", true)) { // Detecting if the NPC is spawned. If it is not spawned or the name is wrong, nothing will happend
        SetSpawnInfo( playerid, 0, 255, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0 );
        //SetSpawnInfo( playerid, Team, Skin, x, y, z, rotation, weapon1, ammo for weapon1, w2, ammo2, w3, ammo3 );
        SetPlayerColor(playerid,0xFFFFFFFF); // Chose any color you want, this is currently white
        PutPlayerInVehicle(playerid, YourVehicle, 0);
        //PutPlayerInVehicle(playerid, vehiclename, seat);
    }
    return 1;
}
// This is to stop remote bots to connect, it will only let your bots connect
// If you dont want it, you may remove it
public OnPlayerConnect(playerid)
{
    if(IsPlayerNPC(playerid)) {
        new ip_addr_npc[64+1];
        new ip_addr_server[64+1];
        GetServerVarAsString("bind",ip_addr_server,64);
        GetPlayerIp(playerid,ip_addr_npc,64);

        if(!strlen(ip_addr_server)) {
            ip_addr_server = "127.0.0.1";
        }

        if(strcmp(ip_addr_npc,ip_addr_server,true) != 0) {
            // this bot is remote connecting
            printf("NPC: Got a remote NPC connecting from %s and I'm kicking it.",ip_addr_npc);
            Kick(playerid);
            return 0;
        }
        printf("NPC: Connection from %s is allowed.",ip_addr_npc);
    }

    return 1;
}
EDIT: I just found a great link for making NPCs. The main reason I put the link here, is that it can help with recording an NPC: https://sampforum.blast.hk/showthread.php?tid=95034
Reply
#2

were do they save to?
Reply
#3

Quote:
Originally Posted by aceisnice
View Post
were do they save to?
What? You just make this as a filterscript, but nothing saves anywhere
Reply
#4

nice tutorial. This will help me in the future times
Reply
#5

If my server have register / login system what this way work ?
Reply
#6

Quote:
Originally Posted by ckdut
View Post
If my server have register / login system what this way work ?
Make an exception in your registerering system by using if(!IsPlayerNPC) if it's NOT a npc, or GetPlayerName (not sure if that works)
Reply
#7

help my vehicle npc , stuck with player vehicle . how to fix it ?
Reply
#8

WTF its work... Thx.. +REP
Reply
#9

Quote:
Originally Posted by Sayaron
View Post
What? You just make this as a filterscript, but nothing saves anywhere
Actually, you're wrong. The .rec file gets saved in the npc folder.
Reply
#10

Can anyone give me the correct code of allowing NPCs through login / register area?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)