SA-MP Forums Archive
Unit numbers - 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: Unit numbers (/showthread.php?tid=418317)



Unit numbers - firemanjv - 24.02.2013

hi

is it possible to assing unit names / numbers
automatical
with a textdraw on the vehicle with the number
and in departement chat / radio chat also the number
like
LSPD U-E32: [message]

and you wi'll see on the car
U-E32

but there only can be 1 unit e32


Re: Unit numbers - Misiur - 24.02.2013

pawn Код:
#define MAX_UNITS 3
enum UnitData {
    vid,
    Text:txd,
    name[4]
}
static currentUnit = 0;
static allUnits[MAX_UNITS][UnitData];

stock GenerateName(uid) {
    new uname[4];
    do {
        format(uname, sizeof uname, "%c%d%d", 65 + Random(26), Random(10), Random(10));
    } while(IsUniqUnitName(uname));
    return strcat(allUnits[uid][name], uname);
}

stock IsUniqUnitName(name[]) {
    for(new i = 0; i < MAX_UNITS; ++i) {
        if(!strcmp(name, allUnits[i][name])) return 0;
    }
    return 1;
}

stock BuildUnit(vehid) {
    allUnits[currentUnit][vid] = vehid;
    GenerateName[currentUnit];

    //Here add some textdraw logic
    return currentUnit++;
}
Now when you create unit:

pawn Код:
new vid = CreateVehicle(...);
new u = BuildUnit(vid);



Re: Unit numbers - Vince - 24.02.2013

I'd say, just incorporate the vehicleid in the name somewhere. This is unique information, so you won't have to check if it already exists.


Re: Unit numbers - firemanjv - 24.02.2013

hmm thanks but can you explain it a little


Re: Unit numbers - Misiur - 24.02.2013

In my code as you can see, the name is generated randomly, and it has to be checked for uniqueness. However if you'd use vehicle id in name, then the uniqueness is guaranteed:

pawn Код:
new v = CreateVehicle(...);
new name[5];
format(name, sizeof name, "E%03d", v);
//Results
//E001, E002, etc.. up to E000, then back to E001



Re: Unit numbers - firemanjv - 24.02.2013

were do i need to place it and does this work for the /d and /r radio ? i dont think so


Re: Unit numbers - Misiur - 24.02.2013

I don't know your /d and /r commands, also I don't know if you know - but you have your own brain! Yes, it comes free at birth. Use it sometimes.

pawn Код:
enum UnitData {
    uname[5]
}
static Units[MAX_VEHICLES][UnitData];

//Creation of unit
new vid = CreateVehicle(...);
new name[5];
format(name, sizeof name, "E%03d", vid);
strcat(Units[vid][uname], name);

//Retrieving example
new vid = GetPlayerVehicleID(playerid);
new msg[24];
if('\0' != Units[vid][uname][0]) {
    format(msg, sizeof msg, "Hello from unit %s", Units[vid][uname]);
    SendClientMessage(playerid, -1, msg);
}



Re: Unit numbers - firemanjv - 24.02.2013

hmm i found something thanks i gonna check if it works