INI_ParseFile
#1

Hello, I found this function "INI_ParseFile" in my stock function, And I don't know how important is it.
INI_ParseFile is in a stock to load actors "y_ini", And the actors files ".ini" are in the "Actors" folder.
Can someone tell me what to do with INI_ParseFile and how to fix it ?

I wrote "load_server_actors();" under OnGameModeInit and they didn't get loaded.

This is the code:
Код:
stock load_server_actors()
{
	for(new i =1; i < MAX_ACTORS; i++)
	{
		if(fexist(acPath(i)))
		{
  			INI_ParseFile(acPath(i), "LoadActors_%s", .bExtra = true, .extra = i);
		    		    
		    actObject[i] = CreateActor(actData[i][Model], actData[i][acPosX], actData[i][acPosY], actData[i][acPosZ], actData[i][acPosFA]);
		    SetActorVirtualWorld(actObject[i], actData[i][acWorld]);
		}
	}
	return 1;
}
EDITION: The actors are getting created at position: X: 0, Y:0, Z:0 with skin id 0 (CJ), But in the scriptfiles I see the positions: -2151 and skin ID 230 and everything looks well.
Reply
#2

can you show us the function where you're loading all the data into the array? the parsefile function.
Reply
#3

Quote:
Originally Posted by Smileys
Посмотреть сообщение
can you show us the function where you're loading all the data into the array? the parsefile function.
All:
Код:
enum acData
{
	Model,
	acPosX,
	acPosY,
	acPosZ,
	acPosFA,
	acWorld
}
new actData[MAX_ACTORS][acData];
new actObject[MAX_ACTORS];
Код:
stock acPath(actorid)
{
	new string[128];
	format(string, sizeof(string), "/Actors/%d.ini", actorid);
	return string;
}

stock load_server_actors()
{
	for(new i =1; i < MAX_ACTORS; i++)
	{
		if(fexist(acPath(i)))
		{
  			INI_ParseFile(acPath(i), "LoadActors_%s", .bExtra = true, .extra = i);
		    		    
		    actObject[i] = CreateActor(actData[i][Model], actData[i][acPosX], actData[i][acPosY], actData[i][acPosZ], actData[i][acPosFA]);
		    SetActorVirtualWorld(actObject[i], actData[i][acWorld]);
		}
	}
	return 1;
}

stock freeAct()
{
	for(new g =1; g < MAX_ACTORS; g++)
	{
	    if(!fexist(acPath(g)))
	    {
	        return g;
	    }
	}
	return -1;
}
Код:
CMD:createactor(playerid, params[])
{
	if(AdminLevel[playerid] < 5) return SCM(playerid, COLOR_WHITE, ""WORD_NADMIN"");
	new amodel, Float:x, Float:y, Float:z, Float:fa, g = freeAct(), string[128];
	if(sscanf(params, "i", amodel)) return SCM(playerid, -1, ""WORD_USAGE"/createactor [SKIN]");
	if(amodel < 0) return SCM(playerid, COLOR_WHITE, ""WORD_ERROR"Invalid skin ID.");
	if(amodel > 311) return SCM(playerid, COLOR_WHITE, ""WORD_ERROR"Invalid skin ID.");
	if(IsPlayerInAnyVehicle(playerid)) return SCM(playerid, COLOR_WHITE, ""WORD_ERROR"Exit your vehicle before using this command.");
	
	GetPlayerPos(playerid, x, y, z);
	GetPlayerFacingAngle(playerid, fa);
 	actObject[g] = CreateActor(amodel, x, y, z, fa);
 	
    new INI:aFile = INI_Open(acPath(g));
    new aWorld = GetPlayerVirtualWorld(playerid);
	INI_WriteInt(aFile, "Model", amodel);
	INI_WriteFloat(aFile, "acPosX", x);
	INI_WriteFloat(aFile, "acPosY", y);
	INI_WriteFloat(aFile, "acPosZ", z);
	INI_WriteFloat(aFile, "acPosFA", fa);
	INI_WriteInt(aFile, "acWorld", aWorld);
	INI_Close(aFile);
	format(string, sizeof(string), ""WORD_SERVER"You have created actor ID {AFAFAF}%d {FFFFFF}with skin: {AFAFAF}%d{FFFFFF}.", g, amodel);
	SCM(playerid, COLOR_WHITE, string);
	return 1;
}
Код:
OnGameModeInit()
{
	load_server_actors();
	return 1;
}
Reply
#4

