I need to make second function on this code, but got an error. Help please!
#1

Hello guys, how i can make second fucntion of command? The first function is so it attach object to vehicle, but i want to do when player type it again and on car is already this item it will destroy it, while I tried to make it i got this.

Errors:
C:\Users\Jakub\Desktop\Server\gamemodes\LVRP.pwn(3 65) : error 029: invalid expression, assumed zero
C:\Users\Jakub\Desktop\Server\gamemodes\LVRP.pwn(3 71) : warning 225: unreachable code
C:\Users\Jakub\Desktop\Server\gamemodes\LVRP.pwn(3 71) : warning 217: loose indentation


pawn Код:
Variable:
new VehicleObject[1];


COMMAND:majak(playerid, cmdtext[])
{
    {
        VehicleObject[0] = CreateObject(18646,0,0,-1000,0,0,0,100);
        AttachObjectToVehicle(VehicleObject[0], 541, 0.449999,0.674999,0.375000,0.000000,0.000000,0.000000);
    }
    else //365 line
    {
        DestroyObject(VehicleObject[0]);
    }
    return 1;
   
return 1; //371 line
}
THANKS.
Reply
#2

Where is if?

pawn Код:
COMMAND:majak(playerid, cmdtext[])
{
    {
if(VehicleObject[1])
{


EDIT:
pawn Код:
COMMAND:majak(playerid, cmdtext[])
{
    if(IsValidObject(VehicleObject[0]))
    {
        VehicleObject[0] = CreateObject(18646,0,0,-1000,0,0,0,100);
        AttachObjectToVehicle(VehicleObject[0], 541, 0.449999,0.674999,0.375000,0.000000,0.000000,0.000000);
    }
    else //365 line
    {
        DestroyObject(VehicleObject[0]);
    }
    return 1;
}
Reply
#3

Got an next error when i added if

C:\Users\Jakub\Desktop\Server\gamemodes\LVRP.pwn(3 62) : error 032: array index out of bounds (variable "VehicleObject")
C:\Users\Jakub\Desktop\Server\gamemodes\LVRP.pwn(3 66) : error 029: invalid expression, assumed zero
C:\Users\Jakub\Desktop\Server\gamemodes\LVRP.pwn(3 72) : warning 225: unreachable code
C:\Users\Jakub\Desktop\Server\gamemodes\LVRP.pwn(3 72) : warning 217: loose indentation
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase

pawn Код:
COMMAND:majak(playerid, cmdtext[])
{
    {
        if(VehicleObject[1]) //362 line
        VehicleObject[0] = CreateObject(18646,0,0,-1000,0,0,0,100);
        AttachObjectToVehicle(VehicleObject[0], 541, 0.449999,0.674999,0.375000,0.000000,0.000000,0.000000);
    }
    else //366 line
    {
        DestroyObject(VehicleObject[0]);
    }
    return 1;

return 1; //372 line


//EDIT: Eh, okay mate i copied your edited post now works thx
Reply
#4

See edit.
Reply
#5

Ehm, mate compiled tried but here is the problem When i type command it keep still removing object. It not place it first..
Reply
#6

Change this:
if(IsValidObject(VehicleObject[0]))
to
if(!IsValidObject(VehicleObject[0]))

Right now, you're doing a check to see if the object is valid, and if it is, you end up creating it again.
Reply
#7

Well still not working, mate pls if u can edit this all code to work correctly thanks.

pawn Код:
COMMAND:majak(playerid, cmdtext[])
{
    if(!IsValidObject(VehicleObject[0]))
    {
        VehicleObject[0] = CreateObject(18646,0,0,-1000,0,0,0,100);
        AttachObjectToVehicle(VehicleObject[0], 541, 0.449999,0.674999,0.375000,0.000000,0.000000,0.000000);
    }
    else
    {
        DestroyObject(VehicleObject[0]);
    }
    return 1;
}
Reply
#8

AttachObjectToVehicle(VehicleObject[0], 541, 0.449999,0.674999,0.375000,0.000000,0.000000,0.000 000);
You do realise this will attach to vehicle ID 541, not model?
Reply
#9

I just put id of Bullet becouse actually for testing attaching. But in future i want to make so only Static Bullet can be used to attach object, becouse it will be police Bullet. What do you advise? What should i do with it? I'm beginner. Can you post the full code how i can make it? Thanks mate alot
Reply
#10

Fixed now, thanks Ben for now i edited this vehicle ID to GetPlayerVehicleID(playerid), but now I want to know how to make it, so it will be possible add this object only to one static vehicle, what I will choose, any ideas? thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)