ziggi / FCNPC

FCNPC - Fully Controllable NPC
Apache License 2.0
137 stars 31 forks source link

Callback Problems #297

Closed AtlanticCityRoleplay closed 1 year ago

AtlanticCityRoleplay commented 1 year ago

Callbacks are not called outside the Filterscript while using FCNPC_OnInit

CODE IN FILTERSCRIPT

public FCNPC_OnInit()
{
    TrainDriverNPCs[0] = FCNPC_Create("TrainDriverLS");
    TrainDriverNPCs[1] = FCNPC_Create("TrainDriverSF");
    TrainDriverNPCs[2] = FCNPC_Create("TrainDriverLV");
    for(new traindriver = 0; traindriver < MAX_STANDARD_NPC_TRAINDRIVERS; traindriver++) {
        if(TrainDriverNPCs[traindriver] != INVALID_PLAYER_ID && TrainDriverVehicles[traindriver] != INVALID_VEHICLE_ID) {
            FCNPC_Spawn(TrainDriverNPCs[traindriver], 255, 0.0, 0.0, 0.0);
            //SetPlayerTeam(TrainDriverNPCs[traindriver], 69);
            FCNPC_SetInvulnerable(TrainDriverNPCs[traindriver], true);
            SetPlayerColor(TrainDriverNPCs[traindriver], COLOR_STANDARD_NPC);
            FCNPC_PutInVehicle(TrainDriverNPCs[traindriver], TrainDriverVehicles[traindriver], 0);
            TrainDriverPlaybackCycle[traindriver] = traindriver;
            TrainDriverNextPlayback(traindriver);
        }
    }
    PilotNPCs[0] = FCNPC_Create("PilotLS");
    PilotNPCs[1] = FCNPC_Create("PilotSF");
    PilotNPCs[2] = FCNPC_Create("PilotLV");
    for(new pilot = 0; pilot < MAX_STANDARD_NPC_PILOTS; pilot++) {
        if(PilotNPCs[pilot] != INVALID_PLAYER_ID && PilotVehicles[pilot] != INVALID_VEHICLE_ID) {
            FCNPC_Spawn(PilotNPCs[pilot], 61, 0.0, 0.0, 0.0);
            //SetPlayerTeam(PilotNPCs[pilot], 69);
            FCNPC_SetInvulnerable(PilotNPCs[pilot], true);
            SetPlayerColor(PilotNPCs[pilot], COLOR_STANDARD_NPC);
            FCNPC_PutInVehicle(PilotNPCs[pilot], PilotVehicles[pilot], 0);
            PilotPlaybackCycle[pilot] = pilot;
            PilotNextPlayback(pilot);
        }
    }
}

CODE IN GAMEMODE

public FCNPC_OnCreate(npcid)
{
    new npcname[MAX_PLAYER_NAME + 1];
    GetPlayerName(npcid, npcname, sizeof(npcname));
    print("The callback is Working Good");
    if(!strcmp(npcname,"TrainDriverLS",true))
    {
        TrainDriverNPCs[0] = npcid;
        printf("TrainDriverLS NPC ID: %i", TrainDriverNPCs[0]);
    }
    else if(!strcmp(npcname,"TrainDriverSF",true))
    {
        TrainDriverNPCs[1] = npcid;
        printf("TrainDriverSF NPC ID: %i", TrainDriverNPCs[1]);
    }
    else if(!strcmp(npcname,"TrainDriverLV",true))
    {
        TrainDriverNPCs[2] = npcid;
        printf("TrainDriverLV NPC ID: %i", TrainDriverNPCs[2]);
    }
    else if(!strcmp(npcname,"PilotLS",true))
    {
        PilotNPCs[0] = npcid;
        printf("PilotLS NPC ID: %i", PilotNPCs[0]);
    }
    else if(!strcmp(npcname,"PilotSF",true))
    {
        PilotNPCs[1] = npcid;
        printf("PilotSF NPC ID: %i", PilotNPCs[1]);
    }
    else if(!strcmp(npcname,"PilotLV",true))
    {
        PilotNPCs[2] = npcid;
        printf("PilotLV NPC ID: %i", PilotNPCs[2]);
    }
    return 1;
}

LOG REFERENCE

[11:07:28] [npc:join] TrainDriverLS has joined the server (99:127.0.0.1)
[11:07:28] [npc:join] TrainDriverSF has joined the server (98:127.0.0.1)
[11:07:28] [npc:join] TrainDriverLV has joined the server (97:127.0.0.1)
[11:07:28] [npc:join] PilotLS has joined the server (96:127.0.0.1)
[11:07:28] [npc:join] PilotSF has joined the server (95:127.0.0.1)
[11:07:28] [npc:join] PilotLV has joined the server (94:127.0.0.1)
[11:07:28] [npc:join] BusDriverLS has joined the server (93:127.0.0.1)
[11:07:28] [npc:join] BusDriverLV has joined the server (92:127.0.0.1)

INFO

If I use the callback in filterscript, Its working Good inside filterscript the callback could not be used outside filterscript....

if i use timer in filterscript while create NPC, i can use the callback in both filterscript and gamemode

I just don't know its some sort of issue or not, I just Let you know.

If used a Timer in Filterscript to delay the creating the NPC the callback is working Good in Gamemode

[11:13:23] [npc:join] TrainDriverLS has joined the server (99:127.0.0.1)
[11:13:23] The callback is Working Good
[11:13:23] TrainDriverLS NPC ID: 99
[11:13:23] [npc:join] TrainDriverSF has joined the server (98:127.0.0.1)
[11:13:23] The callback is Working Good
[11:13:23] TrainDriverSF NPC ID: 98
[11:13:23] [npc:join] TrainDriverLV has joined the server (97:127.0.0.1)
[11:13:23] The callback is Working Good
[11:13:23] TrainDriverLV NPC ID: 97
[11:13:23] [npc:join] PilotLS has joined the server (96:127.0.0.1)
[11:13:23] The callback is Working Good
[11:13:23] PilotLS NPC ID: 96
[11:13:23] [npc:join] PilotSF has joined the server (95:127.0.0.1)
[11:13:23] The callback is Working Good
[11:13:23] PilotSF NPC ID: 95
[11:13:23] [npc:join] PilotLV has joined the server (94:127.0.0.1)
[11:13:23] The callback is Working Good
[11:13:23] PilotLV NPC ID: 94
[11:13:23] [npc:join] BusDriverLS has joined the server (93:127.0.0.1)
[11:13:23] The callback is Working Good
ziggi commented 1 year ago

Should be fixed in 2.0.8