// ***** Special Objects by ONEhelsING
#include <a_players>
#include <a_objects>
#include <functions>
#pragma tabsize 0

#define MAX_SPEC_OBJECTS 400
#define MAX_DRAW_DIS 200.0

forward ObjectsCheck();

enum s_object
{
    sp_model,
	sp_objid,
	Float:sp_x,
	Float:sp_y,
	Float:sp_z,
	Float:sp_rx,
	Float:sp_ry,
	Float:sp_rz,
	bool:sp_use
};

new Objects[MAX_PLAYERS][MAX_SPEC_OBJECTS];
new ObjInfo[MAX_SPEC_OBJECTS][s_object];


/*
native AddSpecObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz);
native RemoveSpecObject(objectid);
native ShowSpecObject(playerid,obj_m);
native HideSpecObject(playerid,obj_m);
*/

stock AddSpecObject(modelid, Float:x, Float:y, Float:z, Float:rX, Float:rY, Float:rZ)
{    
   for(new b = 1; b < MAX_SPEC_OBJECTS;b++)
	{
	if(ObjInfo[b][sp_use] == false)
	    {
		ObjInfo[b][sp_use] = true;
		ObjInfo[b][sp_x] = x;
		ObjInfo[b][sp_y] = y;
		ObjInfo[b][sp_z] = z;
		ObjInfo[b][sp_rx] = rX;
		ObjInfo[b][sp_ry] = rY;
		ObjInfo[b][sp_rz] = rZ;
		ObjInfo[b][sp_model] = modelid;
		ObjInfo[b][sp_objid] = 0;
		return 1;
	    }	
	}
   return 0;
}

stock RemoveSpecObject(obj_m)
{
    if(ObjInfo[obj_m][sp_use] == true)
		{
		ObjInfo[obj_m][sp_use] = false;
		for(new i = 0; i < MAX_PLAYERS; i++)
		    {
		    if(IsPlayerConnected(i))
		        {
		    	if(Objects[i][obj_m] > 0)
		        	{
                	DestroyPlayerObject(i,Objects[i][obj_m]-1);
	    			Objects[i][obj_m] = 0;
	    			}
		        }
		    }
		}
   return 1;
}

stock ShowSpecObject(playerid,obj_m)
{
    if(ObjInfo[obj_m][sp_use] == true)
		{
    	new num = CreatePlayerObject(playerid,ObjInfo[obj_m][sp_model],ObjInfo[obj_m][sp_x],ObjInfo[obj_m][sp_y],ObjInfo[obj_m][sp_z],ObjInfo[obj_m][sp_rx],ObjInfo[obj_m][sp_ry],ObjInfo[obj_m][sp_rz]);
		Objects[playerid][obj_m] = num+1;
		return 1;
		}
    return 0;
}

stock HideSpecObject(playerid,obj_m)
{
	if(ObjInfo[obj_m][sp_use] == true && Objects[playerid][obj_m] > 0)
	    {
	    DestroyPlayerObject(playerid,Objects[playerid][obj_m]-1);
	    Objects[playerid][obj_m] = 0;
	    }
	return 0;
}

public ObjectsCheck()
{
	for(new b = 1; b < MAX_SPEC_OBJECTS; b++)
   		{
		if(ObjInfo[b][sp_use] == true)
       		{
       		for(new i = 0; i < MAX_PLAYERS; i++)
				{
				if(IsPlayerConnected(i))
					{
			       	if(Objects[i][b] > 0 && !PlayerToPoint(MAX_DRAW_DIS, i, ObjInfo[b][sp_x], ObjInfo[b][sp_y], ObjInfo[b][sp_z]))
	               	    {
	               	    HideSpecObject(i,b);
	               	    }
					else if(Objects[i][b] == 0 && PlayerToPoint(MAX_DRAW_DIS, i, ObjInfo[b][sp_x], ObjInfo[b][sp_y], ObjInfo[b][sp_z]))
					    {
					    ShowSpecObject(i,b);
					    }
	               	}
	            }
	        }
	    }

}

stock ObjectsInc()
{
SetTimer("ObjectsCheck",1000,1);
}