pawn Код:
forward LoadActor_data(name[],value[]);
public LoadActor_data(name[],value[])
{
    new ActorInfo[2],Float:Pos[4];
    INI_Int("Skin",ActorInfo[0]);
    INI_Float("PosX",Pos[0]);
    INI_Float("PosY",Pos[1]);
    INI_Float("PosZ",Pos[2]);
    INI_Float("PosA",Pos[3]);
    INI_Int("VirtualWorld",ActorInfo[1]);
    new Actor = CreateActor(ActorInfo[0], Pos[0], Pos[1], Pos[2], Pos[3]);
    SetActorVirtualWorld(Actor, ActorInfo[1]);
    return 1;
}
#define ACTOR_PATH "/Actors/Actor_%d.ini"

ActorPath(actorid)
{
    new string[32];
    format(string,sizeof(string),ACTOR_PATH,actorid);
    return string;
}

OnGameModeInit
for(new actorid=0; actorid < MAX_ACTORS; actorid++)
    INI_ParseFile(ActorPath(actorid), "LoadActor_%s");


AddActor(actorid, skinid, Float:X, Float:Y, Float:Z, Float:A, VirtualWorld)
{
    if(Actor == INVALID_ACTOR_ID) return 0;

    new INI:File = INI_Open(ActorPath(actorid));
    if(File != INI_NO_FILE)
    {
        INI_SetTag(File,"data");
        INI_WriteInt(File,"Skin",skinid);
        INI_WriteFloat(File,"PosX",X);
        INI_WriteFloat(File,"PosY",Y);
        INI_WriteFloat(File,"PosZ",Z);
        INI_WriteFloat(File,"Angle",A);
        INI_WriteInt(File,"VirtualWorld",VirtualWorld);
        return INI_Close(File);
    }
    return 0;
}

RemoveActor(actorid)
{
    if(fremove(ActorPath(actorid)))
    {
        DestroyActor(actorid);
        return 1;
    }
    return 0;
}

CMD:createactor(playerid, params[])
{
    new skin;
    if(AdminLevel[playerid] < 5) SCM(playerid, COLOR_WHITE, ""WORD_NADMIN"");
    else if(IsPlayerInAnyVehicle(playerid)) SCM(playerid, COLOR_WHITE, ""WORD_ERROR"You cannot create actors while inside a vehicle.");
    else if(sscanf(params, "i", skin)) SCM(playerid, COLOR_WHITE, ""WORD_USAGE"/createactor [SKIN_ID]");
    else if(!(0 <= skin < 312) || skin == 74) SCM(playerid, COLOR_WHITE, ""WORD_ERROR"Invalid skin ID.");
    else{
        new Float:X, Float:Y, Float:Z, Float:fa, world = GetPlayerVirtualWorld(playerid), Actor;
        GetPlayerPos(playerid, X, Y, Z);
        GetPlayerFacingAngle(playerid, fa);
        Actor = CreateActor(skin, X, Y, Z, fa);
        if(AddActor(Actor, skin, X, Y, Z, fa, world))
        {
            SetActorVirtualWorld(Actor, world);
            ClearActorAnimations(Actor);
            new string[128];
            format(string, sizeof(string), ""WORD_SERVER"You have created a new actor with skin: %d", skin);
            SCM(playerid, COLOR_WHITE, string);
        }
    }
    return 1;
}
but you can not operate by ids, if you create 4 actors and then removes 2 (1,2) by RemoveActor(actorid) then you restart server - fail
Reply
#5

Bro, Actors are not getting loaded:
Код:
forward LoadActor_data(name[],value[]);
public LoadActor_data(name[],value[])
{
	new ActorInfo[2],Float:Pos[4];
	INI_Int("Skin",ActorInfo[0]);
	INI_Float("PosX",Pos[0]);
	INI_Float("PosY",Pos[1]);
	INI_Float("PosZ",Pos[2]);
	INI_Float("Angle",Pos[3]);
	INI_Int("VirtualWorld",ActorInfo[1]);
	new Actor = CreateActor(ActorInfo[0], Pos[0], Pos[1], Pos[2], Pos[3]);
	SetActorVirtualWorld(Actor, ActorInfo[1]);
 	return 1;
}

OnGameModeInit()
{
	for(new actorid=0; actorid < MAX_ACTORS; actorid++)
	{
		INI_ParseFile(ActorPath(actorid), "LoadActor_%s");
	}
        return 1;
}
This is a name of one of my actors files: Actor_0
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)