SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 25/09/2011, 05:31 PM   #511
RyDeR`
High-roller
 
RyDeR`'s Avatar
 
Join Date: Feb 2009
Location: Belgium
Posts: 2,929
Reputation: 700
Default Re: Useful Snippets

Meta, there's a much easier and more efficient way to do this:
pawn Code:
#define GetStringArg(%0,%1,%2); \
    for(new i = 0; i < (%2); ++i) \
    { \
        if((%1[i] = getarg((%0), i)) != EOS) \
            continue; \
        else \
        { \
            %1[i] = EOS; \
            break; \
        } \
    }
Usage:
pawn Code:
stock foo(...)
{
    new
        szBuf[16]
    ;
    GetStringArg(0, szBuf, sizeof(szBuf));
    print(szBuf);
   
    GetStringArg(1, szBuf, sizeof(szBuf));
    print(szBuf);  
}
pawn Code:
foo("Hello World!", "How are you?"); // Will print us "Hello World!" and "How are you?"
__________________

Sup?

Last edited by RyDeR`; 27/09/2011 at 04:20 PM.
RyDeR` is offline   Reply With Quote
Old 25/09/2011, 10:05 PM   #512
Kar
Banned
 
Join Date: May 2010
Location: Black Asylum
Posts: 2,992
Reputation: 538
Default Re: Useful Snippets

pawn Code:
new gAttached[MAX_PLAYERS];

public OnPlayerUpdate(playerid)
{
    new vehicleid = GetPlayerVehicleID(playerid);
    if (1 <= vehicleid <= 2000)
    {
        new trailerid = GetVehicleTrailer(vehicleid);
        if (gAttached[playerid] != trailerid && (1 <= trailerid <= 2000))
        {
            if (gAttached[playerid] == 0 || gAttached[playerid] == INVALID_VEHICLE_ID)
            {
                CallLocalFunction("OnTrailerDetach", "ii", playerid, vehicleid);
            }
            else if (trailerid)
            {
                CallLocalFunction("OnTrailerAttach", "iii", playerid, vehicleid, trailerid);
            }
            gAttached[playerid] = trailerid;
        }
    }
    return 1;
}
Kar is offline   Reply With Quote
Old 27/09/2011, 12:55 PM   #513
[S]trong
Guest
 
Posts: n/a
Default Re: Useful Snippets

pawn Code:
#define GetArrayArg(%0,%1)  for(new stg%0 = 0;  (%1[stg%0] = getarg(%0, stg%0)); ++stg%0) continue

foo(...)
{
    new
        szBuf[32]
    ;
   
    GetArrayArg(0, szBuf);
    print(szBuf);

    GetArrayArg(1, szBuf);
    print(szBuf);
}

public OnFilterScriptInit()
{
    foo("Hello", "World");
    return true;
}
  Reply With Quote
Old 27/09/2011, 01:41 PM   #514
Slice
High-roller
 
Join Date: Mar 2008
Location: Sweden
Posts: 1,835
Reputation: 1607
Default Re: Useful Snippets

Quote:
Originally Posted by [S]trong View Post
pawn Code:
#define GetArrayArg(%0,%1)  for(new stg%0 = 0;  (%1[stg%0] = getarg(%0, stg%0)); ++stg%0) continue

foo(...)
{
    new
        szBuf[32]
    ;
   
    GetArrayArg(0, szBuf);
    print(szBuf);

    GetArrayArg(1, szBuf);
    print(szBuf);
}

public OnFilterScriptInit()
{
    foo("Hello", "World");
    return true;
}
First off, that function will copy only zero-terminated arrays (strings, for instance). Secondly, RyDeR posted a function just like that 2 posts above yours.
Slice is offline   Reply With Quote
Old 28/09/2011, 01:22 AM   #515
[S]trong
Guest
 
Posts: n/a
Default Re: Useful Snippets

Quote:
First off, that function will copy only zero-terminated arrays (strings, for instance). Secondly, RyDeR posted a function just like that 2 posts above yours.
Just place ! = EOS, sir

******:
Send me link of function?
  Reply With Quote
Old 28/09/2011, 05:18 AM   #516
Slice
High-roller
 
Join Date: Mar 2008
Location: Sweden
Posts: 1,835
Reputation: 1607
Default Re: Useful Snippets

