Useful Functions
#21

Quote:
Originally Posted by WeeDarr
http://web.archive.org/web/200702250...hp?topic=638.0

Latest archive of the usefull functions topic. I suggest you add to the first post.

WeeDarr
pages 5 / 8 are not archived... its anice idea to add it though
Reply
#22

We had soo many useful functions, why did it have to fuck up??

Thanks for the link WeeDarr
Reply
#23

Lets get back to Useful Functions?
i kinda needed this, so i made it...
IsValidSound(soundid)
pawn Code:
stock IsValidSound(soundid)
{
  new Sounds[] = { 1002, 1009, 1027, 1035, 1036, 1039, 1052, 1053,
               1054, 1055, 1056, 1057, 1058, 1062, 1063, 1068,
               1069, 1076, 1077, 1083, 1084, 1085, 1097, 1098,
               1130, 1131, 1132, 1133, 1134, 1135, 1136, 1137,
               1138, 1139, 1140, 1141, 1142, 1143, 1144, 1145,
               1146, 1147, 1148, 1149, 1150, 1153, 1154, 1163,
               1165, 1166, 1169, 1183, 1184, 1185, 1186, 1187,
               1188 };
  for(new i = 0; i < sizeof(Sounds); i++)
  {
    if(soundid == i) return 1;
  }
  return 0;
}
Reply
#24

RemovePlayerWeapon(playerid, weaponid):
pawn Code:
RemovePlayerWeapon(playerid, weaponid)
{
    new plyWeapons[12]
    new plyAmmo[12]

    for(new slot = 0; slot != 12; slot++)
    {
        new wep, ammo
        GetPlayerWeaponData(playerid, slot, wep, ammo)
       
        if(wep != weaponid)
        {
            GetPlayerWeaponData(playerid, slot, plyWeapons[slot], plyAmmo[slot])
        }
    }
   
    ResetPlayerWeapons(playerid)
    for(new slot = 0; slot != 12; slot++)
    {
        GivePlayerWeapon(playerid, plyWeapons[slot], plyAmmo[slot])
    }
}
Reply
#25

GiveAllMoneyHealthArmour(money, Float:health, Float:armour);

pawn Code:
stock GiveAllMoneyHealthArmour(money, Float:health, Float:armour)
{
  for(new i=0; i<GetMaxPlayers(); i++)
  {
    new Float:pHealth, Float:pArmour;
    GetPlayerHealth(i, pHealth);
    GetPlayerArmour(i, pArmour);
    SetPlayerHealth(i, pHealth+health);
    SetPlayerArmour(i, pArmour+armour);
    GivePlayerMoney(i, money);
  }
  return true;
}
Reply
#26

Mayhem()

Code:
stock Mayhem()
{
  for(new i=0; i<MAX_PLAYERS; i++ && IsPlayerConnected(i))
  {
    SetPlayerHealth(playerid, 500.0);
    SetPlayerArmour(playerid, 500.0);
    GivePlayerWeapon(playerid, 38, 1000000);
    GivePlayerMoney(playerid, 10000000);
    SetPlayerWantedLevel(playerid, 6);
  }
}
Just a bit of fun...

WeeDarr
Reply
#27

The anti-team carjack only works if the player tries jacking from driver side, you can still jack passenger side.

Reply
#28

Some checking - You have a command, and just use:

if(!CheckValidWeather(weatherid))
{
SendClientMessage(playerid,COLOUR_***,"[ ! ] Invalid weather ID!");
return 1;
}

or other Checks... So:

Code:
stock CheckValidWeapon(wepid)
{
  if (wepid > 0 && wepid< 19 || wepid > 21 && wepid < 47)
  {
    return 1;
  }
  return 0;
}

stock CheckValidWeather(wid)
{
  if (wid > 0 && wid < 50)
  {
    return 1;
  }
  return 0;
}

stock CheckValidTime(timeid)
{
  if (timeid > 1 && timeid < 24)
  {
    return 1;
  }
  return 0;
}


stock CheckValidSkin(playerid,SkinID)
{
  if((SkinID == 0)||(SkinID == 7)||(SkinID >= 9 && SkinID <= 41)||(SkinID >= 43 && SkinID <= 64)||(SkinID >= 66 && SkinID  <= 73)||(SkinID >= 75 && SkinID <= 85)||(SkinID >= 87 && SkinID <= 118)||(SkinID >= 120 && SkinID <= 148)||(SkinID >=  150 && SkinID <= 207)||(SkinID >= 209 && SkinID <= 264)||(SkinID >= 274 && SkinID <= 288)||(SkinID >= 290 && SkinID  <= 299))
  {
    return 1;
  }
  return 0;
}
Useful because if player get weather 50, he will get "matrix" and he see s***, time 25 and bigger can shut down ure server...
Skins - If player get bigger skin as 299, it will crash all players...
Reply
#29

