Need help with a command.
#1

Hi there.

Iґve created 3 take-able turfs on my server. As a little extra, Iґve created a /turfs command which is supposed to show you the turfs and its occupations. Iґve started like this:

This is inside /turfs:
Код:
  format(turf1, sizeof(turf1), ">> El Quebrados <<: Occupied by %s", zone1owned);
	format(turf2, sizeof(turf2), ">> Gas Station <<: Occupied by %s", zone2owned);
	format(turf3, sizeof(turf3), ">> Snake Farm <<: Occupied by %s", zone3owned);
This is when you successfully take a turf over (One example):

Код:
zone3owned = USA;
Then, at the top of the script:

Код:
#define USA 1
#define Germany 2
#define Russia 3
#define China 4
#define Civilians 5
#define Unoccupied 1227
At OnGameModeinit, Iґve setted all things to "unoccupied".

Now, when you type /turfs ingame, it displays some weird letters, but no occupations. Why?



Reply
#2

Because you are trying to display a number as a string.

When you #define something as a number, then that's what it is when you use the definition. It's a number, so you're trying to format an integer as a string.

The #define is basically pasting that same bit of code (numbers or strings) wherever you put the definition.

Reply
#3

Update: Tried it with the numbers, just like this:

zone3owned = 1;

But that wont work either - still those weird letters displayed.

Thanks for your answer Brendan. Do you have a solution how to get the names instead of integer displayed?
Reply
#4

Anyone?
Reply
#5

That would be one way of doing it

pawn Код:
GetCountryName(zoneid)
{
    switch(zoneid)
    {
        case 1: return "USA";
        case 2: return "Germany";
        case 3: return "Russia";
        case 4: return "China";
        case 5: return "Civilians";
        default: return "Unoccupied";  
    }
}
pawn Код:
format(turf1, sizeof(turf1), ">> El Quebrados <<: Occupied by %s", GetCountryName(zone1owned));
    format(turf2, sizeof(turf2), ">> Gas Station <<: Occupied by %s", GetCountryName(zone2owned));
    format(turf3, sizeof(turf3), ">> Snake Farm <<: Occupied by %s", GetCountryName(zone3owned));
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)