SA-MP Forums Archive
Can i do it like this? - 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: Can i do it like this? (/showthread.php?tid=423664)



Can i do it like this? - Don_Cage - 18.03.2013

pawn Код:
if(PlayerInfo[playerid][pMuted] == 1)
            {
                SendClientMessage(playerid, TEAM_CYAN_COLOR, "You cannot speak, you have been silenced");
                return 1;
            }
            if(PlayerInfo[playerid][pMaskuse] == 1)
            format(string, sizeof(string), "* %s takes out a cellphone.",sendername);
            SetPlayerSpecialAction(playerid, SPECIAL_ACTION_USECELLPHONE);
            ProxDetector(30.0, playerid, string, COLOR_CHAT1,COLOR_CHAT2,COLOR_CHAT3,COLOR_CHAT4,COLOR_CHAT5);
            new phonenumb = strval(tmp);
            if(phonenumb == 115)
           
            if(PlayerInfo[playerid][pMaskuse] == 0)
            format(string, sizeof(string), "* Stranger takes out a cellphone.");
            SetPlayerSpecialAction(playerid, SPECIAL_ACTION_USECELLPHONE);
            ProxDetector(30.0, playerid, string, COLOR_CHAT1,COLOR_CHAT2,COLOR_CHAT3,COLOR_CHAT4,COLOR_CHAT5);
            if(phonenumb == 115)
            {



Re: Can i do it like this? - Jstylezzz - 18.03.2013

Can you be a little more specific about what you want us to answer? Also, if you're not sure it works, why waiting for an answer here if you can simply test it yourself?


Re: Can i do it like this? - Misiur - 18.03.2013

You lack at least 3 curly braces https://sampwiki.blast.hk/wiki/Control_Structures#Brackets


Re: Can i do it like this? - Don_Cage - 18.03.2013

I mean can i just leave a space between
pawn Код:
if(phonenumb == 115) and if(PlayerInfo[playerid][pMaskuse] == 0)
will it still work ingame? i get no errors when i complie but i thougt i was needed to have { between them but maybe i dont? reason im asking is cuz i dont have a test server and dont want to bother my players with something im not sure it will work


Re: Can i do it like this? - Misiur - 18.03.2013

Parser doesn't give a damn about whitespace (except preprocessor stuff). Although I'm little shocked that it works, please, please use brackets, indentation and logic operators for stuff like that. If pMaskuse is 1 then user has mask on?
pawn Код:
if(PlayerInfo[playerid][pMuted] == 1) return SendClientMessage(playerid, TEAM_CYAN_COLOR, "You cannot speak, you have been silenced");
strcat((string[0] = EOS, string), "* Stranger takes out a cellphone.");
if(PlayerInfo[playerid][pMaskuse] == 1) format(string, sizeof(string), "* %s takes out a cellphone.",sendername);
SetPlayerSpecialAction(playerid, SPECIAL_ACTION_USECELLPHONE);
ProxDetector(30.0, playerid, string, COLOR_CHAT1,COLOR_CHAT2,COLOR_CHAT3,COLOR_CHAT4,COLOR_CHAT5);
new phonenumb = strval(tmp);
if(phonenumb == 115)
{



Re: Can i do it like this? - Don_Cage - 19.03.2013

Yes then he have the mask on


Re: Can i do it like this? - Don_Cage - 19.03.2013

I did like this now
pawn Код:
if(PlayerInfo[playerid][pMaskuse] == 1)
            {
                format(string, sizeof(string), "* %s takes out a cellphone.",sendername);
                SetPlayerSpecialAction(playerid, SPECIAL_ACTION_USECELLPHONE);
                ProxDetector(30.0, playerid, string, COLOR_CHAT1,COLOR_CHAT2,COLOR_CHAT3,COLOR_CHAT4,COLOR_CHAT5);
                new phonenumb = strval(tmp);
                if(phonenumb == 115)
            }
            else if(PlayerInfo[playerid][pMaskuse] == 0)
            {
                if(PlayerInfo[playerid][pMaskuse] == 0)
                format(string, sizeof(string), "* Stranger takes out a cellphone.");
                SetPlayerSpecialAction(playerid, SPECIAL_ACTION_USECELLPHONE);
                ProxDetector(30.0, playerid, string, COLOR_CHAT1,COLOR_CHAT2,COLOR_CHAT3,COLOR_CHAT4,COLOR_CHAT5);
                if(phonenumb == 115)
            {
                SendClientMessage(playerid, COLOR_GREEN, "____________Services number list____________");
                SendClientMessage(playerid, COLOR_WHITE, "111 - pizza stack co., 222 - bus services");
                SendClientMessage(playerid, COLOR_WHITE, "103 - medics, 444 - taxi, 555 - mechanic");
                SendClientMessage(playerid, COLOR_WHITE, "151 - Advertisement Agency, 150 - ABC Studios");
                SendClientMessage(playerid, COLOR_GREEN, "____________________________________________");
                return 1;
            }
and i got 26 errors that dosnt even make sense, soooo where did i miss a bracket or something?


Re: Can i do it like this? - Misiur - 19.03.2013

Yup, 26 errors are typical for missing bracket. Also I already gave you piece of fixed code. Now with 20% more comments!

pawn Код:
if(PlayerInfo[playerid][pMuted] == 1) return SendClientMessage(playerid, TEAM_CYAN_COLOR, "You cannot speak, you have been silenced");

//If user has a mask, then change contents of string to "Stranger blahblahb"
format(string, sizeof(string), PlayerInfo[playerid][pMaskuse] == 0 ? ("* %s takes out a cellphone.") : ("* Stranger takes out a cellphone."), sendername);

SetPlayerSpecialAction(playerid, SPECIAL_ACTION_USECELLPHONE);
ProxDetector(30.0, playerid, string, COLOR_CHAT1,COLOR_CHAT2,COLOR_CHAT3,COLOR_CHAT4,COLOR_CHAT5);
if(strval(tmp) == 115)
{
    SendClientMessage(playerid, COLOR_GREEN, "____________Services number list____________");
    SendClientMessage(playerid, COLOR_WHITE, "111 - pizza stack co., 222 - bus services");
    SendClientMessage(playerid, COLOR_WHITE, "103 - medics, 444 - taxi, 555 - mechanic");
    SendClientMessage(playerid, COLOR_WHITE, "151 - Advertisement Agency, 150 - ABC Studios");
    SendClientMessage(playerid, COLOR_GREEN, "____________________________________________");
    return 1;
}



Re: Can i do it like this? - Don_Cage - 19.03.2013

But this
pawn Код:
format(string, sizeof(string), PlayerInfo[playerid][pMaskuse] == 0 ("* %s takes out a cellphone."), sendername);
only checks if the user dont use the mask, its nothing that checks if the user use a mask or what to say when he does?


Re: Can i do it like this? - Misiur - 19.03.2013

Take a closer look

pawn Код:
PlayerInfo[playerid][pMaskuse] == 0 ? ("* %s takes out a cellphone.") : ("* Stranger takes out a cellphone.")
If mask is equal 0, then string formatted will be "* %s takes out a cellphone.", but if the player has a mask on, then it will be "* Stranger takes out a cellphone.". This is called ternary operator