How to remove attached object?
#1

I'm making siren command for now everything is working perfect but I don't know how to make if player write /siren 3 it will remove siren?

here is my command:
pawn Код:
if(strcmp(cmd, "/siren", true) == 0)
    {
        if(!IsPlayerCop(playerid))
        {
            SendClientMessage(playerid, 0xFF0000AA, "You are not authorized to use this command.");
            return 1;
        }
        //new vehicleid = GetPlayerVehicleID(playerid);
        new x_nr[256]; // number
        x_nr = strtok(cmdtext, idx);
        if(!strlen(x_nr))
        {
            SendClientMessage(playerid,0xFF0000AA,"Choose type for siren: 1 - Dashboard, 2 - Roof, 3 - Remove siren!");
            return 1;
        }
        if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, 0xFF0000AA, "You need to be in undercover car first before using this command.");
        if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendClientMessage(playerid, 0xFF0000AA, "You must be a driver to use this command.");
        new vid = GetPlayerVehicleID(playerid); // ID of vehicle
        for(new x = 0; x < 8; x++){
        if(vid == vehicle[x]){

        if(strcmp(x_nr,"1",true) == 0) // Dashboard
        {
            if(vid == vehicle[0]) // ZR350 1
            {
                AttachObjectToVehicle(object[0], vehicle[0], -0.034999, 0.434999, 0.299999, 0.000000, 0.000000, 0.000000); // Siren object at ZR350 1 on Dashboard
                // ProxDetector here "(Name) grabs siren and adjust it on dashboard" or something like this..
                return 1;
            }
            if(vid == vehicle[1]) // ZR350 2
            {
                AttachObjectToVehicle(object[1], vehicle[1], -0.034999, 0.434999, 0.299999, 0.000000, 0.000000, 0.000000); // Siren object at ZR350 2 on Dashboard
                // ProxDetector here "(Name) grabs siren and adjust it on dashboard" or something like this..
                return 1;
            }
            if(vid == vehicle[2]) // Sultan 1
            {
                AttachObjectToVehicle(object[2], vehicle[2], -0.044999, 0.804999, 0.414999, 0.000000, 0.000000, 0.000000); // Siren object at Sultan 1 on Dashboard
                // ProxDetector here "(Name) grabs siren and adjust it on dashboard" or something like this..
                return 1;
            }
            if(vid == vehicle[3]) // Sultan 2
            {
                AttachObjectToVehicle(object[3], vehicle[3], -0.044999, 0.804999, 0.414999, 0.000000, 0.000000, 0.000000); // Siren object at Sultan 2 on Dashboard
                // ProxDetector here "(Name) grabs siren and adjust it on dashboard" or something like this..
                return 1;
            }
            if(vid == vehicle[4]) // Virgo
            {
                AttachObjectToVehicle(object[4],  vehicle[4], 0.000000, 0.419999, 0.304999, 0.000000, 0.000000, 0.000000); // Siren object at Virgo on Dashboard
                // ProxDetector here "(Name) grabs siren and adjust it on dashboard" or something like this..
                return 1;
            }
            if(vid == vehicle[5]) // Greenwood
            {
                AttachObjectToVehicle(object[5],  vehicle[5], 0.000000, 0.749999, 0.384999, 0.000000, 0.000000, 0.000000); // Siren object at Greenwood on Dashboard
                // ProxDetector here "(Name) grabs siren and adjust it on dashboard" or something like this..
                return 1;
            }
            if(vid == vehicle[6]) // Tahoma
            {
                AttachObjectToVehicle(object[6],  vehicle[6], 0.000000, 0.819999, 0.384999, 0.000000, 0.000000, 0.000000); // Siren object at Tahoma on Dashboard
                // ProxDetector here "(Name) grabs siren and adjust it on dashboard" or something like this..
                return 1;
            }
            if(vid == vehicle[7]) // Majestic
            {
                AttachObjectToVehicle(object[7],  vehicle[7], 0.000000, 0.739999, 0.344999, 0.000000, 0.000000, 0.000000); // Siren object at Majestic on Dashboard
                // ProxDetector here "(Name) grabs siren and adjust it on dashboard" or something like this..
                return 1;
            }
        }
        if(strcmp(x_nr,"2",true) == 0) // Roof
        {
            if(vid == vehicle[0]) // ZR350 1
            {
                AttachObjectToVehicle(object[0], vehicle[0], -0.469999, -0.204999, 0.749999, 0.000000, 0.000000, 0.000000); // Siren object at ZR350 1 on Roof
                // ProxDetector here "(Name) grabs siren and adjust it on roof" or something like this..
                return 1;
            }
            if(vid == vehicle[1]) // ZR350 2
            {
                AttachObjectToVehicle(object[1], vehicle[1], -0.469999, -0.204999, 0.749999, 0.000000, 0.000000, 0.000000); // Siren object at ZR350 2 on Roof
                // ProxDetector here "(Name) grabs siren and adjust it on roof" or something like this..
                return 1;
            }
            if(vid == vehicle[2]) // Sultan 1
            {
                AttachObjectToVehicle(object[2], vehicle[2], -0.564999, 0.244999, 0.859999, 0.000000, 0.000000, 0.000000); // Siren object at Sultan 1 on Roof
                // ProxDetector here "(Name) grabs siren and adjust it on roof" or something like this..
                return 1;
            }
            if(vid == vehicle[3]) // Sultan 2
            {
                AttachObjectToVehicle(object[3], vehicle[3], -0.564999, 0.244999, 0.859999, 0.000000, 0.000000, 0.000000); // Siren object at Sultan 2 on Roof
                // ProxDetector here "(Name) grabs siren and adjust it on roof" or something like this..
                return 1;
            }
            if(vid == vehicle[4]) // Virgo
            {
                AttachObjectToVehicle(object[4], vehicle[4], -0.459999, -0.140000, 0.739999, 0.000000, 0.000000, 0.000000); // Siren object at Virgo on Roof
                // ProxDetector here "(Name) grabs siren and adjust it on roof" or something like this..
                return 1;
            }
            if(vid == vehicle[5]) // Greenwood
            {
                AttachObjectToVehicle(object[5], vehicle[5], -0.509999, 0.135000, 0.899999, 0.000000, 0.000000, 0.000000); // Siren object at Greenwood on Roof
                // ProxDetector here "(Name) grabs siren and adjust it on roof" or something like this..
                return 1;
            }
            if(vid == vehicle[6]) // Tahoma
            {
                AttachObjectToVehicle(object[6], vehicle[6], -0.664999, 0.224999, 0.859999, 0.000000, 0.000000, 0.000000); // Siren object at Tahoma on Roof
                // ProxDetector here "(Name) grabs siren and adjust it on roof" or something like this..
                return 1;
            }
            if(vid == vehicle[7]) // Majestic
            {
                AttachObjectToVehicle(object[7], vehicle[7], -0.614999, 0.024999, 0.854999, 0.000000, 0.000000, 0.000000); // Siren object at Majestic on Roof
                // ProxDetector here "(Name) grabs siren and adjust it on roof" or something like this..
                return 1;
            }
            if(strcmp(x_nr,"3",true) == 0) // Removing siren from vehicle
            {
                //
            }
        }
        return SendClientMessage(playerid, 0xFF0000AA, "You can choose only 1 - 3");
        }
        else{
        continue;
        }
        }
        return SendClientMessage(playerid, 0xFF0000AA, "This is not undercover vehicle");
    }
    return 0;
    // In the end return this...
}
You can see towards end of command
pawn Код:
if(strcmp(x_nr,"3",true) == 0) // Removing siren from vehicle
Here I don't know how to make a code to remove siren from car..
Reply
#2

