List of admin commands Log in rcon ( /rcon login [password] )
![]() ![]()
PHP код:
Sorry for my english and if I posted on the wrong topic. |
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[ ])
{
if(dialogid == 888)
if(response)
ShowPlayerDialog(playerid, 889, DIALOG_STYLE_MSGBOX, "Admin Commands", AdminCommands[i][information], "Close","");
}
Select Random Player
PHP Code:
|
SelectRandomPlayer()
{
new players[MAX_PLAYERS], count;
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i ++)
{
IsPlayerConnected(i) && (players[count ++] = i);
}
return ((!count) ? (-1) : (players[random(count)]));
}
no bump please.
Do you know what you're talking about? ![]() @Edit I'm not a machine, just because you do it one way, and you think you're better. This does not mean that you should force people to do the same. https://sampwiki.blast.hk/wiki/OnDialogResponse |
stock IsValidRPName(name[]) //credits: zLink and base Larceny
{
if(('A' <= name[0] <= 'Z') && ('a' <= name[1] <= 'z'))
{
if(IsValidRPInput(name))
{
if(strfind(name, "_") != -1)
{
new underline = strfind(name, "_"), pos = underline +1;
if(('A' <= name[pos] <= 'Z') && ('a' <= name[pos +1] <= 'z'))
{
for(new i; i < strlen(name); ++i)
{
if(('A' <= name[i] <= 'Z') && (i != 0) && (i != pos)) return 0;
else if((name[i] == '_') && (i != underline)) return 0;
else continue;
}
return 1;
}
}
}
}
return 0;
}
IsValidRPInput(const ipstr[]) //credits: zLink and base PT
{
for(new i = 0; ipstr[i] != EOS; ++i)
{
switch(ipstr[i])
{
case 'A'..'Z', 'a'..'z','_': continue;
default: return 0;
}
}
return 1;
}
CMD:test(playerid, params[]) { if(isnull(params)) return SendClientMessage(playerid, 0xFF0000FF,"use: /test [your name]"); if(IsValidRPName(params)) { //is valid } else { //not is valid } return 1; }
Get weapon slot
Код:
stock GetWeaponSlot(weaponid) { switch(weaponid) { case 0,1: return 0; case 2,3,4,5,6,7,8,9: return 1; case 10,11,12,13,14,15: return 10; case 16,17,18: return 8; case 22,23,24: return 2; case 25,26,27: return 3; case 28,29,32: return 4; case 30,31: return 5; case 33,34: return 6; case 35,36,37,38: return 7; case 39: return 8; case 40: return 12; case 41,42,43: return 9; case 44,45,46: return 11; } return -1; } |
// stock GetWeaponSlotID(const weaponid) stock GetWeaponSlot(const weaponid) { switch(weaponid) { case 0,1: return 0; case 2 .. 9: return 1; case 10 .. 15: return 10; case 16 .. 18: return 8; case 22 .. 24: return 2; case 25 .. 27: return 3; case 28,29,32: return 4; case 30,31: return 5; case 33,34: return 6; case 35 .. 38: return 7; case 39: return 8; case 40: return 12; case 41 .. 43: return 9; case 44 .. 46: return 11; } return -1; }
Get weapon slot
Код:
stock GetWeaponSlot(weaponid) { switch(weaponid) { case 0,1: return 0; case 2,3,4,5,6,7,8,9: return 1; case 10,11,12,13,14,15: return 10; case 16,17,18: return 8; case 22,23,24: return 2; case 25,26,27: return 3; case 28,29,32: return 4; case 30,31: return 5; case 33,34: return 6; case 35,36,37,38: return 7; case 39: return 8; case 40: return 12; case 41,42,43: return 9; case 44,45,46: return 11; } return -1; } Код:
CMD:test(playerid, params[]) { new x[15]; format(x, sizeof(x), "Minigun slot: %d", GetWeaponSlot(38)); printf(x); return 1; } Код:
CMD:test2(playerid, params[]) { new x[23]; format(x, sizeof(x), "Your weapon slot is: %d", GetWeaponSlot(GetPlayerWeapon(playerid))); printf(x); return 1; } |
static const WSlot[] = {0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 10, 10, 10, 10, 10, 10, 8, 8, 8, -1, -1, -1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 4, 6, 6, 7, 7, 7, 7, 8, 12, 9, 9, 9, 11, 11, 11};
CMD:test(playerid, params[]) return printf("Minigun slot: %d", WSlot[38]);
About that RandomPlayer function you can use this.
Code:
GetRandomPlayer() { new iPlayer = -1, iID = random(GetPlayerPoolSize()); for(new i = 0; i < GetPlayerPoolSize(); i++){ if(!IsPlayerConnected(i)) continue; if(iID == i){ iPlayer = i; } else { CallLocalFunction("GetRandomPlayer", ""); } } return iPlayer; } |
GetRandomPlayer(loop=3) { RandomCase: loop--; if(loop < 0)return -1; new iID = random(GetPlayerPoolSize()); if(IsPlayerConnected(iID))return iID; else goto RandomCase; }
new randomplayer = random(GetPlayerPoolSize());
Код:
GetRandomPlayer(loop=3) { RandomCase: loop--; if(loop < 0)return -1; new iID = random(GetPlayerPoolSize()); if(IsPlayerConnected(iID))return iID; else goto RandomCase; } |
new iID = random( GetPlayerPoolSize() + 1);
new bool:g_ConnectedPlayers[MAX_PLAYERS char];
public OnPlayerConnect(playerid)
{
g_ConnectedPlayers{playerid} = true;
return 1;
}
public OnPlayerDisconnect(playerid)
{
g_ConnectedPlayers{playerid} = false;
return 1;
}
GetRandomPlayer()
{
new idx;
new true_list[MAX_PLAYERS];
for(new x = 0, t = GetPlayerPoolSize(); x < t; x++)
{
if(!g_ConnectedPlayers{x}) continue;
true_list[idx] = x;
idx++;
}
if(idx)
{
return true_list[random(idx)];
}
return INVALID_PLAYER_ID;
}
It should be like this tho:
PHP код:
|
new iID = Iter_Random(Player);
It should be like this tho:
PHP Code:
|
ReturnRandomPlayer()
{
new
lastPlayer = GetPlayerPoolSize();
for (new i = random(lastPlayer + 1); i < lastPlayer; i++)
{
if (IsPlayerConnected(i))
{
return i;
}
}
return -1;
}
Not everyone uses y_iterate (foreach)
My not recursive version: PHP Code:
|
Stop doing meaningless iterations! Build a list of connected players first then simply randomly choose from that list. Iterating through players then doing a `continue;` if the player isn't connected is possibly the worst way to do it.
|
stock GetRandomPlayer() {
new
online[MAX_PLAYERS],
total;
for(new i, j = GetPlayerPoolSize(); i < j; ++i) {
if(IsPlayerConnected(i)) {
online[total++] = i;
}
}
if(total == 0) {
return INVALID_PLAYER_ID;
}
return online[random(total)];
}
stock bool:strequal(const string1[], const string2[], bool:ignorecase = false, length = cellmax)
{
new
s1 = string1[0],
s2 = string2[0];
if ((s1 == '\0' || s2 == '\0') && (s1 != s2))
return false;
return strcmp(string1, string2, ignorecase, length) == 0;
}
main()
{
new
str_1[12] = "Hello World",
str_2[12] = "Hello World",
bool:inequality = strequal(str_1, str_2);
printf("%i", inequality); //inequality = 1
}
pawn Code:
[O]: true [I]: cmenezes22@gmail.com [O]: true [I]: cmenezes2@1333@hotmail.pt [O]: false (@ is not allowed in emails) [I]: cmen@gmail.com [O]: false (most email service providers need you to register with an handle ranging from 6 to 30 characters long) [I]: c23ddsadmen@gmail.c [O]: false (domain must be equal or longer than 2 characters) |
IsPlayerInRangeOfPointEx(playerid, Float:radius, Float:height, Float:x, Float:y, Float:z)
{
new Float:px, Float:py, Float:pz;
if(!IsPlayerConnected(playerid)) return 0;
GetPlayerPos(playerid, px, py, pz);
if(floatabs((px-x) + (py-y)) <= radius && floatabs((pz-z)) <= height) return 1;
return 0;
}
precent(Float:min, Float:max)
{
return _:(floatabs((min/max)*100));
}