SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 13/07/2017, 12:24 PM   #1
JaakAmigo
Little Clucker
 
Join Date: Jul 2017
Posts: 5
Reputation: 0
Question Zombies dont respawn at all. What i need to do?

Hey!

I have been trying to make them respawn but not success yet.
How should code look like? To respawn dead zombie every 5 min?



Here is the code!
Code:
#include <a_samp>
#include <FCNPC>

#define MAX_ZOMBIES 5
new Float:ZPos[MAX_ZOMBIES][4] = {
{379.8811,-1699.6576,7.5203,135.8003},
{489.1599,-1792.9203,6.6491,66.5531},
{192.8038,-1844.9354,3.5631,256.3835},
{631.2430,-1711.2626,14.2986,177.0387},
{907.7244,-1771.8442,13.3828,264.2476}
};

new Attack[MAX_PLAYERS];
new ZombieEnd;
new ZombieFirst;

public OnFilterScriptInit()
{
    CriarZOMBIES();
	SetTimer("ZombieTimer", 400, true);
	return 1;
}

forward ZombieTimer();
public ZombieTimer()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i) && !IsPlayerNPC(i))
        {
            new Float:zP[3], Float:dist;
	        for(new npcid = ZombieFirst; npcid > ZombieEnd-1; npcid--)
	        {
		     	FCNPC_GetPosition(npcid, zP[0], zP[1], zP[2]);
		     	dist = GetPlayerDistanceFromPoint(i, zP[0], zP[1], zP[2]);
		     	if(dist <= 0.5)
		        {
		            if(Attack[npcid] == 0)
		            {
	        	 		FCNPC_MeleeAttack(npcid, -1);
	        	 		if(dist >= 0.1) FCNPC_SetAngleToPlayer(npcid, i);
			        	Attack[npcid] = 1;
					}
		        }
		        else if(dist <= 20.0)
		     	{
		            new Float:pP[3];
					if(Attack[npcid] == 1)
					{
					    Attack[npcid] = 0;
						FCNPC_StopAttack(npcid);
					}
		            GetPlayerPos(i, pP[0], pP[1], pP[2]);
		            FCNPC_GoTo(npcid, pP[0], pP[1], pP[2], MOVE_TYPE_RUN, 0.5, true, 0.0, true);
				}
				else FCNPC_Stop(npcid);
			}
		}
    }
	return 1;
}

stock CriarZOMBIES()
{
    new str[30];
    for(new i = 0; i < MAX_ZOMBIES; i++)
    {
        format(str, sizeof(str), "Zombie_%i", i);
        new npcid = FCNPC_Create(str);
        if(ZombieFirst == 0) ZombieFirst = npcid;
        ZombieEnd = npcid;
        FCNPC_Spawn(npcid, 162, ZPos[i][0], ZPos[i][1], ZPos[i][2]);
        
		FCNPC_SetAngle(npcid, ZPos[i][3]);
		FCNPC_SetInterior(npcid, 0);
		FCNPC_SetArmour(npcid, 80);
		FCNPC_SetWeapon(npcid, 4);
		FCNPC_SetAmmo(npcid, 1);

        printf("Zombie %d created", i);
    }
    return 1;
}

forward RespawnZombies();
public RespawnZombies()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerNPC(i))
        {
	        if(FCNPC_IsDead(i))
	        {
	            FCNPC_Respawn(i);
	        }
		}
    }
    return 1;
}

public FCNPC_OnDeath(npcid, killerid, weaponid)
{
    if(killerid != INVALID_PLAYER_ID)
    {
    }
    //FCNPC_Respawn(npcid);
    return 1;
}

public FCNPC_OnTakeDamage(npcid, damagerid, weaponid, bodypart, Float:health_loss)
{
	if(bodypart == 9)
	{
	    FCNPC_SetHealth(npcid, -15);
	}
	return 1;
}
JaakAmigo is offline   Reply With Quote
Old 15/07/2017, 05:10 AM   #2
MiyuUchiha
Big Clucker
 
MiyuUchiha's Avatar
 
Join Date: Sep 2015
Location: 192.168.100.4
Posts: 56
Reputation: 22
Default Re: Zombies dont respawn at all. What i need to do?

Code:
#include <a_samp>
#include <FCNPC>

