I was wondering - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: I was wondering (
/showthread.php?tid=143999)
I was wondering -
Hiddos - 25.04.2010
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'?
Re: I was wondering -
Om3n - 25.04.2010
Код:
#define Yes 1
#define No 0
i think its possible
Re: I was wondering -
Hiddos - 25.04.2010
Didn't quite work
Re: I was wondering -
Think - 25.04.2010
pawn Код:
if(HouseInfo[H][hLocked])
{
 format(string,sizeof(string),"|Locked: Yes");
} else {
 format(string,sizeof(string),"|Locked: No");
}
SendClientMessage(playerid,COLOR_STEELBLUE,string);
Re: I was wondering -
Hiddos - 25.04.2010
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.
Re: I was wondering -
Think - 25.04.2010
why do you ask then lol.
Re: I was wondering -
Hiddos - 25.04.2010
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;
}
Re: I was wondering -
Nero_3D - 25.04.2010
or just
pawn Код:
format(string, sizeof(string), "Locked: %s", ((HouseInfo[H][hLocked]) ? ("Yes") : ("No")));
Re: I was wondering -
Babul - 25.04.2010
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...