Useful Functions

Quote:
Originally Posted by TheArcher
Посмотреть сообщение
@DarkPower Why "_" after the variables? E.g "new sNick_" or "new iX__" makes no sense.
Habit, _ in variable's name is the same as every other 'normal' character.

@Emmet_ - I totally forgot to use strfind -.- and why is strlen bad in loop?

And this way?
pawn Код:
stock getName(playerid)
{
     new pName[MAX_PLAYER_NAME], ch = (0);
     GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
     ch = strfind(pName, "_");
     if(ch != -1) pName[ch] = (32);
     return (pName);
}
Reply

So, this is a good way:

pawn Код:
for(new i = (0), size = strlen(playerName); i < size; ++ i)
That is same as:

pawn Код:
new size = strlen(playerName);
for(new i = (0); i < size; ++ i)
It must be out from condition
I understand now, thanks Southclaw
Reply

Quote:
Originally Posted by DarkPower
Посмотреть сообщение
Habit, _ in variable's name is the same as every other 'normal' character.
Indeed is what I'm saying...You don't have to show a code as "hard" if it's not... lol
Reply

Quote:
Originally Posted by TheArcher
Посмотреть сообщение
Indeed is what I'm saying...You don't have to show a code as "hard" if it's not... lol
That is not a reason why i put "_" i know that it is not necessary in this case but as i say, habit
Reply

Quote:
Originally Posted by DarkPower
Посмотреть сообщение
Habit, _ in variable's name is the same as every other 'normal' character.
Quote:
Originally Posted by DarkPower
Посмотреть сообщение
That is not a reason why i put "_" i know that it is not necessary in this case but as i say, habit
What the hell kind of habit is that?

I also don't see how they're the same as alpha-numeric characters - any person that isn't blind will tell you they're different.
Reply

Where can I get Functions Or Filterscript,, AUTO PARK

I mean it, "if we get out of the car or we logout of the server, my car was in last place out of.
Reply

I've made small code requested by a friend so i said if i can write it here ( PS: i cba to check in all these pages if its already there o.o )

pawn Код:
stock IsDateBetween(day1, month1, year1, day2, month2, year2)
{
    new day, month, year;
    getdate(year, month, day);
   
    if((year1 == year2) && (year1 == year))
    {
        if((month1 == month2) && (month1 == month))
        {
            if((day1 < day) && (day2 > day)) return 1;
        }
        else
        if((month1 < month) && (month1 > month)) return 1;
    }
    else
    if((year1 < year) && (year2 > year)) return 1;
    return 0;
}
it checks if the current date is between 2 specified dates.

Usage:
pawn Код:
IsDateBetween(day1, month1, year1, day2, month2, year2);
Example of using

pawn Код:
public OnFilterScriptInit()
{
    printf("IsDateBetween 02/02/2013 and 08/02/2013 returned: %i", IsDateBetween(2, 2, 2013, 8, 2, 2013));
    // as we are in 04/02/2013 now (for me) it will return 1 . after/before the specified date, it will return 0
    return 1;
}
Reply

pawn Код:
timeFromSeconds(seconds, &returnedMinutes, &returnedSeconds)
{
    returnedMinutes = floatround(seconds / 60, floatround_floor);
    returnedSeconds = seconds - (returnedMinutes * 60);
}
Usage:

pawn Код:
new minutes, seconds;
timeFromSeconds(342, minutes, seconds);
Minutes will be 5 and seconds will be 42.
Reply

Quote:
Originally Posted by SuperViper
Посмотреть сообщение
pawn Код:
timeFromSeconds(seconds, &returnedMinutes, &returnedSeconds)
{
    returnedMinutes = floatround(seconds / 60, floatround_floor);
    returnedSeconds = seconds - (returnedMinutes * 60);
}
Usage:

pawn Код:
new minutes, seconds;
timeFromSeconds(342, minutes, seconds);
Minutes will be 5 and seconds will be 42.
This:
pawn Код:
returnedMinutes = floatround(seconds / 60, floatround_floor);
is the same as:
First dividing the numbers normally as integers, then converting the result to a float!
pawn Код:
returnedMinutes = floatround(float(seconds / 60), floatround_floor);
which is the same as:
pawn Код:
returnedMinutes = seconds / 60;
Integer divisions always truncate the decimals (basically just removes them, which is what floatround_floor does to numbers > 0).
Reply

pawn Код:
stock DeductPlayerDamage(playerid, Float:damage, Float:multiplier=1.0)
{
    //WeaponDamage[playerid] = damage * multiplier; You may want to add this if you have a SetPlayerArmourEx anticheat, it's highly recommended and add offsets for the damage.
    new
        Float:health,
        Float:armour;
    GetPlayerHealth(playerid, health);
    GetPlayerArmour(playerid, armour);
    if (armour > 0)
    {
        if (armour - (damage * multiplier) <= 0) {
            SetPlayerArmourEx(playerid, 0);
            if (health - floatabs(armour - (damage * multiplier)) <= 0)
            {
                SetPlayerHealth(playerid, 0);
                return true;
            }
            else
            {
                SetPlayerHealth(playerid, health - floatabs(armour - (damage * multiplier)));
            }
        } else {
            SetPlayerArmourEx(playerid, armour - (damage * multiplier));
        }
    }
    else
    {
        if (health - (damage * multiplier) <= 0) {
            SetPlayerHealth(playerid, 0);
            return true;
        } else {
            SetPlayerHealth(playerid, health - (damage * multiplier));
        }
    }
    return false;//the result doesnt make the target die
}
I created this function, you can enter 200 as the damage and it will damage the player starting from their armor (if they have any) to their health. This supports even health and armour above 100, it will not matter and you can use this for weapon damage boosting. I could not any function similar to this on the forum, thank god I had known of how to use the mathematical function absolute value.
Reply

