Useful Functions

1. You have only one variable defined as a textdraw
2. You always create a new textdraw and save the id in the variable
3. You destroy the textdraw saved in the variable after some seconds

But what will happend if you use the function a second time before the textdraw got destroyed ?
Answer: The variable will get overwriten and the oldtextdraw will stay + the new disapear earlier
Reply

Ok, thanks for telling me, but I won't fix it, I cba XD
Reply

Quote:
Originally Posted by LarzI aka. GloZzy
Ok, thanks for telling me, but I won't fix it, I cba XD
Is it 'I cba' or 'I c' (c obviously meaning 'cant')?
Reply

cba is Can't Be Assed/bothered
Reply

Quote:
Originally Posted by Boylett
An exact copy of the function "rand" in PHP.

pawn Код:
rand(minnum = cellmin,maxnum = cellmax) return random(maxnum - minnum + 1) + minnum;
pawn Код:
#define rand(%1,%2) (random(%2 - %1 + 1) + %1)
not exact, but close enough =p
Reply

NOTE!: This is NOT tested by anyone, so it might won't work!

Credits to: Whoever made PlayerToPoint and Andre9977 for the style of posting a function

IsAtPoint(Float:radi, whatis[], id, Float, Float:y, Float:z)
Float:radi - Radius
whatis - Can be playerid, vehicleid or objectid
id - The ID of either playerid, vehicleid or objectid. Depends on what you entered in whatis
Float, Float:y, Float:z - The position we're checking player's/vehicle's/object's lenght from

