[HELP]Trying to make a Faction Car Script
#1

pawn Код:
forward LoadFactionCars();
forward IsAFactionCar(playerid);
pawn Код:
enum pInfo
{
    pKey[128],
    pLevel,
    pAdmin,
    pDonateRank,
    gPupgrade,
    pConnectTime,
    pReg,
    pSex,
    pAge,
    pOrigin,
    pMuted,
    pExp,
    pCash,
    pAccount,
    pVirWorld,
    pLocked,
    pAccent,
    pLeader,
    pMember,
    pFactionCar,
    //pSQLID,
};
pawn Код:
public LoadFactionCars()
{
    new arrCoords[8][64];
    new strFromFile2[256];
    new File: file = fopen("factioncars.cfg", io_read);
    if (file)
    {
        new idx = 184;
        while (idx < sizeof(CarInfo))
        {
            fread(file, strFromFile2);
            split(strFromFile2, arrCoords, ',');
            CarInfo[idx][cModel] = strval(arrCoords[0]);
            CarInfo[idx][cLocationx] = floatstr(arrCoords[1]);
            CarInfo[idx][cLocationy] = floatstr(arrCoords[2]);
            CarInfo[idx][cLocationz] = floatstr(arrCoords[3]);
            CarInfo[idx][cAngle] = floatstr(arrCoords[4]);
            CarInfo[idx][cColorOne] = strval(arrCoords[5]);
            CarInfo[idx][cColorTwo] = strval(arrCoords[6]);
            strmid(PlayerInfo[idx][pFactionCar], arrCoords[7], 0, strlen(arrCoords[7]), 255);
            idx++;
        }
    }
    return 1;
}

public IsAFactionCar(player)
{
    if(PlayerInfo[playerid][pFactionCar] == 6) { }
    else {
    RemovePlayerFromVehicle(playerid);
    SendClientMessage(playerid, COLOR_GREY,"You don't have keys of this vehicle.");}
}
Started scripting for real a week ago, and I'm still learning, so don't blame me.

I was trying to create this kind of dynamic car script thing, so that I can add faction cars into a .cfg file, and just put the cars into that file and put the faction number on the end.
Made it so that when I make someone leader or invite someone to a family, it automatically changes the [pFactionCar] to the faction number, my only problem is that when I go into the car, I don't get thrown out.

I know it probably has something to do with that I forwarded "IsAFactionCar" as playerid and all that shit, but not sure how to fix it properly.

I would be extremely grateful if someone could give me a little push here,
Thanks in advance.
Reply
#2

That one cant be correct since pFactionCar isnt a string

pawn Код:
strmid(PlayerInfo[idx][pFactionCar], arrCoords[7], 0, strlen(arrCoords[7]), 255);
use strval to get an integer out of a string

another strange thing is the idx
it is used as index in CarInfo
but for PlayerInfo you would mostly need some kind of playerid

Also I would put the fread in the while loop so it stops at the end of the file
Reply
#3

This might sound like a stupid question, but how do I make it strval? Would you care to help me out a little bit? As I said, I'm kind of new to scripting, so I could use a little bit of help

I'm trying to get it done before I go to bed, so I can put it out on our server tomorrow, need to fix a lot of cars.
Reply
#4

******
https://sampwiki.blast.hk/wiki/Strval
Reply
#5

Thank you, got it working
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)