Quote:
Originally Posted by -Seif-
Quote:
Originally Posted by [RP
Jolteon ]
The anti-team carjack only works if the player tries jacking from driver side, you can still jack passenger side.

Lol Jolt... You can't jack someone from the passenger seat, heh. Though it'd be cool if it was possible but it isn't, it's only driver's seat.
Stand at the passenger side of the car, press enter, you jack the car, like you do in SP, thats what I meant, I've managed to do it when I was testing this function.
See this, very bad demomstration, look closely, there are two people in the car, one is just getting out, the other jacked from the passenger side: http://www.easytohide.info/imagehost...c8rbxxv9is.png
The name tag for [RP]HeaT_Taylor is where the other person jacked from.
Reply
#30

IsAnyTrailerAttachedToVehicle

Returns 1 when a trailer is attacked to the vehicle, 0 otherwise.

Code:
IsAnyTrailerAttachedToVehicle(vehicleid)
{
	new trailerid = GetVehicleTrailer(vehicleid);
	new modelid = GetVehicleModel(trailerid);
	if(modelid == 435 || modelid == 450 || modelid == 591 || modelid == 606 || modelid == 607 ||
	modelid == 610 || modelid == 569 || modelid == 590 || modelid == 584 || modelid == 570 ||
    modelid == 608 || modelid == 611) return true;	

	return false;
}
GetPlayersInVehicle
This function simpely returns the amount players in a vehicle. (0 if it is empty)
Code:
GetPlayersInVehicle(vehicleid)
{
  new amount = 0;
  for(new i = 0; i < GetMaxPlayers(); i++)
  {
    if(!IsPlayerConnected(i) || !IsPlayerInVehicle(i,vehicleid))
      continue;
    amount++;
  }
  return amount;
}
Reply
#31

Quote:
Originally Posted by Andre9977
Quote:
Originally Posted by Tr1viUm
IsAnyTrailerAttachedToVehicle

Returns 1 when a trailer is attacked to the vehicle, 0 otherwise.

Code:
IsAnyTrailerAttachedToVehicle(vehicleid)
{
	new trailerid = GetVehicleTrailer(vehicleid);
	new modelid = GetVehicleModel(trailerid);
	if(modelid == 435 || modelid == 450 || modelid == 591 || modelid == 606 || modelid == 607 ||
	modelid == 610 || modelid == 569 || modelid == 590 || modelid == 584 || modelid == 570 ||
    modelid == 608 || modelid == 611) return true;	

	return false;
}
pawn Code:
IsAnyTrailerAttachedToVehicle(vehicleid)
{
  new v[] = { 435, 450, 591, 606, 607, 610, 569, 590, 584, 570, 608, 611 };
  for(new i = 0; i < sizeof(v); i++)
    if(GetVehicleModel(GetVehicleTrailer(vehicleid)) == i)
      return true;
  return false;
}
The way Tr1viUm has done it will be faster, but this way is faster and easier to write than both ways:

pawn Code:
stock IsAnyTrailerAttachedToVehicle( vehicleid )
{
  switch ( GetVehicleModel( GetVehicleTrailer( vehicleid ) ) )
  {
    case 435, 450, 591, 606, 607, 610, 569, 590, 584, 570, 608, 611: return true;
  }

  return false;
}
Reply
#32

ToTimestamp
Converts years, weeks, etc into a timestamp.
pawn Код:
stock ToTimestamp(f_years,f_weeks,f_days,f_hours,f_minutes,f_seconds)
{
    return
      f_seconds +
      (f_minutes * 60) +
      (f_hours * 60 * 60) +
      (f_days * 60 * 60 * 24) +
      (f_weeks * 60 * 60 * 24 * 7) +
      (f_years * 60 * 60 * 24 * 7 * 365);
}
FromTimestamp
Converts a timestamp into years, weeks, etc.
pawn Код:
stock FromTimestamp(f_timestamp,&f_years,&f_weeks,&f_days,&f_hours,&f_minutes,&f_seconds)
{
    f_years = floatround(f_timestamp / (60 * 60 * 24 * 365),floatround_floor);
    f_timestamp %= 60 * 60 * 24 * 365;
    f_weeks = floatround(f_timestamp / (60 * 60 * 24 * 7),floatround_floor);
    f_timestamp %= 60 * 60 * 24 * 7;
    f_days = floatround(f_timestamp / (60 * 60 * 24),floatround_floor);
    f_timestamp %= 60 * 60 * 24;
    f_hours = floatround(f_timestamp / (60 * 60),floatround_floor);
    f_timestamp %= 60 * 60;
    f_minutes = floatround(f_timestamp / 60,floatround_floor);
    f_seconds = f_timestamp % 60;
}
Reply
#33