#define MAX_ZOMBIES 5
new Float:ZPos[MAX_ZOMBIES][4] = {
{379.8811,-1699.6576,7.5203,135.8003},
{489.1599,-1792.9203,6.6491,66.5531},
{192.8038,-1844.9354,3.5631,256.3835},
{631.2430,-1711.2626,14.2986,177.0387},
{907.7244,-1771.8442,13.3828,264.2476}
};

new Attack[MAX_PLAYERS];
new ZombieEnd;
new ZombieFirst;

public OnFilterScriptInit()
{
    CriarZOMBIES();
	SetTimer("ZombieTimer", 400, true);
	return 1;
}

forward ZombieTimer();
public ZombieTimer()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i) && !IsPlayerNPC(i))
        {
            new Float:zP[3], Float:dist;
	        for(new npcid = ZombieFirst; npcid > ZombieEnd-1; npcid--)
	        {
		     	FCNPC_GetPosition(npcid, zP[0], zP[1], zP[2]);
		     	dist = GetPlayerDistanceFromPoint(i, zP[0], zP[1], zP[2]);
		     	if(dist <= 0.5)
		        {
		            if(Attack[npcid] == 0)
		            {
	        	 		FCNPC_MeleeAttack(npcid, -1);
	        	 		if(dist >= 0.1) FCNPC_SetAngleToPlayer(npcid, i);
			        	Attack[npcid] = 1;
					}
		        }
		        else if(dist <= 20.0)
		     	{
		            new Float:pP[3];
					if(Attack[npcid] == 1)
					{
					    Attack[npcid] = 0;
						FCNPC_StopAttack(npcid);
					}
		            GetPlayerPos(i, pP[0], pP[1], pP[2]);
		            FCNPC_GoTo(npcid, pP[0], pP[1], pP[2], MOVE_TYPE_RUN, 0.5, true, 0.0, true);
				}
				else FCNPC_Stop(npcid);
			}
		}
    }
	return 1;
}

stock CriarZOMBIES()
{
    new str[30];
    for(new i = 0; i < MAX_ZOMBIES; i++)
    {
        format(str, sizeof(str), "Zombie_%i", i);
        new npcid = FCNPC_Create(str);
        if(ZombieFirst == 0) ZombieFirst = npcid;
        ZombieEnd = npcid;
        FCNPC_Spawn(npcid, 162, ZPos[i][0], ZPos[i][1], ZPos[i][2]);

		FCNPC_SetAngle(npcid, ZPos[i][3]);
		FCNPC_SetInterior(npcid, 0);
		FCNPC_SetArmour(npcid, 80);
		FCNPC_SetWeapon(npcid, 4);
		FCNPC_SetAmmo(npcid, 1);

        printf("Zombie %d created", i);
    }
    return 1;
}

forward RespawnZombies();
public RespawnZombies()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerNPC(i))
        {
	        if(FCNPC_IsDead(i))
	        {
	            FCNPC_Respawn(i);
	        }
		}
    }
    return 1;
}

forward DeadZombie(playerid)
{
   CriarZOMBIES();
   return 1;
}

public FCNPC_OnDeath(npcid, killerid, weaponid)
{
    if(killerid != INVALID_PLAYER_ID)
    {
	   if(IsPlayerNPC(npcid))
	   {
	      SetTimer("DeadZombie", 300000, false);
	   }
    }
    return 1;
}

public FCNPC_OnTakeDamage(npcid, damagerid, weaponid, bodypart, Float:health_loss)
{
	if(bodypart == 9)
	{
	    FCNPC_SetHealth(npcid, -15);
	}
	return 1;
}
maybe it would work, try
MiyuUchiha is offline   Reply With Quote
Old 15/07/2017, 06:26 AM   #3
iLearner
Gangsta
 
iLearner's Avatar
 
Join Date: Apr 2017
Posts: 576
Reputation: 134
Default Re: Zombies dont respawn at all. What i need to do?

You need to use FCNPC_onrespawn callback.
iLearner is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a way to make when spawned car explode to dont respawn ? bustern Scripting Help 5 06/09/2013 11:16 AM
cars dont respawn. slymatt Help Archive 4 25/07/2011 11:02 AM
vehicle dont respawn good dud Help Archive 5 26/02/2011 12:15 PM
Dont respawn ingamecreated cars Jonni8 Help Archive 11 03/06/2010 09:08 PM


All times are GMT. The time now is 10:50 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.