I was wondering
#1

Is it possible to return a ''1'' into a ''yes'', the same with no (0 = no) without adding too much extra lines?

For example, I've got this housing script I made myself, with this piece of code:

pawn Код:
format(string,sizeof(string),"|Locked: %d",HouseInfo[H][hLocked]);
          SendClientMessage(playerid,COLOR_STEELBLUE,string);
Now because it looks kinda shitty to get a '1' or a '0' in that area, so is it possible to make it show up a 'Yes' or a 'No'?
Reply
#2

Код:
#define Yes 1
#define No 0
i think its possible
Reply
#3

Didn't quite work
Reply
#4

pawn Код:
if(HouseInfo[H][hLocked])
{
 format(string,sizeof(string),"|Locked: Yes");
} else {
 format(string,sizeof(string),"|Locked: No");
}
SendClientMessage(playerid,COLOR_STEELBLUE,string);
Reply
#5

Quote:
Originally Posted by Pandabeer1337
pawn Код:
if(HouseInfo[H][hLocked])
{
 format(string,sizeof(string),"|Locked: Yes");
} else {
 format(string,sizeof(string),"|Locked: No");
}
SendClientMessage(playerid,COLOR_STEELBLUE,string);
Well I actually already knew that, but it did gave me an idea to make a new function.
Reply
#6

why do you ask then lol.
Reply
#7

Quote:
Originally Posted by Pandabeer1337
why do you ask then lol.
I didn't had the idea before you posted that code and I started to think how to do that faster.

for those interested:

pawn Код:
stock SwitchYesNo(input)
{
    new string[4];
    if(input == 1)
    {
      format(string,sizeof(string),"Yes");
    } else {
        format(string,sizeof(string),"No");
    }
    return string;
}
Reply
#8

or just

pawn Код:
format(string, sizeof(string), "Locked: %s", ((HouseInfo[H][hLocked]) ? ("Yes") : ("No")));
Reply
#9

edited, should work now. i forgot that a string adds a dimension to an array >-<
at top of the script:
Код:
new NoOrYes[][]={"No","Yes"};
and in your function (example of a is-car-locked? script)
Код:
public OnPlayerStateChange(playerid,newstate,oldstate)
{
	if(newstate == PLAYER_STATE_DRIVER)
	{
		new VehID=GetPlayerVehicleID(playerid);
 	  	new string[128];
		format(string,sizeof(string),"|Locked: %s",NoOrYes[VehLocked[VehID]][0]);
		SendClientMessage(playerid,0xffffffff,string);
//...
... where the VehLocked[] represents the value assigned to each car.
this wont need a loop or a switch/case statement, only one array-access more...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)