Jump to content

script Nahradenie ID v správe za meno


Tanga

Recommended Posts

Ak to nie je jasné z názvu, funguje to takto:
(Na serveri je hráč Tango (ID 0) a hráč Petr (ID 27))
Tango napíše:
@27ove auto je škaredšie než @0ve.
V chate sa objaví:
Tango: Petrove auto je škaredšie než Tangove.
 

public OnPlayerText(playerid, text[])
{
  for (new i; i < 128; i++) {
    if (text[i] == '@') {
      if ((text[i + 1] > 47) && (text[i + 1] < 58)) {
      	new id = strval(text[i + 1]);
        if (id <= MAX_PLAYERS) {
   	  if (IsPlayerConnected(id)) {
            new menohraca[MAX_PLAYER_NAME];
	    GetPlayerName(id, menohraca, MAX_PLAYER_NAME);
	    new j = (i + 1);
	    while ((j < (i + 5)) && ((text[j] > 47) && (text[j] < 58)))
              j++;
	    strdel(text, i, j);
	    strins(text, menohraca, i, 128);
    	  } else {
	    SendClientMessage(playerid, 0xFF0000FF, "Zlé ID");
	    return 0;
	  }
        } else {
	  SendClientMessage(playerid, 0xFF0000FF, "Zlé ID");
	  return 0;
	}
      }
    }
  }
  SendPlayerMessageToAll(playerid, text);
  return 0;
}

 

Verzia vyššie nie je testovaná. Ak by nefungovala, skús túto:

 

public OnPlayerText(playerid, text[])
{
  new string[128];
  format(string, sizeof(string), "%s", text);
  for (new i; i < 128; i++) {
    if (string[i] == '@') {
      if ((string[i + 1] > 47) && (string[i + 1] < 58)) {
      	new id = strval(string[i + 1]);
        if (id <= 500) {
   	  if (IsPlayerConnected(id)) {
            new menohraca[MAX_PLAYER_NAME];
	    GetPlayerName(id, menohraca, MAX_PLAYER_NAME);
	    new j = (i + 1);
	    while ((j < (i + 5)) && ((string[j] > 47) && (string[j] < 58)))
              j++;
	    strdel(string, i, j);
	    strins(string, menohraca, i, 128);
    	  } else {
	    SendClientMessage(playerid, 0xFF0000FF, "Zlé ID");
	    return 0;
	  }
        } else {
	  SendClientMessage(playerid, 0xFF0000FF, "Zlé ID");
	  return 0;
	}
      }
    }
  }
  SendPlayerMessageToAll(playerid, string);
  return 0;
}

 

 

 

Link to comment
Share on other sites

  • 1 month later...

Môžem sa opýtať prečo mi to nejde nehádže to ani error ani warning ale mám taký pocit že budem musieť pridať nejaký new alebo čo, prosím poradte.

 

//Edit

Skúšali sme to s hráčom ktorý to tu pridal a bugovalo to na nick proste zmenil si si nick a všetko fungovalo ako malo, je to záhadne ale funguje to :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...