Useful Functions

Quote:
Originally Posted by Patrick_
View Post
This will kick a player who just connected because the ping you get on OnPlayerConnect is 6355, so this will kick a player who just connected. I suggest you check if the player is spawned.
Nothing happens, I tried it and did not issue.
Reply

@Hwang

Why 256 cells? OMG
Reply

You should at least note what include you need for ptask (y_timers), foreach (y_iterate) and the Distance function (I hope that this is just a macro for the VectorSize native)

I also noticed that some of the 0.3z functions are missing on the wiki page Scripting Functions
Reply

Send server variables to a website

gamemode:

pawn Код:
#define VARIABLEUPDATE_KEY "q4z2Y5o" //CHANGE THIS TO SOMETHING RANDOM (YOU MUST UPDATE THE KEY IN THE PHP SCRIPT TOO)

forward SendVariable(url[], varname[], value[], id);

public SendVariable(url[], varname[], value[], id)
{
    new str[128];
    format(str, sizeof str, "key=%s&var=%s&val=%s", VARIABLEUPDATE_KEY, varname, value);
    if(HTTP(id, HTTP_POST, url, str, "HTTPResponse")) return 1;
    return 0;
}

forward HTTPResponse(index, response_code, data[]);

public HTTPResponse(index, response_code, data[])
{
    if(response_code == 200) if(!strcmp(data, "false")) printf("HTTP variable update failed (%s).", data);
    else printf("HTTP variable update failed (%d).", response_code);
}
samp.php on your website:

PHP код:
<?php
if($_POST['key'] == "q4z2Y5o"//CHANGE THIS TO SOMETHING RANDOM (YOU MUST UPDATE THE KEY IN YOUR GAMEMODE TOO)
{
    
file_put_contents($_POST['var'] . '.txt'$_POST['val']);
    echo 
'true';
}
else echo 
'false';
?>
Example usage:

pawn Код:
public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME+1];
    GetPlayerName(playerid, name, sizeof(name));
    SendVariable("yoursite.com (without http://) /samp.php", "LastLogged", name, playerid);
    //"LastLogged" is the variable name. name is the value of the variable. playerid can be anything.
    return 1;
}
Printing the variable on a website:

PHP код:
<?php
$text 
file_get_contents('LastLogged.txt');
echo 
$text;
?>
Reply

Quote:
Originally Posted by Vince
Посмотреть сообщение
pawn Код:
SetPlayerMarkerVisibility(playerid, alpha = 0xFF)
    return (GetPlayerColor(playerid) & ~0xFF) | clamp(alpha, 0x00, 0xFF);
I'm confused, how is this 'setting' anything?
Reply

It doesn't. It returns the colour with changed the alpha value only (between 0 and 255).
Reply

Evidently.. I was just pointing out the naming.
Reply

Calculate the amount of seconds between now and the next whole hour (XX:00). May be useful for those making payday systems.

pawn Код:
stock GetSecsBetwnWholeHour() {
    new
        iTime[3];

    gettime(iTime[0], iTime[1], iTime[2]);

    return (59 - iTime[1]) * 60 + (60 - iTime[2]);
}
Reply

showPlayerSkinName

