SA-MP Forums Useful Snippets
 User Name Remember Me? Password
 New Account Members List Search Today's Posts Mark Forums Read

 Thread Tools Display Modes
 13/07/2018, 10:58 PM #1291 Marmeladova Banned   Join Date: Dec 2016 Location: Somewhere Posts: 14 Reputation: 0 Re: Useful Snippets A function that determines the distance between two geographic points based on haversine formula Code: PHP Code: ``` stock Float:GeoDistance(Float:lat1, Float:lon1, Float:lat2, Float:lon2) {     const Float:R = 6371.0087714; // Earth radius     new Float:sin1 = floatsin((lat1 - lat2) /2 );     new Float:sin2 = floatsin((lon1 - lon2) /2 );     return 2 * R * 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", lat1, lon1, lat2, lon2, GeoDistance(lat1, lon1, lat2, lon2));  ```
 30/08/2018, 06:16 PM #1292 Lokii Huge Clucker   Join Date: Sep 2017 Posts: 290 Reputation: 72 Re: Useful Snippets Realistic Car Crash damage if you drive at high speed the player will get damage! PHP Code: ``` #include  Float:GetSpeed(playerid) {     new Float:x, Float:y, Float:z;     GetVehicleVelocity(GetPlayerVehicleID(playerid), x, y, z);     return floatabs(floatsqroot(floatpower(x, 2) + floatpower(y, 2)))*180.5; } public OnVehicleDamageStatusUpdate(vehicleid, playerid) {     new Float:hp, Float:dmg;     dmg = GetSpeed(playerid);     for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)      {         if(IsPlayerNPC(i) || GetPlayerVehicleID(i) != vehicleid) continue;         GetPlayerHealth(i, hp);         SetPlayerHealth(i, hp-(dmg/3));     }     return 1; }  ``` __________________ Code: ```Releases [Include] VDMG (damage vehicles with no driver!) [Include] SkinEx (CHANGES LIKE IN GTA V) [Include] AutoMove (create automatic gates with ONE LINE!) [FileterScript] Area 69 Security Force (FCNPC) [FileterScript] Blood screen when player is damaged)```
 01/09/2018, 08:21 PM #1293 brauf Little Clucker     Join Date: Jul 2018 Location: i live in narnia city Savage: 100% Posts: 31 Reputation: 17 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
03/09/2018, 08:05 PM   #1294
Dayrion
High-roller

Join Date: Jan 2016
Location: France
Posts: 1,931
Reputation: 256
Re: Useful Snippets

Quote:
 Originally Posted by brauf ...
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 »

03/09/2018, 09:03 PM   #1295
Y_Less
Beta Tester

Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,461
Reputation: 3206
Re: Useful Snippets

Quote:
 Originally Posted by Dayrion It will freeze the server and prevent other code running. That’s a veryyyyyyy bad idea.
To be fair, it is called “hang”.
__________________
 | Worst. Exit. Ever. |
 | git.io/Y | y-less.com | jump.pk |

03/09/2018, 09:31 PM   #1296
brauf
Little Clucker

Join Date: Jul 2018
Location: i live in narnia city Savage: 100%
Posts: 31
Reputation: 17
Re: Useful Snippets

Quote:
 Originally Posted by Dayrion 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

03/09/2018, 10:05 PM   #1297
Y_Less
Beta Tester

Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,461
Reputation: 3206
Re: Useful Snippets

Though the much simpler way of doing what you said is a cron job.
__________________
 | Worst. Exit. Ever. |
 | git.io/Y | y-less.com | jump.pk |

 12/09/2018, 02:49 AM #1298 Crystallize Banned   Join Date: Aug 2013 Posts: 1,582 Reputation: 314 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.
23/10/2018, 02:24 AM   #1299
AmirSavand
Big Clucker

Join Date: Sep 2018
Location: Behind Schedule
Posts: 78
Reputation: 8
Re: Useful Snippets

Quote:
 Originally Posted by brauf 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

 31/10/2018, 04:12 PM #1300 TheToretto Huge Clucker     Join Date: Jul 2015 Posts: 278 Reputation: 22 Re: Useful Snippets Halloween accessories First release on Github pawn Code: `#include #include #include 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

 Thread Tools Display Modes Linear Mode

 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 Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post -Sneaky- Help Archive 5 02/05/2009 12:22 PM

All times are GMT. The time now is 01:41 PM.

 -- (EN) English -- (RU) Русски Contact Us - SA-MP - Archive - Top

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