why dont u use SetPVarInt ??
Reply
#3

Destroy the object itself
Reply
#4

you need this?

https://sampwiki.blast.hk/wiki/RemovePlayerAttachedObject
pawn Код:
RemovePlayerAttachedObject(playerid, i);
Reply
#5

Quote:
Originally Posted by Jankingston
Посмотреть сообщение
why dont u use SetPVarInt ??
what is this ?
Reply
#6

Quote:
Originally Posted by TomRedlake
Посмотреть сообщение
you need this?

https://sampwiki.blast.hk/wiki/RemovePlayerAttachedObject
pawn Код:
RemovePlayerAttachedObject(playerid, i);
he's attaching to vehicle not player
Reply
#7

So how should I do it ?
Reply
#8

DestroyObject(yourobject);
Reply
#9

Quote:
Originally Posted by kirollos
Посмотреть сообщение
he's attaching to vehicle not player
ok then he should use this:
https://sampwiki.blast.hk/wiki/AttachObjectToVehicle


pawn Код:
AttachObjectToVehicle(objectid, vehicleid, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0);
EDIT: its better to use SetPVar
Reply
#10

Quote:
Originally Posted by DaniceMcHarley
Посмотреть сообщение
DestroyObject(yourobject);
This. And if you want to use the same command for removing you have to create a variable for the vehicle to check if it has a siren on currently or not.

Quote:
Originally Posted by TomRedlake
Посмотреть сообщение
ok then he should use this:
https://sampwiki.blast.hk/wiki/AttachObjectToVehicle


pawn Код:
AttachObjectToVehicle(objectid, vehicleid, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0);
EDIT: its better to use SetPVar
Yes this could work, however it would be limited to the amount of indexs the vehicle has + he would have to rewrite some of his code.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)