What do you mean? EOS is a constant with the value 0.
Slice is offline   Reply With Quote
Old 04/10/2011, 11:06 AM   #517
Phanto90
Huge Clucker
 
Phanto90's Avatar
 
Join Date: Mar 2011
Location: Milan, Italy
Posts: 337
Reputation: 36
Default Re: Useful Snippets

Well, actually I saw that someone suggested to fix nightvision and thermal ****** bug to sa:mp developers.
Many of you don't know that you can simply disable this bug by de-synching players using thermal ******s or night vision ******s as follow:
Code:
public OnPlayerUpdate(playerid)
{
       if((GetPlayerWeapon(playerid) == 44 || GetPlayerWeapon(playerid) == 45) && !IsPlayerInAnyVehicle(playerid))
       {
               new
                   keys,
                      ud,
                       lr;
               GetPlayerKeys(playerid, keys, ud, lr);
               if(keys & KEY_FIRE)
               {
                       return 0;
               }
       }
       return 1;
}
__________________


Latest Releases
FilterscriptsIncludesMaps
PRaceSystem v1.3 PBlock v1.1Electronic Shop
PVotekick v1.1PInventory v1.1
________________________
I don't script for money, stop asking for it.

Phanto90 is offline   Reply With Quote
Old 04/10/2011, 11:44 AM   #518
Slice
High-roller
 
Join Date: Mar 2008
Location: Sweden
Posts: 1,835
Reputation: 1607
Default Re: Useful Snippets

Quote:
Originally Posted by Phanto90 View Post
Well, actually I saw that someone suggested to fix nightvision and thermal ****** bug to sa:mp developers.
Many of you don't know that you can simply disable this bug by de-synching players using thermal ******s or night vision ******s as follow:
Code:
public OnPlayerUpdate(playerid)
{
       if((GetPlayerWeapon(playerid) == 44 || GetPlayerWeapon(playerid) == 45) && !IsPlayerInAnyVehicle(playerid))
       {
               new
                   keys,
                      ud,
                       lr;
               GetPlayerKeys(playerid, keys, ud, lr);
               if(keys & KEY_FIRE)
               {
                       return 0;
               }
       }
       return 1;
}
The problem with that, however, is you could simply hold the fire key to run around while others see you as standing still. Once you'd release the fire key, your player would have appeared to teleport to wherever you moved.
Slice is offline   Reply With Quote
Old 04/10/2011, 03:32 PM   #519
Phanto90
Huge Clucker
 
Phanto90's Avatar
 
Join Date: Mar 2011
Location: Milan, Italy
Posts: 337
Reputation: 36
Default Re: Useful Snippets

Yeah that's the main problem.
But I see no points in going around with thermal/nightvision ****** armed and keeping pressed a key.
Most of the users would never find it out i think. And I add that this is only a temporary method if someone want to use this in his server waiting this bug to be fixed by developers.

What about this improvement?
Code:
new bool:pressed_before[MAX_PLAYERS] = {false, ...};
public OnPlayerConnect(playerid)
{
     pressed_before[playerid] = false;
     return 1;
}

public OnPlayerUpdate(playerid)
{
       if((GetPlayerWeapon(playerid) == 44 || GetPlayerWeapon(playerid) == 45) && !IsPlayerInAnyVehicle(playerid))
       {
               new
                   keys,
                       ud,
                       lr;
               GetPlayerKeys(playerid, keys, ud, lr);
               if(keys & KEY_FIRE)
               {
                       if(!pressed_before[playerid])
                       {
                       pressed_before[playerid] = true;
                       return 0;
                       }
               }
               else
               {
               pressed_before[playerid] = false;    
               }
       }
       return 1;
}
__________________


Latest Releases
FilterscriptsIncludesMaps
PRaceSystem v1.3 PBlock v1.1Electronic Shop
PVotekick v1.1PInventory v1.1
________________________
I don't script for money, stop asking for it.

Phanto90 is offline   Reply With Quote
Old 04/10/2011, 03:46 PM   #520
Slice
High-roller
 
Join Date: Mar 2008
Location: Sweden
Posts: 1,835
Reputation: 1607
Default Re: Useful Snippets

By doing that you would simply delay the syncing of it by a fraction of a second, unfortunately.
Slice 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 05:09 PM.


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