Reverse loop fails.
#1

Whenever I try to use this decremental loop to spawn NPCs.. It only spawns one NPC with ID 499.

Code:
for(new i = 499; i >= 485;i--)
{
    CreateNPC(i,"Suspect");
}
What on earth is wrong with this loop? :S
Reply
#2

Problem solved with me on MSN. Feel free to lock or remove
Reply
#3

It's probably the fact they all have the same name, try doing this:

pawn Code:
new
    szNPCName[MAX_PLAYER_NAME],
    szIntBuf[4];

for(new i = 499; i >= 485; i--)
{
    // Set the start of string to "Suspect" for each
    // new NPC.
    szNPCName = "Suspect";

    // Convert i to a string, so we can add
    // it to the name of NPC.
    valstr(szIntBuf, i);

    // Add the number (in string form) to the
    // name "Suspect", to get result of "SuspectX"
    strcat(szNPCName, szIntBuf);

    // Create the NPC with the name that has
    // been generated.
    CreateNPC(i, szNPCName);
}
edit: Grr, I miss the "New post" warning from SMF. What was your solution?
Reply
#4

pawn Code:
for(new i=0;i<99;i++)
{
    new n=i+400;
    CreateNpc(n, "Suspect");
    //rest of code which is not meant to be released
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)