Useful Functions

Quote:
Originally Posted by [ĦŁ₣
ЉǾǖŦĦЗŁΛẄ ]
No you need to use the variable defined in the loop:


for(new b = 0; b < sizeof(BlackSkins); b ++){
if(BlackSkins[b] == skinid) return 1;
}
The code doesn't make any sense, What's the point of using for looping Blackskins when you don't use it?
Reply

Don't judge him immediately
Just change BlackSkins to b
Reply

Quote:
Originally Posted by Carlton
Quote:
Originally Posted by [ĦŁ₣
ЉǾǖŦĦЗŁΛẄ ]
No you need to use the variable defined in the loop:


for(new b = 0; b < sizeof(BlackSkins); b ++){
if(BlackSkins[b] == skinid) return 1;
}
The code doesn't make any sense, What's the point of using for looping Blackskins when you don't use it?
It's in bold dude, "BlackSkins[ b ] ==".
Reply

Quote:
Originally Posted by Donny
Quote:
Originally Posted by Carlton
Quote:
Originally Posted by [ĦŁ₣
ЉǾǖŦĦЗŁΛẄ ]
No you need to use the variable defined in the loop:


for(new b = 0; b < sizeof(BlackSkins); b ++){
if(BlackSkins[b] == skinid) return 1;
}
The code doesn't make any sense, What's the point of using for looping Blackskins when you don't use it?
It's in bold dude, "BlackSkins[ b ] ==".
Oh, I didn't read the quote in my reply. Where it says: (BlackSkins[ b ] == skinid).
Reply

pawn Код:
stock bool:IsAnyPlayerInVehicle(vehicleid)
{
    new
        v_end = GetMaxPlayers(),
        i;
    for(i = 0; i < v_end; i++) if(IsPlayerConnected(i) && GetPlayerVehicleID(i) == vehicleid) break;
    return i < v_end;
}
Reply

Quote:
Originally Posted by Gamestar.
pawn Код:
stock IsAnyPlayerInVehicle(vehicleid)
{
    new
        v_end = GetMaxPlayers(), i;
    for(i = 0; i < v_end; i++) if(IsPlayerConnected(i) && GetPlayerVehicleID(i) == vehicleid) break;
    return i < v_end;
}
Nice, good work. But I don't understand why you returned i < v_end, can you explain it to me please?
Reply

Quote:
Originally Posted by Carlton
Quote:
Originally Posted by Gamestar.
pawn Код:
-
Nice, good work. But I don't understand why you returned i < v_end, can you explain it to me please?
Function fixed, please delete in your quoute.

A: Simple logical condition.

[code=Example]new bool:vehicle_used = IsAnyPlayerInVehicle(vehicleid);[/code]

true / false
Reply

Here's a IsPlayerInAmmunation function.

pawn Код:
new Float: Ammunation_Coordinates[][3] = {
    { 286.148986,-40.644397,1001.515625 },
    { 286.800994,-82.547599,1001.515625 },
    { 296.919982,-108.071998,1001.515625 },
    { 314.820983,-141.431991,999.601562 },
    { 316.524993,-167.706985,999.593750 }
};
pawn Код:
stock IsPlayerInAmmunation(playerid) {
    for(new i = 0; i < sizeof(Ammunation_Coordinates); i++) {
      if(IsPlayerInRangeOfPoint(playerid, 70.0, Ammunation_Coordinates[i][0], Ammunation_Coordinates[i][1], Ammunation_Coordinates[i][2])) return 1;
     }
     return 0;
}
Example code:
pawn Код:
if(IsPlayerInAmmunation(playerid)) {
   printf("Id %d is in a Ammunation", playerid);
}
Reply

pawn Код:
stock VehicleLights(vehicleid, bool:status) // By Norn
{
    new panels, doors, lights, tires;
    GetVehicleDamageStatus(vehicleid, panels, doors, lights, tires);
    if(status == true) lights = encode_lights(1, 1, 1, 1); else lights = encode_lights(0, 0, 0, 0);
    UpdateVehicleDamageStatus(vehicleid, panels, doors, lights, tires);
    return 1;
}
stock encode_lights(light1, light2, light3, light4) {
    return light1 | (light2 << 1) | (light3 << 2) | (light4 << 3);
}
Usage:
pawn Код:
VehicleLights(vehicleid, true);
will enable the vehicles lights.
pawn Код:
VehicleLights(vehicleid, false);
will disable the vehicles lights.

