SA-MP Forums Archive
NPC creation timer... - 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: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: NPC creation timer... (/showthread.php?tid=619236)



NPC creation timer... - iLearner - 15.10.2016

Hey again,

i made a small function which created 80 zombies(npcs) at gamemode init, but it seems like creating all 80 messes them up and they dont do what they are supposed to... so i wanted you guys to gimme a suggestion about on gamemode init i can create 80 zombies but like slowly so they dont mess up instead of all at same time...

This is the code i use to create:

PHP код:
forward CreateZombies();
public 
CreateZombies()
{    
    new 
str[50];
    new 
Random random(sizeof(ZombieSpawns));
    for(new 
0;i<MAX_ZOMBIESS;i++)
    {
        
format(str,sizeof(str),"Zombie[%d]",MAX_PLAYERS-(i));
        
FCNPC_Create(str);
        
FCNPC_Spawn(i,DayZ_Z_RandSkinZombie[random(sizeof(DayZ_Z_RandSkinZombie))],ZombieSpawns[Random][0],ZombieSpawns[Random][1],ZombieSpawns[Random][2]+0.7);
        
FCNPC_SetAngle(i,ZombieSpawns[Random][3]);
        
ZombiesAlive MAX_ZOMBIESS;
        
ZombieTimer[i] = repeat ZombieMove(i);
        
SetPlayerColor(i,0xFF0000FF);
        
IsAZombie[i] = 1;
    }
    return 
1;

And i call it on gm init.

All zombies spawned in BB with CJ skin at same pos...


Re: NPC creation timer... - iLearner - 15.10.2016

Anyone?


Re: NPC creation timer... - iLearner - 15.10.2016

Can I do something like... Create new boolean var, and use while(var == true & zombiescreated <81)

..... All code
Var = false;
Zombiescreated++;
SetTimer("myfunc", 500, false);



And set var to true in myfunc? Idk just a wild guess


Respuesta: NPC creation timer... - Marricio - 15.10.2016

I see you're utilizing y_timers, however I won't make it any more complicated for you! Here it is.

pawn Код:
// OnGameModeInit
SetTimerEx("CreateZombies", 500, false, "i", 0);

forward CreateZombies(count);
public CreateZombies(count)
{    
    new str[24];
    new Random = random(sizeof(ZombieSpawns));
    format(str,sizeof(str),"Zombie[%d]",MAX_PLAYERS-(count));
    FCNPC_Create(str);
    FCNPC_Spawn(count,DayZ_Z_RandSkinZombie[random(sizeof(DayZ_Z_RandSkinZombie))],ZombieSpawns[Random][0],ZombieSpawns[Random][1],ZombieSpawns[Random][2]+0.7);
    FCNPC_SetAngle(count,ZombieSpawns[Random][3]);
    ZombiesAlive ++;
    ZombieTimer[count] = repeat ZombieMove(count);
    SetPlayerColor(count,0xFF0000FF);
    IsAZombie[count] = 1;

    if( count < MAX_ZOMBIES ) SetTimerEx("CreateZombies", 500, false, "i", count + 1); // The trick is here!
    return 1;
}



Re: NPC creation timer... - SickAttack - 15.10.2016

Quote:
Originally Posted by Marricio
Посмотреть сообщение
I see you're utilizing y_timers, however I won't make it any more complicated for you! Here it is.

pawn Код:
// OnGameModeInit
SetTimerEx("CreateZombies", 500, false, "i", 0);

forward CreateZombies(count);
public CreateZombies(count)
{    
    new str[24];
    new Random = random(sizeof(ZombieSpawns));
    format(str,sizeof(str),"Zombie[%d]",MAX_PLAYERS-(count));
    FCNPC_Create(str);
    FCNPC_Spawn(count,DayZ_Z_RandSkinZombie[random(sizeof(DayZ_Z_RandSkinZombie))],ZombieSpawns[Random][0],ZombieSpawns[Random][1],ZombieSpawns[Random][2]+0.7);
    FCNPC_SetAngle(count,ZombieSpawns[Random][3]);
    ZombiesAlive ++;
    ZombieTimer[count] = repeat ZombieMove(count);
    SetPlayerColor(count,0xFF0000FF);
    IsAZombie[count] = 1;

    SetTimerEx("CreateZombies", 500, false, "i", count + 1); // The trick is here!
    return 1;
}
Yeah, let's create zombies non-stop!

...

-----------------------------------------

1. Create a global variable with no cells
2. Create a timer that is set to repeat every 800-1000 ms
3. In the timer, spawn the zombie according to the value in the variable
4. Increment the value of the variable by 1
5. When the value of the variable is equal to the amount of zombies you want to spawn, kill the timer


Respuesta: Re: NPC creation timer... - Marricio - 15.10.2016

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
Yeah, let's create zombies non-stop!
Thanks for pointing that out, realized it seconds after posting.


Re: NPC creation timer... - iLearner - 15.10.2016

Creation goes well... waits and thats ok.

But still ... all of them spawn at BB with CJ skin.. ?


Re: NPC creation timer... - iLearner - 15.10.2016

Update:

i made this cmd to spawn them manually, but still no changes:

PHP код:
CMD:rezombies(playeridparams[])
{
    new 
Random random(sizeof(ZombieSpawns));
    for(new 
i=0MAX_ZOMBIESSi++)
    {
        
FCNPC_Spawn(i,DayZ_Z_RandSkinZombie[random(sizeof(DayZ_Z_RandSkinZombie))],ZombieSpawns[Random][0],ZombieSpawns[Random][1],ZombieSpawns[Random][2]);
        
FCNPC_SetAngle(i,ZombieSpawns[Random][3]);
    
    }
    
SendClientMessage(playerid, -1"Zombies respawned!");
    return 
1;

Also, i saw (with a program) they're all "AFK" killing them with cmd or spawning them makes no effect on them
I also tried reducing npc's number to as low as 2! but still same thing.


Respuesta: NPC creation timer... - Marricio - 15.10.2016

You need to store the NPC ID returned by FCNPC_Create in order to be able to make changes to that NPC later on.

pawn Код:
forward CreateZombies(count);
public CreateZombies(count)
{    
    new str[24];
    new Random = random(sizeof(ZombieSpawns));
    format(str,sizeof(str),"Zombie[%d]",MAX_PLAYERS-(count));
    new npc =  FCNPC_Create(str); // See
    FCNPC_Spawn(npc,DayZ_Z_RandSkinZombie[random(sizeof(DayZ_Z_RandSkinZombie))],ZombieSpawns[Random][0],ZombieSpawns[Random][1],ZombieSpawns[Random][2]+0.7);
    FCNPC_SetAngle(npc,ZombieSpawns[Random][3]);
    ZombiesAlive ++;
    ZombieTimer[npc] = repeat ZombieMove(npc);
    SetPlayerColor(npc,0xFF0000FF);
    IsAZombie[npc] = 1;

    if( count < MAX_ZOMBIES ) SetTimerEx("CreateZombies", 500, false, "i", count + 1); // The trick is here!
    return 1;
}
If the problem is still there, I suggest you to check the FCNPC official thread for further help.


Re: NPC creation timer... - NaS - 16.10.2016

Normally you can just create the 80 NPCs at once, no need to delay it. The problem is probably somewhere else.

In some other script I create 998 NPCs in one function without any delay, no problems there.

Make sure to save the NPC IDs like Marricio said, and keep in mind the value FCNPC_Creates is no incrementing ID (unlike objects etc.), it is a playerid starting from the highest available slot to keep the lower IDs free for players.