SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 24/02/2017, 09:46 PM   #1071
Nero_3D
High-roller
 
Nero_3D's Avatar
 
Join Date: Jun 2007
Location: Germany
Posts: 2,852
Reputation: 675
Default Re: Useful Snippets

Quote:
Originally Posted by OstGot View Post
PHP Code:
//CODE 
Code:
[22:47:50] 1 (with 3rd variable): 1398 ms
[22:47:51] 2 (without): 1049 ms
Can't reproduce these results, the 3rd variable is faster for me
Also you could get faster with putting everything in one line ("c = a, a = b, b = c;") (if compiled with debug information -d1,2,3 (deafult is -d1))

Even if I switch the arithmetic with bitwise operations (which should be faster, "a = b | (b = a) & 0;") is not enough to beat it

Anyways use emit if you want to be the fastest within pawn
Nero_3D is offline   Reply With Quote
Old 25/02/2017, 09:30 AM   #1072
OstGot
Gangsta
 
OstGot's Avatar
 
Join Date: Mar 2013
Location: Gomel, Belarus
Posts: 952
Reputation: 333
Default Re: Useful Snippets

Quote:
Originally Posted by Nero_3D View Post
Can't reproduce these results, the 3rd variable is faster for me
I tested it on my home PC with Windows (10) on board. Hmm, anyway it was just interesting to see the results.
Good to know, thanks

Quote:
Originally Posted by Nero_3D View Post
Anyways use emit if you want to be the fastest within pawn
It kills any readability and as a consequence isn't worth it
__________________
aka Nexius
Don't want to always check for updates of my scripts?
Include it the last, after all others
Nexius's Update Checker
OstGot is offline   Reply With Quote
Old 04/03/2017, 06:55 PM   #1073
Flashhiee
Gangsta
 
Flashhiee's Avatar
 
Join Date: Mar 2012
Posts: 919
Reputation: 304
Default Re: Useful Snippets

I know that right now i dont present a script, but this is a cool ideea of making checkpoints for whatever u want.
Image
All those things were coloured using Texture Studio. This was made for a tuning system, and that wrench ive managed to make it spin via a timer. You can actualy replace or remove the wrench if u want to use the checkpoint for something else, for example u can put insead a petrol can if u want the checkpoint for a fuel station. Anyway, to make the checkpoint trigger when i enter in it i use Dynamic Areas from streamer plugin.
__________________
My maps:
The Hell - Space Station[Module I] - Mansion Interior - Mining Village - Desert Village

I create custom maps of any kind, more details on discord at UnuAlex#6567
Flashhiee is offline   Reply With Quote
Old 20/03/2017, 03:29 PM   #1074
SyS
High-roller
 
SyS's Avatar
 
Join Date: Oct 2015
Posts: 1,939
Reputation: 504
Default Re: Useful Snippets

Arrfind

I was told to post it here. So posting it...
This is a very simple macro to find the element index in an array without looping making use of pawn's typless nature and it orginated from this discussion

NOTE:
if we have an element value equal to 0 (as null terminator equals to 0 ) the checking stops on that index and further index would not be checked and will return -1. Therefore it can't be used with array having elements values 0.

PHP Code:
#define arrfind(%0,%1) strfind(%0,{%1},false,0) 

main() 

    new array[]={
6,2,3,3,2340,78}; 

    
printf"index = %d" arrfind(array,3));//will print 2 
     

SyS is offline   Reply With Quote
Old 20/03/2017, 03:53 PM   #1075
Dayrion
High-roller
 
Dayrion's Avatar
 
Join Date: Jan 2016
Location: France
Posts: 1,915
Reputation: 258
Default Re: Useful Snippets