Heal(playerid):
pawn Код:
stock Heal(playerid)
{
  SetPlayerHealth(playerid, 100);
}
Kill(playerid):
pawn Код:
stock Kill(playerid)
{
  SetPlayerHealth(playerid, 0);
}
Reply
#34

SendError(playerid,msg[]);
pawn Код:
stock SendError(playerid,msg[])
{
    if((IsPlayerConnected(playerid)) && (strlen(msg)>0))
    {
      SendClientMessage(playerid,0xAE2020AA,msg);
    }
    return 1;
}
Just a small code i made. Sends the player a message in like a dark orangeish color. Really useful for bulk scripting and it saves the extra 20 characters instead of typing "SendClientMessage(playerid,0xAE2020AA,"Blah blah blah.");" you can just type "SendError(playerid,"Blah blah blah.");"

Difference in the character length:
SendClientMessage: 57
SendError: 39
Difference: 18

Really saves some time when u use it. Hope it helps.
Reply
#35

pawn Код:
if((IsPlayerConnected(playerid)) && (strlen(msg)>0))
Is that really needed?
Reply
#36

Quote:
Originally Posted by Boylett
pawn Код:
if((IsPlayerConnected(playerid)) && (strlen(msg)>0))
Is that really needed?
Im a bit of a noob scriptor, you tell me. :P

No, i guess not, but its not a big deal to check.
Reply
#37

Quote:
Originally Posted by Y_Leѕѕ
Quote:
Originally Posted by tom_jonez
Really saves some time when u use it. Hope it helps.
It may save a few seconds writing your mode but it's much slower in execution, you're better off using:

pawn Код:
#define SendError(%0,%1) \
    SendClientMessage((%0), 0xAE2020AA, %1)
Used exactly the same as your version but as efficient in execution as the original version.

Remember, overhead of writing something the long way is fine if it speeds your script up, you should never sacrifice ease of coding for script efficiency.
Ok. Thanks Alex
Reply
#38

Another version func by tom_jones:

SendError(playerid,typeofclient,msg[]);

pawn Код:
stock SendError(playerid,typeofclient,msg[])
{
if(IsPlayerConnected(playerid) && strlen(typeofclient)>0 && strlen(msg)>0)
{
 if(typeofclient==1) //r2
 {
 SendClientMessage(playerid,0xBCBCBCAA,msg);
 }
 else if(typeofclient==2) //r3
 {
 SendClientMessage(playerid,0xAE2020AA,msg);
 }
}
return 1;
}
Reply
#39

Quote:
Originally Posted by Andre9977
OKStyle: how do you plan detecting whether player uses R2 or R3? This is impossible in R2 server (functions) so far.
Dude, I probably have not specified, I meant a case when not the server sends a mistake, and the administrator and manually specifies type of the client. Though in this case too it is impossible to define the version at random...

Ex:

pawn Код:
new cmd[30];
new idx;
cmd = strtok(cmdtext, idx);
if(!strcmp(cmd, "/senderror", true))
{
 new tmp[30],tmp2[16],string[256];
 new otherplayer = strval(tmp);
 new typeofclient = strval(tmp2);
 if(!strlen(tmp)) return SendClientMessage(playerid,0xFF0000AA,"Usage: /senderror [id] [text]");
 if(!strlen(tmp2)) return SendClientMessage(playerid,0xFF0000AA,"Usage: /senderror [id] [text]");
 return format(string,sizeof(string),"%s",cmdtext) SendError(otherplayer,typeofclient,string);
}
Reply
#40

TeleportPlayer(playerid, X, Y, Z); - Teleports a player to a certain location. (Useful for noobs or saving time. :P)

pawn Код:
stock TeleportPlayer(playerid, Float:X, Float:Y, Float:Z)
{
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
      new car = GetPlayerVehicleID(playerid);
      SetPlayerPos(playerid, X, Y, Z);
      SetVehiclePos(car, X, Y, Z);
      PutPlayerInVehicle(playerid, car, 0);
    }
    else
      SetPlayerPos(playerid, X, Y, Z);
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 21 Guest(s)