View Full Version : Spawn object...

02/01/2012, 02:03 PM
This code spawn the opject "over the head" of the player,
case 5:
new Float:X, Float:Y, Float:Z, Float:A;
GetPlayerPos(playerid, X, Y, Z);
GetPlayerFacingAngle(playerid, A);
if(atblock[playerid] < MAX_ROADBLOCKS)
block[atrb][playerid] = CreateObject(18728, X, Y, Z-0.2, A, 150);
GameTextForPlayer(playerid,"~w~Flare ~b~Created!",3000,1);
#if SEND == true
format(string,sizeof string," %s added a roadblock(%i).",pName,number);
SendClientMessageToAll(COLOR_GREEN, string);
SetTimerEx("ExpireRoadblock", EXPIRE_MINUTES*60000, false, "i", block[atrb][playerid]);
atblock[playerid] += 1;
} else {
format(string,sizeof string,"You cannot place more then %i Roadblocks!",MAX_ROADBLOCKS);
SendClientMessage(playerid, COLOR_RED, string);
return 1;

How i can spawn the object under the foot? (i mean spawn at ground level the object)

02/01/2012, 02:17 PM
the z axis (facing up/down), raises in value when going up. so you want to lower the opbject down by, lets say, 1.6 units - thats a subtraction of 1.6 on the z-pos parameter:

block[atrb][playerid] = CreateObject(18728, X, Y, Z-0.2-1.6, A, 150);

or to make it simpler (it doesnt make AN difference when you are using constant values whcih gets added at the precompile process, so keep it like this fr better readability):

block[atrb][playerid] = CreateObject(18728, X, Y, Z-1.8, A, 150);

if you want the block spawn in front of the player at the ground, you will need to transform the x/y position with the sinus/cosinus and the facing angle.