Liveoliver
Member
- Joined
- Mar 2, 2023
- Messages
- 8
- Reaction score
- 0
new nr;
new text[128];
forward GetPlayerId(name[]);
forward GetPlayerNumber(playerid);
public OnPlayerText(playerid, text[])
{
new player_name[MAX_PLAYER_NAME];
GetPlayerName(playerid, player_name, sizeof(player_name));
new quote_start_pos = strstr(text, "(( ");
if (quote_start_pos != -1)
{
new quote_end_pos = strstr(quote_start_pos + 1, "'");
if (quote_end_pos != -1)
{
new name_start_pos = quote_start_pos + 3;
new name_end_pos = strstr(text, " says:", name_start_pos);
new name[24];
substr(name, text, name_start_pos, name_end_pos - name_start_pos);
trim(name);
nr = GetPlayerNumber(GetPlayerId(name));
substr(text, text, quote_start_pos + 4, quote_end_pos - quote_start_pos - 4);
format(string, sizeof(string), "/sms %d %s", nr, text);
CopyToClipboard(playerid, string);
}
}
return 1;
}
forward GetPlayerName(playerid, name[], len);
forward trim(string[]);
forward substr(dest[], source[], start, end);
public GetPlayerId(name[])
{
new i, name2[MAX_PLAYER_NAME];
for (i = 0; i < MAX_PLAYERS; i++)
{
if (IsPlayerConnected(i))
{
GetPlayerName(i, name2, sizeof(name2));
if (!strcmp(name, name2, true))
{
return i;
}
}
}
return INVALID_PLAYER_ID;
}
public GetPlayerNumber(playerid)
{
new i, j;
for (i = 0; i < MAX_PLAYERS; i++)
{
if (IsPlayerConnected(i))
{
j++;
if (i == playerid)
{
return j;
}
}
}
return 0;
}
public trim(string[])
{
new i, len = strlen(string), start, end;
for (i = 0; i < len; i++)
{
if (string != ' ' && string != '\t' && string != '\n' && string != '\r')
{
start = i;
break;
}
}
for (i = len - 1; i >= 0; i--)
{
if (string != ' ' && string != '\t' && string != '\n' && string != '\r')
{
end = i;
break;
}
}
substr(string, string, start, end - start + 1);
}
public substr(dest[], source[], start, end)
{
new i, j = 0;
for (i = start; i <= end; i++)
{
dest[j++] = source;
}
dest[j] = '\0';
}
so in this code i try to make /sms giveaway code. More specifically i will try to explain with an example.
this is the chat:
(( admin1 says: this is a event of type [/sms] you'll need to type 'this is an example' ))
and i want when this is detected i mean "((" and "[/sms]"
to be saved in a variable the result of the next commands: first /id admin1, and the result from this to be in /number of the result.
In the final product in clipboard i should have the next thing "/sms (what number has admin1) this is an example"
new text[128];
forward GetPlayerId(name[]);
forward GetPlayerNumber(playerid);
public OnPlayerText(playerid, text[])
{
new player_name[MAX_PLAYER_NAME];
GetPlayerName(playerid, player_name, sizeof(player_name));
new quote_start_pos = strstr(text, "(( ");
if (quote_start_pos != -1)
{
new quote_end_pos = strstr(quote_start_pos + 1, "'");
if (quote_end_pos != -1)
{
new name_start_pos = quote_start_pos + 3;
new name_end_pos = strstr(text, " says:", name_start_pos);
new name[24];
substr(name, text, name_start_pos, name_end_pos - name_start_pos);
trim(name);
nr = GetPlayerNumber(GetPlayerId(name));
substr(text, text, quote_start_pos + 4, quote_end_pos - quote_start_pos - 4);
format(string, sizeof(string), "/sms %d %s", nr, text);
CopyToClipboard(playerid, string);
}
}
return 1;
}
forward GetPlayerName(playerid, name[], len);
forward trim(string[]);
forward substr(dest[], source[], start, end);
public GetPlayerId(name[])
{
new i, name2[MAX_PLAYER_NAME];
for (i = 0; i < MAX_PLAYERS; i++)
{
if (IsPlayerConnected(i))
{
GetPlayerName(i, name2, sizeof(name2));
if (!strcmp(name, name2, true))
{
return i;
}
}
}
return INVALID_PLAYER_ID;
}
public GetPlayerNumber(playerid)
{
new i, j;
for (i = 0; i < MAX_PLAYERS; i++)
{
if (IsPlayerConnected(i))
{
j++;
if (i == playerid)
{
return j;
}
}
}
return 0;
}
public trim(string[])
{
new i, len = strlen(string), start, end;
for (i = 0; i < len; i++)
{
if (string != ' ' && string != '\t' && string != '\n' && string != '\r')
{
start = i;
break;
}
}
for (i = len - 1; i >= 0; i--)
{
if (string != ' ' && string != '\t' && string != '\n' && string != '\r')
{
end = i;
break;
}
}
substr(string, string, start, end - start + 1);
}
public substr(dest[], source[], start, end)
{
new i, j = 0;
for (i = start; i <= end; i++)
{
dest[j++] = source;
}
dest[j] = '\0';
}
so in this code i try to make /sms giveaway code. More specifically i will try to explain with an example.
this is the chat:
(( admin1 says: this is a event of type [/sms] you'll need to type 'this is an example' ))
and i want when this is detected i mean "((" and "[/sms]"
to be saved in a variable the result of the next commands: first /id admin1, and the result from this to be in /number of the result.
In the final product in clipboard i should have the next thing "/sms (what number has admin1) this is an example"