CreateObject Command
#1

This is what I have been trying to figure out. I would like to construct a command that I could type in game, like /create (Object id) and the object would spawn in front of me, or about 2 or 3 units away. If someone could point me in the right direction, this would be great.

On an outline i was guessing it would go something like,

if OnPlayerCommandText /create == true
CreateObject (id,float:X, etc. etc.
float:X + 5 //To move the object away from players position so it won't spawn on the player

What I need help on here, is how to get the players position, and how to do this in a nutshell, It seems strcmp doesn't work? or am I incorrect here? I was thinking dcmp? anyways, any help greatly appreciated.

Thanks for your time
Reply
#2

I suggest you use ZCMD and sscanf. With getting pos in fornt of you use this function:

pawn Код:
stock GetXYInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
{
    new Float:a;
    GetPlayerPos(playerid, x, y, a);
    GetPlayerFacingAngle(playerid, a);
    if (GetPlayerVehicleID(playerid))
    {
        GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
    }
    x += (distance * floatsin(-a, degrees));
    y += (distance * floatcos(-a, degrees));
}
- Awaran
Reply
#3

Ok thanks, no is this a vehicle? or actual object? Like I want to spawn a fence, how would this be done?
Reply
#4

Quote:
Originally Posted by unknownuk
is how to get the players position
https://sampwiki.blast.hk/wiki/GetPlayerPos
Reply
#5

btw You dont need this Download MTA:SA v.1.0.3
And after installing run it and choose Map Editor
Its an Best Map Maker

Then convert it to pawn code by
http://gtamap.delux-host.com/converter/

Finished! Ur map is done!
Reply
#6

Quote:
Originally Posted by www.******.com
Quote:
Originally Posted by unknownuk
is how to get the players position
https://sampwiki.blast.hk/wiki/GetPlayerPos
Ok, then if i have the player pos, how do i make the player position like variables so I can spawn an object using those cords
Reply
#7

Quote:
Originally Posted by Awaran[Enemy-Plus
; ]
I suggest you use ZCMD and sscanf. With getting pos in fornt of you use this function:

pawn Код:
stock GetXYInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
{
    new Float:a;
    GetPlayerPos(playerid, x, y, a);
    GetPlayerFacingAngle(playerid, a);
    if (GetPlayerVehicleID(playerid))
    {
        GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
    }
    x += (distance * floatsin(-a, degrees));
    y += (distance * floatcos(-a, degrees));
}
- Awaran
Ok, I have the player position, and I am able to /create and all that, and I have it tell you text.
Код:
public OnPlayerCommandText( playerid,cmdtext[])
{
  	if(strcmp("/create [modelid]", cmdtext, true, 7) == 0)
{
	SendClientMessage(playerid,0xFFFFFFFF,"you have entered a create command");
	new modelid;
	GetPlayerPos(playerid, X, Y, Z);
	new Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ;
	CreateObject(modelid, X, Y, Z, rX, rY, rZ);
	return 1;

}
		return 0;
}
Now, How can I make it create the object? what is wrong here?Thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)