Works best with a timer.
Reply



This is a continuation from the function I posted earlier, which was IsPlayerInAmmunation.

pawn Код:
stock IsPlayerInClothesStore(playerid) {
   new Float: Clothes_Stores[][3] = {
   { 207.737991,-109.019996,1005.132812 },
   { 204.332992,-166.694992,1000.523437 },
   { 207.054992,-138.804992,1003.507812 },
   { 203.777999,-48.492397,1001.804687 },
   { 226.293991,-7.431529,1002.210937 },
   { 161.391006,-93.159156,1001.804687 }
   }
   for(new cs = 0; cs < sizeof(Clothes_Stores); cs++) {
      if(IsPlayerInRangeOfPoint(playerid, 70.0, Clothes_Stores[cs][0], Clothes_Stores[cs][1], Clothes_Stores[cs][2])) return 1;
   }
   return 0;
}
pawn Код:
stock IsPlayerInGym(playerid) {
   new Float: Gyms[][3] = {
     { 772.111999,-3.898649,1000.728820 },
     { 774.213989,-48.924297,1000.585937 },
     { 773.579956,-77.096694,1000.655029 }
   }
   for(new gy = 0; gy < sizeof(Gyms); gy ++) {
     if(IsPlayerInRangeOfPoint(playerid, 70.0, Gyms[gy][0], Gyms[gy][1], Gyms[gy][2])) return 1;
   }
   return 0;
}
pawn Код:
stock IsPlayerInAShop(playerid) { // 24-7
   new Float: Shops[][3] = {
     { -25.884498,-185.868988,1003.546875 },
     { 6.091179,-29.271898,1003.549438 },
     { -30.946699,-89.609596,1003.546875 },
     { -25.132598,-139.066986,1003.546875 },
     { -27.312299,-29.277599,1003.557250 },
     { -26.691598,-55.714897,1003.546875 }    
   }
   for(new s = 0; s < sizeof(Shops); s++ ) {
     if(IsPlayerInRangeOfPoint(playerid, 70.0, Shops[0], Shops[1], Shops[2])) return 1;
   }
   return 0;
}
Reply

