Vehicleid
#1

Hello!

I have big trouble with the vehicleid function in some of my commands, is it samp or the code maybe?
I cant see why the commands shouldnt work and get the right vehicle id for the right player using the cmds.
You have to type the cmd twice sometimes, and when you step out or die in the plane..the rockets removes from all players.
Hope someone can have some ideas about what can be wrong.

You can see on this vid when i type /load and Testing_debugger also getting rockets when he shouldn't get it, and when i get out..the rockets removes from him.
http://*********/OFduRZ02_bI
Reply
#2

You mean
pawn Код:
vehicleid = GetPlayerVehicleID(playerid);
Reply
#3

Quote:
Originally Posted by Spooky
Посмотреть сообщение
You mean
pawn Код:
vehicleid = GetPlayerVehicleID(playerid);
Yeah, for example.. i got this cmd and it affect also other players when you use it like in the vid i posted
pawn Код:
COMMAND:load(playerid,vehicleid, params[])
{
        new id;
        id = GetPlayerVehicleID(playerid);
        if(GetVehicleModel(GetPlayerVehicleID(playerid)))
        {
            new
                Float:x,
                Float:y,
                Float:z;

            GetPlayerPos(playerid,x,y,z);

            AddVehicleMissiles(id,2.0,-1.05,0.0);
            VehicleFire[id] = 0;
        }
        return 1;
}
Reply
#4

GetVehicleModel(GetPlayerVehicleID(playerid)) will always return a positive value since you don't compare it with anything. Please describe in detail what exactly you are trying to achieve?

EDIT: You most likely have to edit the AddVehicleMissiles function to make it do what you want / fix the "bugs".
Reply
#5

Like stated above, you haven't compared GetVehicleModel to anything. Like a vehicle model id, for example 422 is the bobcat, etc.

