Useful Functions

pawn Код:
#define pClass(%1) GetPlayerSkin(playerid)==%1
I needed this.
You don't need anymore
pawn Код:
new plClass = GetPlayerSkin(playerid);
if(plClass == 100 || plClass == 200 || plClass == 300)
Now you can use
pawn Код:
if(pClass(100) || pClass(200) || pClass(300))
{
}
It is not so useful , but if you want to use it, go ahead
Reply

Quote:
Originally Posted by Y_Leѕѕ
You just basically tripled the time that code takes to run!

Also:

pawn Код:
if (!pClass(100))
Try that code, I know, and I suspect you know, what people THINK it should do, but try it. Also, slightly more arbitrary, but still possible, bits of code with unexpected results due to bad macro composition:

pawn Код:
if (pClass(a == 10 ? 100 : 101))
pawn Код:
if (pClass(100) & 0x21)
Think what you would expect from those bits of code, then see what you really get.
I made that macro for myself (not for this forum), not gonna use that code what you write.
I'm just using
pawn Код:
if(pClass(100) || pClass(200) || pClass(300))
{
    SendClientMsg...
    gTeam...
Reply

Actually ****** wanted to help you to improve your macro (indirectly)...
Reply

Quote:
Originally Posted by ♣ ⓐⓢⓢ
Actually ****** wanted to help you to improve your macro (indirectly)...
Yeah I know. Did I insult him?
Reply

Quote:
Originally Posted by Luka™
Quote:
Originally Posted by ♣ ⓐⓢⓢ
Actually ****** wanted to help you to improve your macro (indirectly)...
Yeah I know. Did I insult him?
I don't think you insulted him but why would not want to make your code faster/ more efficient :S
Reply

Quote:
Originally Posted by cyber_punk
why would not want to make your code faster/ more efficient :S
And also, not bugged.
Reply

Quote:
Originally Posted by Y_Leѕѕ
Quote:
Originally Posted by Luka™
I made that macro for myself (not for this forum), not gonna use that code what you write.
You released it on the forum, thus it's made for this forum. If you only make code for yourself then you can get away with having bugs, but if you're going to release it here you should try and not, and definitely should fix things people point out. For reference, the fixed version of your code (which is no slower the way you use it) is:

pawn Код:
#define pClass(%1) (GetPlayerSkin(playerid)==(%1))
Also, if you want to keep that syntax but make it faster you could do:

pawn Код:
#define pClassInit() new _pClass = GetPlayerSkin(playerid)
#define pClass(%1) (_pClass==(%1))
Then instead of what you're doing at the moment you can do:

pawn Код:
pClassInit();
if(pClass(100) || pClass(200) || pClass(300))
{
    SendClientMsg...
    gTeam...
Almost identical code (you only need the "pClassInit" once per function) but with the speed benefits of only calling the function once. PLus if you change the macro the compiler will automatically tell you where to change code.
Thanks
Reply

put your script


Код:
new PlayerText3D:playertextid[MAX_PLAYERS];
stock AddTextPlayer3D(playerid,COLOR,text[],Float:Distance)
{
	playertextid[playerid] = PlayerText3D:Create3DTextLabel(text, COLOR, 0.0,0.0,0.0, Distance, 0, 0);
	Attach3DTextLabelToPlayer(Text3D:playertextid[playerid], playerid, 0.0, 0.0, -0.4);
	return 1;
}

stock DeletePlayerText(playerid)
{
	Delete3DTextLabel(Text3D:playertextid[playerid]);
	return 1;
}
and

Код:
public OnPlayerSpawn(playerid)
{
  if(IsPlayerNPC(playerid)) {

	new playername[64];
	GetPlayerName(playerid,playername,64);

 	if(!strcmp(playername,"Mikael",true)) {
    PutPlayerInVehicle(playerid, Coach1, 0);
    SetPlayerColor(playerid,COLOR_WHITE);
    SetPlayerSkin(playerid,16);
    AddTextPlayer3D(playerid,COLOR_AQUA,"Mikael",40.0);
	}
Reply

IsValidEMail

Features
  • Checks if the eMail is in correct format "localpart@domain.tld"
  • Characters that are allowed for local part (username) are uppercase and lowercase letters, numbers, dot (.), underscore (_) and hyphen (-)
  • You can't use dot (.) at the start and at the end of the local part, and you can't use double dots in local part(..)
  • Local part has to contain one or more characters
  • Charaters that are allowed for the domain name are only lowercase letters and hyphen (-)
  • Domain name has to contain 3 or more characters
  • Top Level Domains must match the ones from the TopLevelDomains list

Function

pawn Код:
stock IsValidEMail(email[])
{
  new lenght = strlen(email),
    emailsplit[2][MAX_PLAYER_EMAIL],
    domainsplit[2][MAX_PLAYER_EMAIL],
    atsign;
       
  split(email, emailsplit, '@');
  if (strlen(emailsplit[0]) > 0)
  {
    // Local part (username) is not empty. Continue...
  }
  else { return 0; } // No need to continue...
 
  split(emailsplit[1], domainsplit, '.');
  if (strlen(domainsplit[0]) > 2)
  {
    // Domain name has 3 or more charaters. Continue...
  }
  else { return 0; } // No need to continue...
 
  new len = strlen(emailsplit[0]),
    doubledot = strfind(emailsplit[0], "..", true);
     
  if ((emailsplit[0][0] == '.') || (emailsplit[0][len - 1] == '.') || (doubledot != -1))
  {
    return 0; // The dot (.) can't be on the start or on the end of the local part (username) and double dot (..) is not allowed. Return false...
  }
 
  for (new i = 0; i < lenght; i++)
  {
    if (emailsplit[0][i])
    {
      if ((emailsplit[0][i] >= &#39;A' && emailsplit[0][i] <= 'Z') || (emailsplit[0][i] >= 'a' && emailsplit[0][i] <= 'z') || (emailsplit[0][i] >= '0' && emailsplit[0][i] <= '9') || (emailsplit[0][i] == '.') || (emailsplit[0][i] == '-') || (emailsplit[0][i] == '_'))
      {
        // Local part contains characters that are allowed. Continue...
      }
      else { return 0; } // No need to continue...
    }
       
    if (domainsplit[0][i])
    {
      if ((domainsplit[0][i] >= &#39;a' && domainsplit[0][i] <= 'z') || (domainsplit[0][i] == '-'))
      {
        // Domain name contains charaters that are allowed. Continue...
      }
      else { return 0; } // No need to continue...
    }
       
    // This checks that '@' sign is used only one time...
    if (email[i] == &#39;@')
    {
      atsign++;
      if (atsign > 1) { return 0; } // No need to continue...
    }
  }
  for (new i = 0; i < MAX_TOPLEVEL_DOMAINS; i++)
  {
    if (strcmp(domainsplit[1], TopLevelDomains[i], true) == 0)
    {
      return 1; // All checks are Ok, eMail is valid...
    }
  }
  return 0; // If the inserted Top Level Domain don't match with the TopLevelDomains then return false...
}

Requirements
  • Split Function
  • Top Level Domain List
  • Some Defines

pawn Код:
forward split(const strsrc[], strdest[][], delimiter);

public split(const strsrc[], strdest[][], delimiter)
{
  new i, li;
  new aNum;
  new len;
  while (i <= strlen(strsrc))
  {
    if (strsrc[i] == delimiter || i == strlen(strsrc))
    {
      len = strmid(strdest[aNum], strsrc, li, i, 128);
      strdest[aNum][len] = 0;
      li = i+1;
      aNum++;
    }
    i++;
  }
  return 1;
}
pawn Код:
new TopLevelDomains[MAX_TOPLEVEL_DOMAINS][] = {
    {"ac"},
    {"ad"},
    {"ae"},
    {"aero"},
    {"af"},
    {"ag"},
    {"ai"},
    {"al"},
    {"am"},
    {"an"},
    {"ao"},
    {"aq"},
    {"ar"},
    {"arpa"},
    {"as"},
    {"asia"},
    {"at"},
    {"au"},
    {"aw"},
    {"ax"},
    {"az"},
    {"ba"},
    {"bb"},
    {"bd"},
    {"be"},
    {"bf"},
    {"bg"},
    {"bh"},
    {"bi"},
    {"biz"},
    {"bj"},
    {"bm"},
    {"bn"},
    {"bo"},
    {"br"},
    {"bs"},
    {"bt"},
    {"bv"},
    {"bw"},
    {"by"},
    {"bz"},
    {"ca"},
    {"cat"},
    {"cc"},
    {"cd"},
    {"cf"},
    {"cg"},
    {"ch"},
    {"ci"},
    {"ck"},
    {"cl"},
    {"cm"},
    {"cn"},
    {"co"},
    {"com"},
    {"coop"},
    {"cr"},
    {"cu"},
    {"cv"},
    {"cx"},
    {"cy"},
    {"cz"},
    {"de"},
    {"dj"},
    {"dk"},
    {"dm"},
    {"do"},
    {"dz"},
    {"ec"},
    {"edu"},
    {"ee"},
    {"eg"},
    {"er"},
    {"es"},
    {"et"},
    {"eu"},
    {"fi"},
    {"fj"},
    {"fk"},
    {"fm"},
    {"fo"},
    {"fr"},
    {"ga"},
    {"gb"},
    {"gd"},
    {"ge"},
    {"gf"},
    {"gg"},
    {"gh"},
    {"gi"},
    {"gl"},
    {"gm"},
    {"gn"},
    {"gov"},
    {"gp"},
    {"gq"},
    {"gr"},
    {"gs"},
    {"gt"},
    {"gu"},
    {"gw"},
    {"gy"},
    {"hk"},
    {"hm"},
    {"hn"},
    {"hr"},
    {"ht"},
    {"hu"},
    {"id"},
    {"ie"},
    {"il"},
    {"im"},
    {"in"},
    {"info"},
    {"int"},
    {"io"},
    {"iq"},
    {"ir"},
    {"is"},
    {"it"},
    {"je"},
    {"jm"},
    {"jo"},
    {"jobs"},
    {"jp"},
    {"ke"},
    {"kg"},
    {"kh"},
    {"ki"},
    {"km"},
    {"kn"},
    {"kp"},
    {"kr"},
    {"kw"},
    {"ky"},
    {"kz"},
    {"la"},
    {"lb"},
    {"lc"},
    {"li"},
    {"lk"},
    {"lr"},
    {"ls"},
    {"lt"},
    {"lu"},
    {"lv"},
    {"ly"},
    {"ma"},
    {"mc"},
    {"md"},
    {"me"},
    {"mg"},
    {"mh"},
    {"mil"},
    {"mk"},
    {"ml"},
    {"mm"},
    {"mn"},
    {"mo"},
    {"mobi"},
    {"mp"},
    {"mq"},
    {"mr"},
    {"ms"},
    {"mt"},
    {"mu"},
    {"museum"},
    {"mv"},
    {"mw"},
    {"mx"},
    {"my"},
    {"mz"},
    {"na"},
    {"name"},
    {"nc"},
    {"ne"},
    {"net"},
    {"nf"},
    {"ng"},
    {"ni"},
    {"nl"},
    {"no"},
    {"np"},
    {"nr"},
    {"nu"},
    {"nz"},
    {"om"},
    {"org"},
    {"pa"},
    {"pe"},
    {"pf"},
    {"pg"},
    {"ph"},
    {"pk"},
    {"pl"},
    {"pm"},
    {"pn"},
    {"pr"},
    {"pro"},
    {"ps"},
    {"pt"},
    {"pw"},
    {"py"},
    {"qa"},
    {"re"},
    {"ro"},
    {"rs"},
    {"ru"},
    {"rw"},
    {"sa"},
    {"sb"},
    {"sc"},
    {"sd"},
    {"se"},
    {"sg"},
    {"sh"},
    {"si"},
    {"sj"},
    {"sk"},
    {"sl"},
    {"sm"},
    {"sn"},
    {"so"},
    {"sr"},
    {"st"},
    {"su"},
    {"sv"},
    {"sy"},
    {"sz"},
    {"tc"},
    {"td"},
    {"tel"},
    {"tf"},
    {"tg"},
    {"th"},
    {"tj"},
    {"tk"},
    {"tl"},
    {"tm"},
    {"tn"},
    {"to"},
    {"tp"},
    {"tr"},
    {"travel"},
    {"tt"},
    {"tv"},
    {"tw"},
    {"tz"},
    {"ua"},
    {"ug"},
    {"uk"},
    {"us"},
    {"uy"},
    {"uz"},
    {"va"},
    {"vc"},
    {"ve"},
    {"vg"},
    {"vi"},
    {"vn"},
    {"vu"},
    {"wf"},
    {"ws"},
    {"ye"},
    {"yt"},
    {"yu"},
    {"za"},
    {"zm"},
    {"zw"}
};
pawn Код:
#define MAX_PLAYER_EMAIL     128
#define MAX_TOPLEVEL_DOMAINS   269

Credits
Reply

Is there maybe GetIDFromName or something like that (it should get ID from player nick).
Reply

Quote:
Originally Posted by Luka™
Is there maybe GetIDFromName or something like that (it should get ID from player nick).
pawn Код:
stock GetIDFromName(name[])
{
  new
      i;
  for(i = 0; i <= MAX_PLAYERS; i++)
  {
    if(IsPlayerConnected(i))
    {
      new
          playername[MAX_PLAYER_NAME];
      GetPlayerName(i, playername, sizeof(playername));
      if(strcmp(playername, name, true, strlen(name)) == 0) return i;
    }
  }
  return INVALID_PLAYER_ID;
}
Reply

pawn Код:
stock IsValidFightingStyle(style)
{
    #define MAX_FIGHT_STYLES  6
    new fightStyles[MAX_FIGHT_STYLES] =
    {
        4, 5, 6, 7, 15, 26
    };

    for (new i = 0; i < MAX_FIGHT_STYLES; i++)
    {
      if (style == fightStyles[i]) return true;
    }

    return false;
}
Reply

Why so much complicating?

pawn Код:
forward IsValidFightingStyle(style);
public IsValidFightingStyle(style)
{
  switch(style)
  {
    case 4,5,6,7,15,26: return 1;
    default: return 0;
  }
}
Reply

Quote:
Originally Posted by $ЂЯĢ
Why so much complicating?

pawn Код:
forward IsValidFightingStyle(style);
public IsValidFightingStyle(style)
{
  switch(style)
  {
    case 4,5,6,7,15,26: return 1;
    default: return 0;
  }
}
+1 for that.

Most of the people just copy scripts like one of the first InvalidSkin function that was made, and people just continued copying it..

There are much more useful ways than this (not yours, the other one).
Reply

pawn Код:
stock GetPlayersInTeam(teamid)
{
    new playersInTeam = 0;

    for(new i=0;i<MAX_PLAYERS<i++;)
    {
        if(IsPlayerConnected(i) && GetPlayerTeam(i) == teamid) playersInTeam++;
    }

    return playersInTeam;
}
With this functon you check how many players have specific team.
Example: you can create a team balancer if you're using SetPlayerTeam, not variables.

pawn Код:
public OnPlayerRequestSpawn(playerid)
{
    new pClass = GetPlayerSkin(playerid);

    switch(pClass)
    {
        case 1,2,3: SetPlayerTeam(playerid,1);
        case 4,5,6: SetPlayerTeam(playerid,2);
    }

    if(GetPlayerTeam(playerid) == 1 && GetPlayersInTeam(1) > GetPlayersInTeam(2))
    {
        SendClientMessage(playerid,color,"Team 1 is full, please choose another team/skin/class.");
        return 0;
    }

    else if(GetPlayerTeam(playerid) == 2 && GetPlayersInTeam(1) < GetPlayersInTeam(2))
    {
        SendClientMessage(playerid,color,"Team 2 is full, please choose another team/skin/class.");
        return 0;
    }

    return 1;
}
Now both codes tested, works!
Reply

ok if i ask a samp player to do that how u thing will be i try to use C++ to make the game mod
Reply

Quote:
Originally Posted by Haly11
ok if i ask a samp player to do that how u thing will be i try to use C++ to make the game mod
gm as a plugin? :P
Reply

anyway witch is the difference from AMX and PWN
pwn i know what but i don't know how amx help
Reply

.pwn is the source code, code you write, pawn code
.amx is compiled code
Reply

Код:
stock IsBotName(playerid, Name[])
{
	new Bot[MAX_PLAYER_NAME];
	GetPlayerName(playerid, Bot, sizeof(Bot));
	if(!strcmp(Bot, Name, true)) return 1;
	return 0;
}
For example:

Код:
public OnPlayerSpawn(playerid)
{
  if(IsPlayerNPC(playerid))
  {
    if(IsBotName(playerid, "Doctor"))
    {
      SetPlayerSkin(playerid, 70);
    }
    return 1;
  }
  return 1;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)