"Drop" object
#1

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);
   }

   if(IsValidDynamicObject(Drop[playerid]) && !IsValidDynamicObject(Drop2[playerid]))
   { //// 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);
   Droplabel2[playerid] = CreateDynamic3DTextLabel("Drop 2", 0xFFFFFFAA,dropcord[0], dropcord[1], dropcord[2]-0.9, 2.5); 
   }
   

return 1;
}
https://www.youtube.com/watch?v=10FP...ature=*********

Why the f it create me 2 objects (as you can see i get message "1" and "2"?
I want to make it like this:
If object "Drop" didn't exist - create object "Drop"
If object "Drop" exist - create object "Drop2"
Reply
#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
#3

Quote:
Originally Posted by Threshold
View Post
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
Thank you, sensei.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)