Useful Snippets

Quote:
Originally Posted by RyDeR`
View Post
DeleteBadWorld? Anyway. I made a similar function which will work a lot faster and do the same thing:
pawn Code:
stock strdel2(szStr[], ...) {
    new
        szArg[128],
        iStart = 12,
        iEnd,
        iLen
    ;
    #emit LOAD.S.PRI 8
    #emit ADD.C 8
    #emit STOR.S.PRI iEnd
   
    for( ; iEnd >= iStart; iEnd -= 4, szArg[0] = EOS) {
        #emit LCTRL 5
        #emit LOAD.S.ALT iEnd
        #emit ADD
        #emit LOAD.I
        #emit MOVE.ALT
       
        #emit PUSH.ALT
        #emit PUSH.C 4
        #emit SYSREQ.C strlen
        #emit INC.PRI
        #emit STOR.S.PRI iLen
       
        #emit PUSH.S iLen
        #emit PUSH.ALT
        #emit PUSH.ADR szArg
        #emit PUSH.C 12
        #emit SYSREQ.C strcat
        #emit STACK 24
       
        new
            iPos
        ;
        while((iPos = strfind(szStr, szArg, true, iPos)) != -1) {
            strdel(szStr, iPos, iPos + iLen);
        }
    }
    return 1;
}
Example:
pawn Code:
new str[] = "this is a test to see if this works as expected!";
strdel2(str, "this", "test", "if", "works", "expected", "!");
print(str); // Prints: "is a to see as "
OoOps, i make "BadWorld" haha, is "BadWord" xD
I'm don't use Assembly codes in my script's..
i prefeer pawn only xD

Very god job!
Reply

Quote:
Originally Posted by Nero_3D
View Post
Cant it be improved if we leave strcat out and pass the address directly to strfind ?
That's very well seen! Changing and releasing it in the other topic.
Reply

Not sure if already posted, but here are 2 functions/formulas that I direly needed.

pawn Code:
#define PI 3.14159265
stock Float:ToRadian(Float:Degrees)return Degrees*(PI/180);
//This was set for On Foot Recording Files usage, maybe be different when used with something else
stock EulerToQuaternion(Float:angle,&Float:w,&Float:x,&Float:y,&Float:z) //Angle = Z rotation
{
    new Float:c1,Float:c2,Float:c3,Float:s1,Float:s2,Float:s3;
    c1=floatcos(0.0);                        //"Heading"   -- Just guessing, but I think X rotation goes here
    c2=floatcos(ToRadian(angle)/2);          //"Attitude"  -- Definitely Z
    c3=floatcos(0.0);                        //"Bank"      -- Possibly Y rotation
    s1=floatsin(0.0);
    s2=floatsin(ToRadian(angle)/2);
    s3=floatsin(0.0);
    w=(c1*c2*c3)-(s1*s2*s3);
    x=(s1*s2*c3)+(c1*c2*s3);
    y=(s1*c2*c3)+(c1*s2*s3);
    z=(c1*s2*c3)-(s1*c2*s3);
}
Reply

Quote:
Originally Posted by Joe Staff
View Post
Not sure if already posted, but here are 2 functions/formulas that I direly needed.

pawn Code:
#define PI 3.14159265
stock Float:ToRadian(Float:Degrees)return Degrees*(PI/180);
//This was set for On Foot Recording Files usage, maybe be different when used with something else
stock EulerToQuaternion(Float:angle,&Float:w,&Float:x,&Float:y,&Float:z) //Angle = Z rotation
{
    new Float:c1,Float:c2,Float:c3,Float:s1,Float:s2,Float:s3;
    c1=floatcos(0.0);                        //"Heading"   -- Just guessing, but I think X rotation goes here
    c2=floatcos(ToRadian(angle)/2);          //"Attitude"  -- Definitely Z
    c3=floatcos(0.0);                        //"Bank"      -- Possibly Y rotation
    s1=floatsin(0.0);
    s2=floatsin(ToRadian(angle)/2);
    s3=floatsin(0.0);
    w=(c1*c2*c3)-(s1*s2*s3);
    x=(s1*s2*c3)+(c1*c2*s3);
    y=(s1*c2*c3)+(c1*s2*s3);
    z=(c1*s2*c3)-(s1*c2*s3);
}
I'm trying to learn about Quaternions my brain finds it about as difficult as trying to percept an extra dimension!
I understand there's an extra "rotation dimension" to stop "gimbal lock" but what is the 'w' or "scalar" parameter.
Is there any way I can make a visual representation in SA:MP to help me understand these damn things!?
Reply

Quote:

I just copied this out of my gamemode, change it how you like.

Don't scan read, READ!
Reply

What is warping ? x)
Reply

[ame]http://www.youtube.com/watch?v=Z85Pt8ImcFE[/ame]

And car warp makes cars rain... They teleport to the sky then drop (in bundles) then kill you via explosions or just collision.

NOT MY VIDEO!
Reply

Yeah, you are pretty much wrong because I've tested it and it does the same thing...

SNIPPET UPDATED!
Reply

car warping is really annoying :\ , makes alot of several lags to ppl , some time i noticed it bug them up
thanks you Lorenc
Reply

Lorenc_ maybe you should detect if the vehicle's ID is differant to the last vehicle before you ban as an extra security measure.
Reply

That's optional, I doubt it'll do a difference lol.
Reply

Quote:
Originally Posted by Lorenc_
Посмотреть сообщение
ANTI-CAR WARP
Fags be car warping, I just copied this out of my gamemode, change it how you like. Just make sure you don't use PutPlayerInVehicle too fast, or you can even simply just hook: p_CarWarpTime[ playerid ] = gettime( ) + 1; to those functions

The average car jack per vehicle is around 400ms (0.4 seconds), the highest I've caught to was 634ms. It's good to be safe than sorry, so I've now set it to 1 second. It's barely possible to enter more than two vehicles in under two seconds anyway, as previously with two seconds. It was possible to enter two cars within 2 seconds.

Version 0.3 - NEW
pawn Код:
new p_CarWarpTime[ MAX_PLAYERS ];
new p_CarWarpVehicleID[ MAX_PLAYERS ];
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if( newstate == PLAYER_STATE_DRIVER && p_AdminLevel[ playerid ] <= 0 )
    {
        if( GetPlayerVehicleID( playerid ) != p_CarWarpVehicleID[ playerid ] )
        {
            if( p_CarWarpTime[ playerid ] > gettime( ) )
            {
                SendClientMessageToAllFormatted( -1, ""COL_AC"[ANTI-CHEAT]{FFFFFF} %s(%d) has been banned for car warping.", ReturnPlayerName( playerid ), playerid );
                BanEx( playerid, "Car Warp" );
                return 1;
            }
            p_CarWarpTime[ playerid ] = gettime( ) + 1;
            p_CarWarpVehicleID[ playerid ] = GetPlayerVehicleID( playerid );
        }
    }
    return 1;
}
I made this around 2 weeks ago and posted it in the filterscripts section, however it got removed for no specific reason.

I'm guessing you got the idea from me?
Reply

[quote=Pizzy;1975220]I made this around 2 weeks ago and posted it in the filterscripts section, however it got removed for no specific reason.

nvm
Reply

Quote:
Originally Posted by Pizzy
Посмотреть сообщение
I made this around 2 weeks ago and posted it in the filterscripts section, however it got removed for no specific reason.

I'm guessing you got the idea from me?
No, my server got attacked dozens of times but I did view yours. I think we have a similar concept though yours is less optimized (as it's using timers).
Reply

Get weapon model ID that can be used in pickups for example:

pawn Code:
GetWeaponModel(weaponid)
{
    switch(weaponid)
    {
        case WEAPON_BRASSKNUCKLE:       return 331;
        case WEAPON_GOLFCLUB:           return 333;
        case WEAPON_NITESTICK:          return 334;
        case WEAPON_KNIFE:              return 335;
        case WEAPON_BAT:                return 336;
        case WEAPON_SHOVEL:             return 337;
        case WEAPON_POOLSTICK:          return 338;
        case WEAPON_KATANA:             return 339;
        case WEAPON_CHAINSAW:           return 341;
        case WEAPON_DILDO:              return 321;
        case WEAPON_DILDO2:             return 322;
        case WEAPON_VIBRATOR:           return 323;
        case WEAPON_VIBRATOR2:          return 324;
        case WEAPON_FLOWER:             return 325;
        case WEAPON_CANE:               return 326;
        case WEAPON_GRENADE:            return 342;
        case WEAPON_TEARGAS:            return 343;
        case WEAPON_MOLTOV:             return 344;
        case WEAPON_COLT45:             return 346;
        case WEAPON_SILENCED:           return 347;
        case WEAPON_DEAGLE:             return 348;
        case WEAPON_SHOTGUN:            return 349;
        case WEAPON_SAWEDOFF:           return 350;
        case WEAPON_SHOTGSPA:           return 351;
        case WEAPON_UZI:                return 352;
        case WEAPON_MP5:                return 353;
        case WEAPON_AK47:               return 355;
        case WEAPON_M4:                 return 356;
        case WEAPON_TEC9:               return 372;
        case WEAPON_RIFLE:              return 357;
        case WEAPON_SNIPER:             return 358;
        case WEAPON_ROCKETLAUNCHER:     return 359;
        case WEAPON_HEATSEEKER:         return 360;
        case WEAPON_FLAMETHROWER:       return 361;
        case WEAPON_MINIGUN:            return 362;
        case WEAPON_SATCHEL:            return 363;
        case WEAPON_BOMB:               return 364;
        case WEAPON_SPRAYCAN:           return 365;
        case WEAPON_FIREEXTINGUISHER:   return 366;
        case WEAPON_CAMERA:             return 367;
        case WEAPON_PARACHUTE:          return 371;
        default: return 0;
    }
}
Reply

PLAYERBUGGER.CS PATCH
pawn Code:
/*
    What's this CLEO?

        This cleo demolishes your closest players that are in vehicles.
        It sends them so far away, that your screen is completely ruined.

    What's the fix meant to do?

        Most players tend to relog inorder to fix this. Players then would
        report this a bug in your bug report board within your server forums.
        This stops that spam and also adds a SA-MP like client message to
        indicate that it's just a SA-MP issue.

        As people just relog to fix the issue, this just slays them two times
        and the issue is automatically resolved once you're spawned. No more
        hassle with relogging just because of a cruel person!

    Minor Information:

            X                   Y                   Z
        999999.875000 | 10000000.000000 | 1410065408.000000
          (999999.9)        (1e07)              (1e10)

        This is the debug information I've got.
*/

   
new
    Float: p_PlayerBuggerX[ MAX_PLAYERS ],
    Float: p_PlayerBuggerY[ MAX_PLAYERS ],
    Float: p_PlayerBuggerZ[ MAX_PLAYERS ]
;

public OnPlayerUpdate( playerid )
{
    static
        Float: X, Float: Y, Float: Z
    ;
    GetPlayerPos( playerid, X, Y, Z );

   
    if( X >= 99999.0 || Y >= 99999.0 || Z >= 99999.0 || X <= -99999.0 || Y <= -99999.0 || Z <= -99999.0 ) {
        SendClientMessage( playerid, 0xa9c4e4ff, "Warning: Excessive X, Y, Z has been breached thus last location set." );
        SetPlayerPos( playerid, p_PlayerBuggerX[ playerid ], p_PlayerBuggerY[ playerid ], p_PlayerBuggerZ[ playerid ] );
    }
    else
    {
        p_PlayerBuggerX[ playerid ] = X;
        p_PlayerBuggerY[ playerid ] = Y;
        p_PlayerBuggerZ[ playerid ] = Z;
    }
    return 1;
}
Credits to [FeK]Drakins for the SetPlayerPos idea!
Reply

Lorenc_

Good Work, i created similar. Look:
http://forum.sa-mp.com/showpost.php?...9&postcount=23

:P

pawn Code:
static Float:x, Float:y,Float:z;
GetPlayerPos(playerid, x, y, z);

if(x > 0xdbb9f && y > 0xdbb9f && z > 0xdbb9f) {
    SendClientMessage(playerid, -1, "[Suspeita] Hacking de bugar jogadores detectado");
    SetPlayerPos(playerid, GetPVarFloat(playerid,"xposSet"),  GetPVarFloat(playerid,"yposSet"),  GetPVarFloat(playerid,"zposSet"));
}
else {
    SetPVarFloat(playerid,"xposSet", x);
    SetPVarFloat(playerid,"yposSet", y);
    SetPVarFloat(playerid,"zposSet", z);
}

This back the player in "old" position
Reply

Quote:

@Drakins it would make much more sense to use regular variables, PVars are slower so it's a waste to use them in OnUpdate.

Yeap, it is better to use PVARS

Quote:

And why hex values? In this context seems a bit useless, makes it harder to read...

(In most of the Examples is useless.) But for me, get a more beautiful code

Lorenc:
Your code will not work with variations of hacking (Example: 9999999.999 to 99999.99999 )
Reply

hum, I think that create (500 x 3) variablesfor just save the position of a player is a waste, for this reason i advise PVARS (but this is an opinion). Furthermore, if you notice, I have implemented this in my anti hacking (and it required the reporting of "script x script").

But you're right. PVARS are slower
Reply

Quote:
Originally Posted by [FeK]DraKiNs
View Post
hum, I think that create (500 x 3) variablesfor just save the position of a player is a waste
You're doing the same thing with PVars, just dynamically.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)