"Drop" object
#2

Look at your code properly..

pawn Code:
CMD:drop(playerid, params[])
{
    //Drop[playerid] is not a valid object
    //Drop2[playerid] is not a valid object
    if(!IsValidDynamicObject(Drop[playerid]) && !IsValidDynamicObject(Drop2[playerid])) //This gets called, as both are not valid objects
    {
        SendClientMessage(playerid, WHITE, "1");
        GetPlayerPos(playerid, dropcord[0], dropcord[1], dropcord[2]);
        Drop[playerid] = CreateDynamicObject(2025, dropcord[0], dropcord[1], dropcord[2]-0.9, 0, 0, 0.00);
        //Drop[playerid] is now a valid object
        Droplabel[playerid] = CreateDynamic3DTextLabel("Drop 1", 0xFFFFFFAA,dropcord[0], dropcord[1], dropcord[2]-0.9, 2.5);
    }
    //Drop[playerid] is a valid object, because it was created above
    //Drop2[playerid] is not a valid object
    if(IsValidDynamicObject(Drop[playerid]) && !IsValidDynamicObject(Drop2[playerid])) //This is called, as Drop is valid, Drop2 is not
    { //// 2
        SendClientMessage(playerid, WHITE, "2");
        GetPlayerPos(playerid, dropcord[0], dropcord[1], dropcord[2]);
        Drop2[playerid] = CreateDynamicObject(2025, dropcord[0], dropcord[1], dropcord[2]-0.9, 0, 0, 0.00);
        //Drop2[playerid] is now a valid object
        Droplabel2[playerid] = CreateDynamic3DTextLabel("Drop 2", 0xFFFFFFAA,dropcord[0], dropcord[1], dropcord[2]-0.9, 2.5);
    }
    //Drop[playerid] is a valid object
    //Drop2[playerid] is a valid object
    return 1;
}
So now lets try and fix it:
pawn Code:
CMD:drop(playerid, params[])
{
    if(!IsValidDynamicObject(Drop[playerid]) && !IsValidDynamicObject(Drop2[playerid]))
    {
        SendClientMessage(playerid, WHITE, "1");
        GetPlayerPos(playerid, dropcord[0], dropcord[1], dropcord[2]);
        Drop[playerid] = CreateDynamicObject(2025, dropcord[0], dropcord[1], dropcord[2]-0.9, 0, 0, 0.00);
        Droplabel[playerid] = CreateDynamic3DTextLabel("Drop 1", 0xFFFFFFAA,dropcord[0], dropcord[1], dropcord[2]-0.9, 2.5);
    }
    else if(IsValidDynamicObject(Drop[playerid]) && !IsValidDynamicObject(Drop2[playerid]))
    {
        SendClientMessage(playerid, WHITE, "2");
        GetPlayerPos(playerid, dropcord[0], dropcord[1], dropcord[2]);
        Drop2[playerid] = CreateDynamicObject(2025, dropcord[0], dropcord[1], dropcord[2]-0.9, 0, 0, 0.00);
        Droplabel2[playerid] = CreateDynamic3DTextLabel("Drop 2", 0xFFFFFFAA,dropcord[0], dropcord[1], dropcord[2]-0.9, 2.5);
    }
    return 1;
}
Oh... that was easy...
I could have found that answer if I searched properly.

References:
https://sampwiki.blast.hk/wiki/Control_Structures
Reply


Messages In This Thread
IsValidDynamicObject problem - by Supermaxultraswag - 17.02.2015, 14:05
Re: "Drop" object - by Threshold - 17.02.2015, 14:36
Re: "Drop" object - by Supermaxultraswag - 17.02.2015, 16:29

Forum Jump:


Users browsing this thread: 1 Guest(s)