Also, why are you using this:
pawn Код:
if(GetVehicleModel(GetPlayerVehicleID(playerid)))
when you created the id variable and you COULD do this:
pawn Код:
if(GetVehicleModel(id) == //modelid)
Reply
#6

It seams it doesnt matter what i am doing..the commands still bugging. I have tried to fix this for 3 days now.
And it seams that when you have to type /load twice bc of someone /unload or crash their vehicle, then it starts to bug.

Here is the AddVehicleMissiles
CODE:
pawn Код:
stock AddVehicleMissiles(vehicleid,Float:offsetx,Float:offsetz)
{
    if(!VehicleFire[vehicleid])
    {
        new Float:x,Float:u;
        GetVehiclePos(vehicleid,x,u,u);
        if(x != 0)
        {
            if(!IsValidObject(VehicleBomb[vehicleid][1]))
            {

                VehicleBomb[vehicleid][0] = CreateObject(3790,2.1,1.7,-1.0,0,0,0,300.0);
                VehicleBomb[vehicleid][1] = CreateObject(3790,2.1,1.7,-1.0,0,0,0,300.0);

                AttachObjectToVehicle(VehicleBomb[vehicleid][0],vehicleid,offsetx,1,offsetz,2,0,270);
                AttachObjectToVehicle(VehicleBomb[vehicleid][1],vehicleid,-offsetx,1,offsetz,2,0,270);

                VehicleOffsetX[vehicleid] = offsetx;
                VehicleOffsetZ[vehicleid] = offsetz;
                return 1;
            }
        }
    }
    return 0;
}
And the cmds
CODE:
pawn Код:
COMMAND:unload(playerid,vehicleid, params[])
{
    new id;
    id = GetPlayerVehicleID(playerid);
    if(GetVehicleModel(GetPlayerVehicleID(playerid)))
    {
        if(GetVehicleModel(id) == 476)
        {
            DestroyObject(VehicleBomb[id][0]);
            DestroyObject(VehicleBomb[id][1]);
            VehicleFire[id] = 1;
        }
    }
    return 1;
}
COMMAND:load(playerid,vehicleid, params[])
{
    new id;
    id = GetPlayerVehicleID(playerid);
    new
        Float:x,
        Float:y,
        Float:z;
    if(GetVehicleModel(GetPlayerVehicleID(playerid)))
    {
        if(GetVehicleModel(id) == 476)
        {
            GetPlayerPos(playerid,x,y,z);

            AddVehicleMissiles(id,2.0,-1.05,0.0);
            VehicleFire[id] = 0;
        }
    }
    return 1;
}
and also OnPlayerKeyStateChange
CODE:
pawn Код:
public VM_OnPlayerKeyStateChange(playerid,newkeys)
{
    if((newkeys & MISSILE_FIRE_KEY) == (MISSILE_FIRE_KEY))
    {
     if(IsPlayerInAnyVehicle(playerid))
        {
            new id = GetPlayerVehicleID(playerid);
            if(!VehicleFire[id])
            {
                if(id)
                {
                    if(IsValidObject(VehicleBomb[id][1]))
                    {
                        new
                        Float:x,
                        Float:y,
                        Float:z,
                        Float:a;


                        VehicleFire[id] = 1;

                        if(IsValidObject(VehicleBomb[id][0]))
                        {
                            DestroyObject(VehicleBomb[id][0]);

                            GetVehiclePos(id,x,y,z);
                            GetVehicleZAngle(id,a);

                            a += 270;
                            z += VehicleOffsetZ[id];

                            x += (VehicleOffsetX[id] * floatsin(-a, degrees));
                            y += (VehicleOffsetX[id] * floatcos(-a, degrees));

                            VehicleBomb[id][0] = CreateObject(3790,x,y,z,2,0,a,300.0);
                            VehicleSmok[id][0] = CreateObject(18731,x,y,z-1.3,0,0,0,300.0);

                            a += 90;

                            x += (300 * floatsin(-a, degrees));
                            y += (300 * floatcos(-a, degrees));

                            MoveObject(VehicleBomb[id][0],x,y,z,MISSILE_SPEED);
                            MoveObject(VehicleSmok[id][0],x,y,z-1.3,MISSILE_SPEED);

                            SetTimerEx("VM_Explode",MISSILE_DETONATE_TIME,0,"dd",id,0);
                            VM_OnVehicleFire(id,0);
                            return 1;
                        }
                        DestroyObject(VehicleBomb[id][1]);

                        GetVehiclePos(id,x,y,z);
                        GetVehicleZAngle(id,a);

                        a += 90;
                        z += VehicleOffsetZ[id];

                        x += (VehicleOffsetX[id] * floatsin(-a, degrees));
                        y += (VehicleOffsetX[id] * floatcos(-a, degrees));

                        VehicleBomb[id][1] = CreateObject(3790,x,y,z,2,0,a+180,300.0);
                        VehicleSmok[id][1] = CreateObject(18731,x,y,z-1.3,0,0,0,300.0);

                        a += 270;

                        x += (300 * floatsin(-a, degrees));
                        y += (300 * floatcos(-a, degrees));

                        MoveObject(VehicleBomb[id][1],x,y,z,MISSILE_SPEED);
                        MoveObject(VehicleSmok[id][1],x,y,z-1.3,MISSILE_SPEED);

                        SetTimerEx("VM_Explode",MISSILE_DETONATE_TIME,0,"dd",id,1);
                        VM_OnVehicleFire(id,1);
                        return 1;
                        }
                    }
                return 1;
            }
        }
    }
    return 1;
}
Reply
#7

VehicleFire[id] = 0; should be placed before you call the function AddVehicleMissiles since it checks if VehicleFire equals false.
Reply
#8

[QUOTE=JamesC;1624287]VehicleFire[id] = 0; should be placed before you call the function AddVehicleMissiles since it checks if VehicleFire equals false.[/QUOT]

So then i just can try with replace AddVehicleMissiles to the bottom of the script?
Reply
#9

pawn Код:
COMMAND:load(playerid,vehicleid, params[])
{
    new id = GetPlayerVehicleID(playerid);
    /*new
        Float:x,
        Float:y,
        Float:z;*/
// Uncomment if you need it.
    if(GetVehicleModel(id) == 476) // Removed previous conditional statement as there was no need for it.
    {
        // GetPlayerPos(playerid,x,y,z); // Uncomment if you need it.

        VehicleFire[id] = 0;
        AddVehicleMissiles(id,2.0,-1.05,0.0); // Since this checks if VehicleFire = 0, set the value of VehicleFire before you call it.
    }
    return 1;
}
There you go, I've commented what was wrong. Also, I have no idea why you get the player's position because you never use it.
Reply
#10

Quote:
Originally Posted by JamesC
Посмотреть сообщение
pawn Код:
COMMAND:load(playerid,vehicleid, params[])
{
    new id = GetPlayerVehicleID(playerid);
    /*new
        Float:x,
        Float:y,
        Float:z;*/
// Uncomment if you need it.
    if(GetVehicleModel(id) == 476) // Removed previous conditional statement as there was no need for it.
    {
        // GetPlayerPos(playerid,x,y,z); // Uncomment if you need it.

        VehicleFire[id] = 0;
        AddVehicleMissiles(id,2.0,-1.05,0.0); // Since this checks if VehicleFire = 0, set the value of VehicleFire before you call it.
    }
    return 1;
}
There you go, I've commented what was wrong. Also, I have no idea why you get the player's position because you never use it.
Hmm..it still bugs. when someone unload/crash for first time after server start and the next one use /load, he needs to type it twice to get the rockets, and only when someone need to type it twice and then if someone press the fire button, he steals the rockets from other even if he never did type the cmd, it must be some other bug in the script that mess up with the vehicle ids or something.

If you want to make a check to find bad codes, heres the whole script
http://pastebin.com/7t5StZ55
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)