SA-MP Forums Archive
How to make it create object on Ground? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: How to make it create object on Ground? (/showthread.php?tid=574253)



How to make it create object on Ground? - GTLS - 15.05.2015

hi guys i created a cmd to create flare when ever a cop uses /flares. it worked correctly but my problem is that flare is created in air i want it to create on ground.
here's my cmd:
Код:
 CMD:flares(playerid, params[])
{
    new rank = arrFaction[playerid][p_iMember] > -1 && arrFaction[playerid][g_iFactionType] == 1;
    if(rank < 0) return SendClientMessage(playerid, COLOR_WHITE, "You are not authorized to use this command.");
	{
            new Float:x, Float:y, Float:z;
            GetPlayerPos(playerid, x, y, z);
            CreateObject(18728, x,y,z, 0.0, 0.0, 96.0);
	}
	return 1;
 }
Also, if you can give me cmd for destroying nearest flare(not all) so that i can create multiple flares and can destroy it oe by one... thanks


Re: How to make it create object on Ground? - Smileys - 15.05.2015

Use z - 0.5 or something like that, experiment with it.


Re: How to make it create object on Ground? - GTLS - 15.05.2015

I'll try to do it thanks anyways!!


Re: How to make it create object on Ground? - rappy93 - 15.05.2015

The Z axis is the height. As GTLS said above, use Z - 0.3 or Z - 0.4 , etc. until you get the desired result. By lowering the Z you are making the object spawn closer to the ground.


Re: How to make it create object on Ground? - JaydenJason - 15.05.2015

getting the player position, the z axis - 2.2 is on the ground for a flare object, I can give you the flare system of an old gamemode I have, it functions great.


Re: How to make it create object on Ground? - JaydenJason - 15.05.2015

Quote:
Originally Posted by GTLS
Посмотреть сообщение
hi guys i created a cmd to create flare when ever a cop uses /flares. it worked correctly but my problem is that flare is created in air i want it to create on ground.
here's my cmd:
Код:
 CMD:flares(playerid, params[])
{
    new rank = arrFaction[playerid][p_iMember] > -1 && arrFaction[playerid][g_iFactionType] == 1;
    if(rank < 0) return SendClientMessage(playerid, COLOR_WHITE, "You are not authorized to use this command.");
	{
            new Float:x, Float:y, Float:z;
            GetPlayerPos(playerid, x, y, z);
            CreateObject(18728, x,y,z, 0.0, 0.0, 96.0);
	}
	return 1;
 }
Also, if you can give me cmd for destroying nearest flare(not all) so that i can create multiple flares and can destroy it oe by one... thanks
Код:
#define MAX_FLARES [amount you want]
Код:
enum flInfo
{
    flCreated,
    Float:flX,
    Float:flY,
    Float:flZ,
    flObject,
};
new FlareInfo[MAX_FLARES][flInfo];
ontop of your script

Код:
stock CreateFlare(Float:x,Float:y,Float:z,Float:Angle)
{
    for(new i = 0; i < sizeof(FlareInfo); i++)
  	{
  	    if(FlareInfo[i][flCreated] == 0)
  	    {
            FlareInfo[i][flCreated]=1;
            FlareInfo[i][flX]=x;
            FlareInfo[i][flY]=y;
            FlareInfo[i][flZ]=z-2.2;
            FlareInfo[i][flObject] = CreateDynamicObject(18728, x, y, z-2.2, 0, 0, Angle-0);
	        return 1;
  	    }
  	}
  	return 0;
}

stock DeleteAllFlare()
{
    for(new i = 0; i < sizeof(FlareInfo); i++)
  	{
  	    if(FlareInfo[i][flCreated] == 1)
  	    {
  	        FlareInfo[i][flCreated]=0;
            FlareInfo[i][flX]=0.0;
            FlareInfo[i][flY]=0.0;
            FlareInfo[i][flZ]=0.0;
			DestroyDynamicObject(FlareInfo[i][flObject]);
  	    }
	}
    return 0;
}

stock DeleteClosestFlare(playerid)
{
    for(new i = 0; i < sizeof(FlareInfo); i++)
  	{
  	    if(IsPlayerInRangeOfPoint(playerid, 4.0, FlareInfo[i][flX], FlareInfo[i][flY], FlareInfo[i][flZ]))
        {
  	        if(FlareInfo[i][flCreated] == 1)
            {
		        format(string, sizeof(string), " You have deleted a flare. ", PlayerRPName(playerid));
				SendClientMessage(playerid, COLOR_[insert color here], string);
                FlareInfo[i][flCreated]=0;
                FlareInfo[i][flX]=0.0;
                FlareInfo[i][flY]=0.0;
                FlareInfo[i][flZ]=0.0;
                DestroyDynamicObject(FlareInfo[i][flObject]);
                return 1;
  	        }
  	    }
  	}
    return 0;
}
anywhere near your other stocks

