[FilterScript] Laser Pointer with crouch support
#1

Laser Pointer 2.6
Description:

- This filterscript adds a laser pointer to the M4, Mp5, Silenced Pistol, AK-47, Spas and Sniper Rifle. If requested I will add more weapons.
- You can change the color of the laser (useful for different teams).
- The laser is accurate also if you crouch.
- The pointer is precisely attached on the weapons, and at the same time it aims perfectly at the crosshair.
- If the laser is active, it will appear when you take one of the weapons, and it will automatically disappear if you are not holding that weapon.
- The laser disappear if you go into a vehicle.
- The laser disappear if you swim / go underwater.
- Works only from 0.3c.

Cmds:

/laseron - activate the laser pointer
/laseroff - deactivate the laser pointer
/lasercol [color] - change the color of the laser, colors: red (default), green, yellow, blue, pink, orange.

Screenshot:





Bugs: Not so far.

Code:

Код:
#include <a_samp>

//----------------------------------------------------------------------------//

public OnFilterScriptInit() {
        print("\n-- Laser Pointer by Skiaffo --\n");
        new p = GetMaxPlayers();
        for (new i=0; i < p; i++) {
                SetPVarInt(i, "laser", 0);
                SetPVarInt(i, "color", 18643);
        }
        return 1;
}

public OnFilterScriptExit() {
        new p = GetMaxPlayers();
        for (new i=0; i < p; i++) {
                SetPVarInt(i, "laser", 0);
                RemovePlayerAttachedObject(i, 0);
        }
        return 1;
}

//----------------------------------------------------------------------------//

public OnPlayerSpawn(playerid) {
    if (!GetPVarInt(playerid, "color")) SetPVarInt(playerid, "color", 18643);
}

public OnPlayerDisconnect(playerid) {
        SetPVarInt(playerid, "laser", 0);
        RemovePlayerAttachedObject(playerid, 0);
        return 1;
}

//----------------------------------------------------------------------------//

public OnPlayerCommandText(playerid, cmdtext[]) {

        new cmd[256];
        new idx;
        cmd = strtok(cmdtext, idx);

        if (!strcmp("/laseron", cmdtext, true)) {
                SetPVarInt(playerid, "laser", 1);
                SetPVarInt(playerid, "color", GetPVarInt(playerid, "color"));
                return 1;
        }

        if (!strcmp("/laseroff", cmdtext, true)) {
                SetPVarInt(playerid, "laser", 0);
                RemovePlayerAttachedObject(playerid, 0);
                return 1;
        }

        if (!strcmp("/lasercol", cmd, true)) {
                new tmp[256];
                tmp = strtok(cmdtext, idx);
                if (!strlen(tmp)) {
                        SendClientMessage(playerid, 0x00E800FF, "Usage: /lasercol [color]");
                        return 1;
                }
                if (!strcmp(tmp, "red", true)) SetPVarInt(playerid, "color", 18643);
                else if (!strcmp(tmp, "blue", true)) SetPVarInt(playerid, "color", 19080);
                else if (!strcmp(tmp, "pink", true)) SetPVarInt(playerid, "color", 19081);
                else if (!strcmp(tmp, "orange", true)) SetPVarInt(playerid, "color", 19082);
                else if (!strcmp(tmp, "green", true)) SetPVarInt(playerid, "color", 19083);
                else if (!strcmp(tmp, "yellow", true)) SetPVarInt(playerid, "color", 19084);
                else SendClientMessage(playerid, 0x00E800FF, "Colour not available!");
                return 1;
        }

        return 0;
}

