Checking if player is armed
#1

Hello everyone.
I have am developing a script which would work as metal detector. If a player walks pass a place (between 2 objects), and he will be armed, a sirens will start flashing, but if he wont be armed, they wont.

I have programmed that but the problem is that the sirens start flashing only if person who is armed has the weapon in his hands. If the weapon is not in his hands but stored somewhere on the player, the lights wont go on. I appreciate every effort of help. Thank you.

Current code:

Код:
new bool:SirenCreated;
new obj1;
new obj2;

public OnPlayerUpdate(playerid)
{
    if(IsPlayerInRangeOfPoint(playerid, 0.3, 1207.0170, -1333.9816, 13.3984) && SirenCreated == false && GetPlayerWeapon(playerid) > 0)
    {
		SirenCreated = true;
        obj1 = CreateObject(18646, 1207.5631, -1334.1051, 13.5816, 0.0, 0.0, 0.0);
        obj2 = CreateObject(18646, 1206.5031, -1334.1051, 13.5816, 0.0, 0.0, 0.0);
    }
	if(!IsPlayerInRangeOfPoint(playerid, 0.3, 1207.0170, -1333.9816, 13.3984) && SirenCreated == true)
	{
        SirenCreated = false;
	    DestroyObject(obj1);
	    DestroyObject(obj2);
	}
    return 1;
}
Reply
#2

pawn Код:
for (new i = 0; i < 13; i++)
{
    new checkdata[2];

    GetPlayerWeaponData(playerid, i, checkdata[0], checkdata[1]);
    if(checkdata[0] != 255)
    {
        //Has a gun, insert what to do here
        break;
    }
}
Reply
#3

GetWeaponData: Use this.
EDIT: The guy above is faster!
Reply
#4

Quote:
Originally Posted by Memoryz
Посмотреть сообщение
pawn Код:
for (new i = 0; i < 13; i++)
{
    new checkdata[2];

    GetPlayerWeaponData(playerid, i, checkdata[0], checkdata[1]);
    if(checkdata[0] != 255)
    {
        //Has a gun, insert what to do here
        break;
    }
}

sorry, but I quite do not understand your idea.

I dont see you spawning the sirens or removing it. I also dont see the isplayerinrange. Would you please mind explaining your script so I can finish it? Thank you.
Reply
#5

Im not sure if I did what you wanted to do but I tried implementing it in my script. What happend though was that once I was in the range, no matter if I had weapon or not, the sirens spawned and when I left the area, they wouldnt despawn.

Code:

Код:
new bool:SirenCreated;
new obj1;
new obj2;

public OnPlayerUpdate(playerid)
{
    if(IsPlayerInRangeOfPoint(playerid, 0.3, 1207.0170, -1333.9816, 13.3984) && SirenCreated == false)
	{
    for (new i = 0; i < 13; i++)
    {
    new checkdata[2];
    GetPlayerWeaponData(playerid, i, checkdata[0], checkdata[1]);
    if(checkdata[0] !=255)
    {
		SirenCreated = true;
        obj1 = CreateObject(18646, 1207.5631, -1334.1051, 13.5816, 0.0, 0.0, 0.0);
        obj2 = CreateObject(18646, 1206.5031, -1334.1051, 13.5816, 0.0, 0.0, 0.0);
    }
	if(!IsPlayerInRangeOfPoint(playerid, 0.3, 1207.0170, -1333.9816, 13.3984) && SirenCreated == true)
	{
        SirenCreated = false;
	    DestroyObject(obj1);
	    DestroyObject(obj2);
	}
	}
	}
    return 1;
}
Reply
#6

pawn Код:
#include <a_samp>

new bool:SirenCreated;
new obj1;
new obj2;

public OnFilterScriptInit() //Or OnGameModeInit()
{
    SirenCreated = false;
    SetTimer("SirenCheck", 1000, true);
    return 1;
}

forward SirenCheck();
public SirenCheck()
{
    for(new i = 0; i < MAX_PLAYERS; i++) //foreach is recommended
    {
        if(IsPlayerConnected(i))
        {
            if(IsPlayerInRangeOfPoint(i, 0.3, 1207.0170, -1333.9816, 13.3984))
            {
                for(new w = 0; w < 13; w++)
                {
                    new checkdata[2];
                    GetPlayerWeaponData(i, w, checkdata[0], checkdata[1]);
                    if(checkdata[0] != 0) //Player can still be unarmed and activate the sirens...
                    {
                        if(SirenCreated == false)
                        {
                            obj1 = CreateObject(18646, 1207.5631, -1334.1051, 13.5816, 0.0, 0.0, 0.0);
                            obj2 = CreateObject(18646, 1206.5031, -1334.1051, 13.5816, 0.0, 0.0, 0.0);
                            SirenCreated = true;
                        }
                    }
                }
            }
            else
            {
                if(SirenCreated == true)
                {
                    DestroyObject(obj1);
                    DestroyObject(obj2);
                    SirenCreated = false;
                }
            }
        }
    }
    return 1;
}
Reply
#7

It works perfect at first, even if the weapon is not on hand, but when I then remove the weapon from me, the sirens still activate when im at the range of point.
Reply
#8

Bump
Reply
#9

Quote:
Originally Posted by Sam5513
Посмотреть сообщение
It works perfect at first, even if the weapon is not on hand, but when I then remove the weapon from me, the sirens still activate when im at the range of point.
How do you "remove" the weapon from you? show us the code.
Reply
#10

I just created a weapon system for testing this weapon detector that would give me a weapon with 1 bullet. So by removing the weapon, I actually just shoot out the 1 bullet, which makes the weapon dissapear.

Код:
CMD:weapon(playerid, params[])
{
     if(!strlen(params)) return SendClientMessage(playerid, COLOR_RED, "Error. Usage: /weapon [weaponid]");
     if(strval(params) > 43 || strval(params) < 1) return SendClientMessage(playerid, COLOR_RED, "Error. Models are between 1 and 43.");
     GivePlayerWeapon(playerid,(strval(params)),1);
     return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)