Useful Snippets

Quote:
Originally Posted by jameskmonger
Посмотреть сообщение
This is probably the best way, considering that most people use "string" for a general string name.
Beside that, I just use a local variable for little things like that.
Reply

Oops didnt think of mistakes in that reload detector.
Thanks all and now I've fixed it.
Reply

<REMOVED>
Reply

Hmmm didn't know you could

if(GetPlayerScore(playerid) == 50,100,150,250) {

That actually works?
Reply

Quote:
Originally Posted by Sniper Kitty
Посмотреть сообщение
Hmmm didn't know you could

if(GetPlayerScore(playerid) == 50,100,150,250) {

That actually works?
Seems to be working.
But I haven't tried with scores.
Reply

even i neveer knew that
Reply

Quote:
Originally Posted by [HLF]Southclaw
Посмотреть сообщение
You're confusing switch with if checks.

In switch cases you can do this

pawn Код:
switch(variable)
{
    case 5, 6, 7, 8:DoSomething();
    case 10..40:DoSomethingElse();
}
You have to use the variable you're checking each time you check a value in an if-statement

pawn Код:
if(variable == 4 || variable == 5 ... etc)
I used to be pretty lazy and wrote macros for this back in my early days:

pawn Код:
#define OR ||variable==
if(variable == 5 OR 6 OR 7 OR 8)
#undef OR
But hey, it worked!
Worked or not working??
Quote:
Originally Posted by [HLF]SouthClaw
One more thing about switch, you can only have static number checks so this isn't valid:
pawn Код:
new check_value = 4;
switch(variable)
{
    case 4, 5, 6:DoSomething();
    case check_value:DoSomethingElse();
}
It will throw a "must be a constant expression; assumed zero" error.
I didn't get you.
Can you explain?

Btw the code which I posted is wrong or correct?
It worked for me before.
Reply

Umm..okay.
Like this :
pawn Код:
#include <a_samp>
#define F_Weaps 38,37,36,35

public OnPlayerUpdate(playerid)
{
   switch(GetPlayerWeapon(playerid))
   {
     case F_Weaps: Ban(playerid);
   }
   return 1;
}
.
Reply

Simple RCON Login Protector:

Thanks to the SA-MP Scripting IRC channel for the login attempt counter
Quote:

#pragma tabsize 0
new RCONLoginCount[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
RCONLoginCount[playerid] = 0;
return 1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
if(!success) //If the password was incorrect
{
printf("Someone tried to login to your RCON! %s tried to login with password: %s",ip, password);
new PlayerIP[16];
for(new i=0; i<MAX_PLAYERS; i++) //Loop through all players
{
GetPlayerIp(i, PlayerIP, sizeof(PlayerIP));
if(!strcmp(ip, PlayerIP, true)) //If a player's IP is the IP that failed the login
{
RCONLoginCount[i] ++;
if(RCONLoginCount[i] >= 5) Ban(i);
print("The hacker has been BANNED.");
}
}
}
return 1;
}

Reply

Quote:
Originally Posted by ******
Посмотреть сообщение
You didn't know that because its wrong.
I knew that, I was being sarcastic
Reply

Here's a huge array of country names I had sitting in my scripts that I made a while back:

pawn Код:
new stock cntNames[][] =
{
    {"Alaska"},
    {"Greenland"},
    {"Canada"},
    {"United States"},
    {"Mexico"},
    {"Guatemala"},
    {"El Salvador"},
    {"Costa Rica"},
    {"Panama"},
    {"Cuba"},
    {"Jamaica"},
    {"Belize"},
    {"Honduras"},
    {"Nicaragua"},
    {"Haiti"},
    {"Puerto Rico"},
    {"Bahamas"},
    {"Dominican Republic"},
    {"Dominica"},
    {"Barbados"},
    {"Trinidad and Tobago"},
    {"Guyana"},
    {"Suriname"},
    {"French Guiana"},
    {"Venezuela"},
    {"Colombia"},
    {"Ecuador"},
    {"Peru"},
    {"Brazil"},
    {"Bolivia"},
    {"Paraguay"},
    {"Uruguay"},
    {"Chile"},
    {"Argentina"},
    {"Europe"},
    {"Iceland"},
    {"Ireland"},
    {"United Kingdom"},
    {"Norway"},
    {"Sweden"},
    {"Finland"},
    {"Estonia"},
    {"Latvia"},
    {"Portugal"},
    {"Spain"},
    {"France"},
    {"The Netherlands"},
    {"Italy"},
    {"Switzerland"},
    {"Austria"},
    {"Bosnia and Herzegovina"},
    {"Hungary"},
    {"Slovakia"},
    {"Slovenia"},
    {"Romania"},
    {"Lithuania"},
    {"Belarus"},
    {"Ukraine"},
    {"Moldova"},
    {"Bulgaria"},
    {"Turkey"},
    {"Greece"},
    {"Albania"},
    {"Czechoslovakia"},
    {"Yugoslavia"},
    {"Croatia"},
    {"Germany"},
    {"Poland"},
    {"Russia"},
    {"Asia"},
    {"Syria"},
    {"Israel"},
    {"Iraq"},
    {"Jordan"},
    {"Kuwait"},
    {"Qatar"},
    {"U.A.E."},
    {"Saudi Arabia"},
    {"Oman"},
    {"Yemen"},
    {"Iran"},
    {"Georgia"},
    {"Armenia"},
    {"Azerbaijan"},
    {"Turkmenistan"},
    {"Uzbekistan"},
    {"Kazakhstan"},
    {"Kyrgyzstan"},
    {"Tajikistan"},
    {"Afghanistan"},
    {"Pakistan"},
    {"India"},
    {"Nepal"},
    {"Bhutan"},
    {"Bangladesh"},
    {"Mongolia"},
    {"Korea"},
    {"Japan"},
    {"China"},
    {"Myanmar"},
    {"Laos"},
    {"Thailand"},
    {"Vietnam"},
    {"Cambodia"},
    {"Sri Lanka"},
    {"Maldives"},
    {"Brunei"},
    {"Malaysia"},
    {"Singapore"},
    {"Indonesia"},
    {"Taiwan"},
    {"Philippines"},
    {"Guam"},
    {"Micronesia"},
    {"Solomon Islands"},
    {"Kiribati"},
    {"Hawaii"},
    {"Papua New Guinea"},
    {"New Caledonia"},
    {"Australia"},
    {"Tasmania"},
    {"New Zealand"},
    {"Fiji"},
    {"Africa"},
    {"Morocco"},
    {"Tunisia"},
    {"Algeria"},
    {"Western Sahara"},
    {"Senegal"},
    {"The Gambia"},
    {"Guinea-Bissau"},
    {"Sierra Leone"},
    {"Liberia"},
    {"Guinea"},
    {"Mauritania"},
    {"Libya"},
    {"Egypt"},
    {"Sudan"},
    {"Ethiopia"},
    {"Somalia"},
    {"Dijbouti"},
    {"Chad"},
    {"Congo"},
    {"C.A.R."},
    {"Niger"},
    {"Nigeria"},
    {"Cameroon"},
    {"Benin"},
    {"Burkina Faso"},
    {"Mali"},
    {"Ghana"},
    {"Togo"},
    {"Sao Tome & Principe"},
    {"Gabon"},
    {"Uganda"},
    {"Rwanda"},
    {"Zaire"},
    {"Kenya"},
    {"Burundi"},
    {"Tanzania"},
    {"Mozambique"},
    {"Zimbabwe"},
    {"Swaziland"},
    {"Lesotho"},
    {"Madagascar"},
    {"South Africa"},
    {"Botswana"},
    {"Zambia"},
    {"Malawi"},
    {"Angola"},
    {"Namibia"},
    {"Antarctica"},
    {"North Pole"},
    {"South Pole"}
};
Can't find a use for it, xD.
Reply

Quote:
Originally Posted by [HLF]Southclaw
Посмотреть сообщение
Here's a use: I have the GeoIP plugin, and often players connect with an un-listed IP so GeoIP just returns a blank country name, in this case I have a randomiser that chooses from: Liberty City, Mordor, Narnia, Mars... and a few more random places, you could use it for that!
Never thought of that; good idea!

Or, for example, if a player is entering a country name in a dialog box, you can loop through the whole array and find similar matches, then display them to the player.

I've been tampering with that huge array for a while now. :S
Reply

@Emmet_ Yugoslavia does not exist anymore. It's now Serbia, Croatia, Montenegro etc. :3
Reply

Chat while server restart(only tested in a local server):

Make a FS with this code:
pawn Код:
#include <a_samp>

public OnPlayerText(playerid, text[])
{
    if(!CallRemoteFunction("Running", ""))
    {
        new str[128 + MAX_PLAYER_NAME];
        GetPlayerName(playerid, str, MAX_PLAYER_NAME);
        format(str, sizeof str, "{808080}%s:{FFFFFF} %s", str, text);
        SendClientMessageToAll(-1, str);
    }
    return 1;
}
Add this to your gamemode:
pawn Код:
forward Running();
public Running() return 1;
Reply

Get player id from part of name.

pawn Код:
if(!strfind(cmdtext, "/pegarid", true)){
   
        if(strlen(cmdtext) == 9 || strlen(cmdtext) == 8)
            return SendClientMessage(playerid, -1, "/Pegarid <nome>");
           
        static
            NickName[32],
            TotalPlayers,
            iString[60],
            Integer
        ;
        strdel(cmdtext, 0, 9);
       
        for(TotalPlayers = GetMaxPlayers(), Integer = 0; Integer != TotalPlayers; ++Integer){
            GetPlayerName(Integer, NickName, 24);
           
            if(strfind(NickName, cmdtext, true) != -1){
           

                format(iString, 128, "%s[ID:%i]", NickName, Integer);
                SendClientMessage(playerid, -1, iString);
                break;
            }
        }
       
       
        if(Integer == (TotalPlayers)){
            SendClientMessage(playerid, -1, "NUN ACHO, I AGORA ?");
        }
       
        return true;
    }
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

pawn Код:
#define cache_get_row_int(%0,%1,%2,%3) cache_get_row(%0,%1,temporaryVariable,%3), %2 = strval(temporaryVariable)
For MySQL R7, this function is just like cache_get_row but for integers. Example:

pawn Код:
new temporaryVariable[128];
cache_get_row_int(0, 44, playersAge, mConnectionHandle);
cache_get_row_int(0, 45, playersGender, mConnectionHandle);
Reply

It's not much...made it in like 5 minutes...but I guess it can be quite useful

Код:
#define COLOR_YELLOW 0xFFFF00AA //<--Incase you don't have yellow defined, add it to the top of your script with all your other definitions

CMD:arims(playerid, params[])
{
        if(PlayerInfo[playerid][pAdmin] >= changeme) //Change this to whatever you use
	{
		if(isnull(params))
		{
			SendClientMessage(playerid, COLOR_WHITE, "USAGE: /arims [rim model]");
			SendClientMessage(playerid, COLOR_GRAD1, "Rim Models: Cutter, Switch, OffRoad, Shadow, Mega, Rimshine, Wire");
			return 1;
		}
		if(strcmp(params,"cutter",true) == 0)
		{
			SendClientMessage(playerid, COLOR_YELLOW, "You have placed Cutter Rims on this vehicle.");
			AddVehicleComponent(GetPlayerVehicleID(playerid), 1079);
		}

		else if(strcmp(params,"switch",true) == 0)
		{
			SendClientMessage(playerid, COLOR_YELLOW, "You have placed Switch Rims on this vehicle.");
			AddVehicleComponent(GetPlayerVehicleID(playerid), 1080);
		}

		else if(strcmp(params,"offroad",true) == 0)
		{
			SendClientMessage(playerid, COLOR_YELLOW, "You have placed OffRoad Rims on this vehicle.");
			AddVehicleComponent(GetPlayerVehicleID(playerid), 1026);
		}
		
		else if(strcmp(params,"shadow",true) == 0)
		{
			SendClientMessage(playerid, COLOR_YELLOW, "You have placed Shadow Rims on this vehicle.");
			AddVehicleComponent(GetPlayerVehicleID(playerid), 1073);
		}
		
		else if(strcmp(params,"mega",true) == 0)
		{
			SendClientMessage(playerid, COLOR_YELLOW, "You have placed Mega Rims on this vehicle.");
			AddVehicleComponent(GetPlayerVehicleID(playerid), 1074);
		}
		
		else if(strcmp(params,"rimshine",true) == 0)
		{
			SendClientMessage(playerid, COLOR_YELLOW, "You have placed Rimshine Rims on this vehicle.");
			AddVehicleComponent(GetPlayerVehicleID(playerid), 1075);
		}
		
		else if(strcmp(params,"wire",true) == 0)
		{
			SendClientMessage(playerid, COLOR_YELLOW, "You have placed Wire Rims on this vehicle.");
			AddVehicleComponent(GetPlayerVehicleID(playerid), 1076);
		}
	}
	else
	{
		SendClientMessage(playerid, COLOR_GRAD1, "You're not authorized to use that command!");
	}
	return 1;
}
Reply

Don't know if anyone posted something like this but just created it for myself , could be used by someone:

Код:
stock FindFreeObjectSlot(playerid)
{
    for(new i; i < MAX_PLAYER_ATTACHED_OBJECTS; i++)
    {
        if(!IsPlayerAttachedObjectSlotUsed(playerid, i))
        {
            return i;
        }
    }
    return -1;
}
Reply

Quote:
Originally Posted by JordanMaddox
Посмотреть сообщение
It's not much...made it in like 5 minutes...but I guess it can be quite useful

Код:
#define COLOR_YELLOW 0xFFFF00AA //<--Incase you don't have yellow defined, add it to the top of your script with all your other definitions

CMD:arims(playerid, params[])
{
        if(PlayerInfo[playerid][pAdmin] >= changeme) //Change this to whatever you use
	{
		if(isnull(params))
		{
			SendClientMessage(playerid, COLOR_WHITE, "USAGE: /arims [rim model]");
			SendClientMessage(playerid, COLOR_GRAD1, "Rim Models: Cutter, Switch, OffRoad, Shadow, Mega, Rimshine, Wire");
			return 1;
		}
		if(strcmp(params,"cutter",true) == 0)
		{
			SendClientMessage(playerid, COLOR_YELLOW, "You have placed Cutter Rims on this vehicle.");
			AddVehicleComponent(GetPlayerVehicleID(playerid), 1079);
		}

		else if(strcmp(params,"switch",true) == 0)
		{
			SendClientMessage(playerid, COLOR_YELLOW, "You have placed Switch Rims on this vehicle.");
			AddVehicleComponent(GetPlayerVehicleID(playerid), 1080);
		}

		else if(strcmp(params,"offroad",true) == 0)
		{
			SendClientMessage(playerid, COLOR_YELLOW, "You have placed OffRoad Rims on this vehicle.");
			AddVehicleComponent(GetPlayerVehicleID(playerid), 1026);
		}
		
		else if(strcmp(params,"shadow",true) == 0)
		{
			SendClientMessage(playerid, COLOR_YELLOW, "You have placed Shadow Rims on this vehicle.");
			AddVehicleComponent(GetPlayerVehicleID(playerid), 1073);
		}
		
		else if(strcmp(params,"mega",true) == 0)
		{
			SendClientMessage(playerid, COLOR_YELLOW, "You have placed Mega Rims on this vehicle.");
			AddVehicleComponent(GetPlayerVehicleID(playerid), 1074);
		}
		
		else if(strcmp(params,"rimshine",true) == 0)
		{
			SendClientMessage(playerid, COLOR_YELLOW, "You have placed Rimshine Rims on this vehicle.");
			AddVehicleComponent(GetPlayerVehicleID(playerid), 1075);
		}
		
		else if(strcmp(params,"wire",true) == 0)
		{
			SendClientMessage(playerid, COLOR_YELLOW, "You have placed Wire Rims on this vehicle.");
			AddVehicleComponent(GetPlayerVehicleID(playerid), 1076);
		}
	}
	else
	{
		SendClientMessage(playerid, COLOR_GRAD1, "You're not authorized to use that command!");
	}
	return 1;
}
where
pawn Код:
PlayerInfo[playerid][pAdmin] >= changeme
comes from? o.o
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)