Quote:
Originally Posted by OstGot View Post
PHP Code:
public OnGameModeInit()
{
    new 
gtc;
    
gtc GetTickCount();
    for(new 
i34628c10_000_000i++)
    {
        
a;
        
b;
        
c;
    }
    
printf("1 (with 3rd variable): %d ms"GetTickCount() - gtc);
    
gtc GetTickCount();
    for(new 
i3462810_000_000i++)
    {
        
- (a);
    }
    
printf("2 (without): %d ms"GetTickCount() - gtc);
    return 
1;

Code:
[22:47:50] 1 (with 3rd variable): 1398 ms
[22:47:51] 2 (without): 1049 ms
Credits to @Dutheil

Your function:
PHP Code:
swap(&a, &b)
{
    
- (a);

Code:
proc	; swap
lref.s.pri c
push.pri
lref.s.pri 10
pop.alt
add
push.pri
lref.s.pri c
sref.s.pri 10
pop.alt
sub.alt
sref.s.pri c
zero.pri
retn

The simplest function:
PHP Code:
swap(&a, &b)
{
    new
        
a;
        
    
b;
    
c;

Code:
proc	; swap
stack fffffffc
lref.s.pri c
stor.s.pri fffffffc
lref.s.pri 10
sref.s.pri c
load.s.pri fffffffc
sref.s.pri 10
stack 4
zero.pri
retn
Fatest function without using a 3rd var.
PHP Code:
swap(&a, &b)
{
    
#emit LREF.S.pri a
    #emit LREF.S.alt b
    #emit SREF.S.pri b
    #emit SREF.S.alt a

__________________
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 20/03/2017, 04:28 PM   #1076
Crayder
Banned
 
Join Date: Sep 2013
Location: Flames of Hell
Posts: 3,324
Reputation: 652
Default Re: Useful Snippets

Quote:
Originally Posted by Dayrion View Post
...
Don't forget XOR swap...
Crayder is offline   Reply With Quote
Old 21/03/2017, 12:02 PM   #1077
Logic_
Banned
 
Join Date: Jun 2015
Posts: 1,506
Reputation: 305
Default Re: Useful Snippets

Nothing special but I use it personally for some systems in my script.

PHP Code:
hash(bufwith)
{
    new 
num buf << with;
    if(
IsEven(num)) num *= 2;
    else 
num *= 3;
    return 
num;
}

unhash(bufwith)
{
    new 
num buf >> with;
    if(
IsEven(num)) num /= 2;
    else 
num /= 3;
    return 
num;

Logic_ is offline   Reply With Quote
Old 21/03/2017, 10:06 PM   #1078
OneDay
Huge Clucker
 
Join Date: Sep 2015
Posts: 294
Reputation: 139
Default Re: Useful Snippets

Quote:
Originally Posted by Logic_ View Post
Nothing special but I use it personally for some systems in my script.

PHP Code:
hash(bufwith)
{
    new 
num buf << with;
    if(
IsEven(num)) num *= 2;
    else 
num *= 3;
    return 
num;
}

unhash(bufwith)
{
    new 
num buf >> with;
    if(
IsEven(num)) num /= 2;
    else 
num /= 3;
    return 
num;

that is just:

PHP Code:
hash(bufwith)
{
    return 
buf << (with 1);
}

unhash(bufwith)
{
    return 
buf >> (with 1);

except on huge numbers:

PHP Code:
hash(838860810); // 0
unhash(010); // 0 
or "with" is 0:

PHP Code:
hash(30); // 9
unhash(90); // 3 
OneDay is offline   Reply With Quote
Old 24/03/2017, 09:02 PM   #1079
AbyssMorgan
Banned
 
Join Date: Apr 2015
Location: Poland
Posts: 1,208
Reputation: 352
Default Re: Useful Snippets

Random Easter Egg Generator (Decoration)

http://imgur.com/a/34czh

PHP Code:
#include <a_samp>
#include <streamer>
#include <colandreas> //OR mapandreas
#include <SAM/3DTryg> //http://forum.sa-mp.com/showthread.php?t=591010

#define MAX_EASTER_EGG        10000

stock EasterEggCreate(){
    new 
Float:pioxFloat:pioyFloat:pioz;
    
GetRandomPointInRectangle(-3000.0,-3000.0,3000.0,3000.0,piox,pioy);
    while(
IsPointInWater(piox,pioy,0.0)){
        
GetRandomPointInRectangle(-3000.0,-3000.0,3000.0,3000.0,piox,pioy);
    }
    
Tryg3D_MapAndreasFindZ(piox,pioy,pioz);
    new 
tmpobj CreateDynamicObject(19341,piox,pioy,pioz+0.55,0.0,0.0,0.0,0,0,-1,50.0);
    switch(
random(14)){
        case 
1SetDynamicObjectMaterial(tmpobj,0,18841,"MickyTextures","ws_gayflag1");
        case 
2SetDynamicObjectMaterial(tmpobj,0,18841,"MickyTextures","Smileyface2");
        case 
3SetDynamicObjectMaterial(tmpobj,0,18841,"MickyTextures","orang006");
        case 
4SetDynamicObjectMaterial(tmpobj,0,18841,"MickyTextures","brown013");
        case 
5SetDynamicObjectMaterial(tmpobj,0,18841,"MickyTextures","red032");
        case 
6SetDynamicObjectMaterial(tmpobj,0,18841,"MickyTextures","yello007");
        case 
7SetDynamicObjectMaterial(tmpobj,0,18841,"MickyTextures","wood051");
        case 
8SetDynamicObjectMaterial(tmpobj,0,18841,"MickyTextures","waterclear256");
        case 
9SetDynamicObjectMaterial(tmpobj,0,18841,"MickyTextures","tubelite");
        case 
10SetDynamicObjectMaterial(tmpobj,0,18841,"MickyTextures","marb002");
        case 
11SetDynamicObjectMaterial(tmpobj,0,18841,"MickyTextures","grey002");
        case 
12SetDynamicObjectMaterial(tmpobj,0,18841,"MickyTextures","metal013");
        case 
13SetDynamicObjectMaterial(tmpobj,0,18841,"MickyTextures","brick008");
    }
}

public 
OnFilterScriptInit(){
    
    for(new 
0MAX_EASTER_EGGi++){
        
EasterEggCreate();
    }
    
    return 
1;

AbyssMorgan is offline   Reply With Quote
Old 14/04/2017, 06:11 AM   #1080
JakeWalker
Little Clucker
 
Join Date: Jun 2016
Posts: 27
Reputation: 0
Default Re: Useful Snippets

Well, I builded it all myself, I tried to take a look at other scripts with audio script and see what they made there, until I've done that, +REP me if you tried it out and you liked it
Code:
Code:
CMD:play4all(playerid, params[])
{
 if (PlayerInfo[playerid][pAdmin] >= 1338)
 {
  if(isnull(params)) return SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /play4all [Link]");
      for(new i = 0; i < MAX_PLAYERS; i++)
  {
        PlayAudioStreamForPlayer(i, params);
      }
     SendClientMessageToAllEx(COLOR_LIGHTBLUE, "* Use /stopaudio to stop the music.");
 }
     return 1;
}
Code:
CMD:stopmusic(playerid, params[])
{
  	if(PlayerInfo[playerid][pAdmin] >= 3)
  	{
		SendClientMessageToAllEx(COLOR_LIGHTBLUE, "* Music has been stopped.");
	  	for(new i = 0; i < MAX_PLAYERS; i++)
	  	{
	          StopAudioStreamForPlayer(i);
	  	}
 	}
  	return 1;
}
If you find any bugs / errors in the script, tell me & fix it and repost so I'll update the thread
btw here's the cmd of /stopaudio:
Code:
CMD:stopaudio(playerid, params[])
{
    SendClientMessage(playerid, 0xAD1515FF, "You have stopped the music.");
	StopAudioStreamForPlayer(playerid);
    return 1;
If I'll get engouh +reps I'll post DJ System that works with this
EDIT P.W: This plugin was made in Roleplay script which the highest rank was 1338, edit the rank to your server's admin ranks
__________________
My first work!
Music System: http://forum.sa-mp.com/showthread.php?t=632403
JakeWalker 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 11:22 AM


All times are GMT. The time now is 07:12 PM.


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