Quote:
Originally Posted by » RyDeR «
Quote:
Originally Posted by Luka P.
Quick one. I was not sure if theres an native function for this, I didn't wanted to search, so I made my own xD
pawn Код:
stock GetWeaponIDByName(const name[])
{
    new id = 0;
    if(!strcmp(name, "Unarmed", true))             id = 0;
    else if(!strcmp(name, "Brass Knuckles", true))       id = 1;
    else if(!strcmp(name, "Golf Club", true))         id = 2;
    else if(!strcmp(name, "Nite Stick", true))         id = 3;
    else if(!strcmp(name, "Knife", true))           id = 4;
    else if(!strcmp(name, "Baseball Bat", true))        id = 5;
    else if(!strcmp(name, "Shovel", true))           id = 6;
    else if(!strcmp(name, "Pool Cue", true))          id = 7;
    else if(!strcmp(name, "Katana", true))           id = 8;
    else if(!strcmp(name, "Chainsaw", true))          id = 9;
    else if(!strcmp(name, "Purple Dildo", true))        id = 10;
    else if(!strcmp(name, "Small White Vibrator", true))    id = 11;
    else if(!strcmp(name, "Large White Vibrator", true))    id = 12;
    else if(!strcmp(name, "Silver Vibrator", true))      id = 13;
    else if(!strcmp(name, "Flowers", true))          id = 14;
    else if(!strcmp(name, "Cane", true))            id = 15;
    else if(!strcmp(name, "Grenade", true))          id = 16;
    else if(!strcmp(name, "Tear Gas", true))          id = 17;
    else if(!strcmp(name, "Molotov Cocktail", true))      id = 18;
    else if(!strcmp(name, "9mm", true))            id = 22;
    else if(!strcmp(name, "Silenced 9mm", true))        id = 23;
    else if(!strcmp(name, "Desert Eagle", true))        id = 24;
    else if(!strcmp(name, "Shotgun", true))          id = 25;
    else if(!strcmp(name, "Sawn-Off Shotgun", true))      id = 26;
    else if(!strcmp(name, "Combat Shotgun", true))       id = 27;
    else if(!strcmp(name, "Micro SMG", true))         id = 28;
    else if(!strcmp(name, "SMG", true))            id = 29;
    else if(!strcmp(name, "AK47", true))            id = 30;
    else if(!strcmp(name, "M4", true))             id = 31;
    else if(!strcmp(name, "Tec9", true))            id = 32;
    else if(!strcmp(name, "Country Rifle", true))       id = 33;
    else if(!strcmp(name, "Sniper Rifle", true))        id = 34;
    else if(!strcmp(name, "Rocket Launcher", true))      id = 35;
    else if(!strcmp(name, "HS Rocket Launcher", true))     id = 26;
    else if(!strcmp(name, "Flamethrower", true))        id = 37;
    else if(!strcmp(name, "Minigun", true))          id = 38;
    else if(!strcmp(name, "Satchel Charge", true))       id = 39;
    else if(!strcmp(name, "Detonator", true))         id = 40;
    else if(!strcmp(name, "Spraycan", true))          id = 41;
    else if(!strcmp(name, "Fire Extinguisher", true))     id = 42;
    else if(!strcmp(name, "Camera", true))           id = 43;
    else if(!strcmp(name, "Nightvision Goggles", true))    id = 44;
    else if(!strcmp(name, "Thermal Goggles", true))      id = 45;
    else if(!strcmp(name, "Parachute", true))         id = 46;
    else id = (-1);
    return id;
}
lol. You used a very long way to make that simple piece of code.

pawn Код:
GetWeaponIDByName(const name[])
{
    for(new x; x != 46; x++)
    {
        new
            wNames[32]
        ;
        GetWeaponName(x, wNames, sizeof(wNames));
        if(strfind(wNames, name, true) != -1) return x;
    }
    return 0xFFFF;
}
Hmm.
Tested GetWeaponName:
pawn Код:
stock TestGetWeaponName()
{
    new
        Weapon_Name[32];
    print(" ");
    for(new i; i != 46; i++)
    {
        GetWeaponName(i, Weapon_Name, sizeof Weapon_Name);
        printf("weaponid: %d | %s", i, Weapon_Name);
    }
    print(" ");
}
Example:
Код:
[22:01:03] weaponid: 0 | 
[22:01:03] weaponid: 1 | Brass Knuckles
[22:01:03] weaponid: 2 | Golf Club
[22:01:03] weaponid: 3 | Nite Stick
[22:01:03] weaponid: 4 | Knife
[22:01:03] weaponid: 5 | Baseball Bat
[22:01:03] weaponid: 6 | Shovel
[22:01:03] weaponid: 7 | Pool Cue
[22:01:03] weaponid: 8 | Katana
[22:01:03] weaponid: 9 | Chainsaw
[22:01:03] weaponid: 10 | Dildo
[22:01:03] weaponid: 11 | Dildo
[22:01:03] weaponid: 12 | Vibrator
[22:01:03] weaponid: 13 | Vibrator
[22:01:03] weaponid: 14 | Flowers
[22:01:03] weaponid: 15 | Cane
[22:01:03] weaponid: 16 | Grenade
[22:01:03] weaponid: 17 | Teargas
[22:01:03] weaponid: 18 | 
[22:01:03] weaponid: 19 | 
[22:01:03] weaponid: 20 | 
[22:01:03] weaponid: 21 | 
[22:01:03] weaponid: 22 | Colt 45
[22:01:03] weaponid: 23 | Silenced Pistol
[22:01:03] weaponid: 24 | Desert Eagle
[22:01:03] weaponid: 25 | Shotgun
[22:01:03] weaponid: 26 | Sawn-off Shotgun
[22:01:03] weaponid: 27 | Combat Shotgun
[22:01:03] weaponid: 28 | UZI
[22:01:03] weaponid: 29 | MP5
[22:01:03] weaponid: 30 | AK47
[22:01:03] weaponid: 31 | M4
[22:01:03] weaponid: 32 | TEC9
[22:01:03] weaponid: 33 | Rifle
[22:01:03] weaponid: 34 | Sniper Rifle
[22:01:03] weaponid: 35 | Rocket Launcher
[22:01:03] weaponid: 36 | Heat Seaker
[22:01:03] weaponid: 37 | Flamethrower
[22:01:03] weaponid: 38 | Minigun
[22:01:03] weaponid: 39 | Satchel Explosives
[22:01:03] weaponid: 40 | Bomb
[22:01:03] weaponid: 41 | Spray Can
[22:01:03] weaponid: 42 | Fire Extinguisher
[22:01:03] weaponid: 43 | Camera
[22:01:03] weaponid: 44 | 
[22:01:03] weaponid: 45 |
Reply