pawn Code:
static const
    s_aszSkinNames[299][41 char] = {
        !"Carl \'CJ\' Johnson",
        !"The Truth",
        !"Maccer",
        !"Andre",
        !"Barry \'Big Bear\' Thorne (Thin)",
        !"Barry \'Big Bear\' Thorne (Big)",
        !"Emmet",
        !"Taxi Driver/Train Driver",
        !"Janitor",
        !"Normal Eleman",
        !"Old Woman",
        !"Casino Croupier",
        !"Rich Woman",
        !"Street Girl",
        !"Normal Eleman",
        !"Mr.Whittaker (RS Haul Owner)",
        !"Airport Ground Worker",
        !"Businessman",
        !"Beach Visitor",
        !"DJ",
        !"Rich Guy (Madd Dogg\'s Manager",
        !"Normal Eleman",
        !"Normal Eleman",
        !"BMXer",
        !"Madd Dogg\'s Bodyguard",
        !"Madd Dogg\'s Bodyguard",
        !"Backpacker",
        !"Construction Work",
        !"Drug Dealer",
        !"Drug Dealer",
        !"Drug Dealer",
        !"Farm Town Inhabitant",
        !"Farm Town Inhabitant",
        !"Farm Town Inhabitant",
        !"Farm Town Inhabitant",
        !"Gardener",
        !"Golfer",
        !"Golfer",
        !"Normal Eleman",
        !"Normal Eleman",
        !"Normal Eleman",
        !"Normal Eleman",
        !"Jethro",
        !"Normal Eleman",
        !"Normal Eleman",
        !"Beach Visitor",
        !"Normal Eleman",
        !"Normal Eleman",
        !"Normal Eleman",
        !"Snakehead (Da Nang)",
        !"Mechanic",
        !"Mountain Biker",
        !"Unknown",
        !"Street Girl",
        !"Normal Eleman",
        !"Normal Eleman",
        !"Normal Eleman",
        !"Feds",
        !"Normal Eleman",
        !"Normal Eleman",
        !"Normal Eleman",
        !"Pilot",
        !"Colonel Fuhrberger",
        !"Prostitute",
        !"Prostitute",
        !"Kendl Johnson",
        !"Pool Player",
        !"Pool Player",
        !"Priest/Preacher",
        !"Normal Eleman",
        !"Doktor",
        !"Security Guard",
        !"Hippy",
        !"Hippy",
        !"Prostitute",
        !"Normal Eleman",
        !"Homeless",
        !"Homeless",
        !"Homeless",
        !"Boxer",
        !"Boxer",
        !"Black Elvis",
        !"White Elvis",
        !"Blue Elvis",
        !"Prostitute",
        !"Ryder With Robbery Mask",
        !"Stripper",
        !"Normal Eleman",
        !"Normal Eleman",
        !"Jogger",
        !"Rich Woman",
        !"Rollerskater",
        !"Normal Eleman",
        !"Normal Eleman",
        !"Normal Eleman",
        !"Jogger",
        !"Lifeguard",
        !"Normal Eleman",
        !"Homeless",
        !"Biker",
        !"Normal Eleman",
        !"Balla",
        !"Balla",
        !"Balla",
        !"Grove Street Families",
        !"Grove Street Families",
        !"Grove Street Families",
        !"Los Santos Vagos",
        !"Los Santos Vagos",
        !"Los Santos Vagos",
        !"The Russian Mafia",
        !"The Russian Mafia",
        !"The Russian Mafia",
        !"Varios Los Aztecas",
        !"Varios Los Aztecas",
        !"Varios Los Aztecas",
        !"Triad",
        !"Triad",
        !"Johhny Sindacco",
        !"Triad Boss",
        !"Da Nang Boy",
        !"Da Nang Boy",
        !"Da Nang Boy",
        !"Mafia",
        !"Mafia",
        !"Mafia",
        !"Mafia",
        !"Farm Inhabitant",
        !"Farm Inhabitant",
        !"Farm Inhabitant",
        !"Farm Inhabitant",
        !"Farm Inhabitant",
        !"Farm Inhabitant",
        !"Homeless",
        !"Homeless",
        !"Homeless",
        !"Homeless",
        !"Beach Visitor",
        !"Beach Visitor",
        !"Beach Visitor",
        !"Businesswoman",
        !"Taxi Driver",
        !"Crack Maker",
        !"Crack Maker",
        !"Crack Maker",
        !"Normal Eleman",
        !"Businessman",
        !"Businesswoman",
        !"Big Smoke Armored",
        !"Businesswoman",
        !"Normal Eleman",
        !"Prostitute",
        !"Construction Worker",
        !"Beach Visitor",
        !"Well Stacked Pizza Worker",
        !"Barber",
        !"Hillbilly",
        !"Farmer",
        !"Hillbilly",
        !"Hillbilly",
        !"Farmer",
        !"Hillbilly",
        !"Black Bouncer",
        !"White Bouncer",
        !"White MIB Agent",
        !"Black MIB Agent",
        !"Cluckin\' Bell Worker",
        !"Hotdog/Chilli Dog Vendor",
        !"Normal Eleman",
        !"Normal Eleman",
        !"Blackjack Dealer",
        !"Casino Croupier",
        !"San Fierro Rifa",
        !"San Fierro Rifa",
        !"San Fierro Rifa",
        !"Barber",
        !"Barber",
        !"Whore",
        !"Ammunation Salesman",
        !"Tattoo Artist",
        !"Punk",
        !"Cab Driver",
        !"Normal Eleman",
        !"Normal Eleman",
        !"Normal Eleman",
        !"Normal Eleman",
        !"Businessman",
        !"Normal Eleman",
        !"Valet",
        !"Barbara Schternvart",
        !"Helena Wankstein",
        !"Michelle Cannes",
        !"Katie Zhan",
        !"Millie Perkins",
        !"Denise Robinson",
        !"Farm Town Inhabitant",
        !"Hillbilly",
        !"Farm Town Inhabitant",
        !"Farm Town Inhabitant",
        !"Hillbilly",
        !"Farmer",
        !"Farmer",
        !"Karate Teacher",
        !"Karate Teacher",
        !"Burger Shot Cashier",
        !"Cab Driver",
        !"Prostitute",
        !"Su Xi Mu (Suzie)",
        !"Noodle Stand Vendor",
        !"Boater",
        !"Clothes Shop Staff",
        !"Homeless",
        !"Weird Old Man",
        !"Waitress (Maria Latore)",
        !"Normal Eleman",
        !"Normal Eleman",
        !"Clothes Shop Staff",
        !"Normal Eleman",
        !"Rich Woman",
        !"Cab Driver",
        !"Normal Eleman",
        !"Normal Eleman",
        !"Normal Eleman",
        !"Normal Eleman",
        !"Hillbilly",
        !"Normal Eleman",
        !"Businessman",
        !"Normal Eleman",
        !"Normal Eleman",
        !"Homeless",
        !"Normal Eleman",
        !"Normal Eleman",
        !"Normal Eleman",
        !"Cab Driver",
        !"Normal Eleman",
        !"Normal Eleman",
        !"Prostitute",
        !"Prostitute",
        !"Homeless",
        !"The D.A",
        !"Afro American",
        !"Mexican",
        !"Prostitute",
        !"Stripper",
        !"Prostitute",
        !"Stripper",
        !"Biker",
        !"Biker",
        !"Pimp",
        !"Normal Eleman",
        !"Lifeguard",
        !"Naked Valet",
        !"Bus Driver",
        !"Biker Drug Dealer",
        !"Chauffeur (Limo Driver)",
        !"Stripper",
        !"Stripper",
        !"Heckler",
        !"Heckler",
        !"Construction Worker",
        !"Cab Driver",
        !"Cab Driver",
        !"Normal Eleman",
        !"Clown",
        !"Officer Frank Tenpenny (Corrupt Cop)",
        !"Officer Eddie Pulaski (Corrupt Cop)",
        !"Officer Jimmy Hernandez",
        !"Dwaine/Dwayne",
        !"Melvin \'Big Smoke\' Harris",
        !"Sean \'Sweet\' Johnson",
        !"Lance \'Ryder\' Wilson",
        !"Mafia Boss",
        !"T-Bone Mendez",
        !"Paramedic (Emergency Medical Technician)",
        !"Paramedic (Emergency Medical Technician)",
        !"Paramedic (Emergency Medical Technician)",
        !"Itfaiyeci",
        !"Itfaiyeci",
        !"Itfaiyeci",
        !"Los Santos Polis",
        !"San Fierro Polis",
        !"Las Venturas Polis",
        !"Country Sheriff",
        !"LSPD Motorbike Cop",
        !"S.W.A.T. Special Forces",
        !"Federal Agent",
        !"San Andreas Army",
        !"Desert Sheriff",
        !"Zero",
        !"Ken Rosenberg",
        !"Kent Paul",
        !"Cesar Vialpando",
        !"Jeffery \'OG Loc\' Martin/Cross",
        !"Wu Zi Mu (Woozie)",
        !"Michael Toreno",
        !"Jizzy B",
        !"Madd Dogg",
        !"Catalina",
        !"Claude Speed"
    }