rest is up to you


Re: How to make it create object on Ground? - GTLS - 15.05.2015

Quote:
Originally Posted by JaydenJason
Originally Posted by GTLS View Post
hi guys i created a cmd to create flare when ever a cop uses /flares. it worked correctly but my problem is that flare is created in air i want it to create on ground.
here's my cmd:
Код:
 CMD:flares(playerid, params[])
{
    new rank = arrFaction[playerid][p_iMember] > -1 && arrFaction[playerid][g_iFactionType] == 1;
    if(rank < 0) return SendClientMessage(playerid, COLOR_WHITE, "You are not authorized to use this command.");
	{
            new Float:x, Float:y, Float:z;
            GetPlayerPos(playerid, x, y, z);
            CreateObject(18728, x,y,z, 0.0, 0.0, 96.0);
	}
	return 1;
 }
Also, if you can give me cmd for destroying nearest flare(not all) so that i can create multiple flares and can destroy it oe by one... thanks
Код:
#define MAX_FLARES [amount you want]
Код:
enum flInfo
{
    flCreated,
    Float:flX,
    Float:flY,
    Float:flZ,
    flObject,
};
new FlareInfo[MAX_FLARES][flInfo];
ontop of your script

Код:
stock CreateFlare(Float:x,Float:y,Float:z,Float:Angle)
{
    for(new i = 0; i < sizeof(FlareInfo); i++)
  	{
  	    if(FlareInfo[i][flCreated] == 0)
  	    {
            FlareInfo[i][flCreated]=1;
            FlareInfo[i][flX]=x;
            FlareInfo[i][flY]=y;
            FlareInfo[i][flZ]=z-2.2;
            FlareInfo[i][flObject] = CreateDynamicObject(18728, x, y, z-2.2, 0, 0, Angle-0);
	        return 1;
  	    }
  	}
  	return 0;
}

stock DeleteAllFlare()
{
    for(new i = 0; i < sizeof(FlareInfo); i++)
  	{
  	    if(FlareInfo[i][flCreated] == 1)
  	    {
  	        FlareInfo[i][flCreated]=0;
            FlareInfo[i][flX]=0.0;
            FlareInfo[i][flY]=0.0;
            FlareInfo[i][flZ]=0.0;
			DestroyDynamicObject(FlareInfo[i][flObject]);
  	    }
	}
    return 0;
}

stock DeleteClosestFlare(playerid)
{
    for(new i = 0; i < sizeof(FlareInfo); i++)
  	{
  	    if(IsPlayerInRangeOfPoint(playerid, 4.0, FlareInfo[i][flX], FlareInfo[i][flY], FlareInfo[i][flZ]))
        {
  	        if(FlareInfo[i][flCreated] == 1)
            {
		        format(string, sizeof(string), " You have deleted a flare. ", PlayerRPName(playerid));
				SendClientMessage(playerid, COLOR_[insert color here], string);
                FlareInfo[i][flCreated]=0;
                FlareInfo[i][flX]=0.0;
                FlareInfo[i][flY]=0.0;
                FlareInfo[i][flZ]=0.0;
                DestroyDynamicObject(FlareInfo[i][flObject]);
                return 1;
  	        }
  	    }
  	}
    return 0;
}
anywhere near your other stocks

rest is up to you
thanks dude..


Re: How to make it create object on Ground? - JaydenJason - 17.05.2015

Quote:
Originally Posted by GTLS
Посмотреть сообщение
thanks dude..
no worries, if any errors occur or if you need cmds for it vm me or post here


Re: How to make it create object on Ground? - Crayder - 17.05.2015

Quote:
Originally Posted by GTLS
Посмотреть сообщение
thanks dude..
-2.2?

Skin models are usually centered at 0.5 and are mostly ~1.0 in height.


Re: How to make it create object on Ground? - JaydenJason - 18.05.2015

Quote:
Originally Posted by Crayder
Посмотреть сообщение
-2.2?

Skin models are usually centered at 0.5 and are mostly ~1.0 in height.
Yes,
Код:
new Float:angle, Float:x, Float:y, Float:z;
GetPlayerPos(x, y, z);
GetPlayerFacingAngle(playerid, angle);
Createflare(x, y, z-2.2, angle);