Despawning object.
#1

Hey guys.
Recently I was trying to develop a script for a server, by which if you would stand on a place, a siren would spawn and once you would get out, it would despawn.
I have been trying to work it out the whole day now but whenever I exit the place, the sirens dont despawn.
I'd really appreciate if you could help me please. Thank you.
Here is so far what I have done:

Код:
public OnPlayerUpdate(playerid)
{
        if(IsPlayerInRangeOfPoint(playerid, 0.1, 1207.0170, -1333.9816, 13.3984))
    {
        CreateObject(18646, 1207.5631, -1334.1051, 13.5816);
        CreateObject(18646, 1206.5031, -1334.1051, 13.5816);
    }
    if(!IsPlayerInRangeOfPoint(playerid, 0.1, 1207.0170, -1333.9816, 13.3984))
    {
    if(IsValidObject(18646, 1207.5631, -1334.1051, 13.5816))
    {
    DestroyObject(18646, 1207.5631, -1334.1051, 13.5816);
    DestroyObject(18646, 1206.5031, -1334.1051, 13.5816);
	}
    }

	    return 1;
}
Reply
#2

pawn Код:
public OnPlayerUpdate(playerid)
{
    if(IsPlayerInRangeOfPoint(playerid, 0.1, 1207.0170, -1333.9816, 13.3984))
    {
        CreateObject(18646, 1207.5631, -1334.1051, 13.5816);
        CreateObject(18646, 1206.5031, -1334.1051, 13.5816);
    }
    else
    {
        if(IsValidObject(18646, 1207.5631, -1334.1051, 13.5816))
        {
            DestroyObject(18646);
        }
    }
    return 1;
}
Note: Untested
Reply
#3

Thank you for your effort but it doesnt work.
The objects still stay there when exiting the area.
Besides I noticed you were trying to remove only one object, and not both of them.
Thank you for your effort though.
Reply
#4

pawn Код:
new a,b;
public OnPlayerUpdate(playerid)
{
    if(IsPlayerInRangeOfPoint(playerid, 1.0, 1207.0170, -1333.9816, 13.3984))
    {
       if(!IsValidObject(a)) a=CreateObject(18646, 1207.5631, -1334.1051, 13.5816);
       if(!IsValidObject(b)) b=CreateObject(18646, 1206.5031, -1334.1051, 13.5816);
    }
    else
    {
      if(IsValidObject(a)) DestroyObject(a);
      if(IsValidObject(b)) DestroyObject(b);
    }
    return 1;
}
this is just a fix for your code
if ANY player IS NOT near that point ,it will destroy the object for all.
Reply
#5

Try this.

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

public OnPlayerUpdate(playerid)
{
    if(IsPlayerInRangeOfPoint(playerid, 0.1, 1207.0170, -1333.9816, 13.3984) && SirenCreated == false)
    {
		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.1, 1207.0170, -1333.9816, 13.3984) && SirenCreated == true)
	{
            SirenCreated = false;
	    DestroyObject(obj1);
	    DestroyObject(obj2);
	}
    return 1;
}
Reply
#6

Quote:
Originally Posted by HuSs3n
Посмотреть сообщение
pawn Код:
new a,b;
public OnPlayerUpdate(playerid)
{
    if(IsPlayerInRangeOfPoint(playerid, 1.0, 1207.0170, -1333.9816, 13.3984))
    {
       if(!IsValidObject(a)) a=CreateObject(18646, 1207.5631, -1334.1051, 13.5816);
       if(!IsValidObject(b)) b=CreateObject(18646, 1206.5031, -1334.1051, 13.5816);
    }
    else
    {
      if(IsValidObject(a)) DestroyObject(a);
      if(IsValidObject(b)) DestroyObject(b);
    }
    return 1;
}
this is just a fix for your code
if ANY player IS NOT near that point ,it will destroy the object for all.
Doesnt work. Still is spawned when leaving the area.
Reply
#7

Quote:
Originally Posted by Shetch
Посмотреть сообщение
Try this.

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

public OnPlayerUpdate(playerid)
{
    if(IsPlayerInRangeOfPoint(playerid, 0.1, 1207.0170, -1333.9816, 13.3984) && SirenCreated == false)
    {
		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.1, 1207.0170, -1333.9816, 13.3984) && SirenCreated == true)
	{
            SirenCreated = false;
	    DestroyObject(obj1);
	    DestroyObject(obj2);
	}
    return 1;
}
Works perfectly! Thank you very much!
I have one more question though. Do you think you would know a way to make it shine with all those colors like some unmarked cruisers have on rp servers? It would be great.


EDIT: I found out I only have to set the weather to 2 for the siren flashing to work. Thanks anyways for all who helped and all who were trying to help! Appreciate it.
Reply
#8

With help of Schetch, we have eddited the script so that the sirens will spawn only when player is armed, although there is a bug. The sirens will go only on if the armed player has the weapon in hand. If the weapon is on him but the weapon is not in his hand, the sirens will not go on.
I could really use some more help, please.
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


Forum Jump:


Users browsing this thread: 1 Guest(s)