CMD:chair(playerid, params[])
{
static
type[24];
new
Float:x,
Float:y,
Float:z,
Float:a;
GetPlayerPos(playerid, x, y, z);
if (sscanf(params, "s[24]", type))
{
SendSyntaxMessage(playerid, "/chair [option]");
SendClientMessage(playerid, COLOR_YELLOW, "[OPTIONS]:{FFFFFF} get, drop, pickup");
return 1;
}
if (!strcmp(type, "get", true))
{
if (GetPVarInt(playerid, "pCarryingChair") == 1)
return SendErrorMessage(playerid, "You are already carrying a chair.");
for (new i = 0; i != MAX_VEHICLES; i ++)
if (IsPlayerNearBoot(playerid, i)
{
SetPlayerAttachedObject(playerid, 1, 1765, 1, -1.106504, 1.504988, 0.031584, 0.000000, 89.566635, 0.000000);
SetPVarInt(playerid, "pCarryingChair", 1);
}
}
if (!strcmp(type, "drop", true))
{
if (GetPVarInt(playerid, "pCarryingChair") == 0)
return SendErrorMessage(playerid, "You are not carrying a chair.");
GetPlayerFacingAngle(playerid, a);
CreateObject(1765, x, y z - 1.0, 0.0, 0.0, a, 50.0);
RemovePlayerAttachedObject(playerid, 1);
SetPVarInt(playerid, "pCarryingChair", 0);
}
if (!strcmp(type, "pickup", true))
{
if (GetPVarInt(playerid, "pCarryingChair) == 1)
return SendErrorMessage(playerid, "You are already carrying a chair.");
}
return 1;
}
new chair;
chair = CreateObject(playerid, 1765, x, y, z, 0.0, 0.0, 0.0);
I've been toying around with something and I am trying to learn how to use objects.
This is a simple command, it allows you to get, drop and pickup a chair. It's got no purpose, I am simply using it to learn. I know that to pick up the chair you will have to check the player is near the object and then destroy it, which requires an objectid. How can I assign an id to the object? This is the command... PHP код:
PHP код:
|
CMD:chair(playerid, params[])
{
static
p_objects[MAX_PLAYERS] = {INVALID_OBJECT_ID,...}, // Local array. 1 player has = 1 object
type[24];
new
Float:x,
Float:y,
Float:z,
Float:a;
if (sscanf(params, "s[24]", type))
{
SendSyntaxMessage(playerid, "/chair [option]");
SendClientMessage(playerid, COLOR_YELLOW, "[OPTIONS]:{FFFFFF} get, drop, pickup");
return 1;
}
if (!strcmp(type, "get", true))
{
if (p_objects[playerid] != INVALID_OBJECT_ID) return SendErrorMessage(playerid, "You are already carrying a chair.");
new
Float: x,
Float: y,
Float: z
;
for (new p = GetPlayerPoolSize(); p >= 0; --p) {
GetObjectPos(p_objects[p], x, y, z);
if (IsPlayerInRangeOfPoint(playerid, 3.0, x, y, z)) {
if (p_objects[p] != INVALID_OBJECT_ID) DestroyObject(p_objects[p]);
p_objects[p] = INVALID_OBJECT_ID;
SetPlayerAttachedObject(playerid, 1, 1765, 1, -1.106504, 1.504988, 0.031584, 0.000000, 89.566635, 0.000000);
//SetPVarInt(playerid, "pCarryingChair", 1);
return 1;
}
}
}
if (!strcmp(type, "drop", true))
{
if (p_objects[playerid] == INVALID_OBJECT_ID) return SendErrorMessage(playerid, "You are not carrying a chair.");
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, a);
RemovePlayerAttachedObject(playerid, 1);
p_objects[playerid] = CreateObject(1765, x + 2.0 * floatcos(a, degrees), y + 2.0 * floatsin(a, degrees), z - 1.0, 0.0, 0.0, a, 50.0);
if (p_objects[playerid] == INVALID_OBJECT_ID) return 1;
//SetPVarInt(playerid, "pCarryingChair", 0);
}
if (!strcmp(type, "pickup", true))
{
if (p_objects[playerid] != INVALID_OBJECT_ID) return SendErrorMessage(playerid, "You are already carrying a chair.");
p_objects[playerid] = CreateObject(1765, 0, 0, 0, 0.0, 0.0, 0, 50.0);
if (p_objects[playerid] == INVALID_OBJECT_ID) return 1;
SetPlayerAttachedObject(playerid, 1, 1765, 1, -1.106504, 1.504988, 0.031584, 0.000000, 89.566635, 0.000000);
}
return 1;
}
new chair = CreateObject(1495, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
if(IsValidObject(chair))
{
DestroyObject(chair);
}
Yes using chair = CreateObject.... ( would be correct. CreateObject simply returns an integer which holds the ID of the object.
You can then use the ID to interact with it, i.g: pawn Код:
|
new chair = CreateObject(1765, x - floatsin(a, degrees), y + floatcos(a, degrees), z - 1.0, 0.0, 0.0, a, 50.0);
chair = CreateObject(1765, x - floatsin(a, degrees), y + floatcos(a, degrees), z - 1.0, 0.0, 0.0, a, 50.0);
if (!strcmp(type, "pickup", true))
{
if (GetPVarInt(playerid, "pUsingChair") == 1)
return SendErrorMessage(playerid, "You are already carrying a chair.");
if (IsPlayerNearObject(playerid, chair, 3.0))
{
SetPlayerAttachedObject(playerid, 1, chair, 1, -1.106504, 1.504988, 0.031584, 0.000000, 89.566635, 0.000000);
}
}
stock IsPlayerNearObject(playerid, objectid, Float:range)
{
new Float:X, Float:Y, Float:Z;
GetObjectPos(objectid, X, Y, Z);
if(IsPlayerInRangeOfPoint(playerid, range, X, Y, Z)) return true;
return false;
}
I have done it like this...
At the top of my command I have defined it PHP код:
PHP код:
PHP код:
PHP код:
|
SetPlayerAttachedObject(playerid, INDEX, MODEL, BONE, -1.106504, 1.504988, 0.031584, 0.000000, 89.566635, 0.000000);
// Attached to bone objects #define MAX_PLAYER_ATTACHED_OBJECTS 10 // This is the number of attached indexes available ie 10 = 0-9 native SetPlayerAttachedObject(playerid, index, modelid, bone, Float:fOffsetX = 0.0, Float:fOffsetY = 0.0, Float:fOffsetZ = 0.0, Float:fRotX = 0.0, Float:fRotY = 0.0, Float:fRotZ = 0.0, Float:fScaleX = 1.0, Float:fScaleY = 1.0, Float:fScaleZ = 1.0, materialcolor1 = 0, materialcolor2 = 0); native RemovePlayerAttachedObject(playerid, index); native IsPlayerAttachedObjectSlotUsed(playerid, index); native EditAttachedObject(playerid, index);
Код:
SetPlayerAttachedObject(playerid, INDEX, MODEL, BONE, -1.106504, 1.504988, 0.031584, 0.000000, 89.566635, 0.000000); Index object info: Код:
// Attached to bone objects #define MAX_PLAYER_ATTACHED_OBJECTS 10 // This is the number of attached indexes available ie 10 = 0-9 native SetPlayerAttachedObject(playerid, index, modelid, bone, Float:fOffsetX = 0.0, Float:fOffsetY = 0.0, Float:fOffsetZ = 0.0, Float:fRotX = 0.0, Float:fRotY = 0.0, Float:fRotZ = 0.0, Float:fScaleX = 1.0, Float:fScaleY = 1.0, Float:fScaleZ = 1.0, materialcolor1 = 0, materialcolor2 = 0); native RemovePlayerAttachedObject(playerid, index); native IsPlayerAttachedObjectSlotUsed(playerid, index); native EditAttachedObject(playerid, index); |
#define INVALID_PLAYER_ATTACHED_OBJECT_ID (11)
/*
* native CreatePlayerAttachedObject(playerid, modelid, boneid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, Float:sx=1.0, Float:sy=1.0, Float:sz=1.0, materialcolor1, materialcolor2);
*/
stock CreatePlayerAttachedObject(playerid, modelid, boneid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, Float:sx=1.0, Float:sy=1.0, Float:sz=1.0, materialcolor1, materialcolor2) {
for (new objectid; objectid < MAX_PLAYER_ATTACHED_OBJECTS; objectid++) {
if (!IsPlayerAttachedObjectSlotUsed(playerid, objectid)) {
SetPlayerAttachedObject(playerid, objectid, modelid, boneid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, Float:sx, Float:sy, Float:sz, materialcolor1, materialcolor2);
return objectid;
}
}
return INVALID_PLAYER_ATTACHED_OBJECT_ID;
}
/*
* native DestroyPlayerAttachedObject(playerid, objectid);
*/
stock DestroyPlayerAttachedObject(playerid, objectid) {
if (IsPlayerAttachedObjectSlotUsed(playerid, objectid)) {
RemovePlayerAttachedObject(playerid, objectid);
return true;
}
return false;
}
//example
new l_objects[MAX_PLAYERS];
CMD:add(playerid, params[]) {
new id = CreatePlayerAttachedObject(playerid, 354, 1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0, 0);
if (id == INVALID_PLAYER_ATTACHED_OBJECT_ID) return true;
l_objects[playerid] = id;
return true;
}
CMD:del(playerid, params[]) {
DestroyPlayerAttachedObject(playerid, l_objects[playerid]);
l_objects[playerid] = INVALID_PLAYER_ATTACHED_OBJECT_ID;
return true;
}
To help you, I wrote a simple utility functions for controlling the index object.
Try to understand how it works and apply in practice. PHP код:
|