Assigning an object an ID
#1

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 код:
CMD:chair(playeridparams[])
{
    static
        
type[24];
        
    new
        
Float:x,
        
Float:y,
        
Float:z,
        
Float:a;
    
GetPlayerPos(playeridxyz);
    if (
sscanf(params"s[24]"type))
    {
         
SendSyntaxMessage(playerid"/chair [option]");
        
SendClientMessage(playeridCOLOR_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 
0!= MAX_VEHICLES++)
        if (
IsPlayerNearBoot(playeridi)
        {
            
SetPlayerAttachedObject(playerid117651, -1.1065041.5049880.0315840.00000089.5666350.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(playerida);
        
CreateObject(1765xy z 1.00.00.0a50.0);
        
RemovePlayerAttachedObject(playerid1);
        
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;

Is it something like this?

PHP код:
new chair;
chair CreateObject(playerid1765xyz0.00.00.0); 
Reply
#2

Quote:
Originally Posted by Luke_James
Посмотреть сообщение
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 код:
CMD:chair(playeridparams[])
{
    static
        
type[24];
        
    new
        
Float:x,
        
Float:y,
        
Float:z,
        
Float:a;
    
GetPlayerPos(playeridxyz);
    if (
sscanf(params"s[24]"type))
    {
         
SendSyntaxMessage(playerid"/chair [option]");
        
SendClientMessage(playeridCOLOR_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 
0!= MAX_VEHICLES++)
        if (
IsPlayerNearBoot(playeridi)
        {
            
SetPlayerAttachedObject(playerid117651, -1.1065041.5049880.0315840.00000089.5666350.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(playerida);
        
CreateObject(1765xy z 1.00.00.0a50.0);
        
RemovePlayerAttachedObject(playerid1);
        
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;

Is it something like this?

PHP код:
new chair;
chair CreateObject(playerid1765xyz0.00.00.0); 
Example:
PHP код:
CMD:chair(playeridparams[])
{
    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(playeridCOLOR_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
            
Floatx,
            
Floaty,
            
Floatz
        
;
        for (new 
GetPlayerPoolSize(); >= 0; --p) {
            
GetObjectPos(p_objects[p], xyz);
            if (
IsPlayerInRangeOfPoint(playerid3.0xyz)) {
                 if (
p_objects[p] != INVALID_OBJECT_IDDestroyObject(p_objects[p]);
                 
p_objects[p] = INVALID_OBJECT_ID;
                 
SetPlayerAttachedObject(playerid117651, -1.1065041.5049880.0315840.00000089.5666350.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(playeridxyz);
        
GetPlayerFacingAngle(playerida);      
        
RemovePlayerAttachedObject(playerid1);  
             
        
p_objects[playerid] = CreateObject(17652.0 floatcos(adegrees), 2.0 floatsin(adegrees), 1.00.00.0a50.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(17650000.00.0050.0);
        if (
p_objects[playerid] == INVALID_OBJECT_ID) return 1
        
SetPlayerAttachedObject(playerid117651, -1.1065041.5049880.0315840.00000089.5666350.000000);
    }
    return 
1;

Reply
#3

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(1495, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
    if(IsValidObject(chair))
    {
        DestroyObject(chair);
    }
Reply
#4

Quote:
Originally Posted by Abagail
Посмотреть сообщение
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(1495, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
    if(IsValidObject(chair))
    {
        DestroyObject(chair);
    }
I have done it like this...

At the top of my command I have defined it
PHP код:
    new chair CreateObject(1765floatsin(adegrees), floatcos(adegrees), 1.00.00.0a50.0); 
And the /chair drop command does this
PHP код:
        chair CreateObject(1765floatsin(adegrees), floatcos(adegrees), 1.00.00.0a50.0); 
But, I cannot pick it up using /chair pickup, nothing happens.

PHP код:
    if (!strcmp(type"pickup"true))
    {
        if (
GetPVarInt(playerid"pUsingChair") == 1)
            return 
SendErrorMessage(playerid"You are already carrying a chair.");
            
        if (
IsPlayerNearObject(playeridchair3.0))
        {
            
SetPlayerAttachedObject(playerid1chair1, -1.1065041.5049880.0315840.00000089.5666350.000000);
        }
    } 
PHP код:
stock IsPlayerNearObject(playeridobjectidFloat:range)
{
    new 
Float:XFloat:YFloat:Z;
    
GetObjectPos(objectidXYZ);
    if(
IsPlayerInRangeOfPoint(playeridrangeXYZ)) return true;
    return 
false;

Reply
#5

Quote:
Originally Posted by Luke_James
Посмотреть сообщение
I have done it like this...

At the top of my command I have defined it
PHP код:
    new chair CreateObject(1765floatsin(adegrees), floatcos(adegrees), 1.00.00.0a50.0); 
And the /chair drop command does this
PHP код:
        chair CreateObject(1765floatsin(adegrees), floatcos(adegrees), 1.00.00.0a50.0); 
But, I cannot pick it up using /chair pickup, nothing happens.

PHP код:
    if (!strcmp(type"pickup"true))
    {
        if (
GetPVarInt(playerid"pUsingChair") == 1)
            return 
SendErrorMessage(playerid"You are already carrying a chair.");
            
        if (
IsPlayerNearObject(playeridchair3.0))
        {
            
SetPlayerAttachedObject(playerid1chair1, -1.1065041.5049880.0315840.00000089.5666350.000000);
        }
    } 
PHP код:
stock IsPlayerNearObject(playeridobjectidFloat:range)
{
    new 
Float:XFloat:YFloat:Z;
    
GetObjectPos(objectidXYZ);
    if(
IsPlayerInRangeOfPoint(playeridrangeXYZ)) return true;
    return 
false;

Код:
SetPlayerAttachedObject(playerid, INDEX, MODEL, BONE, -1.106504, 1.504988, 0.031584, 0.000000, 89.566635, 0.000000);
INDEX - This not global/player object, is the local index object. You can not use chair = CreateObject(1765, x - floatsin(a, degrees), y + floatcos(a, degrees), z - 1.0, 0.0, 0.0, a, 50.0);

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);
Reply
#6

Quote:
Originally Posted by Logofero
Посмотреть сообщение
Код:
SetPlayerAttachedObject(playerid, INDEX, MODEL, BONE, -1.106504, 1.504988, 0.031584, 0.000000, 89.566635, 0.000000);
INDEX - This not global/player object, is the local index object. You can not use chair = CreateObject(1765, x - floatsin(a, degrees), y + floatcos(a, degrees), z - 1.0, 0.0, 0.0, a, 50.0);

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);
How would I go about making it work?
Reply
#7

Quote:
Originally Posted by Luke_James
Посмотреть сообщение
How would I go about making it work?
You have to do a system to index objects that use a limit of 10
For starters learn to work with one object.
Reply
#8

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 код:
#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(playeridmodelidboneidFloat:xFloat:yFloat:zFloat:rxFloat:ryFloat:rzFloat:sx=1.0Float:sy=1.0Float:sz=1.0materialcolor1materialcolor2) {
    for (new 
objectidobjectid MAX_PLAYER_ATTACHED_OBJECTSobjectid++) {
        if (!
IsPlayerAttachedObjectSlotUsed(playeridobjectid)) {
            
SetPlayerAttachedObject(playeridobjectidmodelidboneidFloat:xFloat:yFloat:zFloat:rxFloat:ryFloat:rzFloat:sxFloat:syFloat:szmaterialcolor1materialcolor2);
            return 
objectid;
        }
    }
    return 
INVALID_PLAYER_ATTACHED_OBJECT_ID;
}
/* 
 * native DestroyPlayerAttachedObject(playerid, objectid);
 */
stock DestroyPlayerAttachedObject(playeridobjectid) {
    if (
IsPlayerAttachedObjectSlotUsed(playeridobjectid)) {
        
RemovePlayerAttachedObject(playeridobjectid);
        return 
true;
    }
    return 
false;
}
//example
new l_objects[MAX_PLAYERS];
CMD:add(playeridparams[]) {
    new 
id CreatePlayerAttachedObject(playerid35410.00.00.00.00.00.01.01.01.000);
    if (
id == INVALID_PLAYER_ATTACHED_OBJECT_ID) return true;
    
l_objects[playerid] = id;
    return 
true;
}
CMD:del(playeridparams[]) {
    
DestroyPlayerAttachedObject(playeridl_objects[playerid]);
    
l_objects[playerid] = INVALID_PLAYER_ATTACHED_OBJECT_ID;
    return 
true;

Reply
#9

Quote:
Originally Posted by Logofero
Посмотреть сообщение
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 код:
#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(playeridmodelidboneidFloat:xFloat:yFloat:zFloat:rxFloat:ryFloat:rzFloat:sx=1.0Float:sy=1.0Float:sz=1.0materialcolor1materialcolor2) {
    for (new 
objectidobjectid MAX_PLAYER_ATTACHED_OBJECTSobjectid++) {
        if (!
IsPlayerAttachedObjectSlotUsed(playeridobjectid)) {
            
SetPlayerAttachedObject(playeridobjectidmodelidboneidFloat:xFloat:yFloat:zFloat:rxFloat:ryFloat:rzFloat:sxFloat:syFloat:szmaterialcolor1materialcolor2);
            return 
objectid;
        }
    }
    return 
INVALID_PLAYER_ATTACHED_OBJECT_ID;
}
/* 
 * native DestroyPlayerAttachedObject(playerid, objectid);
 */
stock DestroyPlayerAttachedObject(playeridobjectid) {
    if (
IsPlayerAttachedObjectSlotUsed(playeridobjectid)) {
        
RemovePlayerAttachedObject(playeridobjectid);
        return 
true;
    }
    return 
false;
}
//example
new l_objects[MAX_PLAYERS];
CMD:add(playeridparams[]) {
    new 
id CreatePlayerAttachedObject(playerid35410.00.00.00.00.00.01.01.01.000);
    if (
id == INVALID_PLAYER_ATTACHED_OBJECT_ID) return true;
    
l_objects[playerid] = id;
    return 
true;
}
CMD:del(playeridparams[]) {
    
DestroyPlayerAttachedObject(playeridl_objects[playerid]);
    
l_objects[playerid] = INVALID_PLAYER_ATTACHED_OBJECT_ID;
    return 
true;

I can see how that works, but I don't understand how I count integrate that in to my command.
Reply
#10

@Luke_James
> I can see how that works, but I don't understand how I count integrate that in to my command.
I can not decide everything for you. You'll have to figure it out. A programmer should be able to rely on
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)