pawn Код:
stock IsAtPoint(Float:radi, whatis, id, Float:x, Float:y, Float:z)
{
  new Float:oldposx, Float:oldposy, Float:oldposz;
  new Float:tempposx, Float:tempposy, Float:tempposz;
  if(whatis == playerid)
    GetPlayerPos(id, oldposx, oldposy, oldposz);
    else if(whatis == objectid
      GetObjectPos(id, oldposx, oldposy, oldposz);
    else if(whatis == vehicleid
      GetVehiclePos(id, oldposx, oldposy, oldposz);
    else
      return false;
  tempposx = (oldposx -x);
  tempposy = (oldposy -y);
  tempposz = (oldposz -z);
  if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
  {
    return 1;
  }
  return 0;
}
Please if you test this, or just see it, tell me if this won't/doesn't work.
Then I'll just edit this post, without the code and all
Reply

LarzI this wont work

/Working on a fixed version/
Reply

Forgot to compile in an if statement, sorry for that...
And thanks for fixing it
Reply

Quote:
Originally Posted by Seif_
You should have at least compiled it. This will give multiple errors.
No it wont give any error because he never used it so the server never calls it and dont care how much wrong is

and here my version
pawn Код:
enum IAPModes
{
    iap_playerid,
    iap_vehicleid,
    iap_objectid
}
pawn Код:
stock IsAtPoint(Float:radi, IAPModes:mode, id, Float:X, Float:Y, Float:Z)
{
    new Float:Pos[3];
    switch(mode)
    {
        case iap_playerid:  GetPlayerPos(id, Pos[0], Pos[1], Pos[2]);
        case iap_vehicleid: GetVehiclePos(id, Pos[0], Pos[1], Pos[2]);
        case iap_objectid:  GetObjectPos(id, Pos[0], Pos[1], Pos[2]);
    }
    if( -radi < floatsub(Pos[0], X) < radi &&
        -radi < floatsub(Pos[1], Y) < radi &&
        -radi < floatsub(Pos[2], Z) < radi ) return 1;
    return 0;
}
Reply

Atleast someone fixes the function so it usable :P
Reply

Quote:
Originally Posted by ssǝן‾ʎ
Quote:
Originally Posted by Zezombia
RandomEx(min, max);

pawn Код:
RandomEx(min, max)
{
    return random(min) + max - min;
}
That's wrong:

pawn Код:
RandomEx(8, 10);
That can return:

Код:
2, 3, 4, 5, 6, 7, 8, 9
Proper minrand (as I posted many years ago) is:

pawn Код:
RandomEx(min, max)
{
    return random(max - min) + min;
}
and therefore 128 is the proper string size.
Reply

pawn Код:
new FALSE = false;
#define PrintEx(%1,%2) do{ new strz[256]; valstr(strz, %2); format(strz, sizeof(strz), (%1),strz); print(strz); }while(FALSE)
#define SendRconCommandX(%1,%2) do{ new st[256]; format(st, sizeof(st), (%1), %2); SendRconCommand(st); }while(FALSE)
#define SendRconCommandEx(%1,%2) do{ new st[256]; valstr(st, (%2)); format(st, sizeof(st), (%1), st); SendRconCommand(st); }while(FALSE)
Functions:
pawn Код:
PrintEx(format[], {Float,_}:...);
SendRconCommandX(format[], {Float,_}:...);
SendRconCommandEX(format[], {Float,_}:...);
Example usage:
pawn Код:
public OnPlayerConnect(playerid)
{
  PrintEx("Player %s: Has joined the server!", GetName(playerid));
  SendRconCommandX("banip %s", GetIp(playerid));
  SendRconCommandEx("rcon_password %s", 123);
  return 1;
}
Reply

pawn Код:
Replace(string[128], find[128], replace[128])
{
    new pos;
    while((pos = strfind(string, find, true)) != -1)
    {
        strdel(string, pos, pos + strlen(find));
        strins(string, replace, pos);
    }
    return string;
}
Reply

pawn Код:
public UnderscoreToSpace(name[])
{
  for(new i = 0; name[i] != 0; i++)
  if(name[i] == '_') name[i] = ' ';
}
Faster one...
Reply

Even better (maybe not faster though)
pawn Код:
public UnderscoreToSpace(name[])
{
  for(new i = 0; i<24; i++)
  if(name[i] == '_') name[i] = ' ';
}
Correct me if I'm wrong...
Reply

Quote:
Originally Posted by non-l33t'pWnzor
Even better (maybe not faster though)
pawn Код:
public UnderscoreToSpace(name[])
{
  for(new i = 0; i<24; i++)
  if(name[i] == '_') name[i] = ' ';
}
Correct me if I'm wrong...
Fire Dragons one is better.. yours would halt execution on an array smaller then 24 cells, and wouldn't work on a whole string bigger than 24 cells..

BTW, public isn't needed on either.

pawn Код:
UnderscoreToSpace(name[])
{
  for(new i = 0; name[i] != 0; i++)
    if(name[i] == '_') name[i] = ' ';
}
Reply

Ok, thanks for pointing that out
Reply

Код:
stock RangeBan(playerid)
{
 new ip[20];
 GetPlayerIp(playerid,ip,20);
 strdel(ip,strlen(ip)-2,strlen(ip));
 format(ip,128,"%s**",ip);
 format(ip,128,"banip %s",ip);
 SendRconCommand(ip);
}

stock Slap(playerid)
{
 new Float:X,Float:Y,Float:Z,
 Float:pHealth;
 GetPlayerPos(playerid,X,Y,Z);
 SetPlayerPos(playerid,X,Y,Z+7);
 GetPlayerHealth(playerid,pHealth);
 SetPlayerHealth(playerid,pHealth - 10);
}

stock Explode(playerid)
{
 new Float:X,Float:Y,Float:Z;
 GetPlayerPos(playerid,X,Y,Z);
 CreateExplosion(X,Y,Z,13,25);
 Kill(playerid);
}

stock Crash(playerid)
{
 new Float:X,Float:Y,Float:Z;
 GetPlayerPos(playerid,X,Y,Z);
 CreatePlayerObject(playerid,111111,X,Y,Z,0,0,0);
}

stock GiveCar(playerid,vehid)
{
 new Float:X,Float:Y,Float:Z;
 GetPlayerPos(playerid,X,Y,Z);
 CreateVehicle(vehid,X,Y,Z,0,-1,-1,6000);
}

stock Freeze(playerid)
{
 TogglePlayerControllable(playerid,false);
}

stock Unfreeze(playerid)
{
 TogglePlayerControllable(playerid,true);
}

stock GivePlayerHealth(playerid,amount)
{
 new Float:Health;
 GetPlayerHealth(playerid,Health);
 if(IsPlayerConnected(playerid))
 {
	SetPlayerHealth(playerid,Health + amount);
 }
 return 1;
}

stock TakePlayerHealth(playerid,amount)
{
 new Float:Health;
 GetPlayerHealth(playerid,Health);
 if(IsPlayerConnected(playerid))
 {
	SetPlayerHealth(playerid,Health - amount);
 }
 return 1;
}

stock GivePlayerArmour(playerid,amount)
{
 new Float:Armour;
 GetPlayerArmour(playerid,Armour);
 if(IsPlayerConnected(playerid))
 {
	SetPlayerArmour(playerid,Armour + amount);
 }
 return 1;
}

stock TakePlayerArmour(playerid,amount)
{
 new Float:Armour;
 GetPlayerArmour(playerid,Armour);
 if(IsPlayerConnected(playerid))
 {
	SetPlayerArmour(playerid,Armour - amount);
 }
 return 1;
}

stock Kill(playerid)
{
 SetPlayerHealth(playerid,0.0);
 return 1;
}
TakePlayerArmour and TakePlayerHealth are used like in the sense that if say John has 100 health and i do TakePlayerHealth(John,20); John would have 80 health, same thing goes for TakePlayerArmour, GivePlayerArmour just adds to the players armour not sets it.
Reply

not, Ladmin uses it too, the only thing we all have in common is the object id.
Reply

Big Strtok Function (Not by me, Dunno who made it.)
pawn Код:
stock bigstrtok(const string[], &idx)
{
  new length = strlen(string);
    while ((idx < length) && (string[idx] <= ' '))
    {
        idx++;
    }
    new offset = idx;
    new result[128];
    while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
    {
        result[idx - offset] = string[idx];
        idx++;
    }
    result[idx - offset] = EOS;
    return result;
}
/kick with big strtok function.
pawn Код:
if(strcmp(cmd, "/kick", true) == 0)
    {
        new reason[128]; // 128 cells.
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /kick [playerid] [reason]");
        new id = ReturnUser(tmp);
        GetPlayerName(id, giveplayer, sizeof(giveplayer));
        GetPlayerName(playerid, sendername, sizeof(sendername));
        reason = bigstrtok(cmdtext, idx); // The reason becomes as a big strtok.
        if(!strlen(reason)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /kick [playerid] [reason]");
        if(!IsPlayerConnected(id)) return SendClientMessage(playerid,COLOR_GREY,"SERVER: Invalid Player ID");
        format(string, sizeof(string), "Administrator %s has kicked %s, the reason: %s", sendername, giveplayer, reason); // Reason = big strtok.
        SendClientMessageToAll(COLOR_GREY, string);
        Kick(id);
        return 1;
    }
Reply


Forum Jump:


Users browsing this thread: 26 Guest(s)