Objects attached to cars, cmds to delete them and stuff.
#1

Okay, so, I've been setting up a few commands to place and remove some object above my car.
I would like that command work for everyone though, so everyone can place and remove (that's the most difficult part) HIS OWN objects, and not others ones.
I've done this cmd:
pawn Код:
//these are just 5 spoilers i want to attach, I'm using 40 of them at the mom, but it's just for example I've put 5 of them
new spoiler;
new spoiler2;
new spoiler3;
new spoiler4;
new spoiler5;
then I use this to put these objects on:
pawn Код:
if(strcmp("/ston",cmdtext,true) == 0)
{
    if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
    {
       SendClientMessage(playerid, COLOR_BRIGHTRED, "You have to be the driver.");
    }
    else if(IsPlayerInAnyVehicle(playerid))
    {
    new vehicleid = GetPlayerVehicleID(playerid);
    spoiler = CreateObject(1000,0,0,0,0,0,0);
    spoiler2 = CreateObject(1000,0,0,0,0,0,0);
    spoiler3 = CreateObject(1000,0,0,0,0,0,0);
    spoiler4 = CreateObject(1000,0,0,0,0,0,0);
    spoiler5 = CreateObject(1000,0,0,0,0,0,0);
    AttachObjectToVehicle(spoiler, vehicleid, 0.000000, -2.420007, -0.399999, 0.000000, 0.000000, 0.000000); //Object Model: 1000 |
    AttachObjectToVehicle(spoiler2, vehicleid, 0.000000, -2.420007, -0.339999, 0.000000, 0.000000, 0.000000); //Object Model: 1000 |
    AttachObjectToVehicle(spoiler3, vehicleid, 0.000000, -2.420007, -0.284999, 0.000000, 0.000000, 0.000000); //Object Model: 1000 |
    AttachObjectToVehicle(spoiler4, vehicleid, 0.000000, -2.420007, -0.224999, 0.000000, 0.000000, 0.000000); //Object Model: 1000 |
    AttachObjectToVehicle(spoiler5, vehicleid, 0.000000, -2.420007, -0.169999, 0.000000, 0.000000, 0.000000); //Object Model: 1000 |
    }
    return 1;
}
And this is ok. When I want to remove them I'm using this instead:

pawn Код:
if(strcmp(cmdtext, "/stoff", true) == 0)
    {
        if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
        {
       SendClientMessage(playerid, COLOR_BRIGHTRED, "You have to be the driver.");
        }
        else if(IsPlayerInAnyVehicle(playerid))
        {
        DestroyObject(spoiler);
        DestroyObject(spoiler2);
        DestroyObject(spoiler3);
        DestroyObject(spoiler4);
        DestroyObject(spoiler5);
        }
        return 1;
    }
And that's on vehicle death..
pawn Код:
public OnVehicleDeath(vehicleid)
    {
    DestroyObject(spoiler);
    DestroyObject(spoiler2);
    DestroyObject(spoiler3);
    DestroyObject(spoiler4);
    DestroyObject(spoiler5);
    return 1;
    }
The problem is: if I attach these spoilers on my car, another one attachs them and then I do /stoff, it removes his spoilers, and not mines.
All I want to know is if I can do a cmd that works with your own objects, so you remove your objects and not other ones. I think it's because of some conflicts with objects so it removes another player's objects. It happens too with my OnVehicleDeath. It happens it removes other people spoilers and not mines.
Any help?
Thanks in advance!
Reply
#2

You must do variables once for all players, like :
pawn Код:
new spoiler[MAX_PLAYERS] ;
new spoiler2[MAX_PLAYERS];
new spoiler3[MAX_PLAYERS] ;
new spoiler4[MAX_PLAYERS] ;
new spoiler5[MAX_PLAYERS] ;
And then rewrite spoiler(1-5) to spoiler[playerid]
Reply
#3

so it comes out
pawn Код:
spoiler[playerid]
spoiler2[playerid]
spoiler3[playerid]
Could you show me, please?
Thank you.
Reply
#4

Like this :
pawn Код:
if(strcmp("/ston",cmdtext,true) == 0)
{
    if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
    {
       SendClientMessage(playerid, COLOR_BRIGHTRED, "You have to be the driver.");
    }
    else if(IsPlayerInAnyVehicle(playerid))
    {
    new vehicleid = GetPlayerVehicleID(playerid);
    spoiler[playerid] = CreateObject(1000,0,0,0,0,0,0);
    spoiler2[playerid] = CreateObject(1000,0,0,0,0,0,0);
    spoiler3[playerid] = CreateObject(1000,0,0,0,0,0,0);
    spoiler4[playerid] = CreateObject(1000,0,0,0,0,0,0);
    spoiler5[playerid] = CreateObject(1000,0,0,0,0,0,0);
    AttachObjectToVehicle(spoiler[playerid] , vehicleid, 0.000000, -2.420007, -0.399999, 0.000000, 0.000000, 0.000000); //Object Model: 1000 |
    AttachObjectToVehicle(spoiler2[playerid] , vehicleid, 0.000000, -2.420007, -0.339999, 0.000000, 0.000000, 0.000000); //Object Model: 1000 |
    AttachObjectToVehicle(spoiler3[playerid] , vehicleid, 0.000000, -2.420007, -0.284999, 0.000000, 0.000000, 0.000000); //Object Model: 1000 |
    AttachObjectToVehicle(spoiler4[playerid] , vehicleid, 0.000000, -2.420007, -0.224999, 0.000000, 0.000000, 0.000000); //Object Model: 1000 |
    AttachObjectToVehicle(spoiler5[playerid], vehicleid, 0.000000, -2.420007, -0.169999, 0.000000, 0.000000, 0.000000); //Object Model: 1000 |
    }
    return 1;
}
Reply
#5

I understand now.
And If I wanna create and remove different objects from vehicles I'm in, should I add
pawn Код:
new vehicleid = GetPlayerVehicleID(playerid);
    spoiler[playerid][vehicleid] = CreateObject(1000,0,0,0,0,0,0);
Should I add [vehicleid]? even in ..
pawn Код:
new spoiler[MAX_PLAYERS][vehicleid];
//or maybe it's
new spoiler[MAX_PLAYERS][MAX_VEHICLES]; //???
Thanks.
Reply
#6

I would use only MAX_VEHICLES because you remove the spoilers from the vehicles not the players. so on the add spoiler i would GetPlayerVehicleID and then spoiler[MAX_VEHICLES] = whatever you use for creating objects.

btw u only need 1 spoiler like new spoiler[MAX_VEHICLES] not until 20 now.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)