Need help!
#1

Hi SA-MP Community,

How to assign an object its own variable?
Like I created an object, suppose that object is a mine. When I drive my car on the mine, the object should be destroyed along with the car. Though the object is destroyed, then also the object(not virtually, the saved position of the object) is still there.
I want that object also be destroyed not only virtually. So I tried assigning a variable to the specific object, but failed.

I have tried assigning a variable to the object when it is created.
pawn Код:
MinInfo[mCreated] = 1;
When I return
pawn Код:
MineInfo[mCreated] = 0;
All the rest objects which I created earlier were also disabled.
I want that specific object(over which I drove my car) to be disabled.
Reply
#2

pawn Код:
new yourobject; //Create a variable for the object you want to delete.

yourobject = CreateObject(....) //Here, yourobject will be defined as that particular object.
So then you can destroy it just by executing the variable on DestroyObject function.
Reply
#3

Dude I tried that:
pawn Код:
MineInfo[mObject]=CreateObject(18646, x, y, z-0.72, 0.0, 0.0, 0.0);
Reply
#4

/BUMP!
Reply
#5

Yeah exactly, I want multiple mines. I tried with creating arrays many times but failed. Can someone help me with it.
Reply
#6

Something like this:
pawn Код:
enum mInfo
{
    Float:mX,
    Float:mY,
    Float:mZ,
    mObject,
    mType
};
new MineInfo[mInfo];
And
pawn Код:
stock CreateAntiVehicleMine(Float:x,Float:y,Float:z)
{
    MineInfo[mX]=x;
    MineInfo[mY]=y;
    MineInfo[mZ]=z;
    MineInfo[mObject]=CreateObject(18646, x, y, z-0.72, 0.0, 0.0, 0.0);
    MineInfo[mType]=1;
    SendClientMessageToAll(0xFFFFFFAA, "You have set an Anti-Vehicle mine.");
    return 1;
}
Reply
#7

that code will have only one object like if u do
Код:
MineInfo[mObject] = CreateObject(..)//first
MineInfo[mObject] = CreateObject(..)//second
that variable will have only one ID of object so no matter how much object u assign to this variable it will have latest/last createobject id in it , that means if u got multiple mines it will delete only one.

to make it work you will be needing following things:
- 2d Array new MineInfo[MAX_MINES][mInfo]; // MAX_MINES a constant of maxmimum number of mines u would like to have , you can rename it to any thing :P
- a function that will have a loop and it will fetch out next Slot of MineInfo and assign all enumertated elemnts accordingly

e.g.:

PHP код:
stock CreateAntiVehicleMine(Float:x,Float:y,Float:z)
{
    new 
mineid GetNextSlot();// this function u'll need to make 
    
MineInfo[mineid ][mX]=x;
    
MineInfo[mineid ][mY]=y;
    
MineInfo[mineid ][mZ]=z;
    
MineInfo[mineid ][mObject]=CreateObject(18646xyz-0.720.00.00.0);
    
MineInfo[mineid ][mType]=1;
    
SendClientMessageToAll(0xFFFFFFAA"You have set an Anti-Vehicle mine.");
       return 
1;

^- so u will be able to add multiple mines in ur server, and

- to delete them u need to fetch out their ID by loop or whatever you use it like and Destroy it


P.S: i am bad at explaining stuff
Reply
#8

So I will have to assign an ID using MAX_MINES or something like that?

How will I destroy them if I don't wanna run a loop (although I will run a loop, just for some knowledge.)
Reply
#9

/Bump
Reply
#10

I'll try to help you. You should use the MAX_OBJECTS in it, because you now only support one object. It's just like stuff as "PlayerInfo[playerid][data]"
pawn Код:
enum mInfo
{
    Float:mX,
    Float:mY,
    Float:mZ,
    mObject,
    mType
};
new MineInfo[mInfo];
The new MineInfo[mInfo]; should be then new MineInfo[MAX_OBJECTS][mInfo];. The [MAX_OBJECTS] part then would be the ID of the object.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)