SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts

Reply
 
Thread Tools Display Modes
Old 13/07/2018, 10:58 PM   #1291
Marmeladova
Banned
 
Join Date: Dec 2016
Location: Somewhere
Posts: 14
Reputation: 0
Default Re: Useful Snippets

A function that determines the distance between two geographic points based on haversine formula

Code:
PHP Code:
stock Float:GeoDistance(Float:lat1Float:lon1Float:lat2Float:lon2)
{
    const 
Float:6371.0087714// Earth radius
    
new Float:sin1 floatsin((lat1 lat2) /);
    new 
Float:sin2 floatsin((lon1 lon2) /);
    return 
asin(floatsqroot(sin1 sin1 sin2 sin2 floatcos(lat1) * floatcos(lat2))) * (3.14 180);

  • lat1 - latitude of the first point (in radians)
  • lon1 - longitude of the first point (in radians)
  • lat2 - latitude of the second point (in radians)
  • lon2 - longitude of the second point (in radians)

Example of use:
PHP Code:
new Float:lat1 52.5243700 * (3.14 180);
new 
Float:lon1 13.4105300 * (3.14 180);

new 
Float:lat2 50.4546600 * (3.14 180);
new 
Float:lon2 30.5238000 * (3.14 180);

printf("Latitude 1: %f | Longtitude 1: %f\n\
        Latitude 2: %f | Longtitude 2: %f\n\
        Distance: %f"
lat1lon1lat2lon2GeoDistance(lat1lon1lat2lon2)); 
Marmeladova is offline   Reply With Quote
Old 30/08/2018, 06:16 PM   #1292
Lokii
Huge Clucker
 
Join Date: Sep 2017
Posts: 281
Reputation: 72
Default Re: Useful Snippets

Realistic Car Crash damage

if you drive at high speed the player will get damage!

PHP Code:
#include <a_samp>

Float:GetSpeed(playerid)
{
    new 
Float:xFloat:yFloat:z;
    
GetVehicleVelocity(GetPlayerVehicleID(playerid), xyz);
    return 
floatabs(floatsqroot(floatpower(x2) + floatpower(y2)))*180.5;
}

public 
OnVehicleDamageStatusUpdate(vehicleidplayerid)
{
    new 
Float:hpFloat:dmg;
    
dmg GetSpeed(playerid);
    for(new 
0GetPlayerPoolSize(); <= ji++) 
    {
        if(
IsPlayerNPC(i) || GetPlayerVehicleID(i) != vehicleid) continue;
        
GetPlayerHealth(ihp);
        
SetPlayerHealth(ihp-(dmg/3));
    }
    return 
1;

Lokii is offline   Reply With Quote
Old 01/09/2018, 08:21 PM   #1293
brauf
Little Clucker
 
brauf's Avatar
 
Join Date: Jul 2018
Location: i live in narnia city Savage: 100%
Posts: 31
Reputation: 17
Default Re: Useful Snippets

serverHang Hangs/pauses your server for what ever reason you would want it to.
param 1 = seconds
param 2 = bool


How it can be used:
Code:
If a server would like to release at a specific time, then they can convert seconds 
to mins by adding *3600 at the end their number (multiply by an hour). This will be good
if a server is having a opening beta release and they want their server to open/start at that
exact time, will the server is already running but not fully loaded. Place the function on
public OnGamemodeInit()

For example:

public OnGameModeInit()
{
    printf("Starting hang...");
    hang(1*3600, false); // hang the server for 3600 seconds = 1 hour
}

Output:

log.txt

Starting hang...

/* 3600 seconds later */

----------------------------------
  Bare Script

----------------------------------

Number of vehicle models: 0
Code:
Code:
hang(count, bool:hangDebug)
{
    new hangTick[2];
    hangTick[0] = GetTickCount();

    new hangTime = 0;

    for(;;)
    {
        new hangStamp = tickcount();
        while(tickcount() - hangStamp < 1000) {}
        if(hangTime > count) break;

        hangTick[1] = GetTickCount();

        hangTime++;

        if(hangDebug) printf("hanged for %ims", hangTick[1]-hangTick[0]); 
    }
    
    if(hangDebug) printf("hang stopped at %i seconds", hangTime);
}
Usage:
Code:
hang(4, false);

Output:
Code:
hanged for 998ms
hanged for 1999ms
hanged for 2999ms
hanged for 3999ms
hang stopped at 4 seconds
__________________
[SNIPPET] serverHang

brauf is offline   Reply With Quote
Old 03/09/2018, 08:05 PM   #1294
Dayrion
High-roller
 
Dayrion's Avatar
 
Join Date: Jan 2016
Location: France
Posts: 1,916
Reputation: 256
Default Re: Useful Snippets

Quote:
Originally Posted by brauf View Post
...
It will freeze the server and prevent other code running. That's a veryyyyyyy bad idea.
__________________
actor_plus - v5.0.2
« I'm a goner, somebody catch my breath,
I'm a goner, somebody catch my breath »
Dayrion is offline   Reply With Quote
Old 03/09/2018, 09:03 PM   #1295
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,223
Reputation: 3183
Default Re: Useful Snippets

Quote:
Originally Posted by Dayrion View Post
It will freeze the server and prevent other code running. That’s a veryyyyyyy bad idea.
To be fair, it is called “hang”.
Y_Less is offline   Reply With Quote
Old 03/09/2018, 09:31 PM   #1296
brauf
Little Clucker
 
brauf's Avatar
 
Join Date: Jul 2018
Location: i live in narnia city Savage: 100%
Posts: 31
Reputation: 17
Default Re: Useful Snippets

Quote:
Originally Posted by Dayrion View Post
It will freeze the server and prevent other code running. That's a veryyyyyyy bad idea.
That's why I said it's useful if there's a new server and they want to launch on the exact time (e.g 5:00PM), automatically. They run that script, then after it stops "hanging" the server will fully load, allowing players to login.
__________________
[SNIPPET] serverHang

brauf is offline   Reply With Quote
Old 03/09/2018, 10:05 PM   #1297
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,223
Reputation: 3183
Default Re: Useful Snippets

Though the much simpler way of doing what you said is a cron job.
Y_Less is offline   Reply With Quote
Old 12/09/2018, 02:49 AM   #1298
Crystallize
Banned
 
Join Date: Aug 2013
Posts: 1,583
Reputation: 314
Default Re: Useful Snippets

Make NPC respond to you
Code:
public OnPlayerText(playerid, text[])
{
    if (strfind(text, "I need a taxi") != -1)
    {
        new string[80], name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
 new Float:X, Float:Y, Float:Z, Float:Angle;

        
        format(string, sizeof(string), "Hey %s taxi is in your way!", name);
        SendChat(string);
GetPlayerPos(playerid, X, Y, Z);
GetPlayerFacingAngle(playerid, Angle);
Createvehicle// here 
    }
    return 1;
}
Make NPC write a command

Code:
 public OnPlayerText(playerid, text[])
{
    if (strfind(text, "fuck you") != -1)
    {
        new string[80], name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
 
        SendCommand("/kick %i", playerid);
        format(string, sizeof(string), "Hey %s Fuck off!", name); // you can set a timer so the player can see the message
        SendChat(string);
    }
    return 1;
}
Not sure if the last snippet will work since I wrote it off phone but neverthless it’s funny how you can experiment with NPCs.
Also this is just an entertaining snippet.
Crystallize is offline   Reply With Quote
Old 23/10/2018, 02:24 AM   #1299
AmirSavand
Big Clucker
 
AmirSavand's Avatar
 
Join Date: Sep 2018
Location: Behind Schedule
Posts: 75
Reputation: 8
Default Re: Useful Snippets

Quote:
Originally Posted by brauf View Post
serverHang Hangs/pauses your server for what ever reason you would want it to.
param 1 = seconds
param 2 = bool


How it can be used:
Code:
If a server would like to release at a specific time, then they can convert seconds 
to mins by adding *3600 at the end their number (multiply by an hour). This will be good
if a server is having a opening beta release and they want their server to open/start at that
exact time, will the server is already running but not fully loaded. Place the function on
public OnGamemodeInit()
...
This is a terrible script. Some hosts may even disable your VPS if you're running at max CPU usage for a long time.
__________________

GitHub - Website - Contact

C# - Python - PHP - Angular
Unity 3D - Django - Electron

AmirSavand is offline   Reply With Quote
Old 31/10/2018, 04:12 PM   #1300
TheToretto
Huge Clucker
 
TheToretto's Avatar
 
Join Date: Jul 2015
Posts: 271
Reputation: 22
Default Re: Useful Snippets

Halloween accessories

First release on Github
pawn Code:
#include <a_samp>
#include <sscanf2>
#include <zcmd>

CMD:halloween(playerid, params[])
{
    new option;
    if(sscanf(params, "d", option))
        {
            SendClientMessage(playerid, 0x8CAA63FF, "SYNTAX: {FFFFFF}/halloween 1 : Wizard Hat - 2 : Devil Mask");
            return SendClientMessage(playerid, 0x8CAA63FF, "DESCRIPTION: {FFFFFF}Used to attach either a hat or a mask on your head");
        }
   
    switch(option)
    {
        case 1:
        {
            if(IsPlayerAttachedObjectSlotUsed(playerid, 8))
                {
                    RemovePlayerAttachedObject(playerid, 8);
                    return SendClientMessage(playerid, 0x33CCFFFF, "INFO: {FFFFFF}You've just removed your Halloween hat successfully.");
                }
                 
            SetPlayerAttachedObject(playerid, 8, 19528, 2, 0.125, -0.015, 0.01, 0.0, 0.0, -32.5, 0.9, 0.84, 1.01, 0, 0);
            EditAttachedObject(playerid, 8);
            SendClientMessage(playerid, 0x33CCFFFF, "INFO: {FFFFFF}You've just put on your Halloween hat! You can remove it by retyping the command.");
        }
        case 2:
        {
            if(IsPlayerAttachedObjectSlotUsed(playerid, 9))
                {
                    RemovePlayerAttachedObject(playerid, 9);
                    return SendClientMessage(playerid, 0x33CCFFFF, "INFO: {FFFFFF}You've just removed your Halloween mask successfully.");
                }

            SetPlayerAttachedObject(playerid, 9, 11704, 2, 0.05, 0.1, 0.0, -5.099, 85.6, -179.4, 0.396, 0.739, 0.422, 0, 0);
            // Resized the original object which was too big by default
            EditAttachedObject(playerid, 9);  
            SendClientMessage(playerid, 0x33CCFFFF, "INFO: {FFFFFF}You've just put on your Halloween mask! You can remove it by retyping the command.");
        }
    }
    return 1;
}
__________________






Toretto#9902

Rest in peace grandpa, 03 November 2018
TheToretto is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
READ Usefull Links to snippets and other -Sneaky- Help Archive 5 02/05/2009 12:22 PM


All times are GMT. The time now is 02:18 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.