Where " SetPlayerArmourEx " comes from?
Reply

Quote:
Originally Posted by Jack_Wilson
Посмотреть сообщение
pawn Код:
stock DeductPlayerDamage(playerid, Float:damage, Float:multiplier=1.0)
{
    //WeaponDamage[playerid] = damage * multiplier; You may want to add this if you have a SetPlayerArmourEx anticheat, it's highly recommended and add offsets for the damage.
    new
        Float:health,
        Float:armour;
    GetPlayerHealth(playerid, health);
    GetPlayerArmour(playerid, armour);
    if (armour > 0)
    {
        if (armour - (damage * multiplier) <= 0) {
            SetPlayerArmourEx(playerid, 0);
            if (health - floatabs(armour - (damage * multiplier)) <= 0)
            {
                SetPlayerHealth(playerid, 0);
                return true;
            }
            else
            {
                SetPlayerHealth(playerid, health - floatabs(armour - (damage * multiplier)));
            }
        } else {
            SetPlayerArmourEx(playerid, armour - (damage * multiplier));
        }
    }
    else
    {
        if (health - (damage * multiplier) <= 0) {
            SetPlayerHealth(playerid, 0);
            return true;
        } else {
            SetPlayerHealth(playerid, health - (damage * multiplier));
        }
    }
    return false;//the result doesnt make the target die
}
I created this function, you can enter 200 as the damage and it will damage the player starting from their armor (if they have any) to their health. This supports even health and armour above 100, it will not matter and you can use this for weapon damage boosting. I could not any function similar to this on the forum, thank god I had known of how to use the mathematical function absolute value.
https://sampforum.blast.hk/showthread.php?tid=348044

DealPlayerDamage.
Reply

pawn Код:
stock GetPlayerIdFromIp(ip[])
{
    new pip[32], playerid;
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i) == 1)
        {
            GetPlayerIp(i, pip, sizeof(pip));
            if(!strcmp(ip, pip, true))
            {
                playerid = i;
                break;
            }
        }
    }
    return playerid;
}
Example usage:

pawn Код:
public OnRconLoginAttempt(ip[], password[], success)
{
    new playerid;
    playerid = GetPlayerIdFromIp(ip);
    CallLocalFunction("OnRconLoginAttempEx", "dsb", playerid, password, success);
    return 1;
}
pawn Код:
forward OnRconLoginAttempEx(playerid, password[], success);
public OnRconLoginAttempEx(playerid, password[], success)
{
    if(!success)
    {
        //do code here
    }
    else GameTextForPlayer(playerid,"~g~WELCOME, ~r~ADMINISTRATOR!", 3000, 5);
    return 1;
}
Reply

Quote:
Originally Posted by fiki574_CRO
Посмотреть сообщение
pawn Код:
stock GetPlayerIdFromIp(ip[])
{
    new pip[32], playerid;
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i) == 1)
        {
            GetPlayerIp(i, pip, sizeof(pip));
            if(!strcmp(ip, pip, true))
            {
                playerid = i;
                break;
            }
        }
    }
    return playerid;
}
Example usage:

pawn Код:
public OnRconLoginAttempt(ip[], password[], success)
{
    new playerid;
    playerid = GetPlayerIdFromIp(ip);
    CallLocalFunction("OnRconLoginAttempEx", "dsb", playerid, password, success);
    return 1;
}
pawn Код:
forward OnRconLoginAttempEx(playerid, password[], success);
public OnRconLoginAttempEx(playerid, password[], success)
{
    if(!success)
    {
        //do code here
    }
    else GameTextForPlayer(playerid,"~g~WELCOME, ~r~ADMINISTRATOR!", 3000, 5);
    return 1;
}
If it's from console it will be recognized as id = 1
Reply

Quote:
Originally Posted by Rapgangsta
Посмотреть сообщение
If it's from console it will be recognized as id = 1
But if it isnt, will be recognized as it is meant to be!
Reply

Quote:
Originally Posted by fiki574_CRO
Посмотреть сообщение
But if it isnt, will be recognized as it is meant to be!
But you should consider this,
if someone putss this for ban who logs as RCON and i log with RCON from the console, id 1 will be banned
Reply

@Misiur Me neither :O , The page was viewed ~1000 times, so it is not so popular.
Reply

GetPlayerPosFindZ

pawn Код:
stock GetPlayerPosFindZ(playerid, Float:X, Float:Y, &Float:Z)
{
    new Float:pos[5];
    GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
   
    SetPlayerPosFindZ(playerid, X, Y, Z);
   
    GetPlayerPos(playerid, pos[3], pos[4], Z);
   
    SetPlayerPos(playerid, pos[0], pos[1], pos[2]);
    return 1;
}

Example
pawn Код:
CMD:a(playerid, params[])
{
    new Float:pos;
    GetPlayerPosFindZ(playerid, 0.0, 0.0, pos);
    printf("%f", pos);
    return 1;
}
Reply

Removed.
Reply

Quote:
Originally Posted by ******
Посмотреть сообщение
That's not what an ini file looks like...
It was made for my INI system, I used the INI_ prefix because it looks better ;d
Sorry
Reply


Forum Jump:


Users browsing this thread: 8 Guest(s)