;
pawn Code:
stock showPlayerSkinName(playerid) {
    static
        s_szName[41]
    ;
    strunpack(s_szName, s_aszSkinNames[GetPlayerSkin(playerid) % sizeof(s_aszSkinNames)]);
    GameTextForPlayer(playerid, s_szName, 2000, 4);
}


edit by RyDeR` thanks.
Reply

nvm...
Reply

Quote:
Originally Posted by Calgon
Посмотреть сообщение
Calculate the amount of seconds between now and the next whole hour (XX:00). May be useful for those making payday systems.

pawn Код:
stock GetSecsBetwnWholeHour() {
    new
        iTime[3];

    gettime(iTime[0], iTime[1], iTime[2]);

    return (59 - iTime[1]) * 60 + (60 - iTime[2]);
}
Going to use this with my Payday system I think. Can I ask though, what format does it return? Just the second?
Reply

Just seconds
Reply

Quote:
Originally Posted by ******
Посмотреть сообщение
You add the current seconds, that seems like it should be a subtraction:

XX.59.00 gives 60, correctly, but XX.59.01 gives 61, and XX.59.59 gives 119.

Just from thinking about it:

pawn Код:
return (59 - iTime[1]) * 60 + (60 - iTime[2]);
The "59" came from double checking those three examples and finding them all not a minute out with "60".
Thanks, that fixed it. Updated.
Reply

anyone have a Anti-CarPush System?

Thanks
Reply

This Is Simple Teleport System

pawn Код:
stock TeleportPlayer(playerid,Float:x,Float:y,Float:z,telename[],telecmd[])
{
    new sendername[MAX_PLAYER_NAME], string[500];
    GetPlayerName(playerid, sendername, sizeof(sendername));
    format(string, sizeof(string), "%s(%d) Has Teleported To %s (%s)", sendername,playerid,telename,telecmd);
    SendClientMessageToAll(-1, string);
    SetPlayerPos(playerid,x,y,z);
    return 1;
}
IN CMD:

pawn Код:
CMD:ls(playerid,params[])
{
TeleportPlayer(playerid,0.00,0.00,0.00+5,"Blueberry","/bb");
return 1;
}
so it will be
PHP код:

Player_Name
(0Has Teleported To Blueberry (/bb
Reply

This function stores random characters from a string to the one mentioned. The storing length is the size of that array by default however it can be lowered.
pawn Код:
stock GetRandomizedChars(const rchar_array[], trchars[], size = sizeof(trchars),
    rsize = sizeof(rchar_array))
{
    new
        temp_rchar;
    for(new i; i< size; i++)
    {
        temp_rchar = rchar_array[random(rsize)];
        trchars[i] = temp_rchar;
    }
    return 1;
}
Example:
pawn Код:
new
    r_Chars[] = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ0123456789"
    ;


public OnRconCommand(cmd[])
{
    if(!strcmp(cmd, "rcharprint", true)) {
        new
            tenchar[10];
        GetRandomizedChars(r_Chars, tenchar, sizeof(tenchar));
        printf("%s", tenchar);
        return 1;
    }
    return 1;
}
It can be used for various types of reactions or any sort of random stuffs.
Reply

hi guys , i need help about how to make 2 commands for 1 function using dcmd
Code:
/rob /rb , /rape /ra , /heal /h
Reply

pawn Код:
space(chr)
    return chr == 0x20 || chr == 0x09 || chr == 0x0a || chr == 0x0b || chr == 0x0c || chr == 0x0d;
Reply

I was tired of escaping strings in SQLite every time I execute a query so I decided to use formatex include by Slice and created a simple specifier %E, the reason I didn't use %e because it will collide with MySQL who ever uses MySQL + SQLite.

You need Function

pawn Код:
FormatSpecifier<'e'>(output[], string[])
{
    if(string[0] == EOS)
        print("Error: Empty string, the system can't escape anything.");
    else
        format(output, sizeof(output), "%s", DB_Escape(string));
}
Usage

pawn Код:
new string[128];
format(string, sizeof(string), "INSERT INTO Table (RowID1) VALUES ('%e')", "EscapeMe");
db_query(dbHandle, string);
EDIT: Spoke to ****** and assuming mysql_format and format is different, I decided to change the specifier to %e instead of %E
Reply

Hey i saw a function here (SetObjectFaceCoords3D) and now ,
i want to know how can i use it for a player
i want to Set Player Facing Angle to an Object like a KeyPad
Reply


Forum Jump:


Users browsing this thread: 39 Guest(s)