public OnPlayerUpdate(playerid) {
        if (GetPVarInt(playerid, "laser")) {
                RemovePlayerAttachedObject(playerid, 0);
                if ((IsPlayerInAnyVehicle(playerid)) || (IsPlayerInWater(playerid))) return 1;
                switch (GetPlayerWeapon(playerid)) {
                        case 23: {
                                if (IsPlayerAiming(playerid)) {
                                        if (GetPlayerSpecialAction(playerid) != SPECIAL_ACTION_DUCK) {
                                                SetPlayerAttachedObject(playerid, 0, GetPVarInt(playerid, "color"), 6, // SP standing aiming
                                                0.108249, 0.030232, 0.118051, 1.468254, 350.512573, 364.284240);
                                        } else {
                                                SetPlayerAttachedObject(playerid, 0, GetPVarInt(playerid, "color"), 6, // SP crouched aiming
                                                0.108249, 0.030232, 0.118051, 1.468254, 349.862579, 364.784240);
                                        }
                                } else {
                                        if (GetPlayerSpecialAction(playerid) != SPECIAL_ACTION_DUCK) {
                                                SetPlayerAttachedObject(playerid, 0, GetPVarInt(playerid, "color"), 6, // SP standing not aiming
                                                0.078248, 0.027239, 0.113051, -11.131746, 350.602722, 362.384216);
                                        } else {
                                                SetPlayerAttachedObject(playerid, 0, GetPVarInt(playerid, "color"), 6, // SP crouched not aiming
                                                0.078248, 0.027239, 0.113051, -11.131746, 350.602722, 362.384216);
                        }       }       }
                        case 27: {
                                if (IsPlayerAiming(playerid)) {
                                        if (GetPlayerSpecialAction(playerid) != SPECIAL_ACTION_DUCK) {
                                                SetPlayerAttachedObject(playerid, 0, GetPVarInt(playerid, "color"), 6, // SPAS standing aiming
                                                0.588246, -0.022766, 0.138052, -11.531745, 347.712585, 352.784271);
                                        } else {
                                                SetPlayerAttachedObject(playerid, 0, GetPVarInt(playerid, "color"), 6, // SPAS crouched aiming
                                                0.588246, -0.022766, 0.138052, 1.468254, 350.712585, 352.784271);
                                        }
                                } else {
                                        if (GetPlayerSpecialAction(playerid) != SPECIAL_ACTION_DUCK) {
                                                SetPlayerAttachedObject(playerid, 0, GetPVarInt(playerid, "color"), 6, // SPAS standing not aiming
                                                0.563249, -0.01976, 0.134051, -11.131746, 351.602722, 351.384216);
                                        } else {
                                                SetPlayerAttachedObject(playerid, 0, GetPVarInt(playerid, "color"), 6, // SPAS crouched not aiming
                                                0.563249, -0.01976, 0.134051, -11.131746, 351.602722, 351.384216);
                        }       }       }
                        case 30: {
                                if (IsPlayerAiming(playerid)) {
                                        if (GetPlayerSpecialAction(playerid) != SPECIAL_ACTION_DUCK) {
                                                SetPlayerAttachedObject(playerid, 0, GetPVarInt(playerid, "color"), 6, // AK standing aiming
                                                0.628249, -0.027766, 0.078052, -6.621746, 352.552642, 355.084289);
                                        } else {
                                                SetPlayerAttachedObject(playerid, 0, GetPVarInt(playerid, "color"), 6, // AK crouched aiming
                                                0.628249, -0.027766, 0.078052, -1.621746, 356.202667, 355.084289);
                                        }
                                } else {
                                        if (GetPlayerSpecialAction(playerid) != SPECIAL_ACTION_DUCK) {
                                                SetPlayerAttachedObject(playerid, 0, GetPVarInt(playerid, "color"), 6, // AK standing not aiming
                                                0.663249, -0.02976, 0.080051, -11.131746, 358.302734, 353.384216);
                                        } else {
                                                SetPlayerAttachedObject(playerid, 0, GetPVarInt(playerid, "color"), 6, // AK crouched not aiming
                                                0.663249, -0.02976, 0.080051, -11.131746, 358.302734, 353.384216);
                        }       }       }
                        case 31: {
                                if (IsPlayerAiming(playerid)) {
                                        if (GetPlayerSpecialAction(playerid) != SPECIAL_ACTION_DUCK) {
                                                SetPlayerAttachedObject(playerid, 0, GetPVarInt(playerid, "color"), 6, // M4 standing aiming
                                                0.528249, -0.020266, 0.068052, -6.621746, 352.552642, 355.084289);
                                        } else {
                                                SetPlayerAttachedObject(playerid, 0, GetPVarInt(playerid, "color"), 6, // M4 crouched aiming
                                                0.528249, -0.020266, 0.068052, -1.621746, 356.202667, 355.084289);
                                        }
                                } else {
                                        if (GetPlayerSpecialAction(playerid) != SPECIAL_ACTION_DUCK) {
                                                SetPlayerAttachedObject(playerid, 0, GetPVarInt(playerid, "color"), 6, // M4 standing not aiming
                                                0.503249, -0.02376, 0.065051, -11.131746, 357.302734, 354.484222);
                                        } else {
                                                SetPlayerAttachedObject(playerid, 0, GetPVarInt(playerid, "color"), 6, // M4 crouched not aiming
                                                0.503249, -0.02376, 0.065051, -11.131746, 357.302734, 354.484222);
                        }       }       }
			case 34: {
				if (IsPlayerAiming(playerid)) {
					/*if (GetPlayerSpecialAction(playerid) != SPECIAL_ACTION_DUCK) {
						SetPlayerAttachedObject(playerid, 0, GetPVarInt(playerid, "color"), 6, // Sniper standing aiming
						0.528249, -0.020266, 0.068052, -6.621746, 352.552642, 355.084289);
					} else {
						SetPlayerAttachedObject(playerid, 0, GetPVarInt(playerid, "color"), 6, // Sniper crouched aiming
						0.528249, -0.020266, 0.068052, -1.621746, 356.202667, 355.084289);
					}*/
					return 1;
				} else {
					if (GetPlayerSpecialAction(playerid) != SPECIAL_ACTION_DUCK) {
						SetPlayerAttachedObject(playerid, 0, GetPVarInt(playerid, "color"), 6, // Sniper standing not aiming
						0.658248, -0.03276, 0.133051, -11.631746, 355.302673, 353.584259);
					} else {
						SetPlayerAttachedObject(playerid, 0, GetPVarInt(playerid, "color"), 6, // Sniper crouched not aiming
						0.658248, -0.03276, 0.133051, -11.631746, 355.302673, 353.584259);
			}	}	}
                        case 29: {
                                if (IsPlayerAiming(playerid)) {
                                        if (GetPlayerSpecialAction(playerid) != SPECIAL_ACTION_DUCK) {
                                                SetPlayerAttachedObject(playerid, 0, GetPVarInt(playerid, "color"), 6, // MP5 standing aiming
                                                0.298249, -0.02776, 0.158052, -11.631746, 359.302673, 357.584259);
                                        } else {
                                                SetPlayerAttachedObject(playerid, 0, GetPVarInt(playerid, "color"), 6, // MP5 crouched aiming
                                                0.298249, -0.02776, 0.158052, 8.368253, 358.302673, 352.584259);
                                        }
                                } else {
                                        if (GetPlayerSpecialAction(playerid) != SPECIAL_ACTION_DUCK) {
                                                SetPlayerAttachedObject(playerid, 0, GetPVarInt(playerid, "color"), 6, // MP5 standing not aiming
                                                0.293249, -0.027759, 0.195051, -12.131746, 354.302734, 352.484222);
                                        } else {
                                                SetPlayerAttachedObject(playerid, 0, GetPVarInt(playerid, "color"), 6, // MP5 crouched not aiming
                                                0.293249, -0.027759, 0.195051, -12.131746, 354.302734, 352.484222);
        }       }       }       }       }
        return 1;
}