Well Ryder, why the heck are you returning hex code 0xFFFF if you can simply return -1 ?
Reply

Or better yet returning 0, so you can just do
pawn Код:
if (GetWeaponIDByName("Katana"))
{
    //correct name
}
Reply

Quote:
Originally Posted by dice7
Or better yet returning 0, so you can just do
pawn Код:
if (GetWeaponIDByName("Katana"))
{
    //correct name
}
Because 0 is a valid weapon ID (Unarmed)
Reply

pawn Код:
RemovePlayerWeapon ( playerid, weaponid )
{
    new
        w [ 13 ],
        a [ 13 ];
       
    for ( new slot; slot < 13; slot++ )
        GetPlayerWeaponData ( playerid, slot, w [ slot ], a [ slot ] );
       
    ResetPlayerWeapons ( playerid );
   
    for ( new wep; wep < 13; wep++ )
    {
        if ( w [ wep ] == weaponid )
            continue;

        GivePlayerWeapon ( playerid, w [ wep ], a [ wep ] );
    }
}
Reply

Quote:
Originally Posted by Scottas
Посмотреть сообщение
pawn Код:
RemovePlayerWeapon ( playerid, weaponid )
{
    new
        w [ 13 ],
        a [ 13 ];
       
    for ( new slot; slot < 13; slot++ )
        GetPlayerWeaponData ( playerid, slot, w [ slot ], a [ slot ] );
       
    ResetPlayerWeapons ( playerid );
   
    for ( new wep; wep < 13; wep++ )
    {
        if ( w [ wep ] == weaponid )
            continue;

        GivePlayerWeapon ( playerid, w [ wep ], a [ wep ] );
    }
}
pawn Код:
RemovePlayerWeapon ( playerid, weaponid ) {
      new
            wd[2][13],
            cloop;
      for (cloop = 0; cloop < 13; cloop++ ) {
        GetPlayerWeaponData ( playerid, cloop, wd[0][cloop], wd[1][cloop] );
      }
      ResetPlayerWeapons ( playerid );
      for(cloop = 0; cloop < 13; cloop ++ ) {
           if(wd[0][cloop] == weaponid) continue;
           GivePlayerWeapon ( playerid, wd[0][cloop], wd[1][cloop]);
      }
}
pawn Код:
stock ChangeTextDrawColorForAll(Text:txtid, color) {
     TextDrawHideForAll(txtid);
     TextDrawColor(txtid,color);
     TextDrawShowForAll(txtid);
}

stock ChangeTextDrawColorForPlayer(playerid, Text:txtid, color) {
     TextDrawHideForPlayer(playerid, txtid);
     TextDrawColor(txtid,color);
     TextDrawShowForPlayer(playerid, txtid);
}
Reply

Quote:
Originally Posted by Luka P.
Посмотреть сообщение
Well Ryder, why the heck are you returning hex code 0xFFFF if you can simply return -1 ?
Dunno, but that doesn't matter.. ^^
Reply

