Unit numbers
#1

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
Reply
#2

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);
Reply
#3

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.
Reply
#4

hmm thanks but can you explain it a little
Reply
#5

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
Reply
#6

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

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);
}
Reply
#8

hmm i found something thanks i gonna check if it works
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)