stock IsPlayerInWater(playerid) {
        new anim = GetPlayerAnimationIndex(playerid);
        if (((anim >=  1538) && (anim <= 1542)) || (anim == 1544) || (anim == 1250) || (anim == 1062)) return 1;
        return 0;
}

stock IsPlayerAiming(playerid) {
	new anim = GetPlayerAnimationIndex(playerid);
	if (((anim >= 1160) && (anim <= 1163)) || (anim == 1167) || (anim == 1365) ||
	(anim == 1643) || (anim == 1453) || (anim == 220)) return 1;
        return 0;
}

//----------------------------------------------------------------------------//

strtok(const string[], &index)
{
        new length = strlen(string);
        while ((index < length) && (string[index] <= ' '))
        {
                index++;
        }

        new offset = index;
        new result[20];
        while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
        {
                result[index - offset] = string[index];
                index++;
        }
        result[index - offset] = EOS;
        return result;
}

//----------------------------------------------------------------------------//
Reply
#2

Cool. Looks nice.
Reply
#3

Idea: https://sampforum.blast.hk/showthread.php?tid=196378 ?

But..gj
Reply
#4

Looks pretty awesome dude, i'm going to go test this out right now,

suggestion - make a zcmd version also.
Reply
#5

Quote:
Originally Posted by Speederx
Посмотреть сообщение
Actually I was inspired by this topic http://forum.sa-mp.com/showthread.ph...ighlight=laser

But I found nothing that suited for me, so I made myself one and released it.
Reply
#6

Sorry for double post. I updated the code and fixed the last issue:

Now the laser pointer is correctly attached to any weapon and it aims exactly at the crosshair at the same time.

Hope you enjoy.
Reply
#7

Where do i need to add the code?:3
Reply
#8

Quote:
Originally Posted by Isotoxin
Посмотреть сообщение
Where do i need to add the code?:3
It's a filterscript. Just paste the code in a blank pwn document, compile it, put the amx in the filterscript folder and load it on your server.

This is all basic stuff.
Reply
#9

Goood Job
10/10
Downloaded ._.
Reply
#10

Wow this is awesome! Nice job man! I have always waited for osmething like this. Before you had to use mods, but now you don't!
Reply
#11

Lol thats so cool, i never knew that was an object, AWESOME!
Reply
#12

this is cooooooooooooool, great release!
Reply
#13

Quote:
Originally Posted by ToPhrESH
Посмотреть сообщение
Wow this is awesome! Nice job man! I have always waited for osmething like this. Before you had to use mods, but now you don't!
Where can I find those mods?
Reply
#14

wow really cool
gj
Reply
#15

It's not realistic but It's nice
(Seeing that the "laser" would be visible all the way and not only at the target as in real life)
Reply
#16

Don't forget to add swimming detection... You don't wana swim with a laser sticked 1ft away from your arm.
Reply
#17

Congratz , very nice script | 15/10
Reply
#18

very good & beauty
Reply
#19

Quote:
Originally Posted by Alec
Посмотреть сообщение
Don't forget to add swimming detection... You don't wana swim with a laser sticked 1ft away from your arm.
Fix for swimming:

Add this
Код:
if(IsPlayerSwimming(playerid)) return 1;
After this
Код:
if(IsPlayerInAnyVehicle(playerid)) return 1;
Finally add this to the filterscript:
Код:
stock IsPlayerSwimming(playerid)
{
     new animation = GetPlayerAnimationIndex(playerid);
     if(animation == 1538 || animation == 1539)
          return 1;
     return 0;
}
Reply
#20

I might download this it looks pretty awesome.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)