Quote:
Originally Posted by Carlton
Посмотреть сообщение
pawn Код:
RemovePlayerWeapon ( playerid, weaponid ) {
      new
            wd[2][13],
            cloop;
      for (cloop = 0; cloop < 13; cloop++ ) {
        GetPlayerWeaponData ( playerid, cloop, wd[0][cloop], wd[1][cloop] );
      }
      ResetPlayerWeapons ( playerid );
      for(cloop = 0; cloop < 13; cloop ++ ) {
           if(wd[0][cloop] == weaponid) continue;
           GivePlayerWeapon ( playerid, wd[0][cloop], wd[1][cloop]);
      }
}
pawn Код:
stock ChangeTextDrawColorForAll(Text:txtid, color) {
     TextDrawHideForAll(txtid);
     TextDrawColor(txtid,color);
     TextDrawShowForAll(txtid);
}

stock ChangeTextDrawColorForPlayer(playerid, Text:txtid, color) {
     TextDrawHideForPlayer(playerid, txtid);
     TextDrawColor(txtid,color);
     TextDrawShowForPlayer(playerid, txtid);
}
Aren't 2d arrays slower?
Reply

not tested:
http://pastebin.com/4KXJkU4V

Function:
Quote:

CreatePrivateVehicle
RemovePrivateVehicle
PrivateVehicleForTeam
UnPrivateVehicleForTeam

Reply

So here is one of mine new Function
Its call SetPlayerBlind(playerid,toggle);

Very useful for punishing some server rule ignorer xD

pawn Код:
new Text:Blind;
new PlayerIsBlind[MAX_PLAYERS]; >> OnPlayerConnect should be set to 0

forward CreateTextDrawForAll(); >> put it in OnGameModeInit();
forward SetPlayerBlind(playerid,toggle);

public CreateTextDrawForAll()
{
    Blind = TextDrawCreate(0.0,0.0,"00000"); //For /blind cmd
    TextDrawUseBox(Blind,1);
    TextDrawBoxColor(Blind,0x000000FF);
    TextDrawTextSize(Blind,950,950);
    TextDrawFont(Blind,3);
    TextDrawLetterSize(Blind,5,100);
    TextDrawColor(Blind,0x000000FF);
}

public SetPlayerBlind(playerid,toggle)
{
    if(toggle == 1)
    {
        TextDrawShowForPlayer(playerid,Blind);
        PlayerIsBlind[playerid] = 1;
    }
    else if (toggle == 0)
    {
        TextDrawHideForPlayer(playerid,Blind);
        PlayerIsBlind[playerid] = 0;
    }
}
Example
pawn Код:
if(strcmp(cmd, "/blind", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            if (PlayerInfo[playerid][pAdmin] >= 1)
            {
                tmp = strtok(cmdtext, idx);
                if(!strlen(tmp))
                {
                    SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /blind [playerid/PartOfName]");
                    return 1;
                }
                new playa;
                playa = ReturnUser(tmp);
                if(IsPlayerConnected(playa))
                {
                    if(playa != INVALID_PLAYER_ID)
                    {
                        GetPlayerName(playa, giveplayer, sizeof(giveplayer));
                        GetPlayerName(playerid, sendername, sizeof(sendername));
                        if(PlayerIsBlind[playa])
                        {
                            SetPlayerBlind(playa,0);
                            format(string, sizeof(string), "AdmCmd: %s is Unblinded by %s",giveplayer ,sendername);
                            SendClientMessage(playa,COLOR_LIGHTBLUE,"*   You can now see, you was unblinded by Admin.");
                        }
                        else
                        {
                            SetPlayerBlind(playa,1);
                            SendClientMessage(playa,COLOR_LIGHTBLUE,"*   You are now blind, you was blinded by Admin.");
                            format(string, sizeof(string), "AdmCmd: %s is Blinded by %s",giveplayer ,sendername);
                        }
                        SendMessageToAdmin(COLOR_LIGHTRED,string,1);
                    }
                }
            }
            else
            {
                SendFalseText(playerid,"You cannot use this command.");
            }
        }
        return 1;
    }
Reply


Forum Jump:


Users browsing this thread: 20 Guest(s)