Animation won't play
#1

There's one animation that I want to play when someone locks their house. However, when the command is executed, the animation doesn't play.

pawn Код:
CMD:lock(playerid, params[])
{
    if(GetPVarInt(playerid, "LoggedIn") == 0) return SendClientMessage(playerid, COLOR_RED, "[ERROR]: You need to be logged in to use this command.");
    new string[128], Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    for(new i = 0; i<MAX_HOUSES; i++)
    {
        if(fexist(HousePath(i)))
        {
            if(IsPlayerInRangeOfPoint(playerid, 2, House[i][ExtPosX], House[i][ExtPosY], House[i][ExtPosZ]) || IsPlayerInRangeOfPoint(playerid, 2, House[i][IntPosX], House[i][IntPosY], House[i][IntPosZ]))
            {
                if(Player[playerid][HouseID] == House[i][hID])
                {
                    if(House[i][hLocked] == 0)
                    {
                        House[i][hLocked] = 1;
                        ApplyAnimation(playerid, "BD_FIRE", "wash_up", 4.0, 0, 0, 0, 0, 1);
                        format(string, sizeof(string), " * %s locks the door to the house.", GetName(playerid));
                        SetPlayerChatBubble(playerid, string, COLOR_LIGHTPURPLE, 10, 7000);
                        SendClientMessage(playerid, COLOR_LIGHTPURPLE, string);
                    }
                    else
                    {
                        House[i][hLocked] = 0;
                        ApplyAnimation(playerid, "BD_FIRE", "wash_up", 4.0, 0, 0, 0, 0, 1);
                        format(string, sizeof(string), " * %s unlocks the door to the house.", GetName(playerid));
                        SetPlayerChatBubble(playerid, string, COLOR_LIGHTPURPLE, 10, 7000);
                        SendClientMessage(playerid, COLOR_LIGHTPURPLE, string);
                    }
                }
                else return SendClientMessage(playerid, COLOR_GREY, "You don't own this house.");
            }
        }
    }
    return 1;
}
I have the animation library pre loaded and I even have the animation used for something else and it works fine there with no changes to ApplyAnimation. Anyone know the issue?
Reply
#2

It's a samp bug, you should write the Animation code twice, Look at the Applyanimation codes to understand what do I mean:

pawn Код:
CMD:lock(playerid, params[])
{
    if(GetPVarInt(playerid, "LoggedIn") == 0) return SendClientMessage(playerid, COLOR_RED, "[ERROR]: You need to be logged in to use this command.");
    new string[128], Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    for(new i = 0; i<MAX_HOUSES; i++)
    {
        if(fexist(HousePath(i)))
        {
            if(IsPlayerInRangeOfPoint(playerid, 2, House[i][ExtPosX], House[i][ExtPosY], House[i][ExtPosZ]) || IsPlayerInRangeOfPoint(playerid, 2, House[i][IntPosX], House[i][IntPosY], House[i][IntPosZ]))
            {
                if(Player[playerid][HouseID] == House[i][hID])
                {
                    if(House[i][hLocked] == 0)
                    {
                        House[i][hLocked] = 1;
                        ApplyAnimation(playerid, "BD_FIRE", "wash_up", 4.0, 0, 0, 0, 0, 1);
                                            ApplyAnimation(playerid, "BD_FIRE", "wash_up", 4.0, 0, 0, 0, 0, 1);//If I repeated this code, it will work
                        format(string, sizeof(string), " * %s locks the door to the house.", GetName(playerid));
                        SetPlayerChatBubble(playerid, string, COLOR_LIGHTPURPLE, 10, 7000);
                        SendClientMessage(playerid, COLOR_LIGHTPURPLE, string);
                    }
                    else
                    {
                        House[i][hLocked] = 0;
                        ApplyAnimation(playerid, "BD_FIRE", "wash_up", 4.0, 0, 0, 0, 0, 1);
                                           vApplyAnimation(playerid, "BD_FIRE", "wash_up", 4.0, 0, 0, 0, 0, 1); // same here
                        format(string, sizeof(string), " * %s unlocks the door to the house.", GetName(playerid));
                        SetPlayerChatBubble(playerid, string, COLOR_LIGHTPURPLE, 10, 7000);
                        SendClientMessage(playerid, COLOR_LIGHTPURPLE, string);
                    }
                }
                else return SendClientMessage(playerid, COLOR_GREY, "You don't own this house.");
            }
        }
    }
    return 1;
}
Reply
#3

You should use "PreloadAnimationLib" function.

Ex.

Код:
public OnPlayerSpawn(playerid) {
    PreloadAnimationLib(playerid, "BD_FIRE");
}
Reply
#4

Quote:
Originally Posted by icra
Посмотреть сообщение
You should use "PreloadAnimationLib" function.

Ex.

Код:
public OnPlayerSpawn(playerid) {
    PreloadAnimationLib(playerid, "BD_FIRE");
}
Quote:
Originally Posted by DTV
Посмотреть сообщение
I have the animation library pre loaded and I even have the animation used for something else and it works fine there with no changes to ApplyAnimation. Anyone know the issue?
I have it loaded already.
Reply
#5

Quote:
Originally Posted by Youssef221
Посмотреть сообщение
It's a samp bug, you should write the Animation code twice, Look at the Applyanimation codes to understand what do I mean:

pawn Код:
CMD:lock(playerid, params[])
{
    if(GetPVarInt(playerid, "LoggedIn") == 0) return SendClientMessage(playerid, COLOR_RED, "[ERROR]: You need to be logged in to use this command.");
    new string[128], Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    for(new i = 0; i<MAX_HOUSES; i++)
    {
        if(fexist(HousePath(i)))
        {
            if(IsPlayerInRangeOfPoint(playerid, 2, House[i][ExtPosX], House[i][ExtPosY], House[i][ExtPosZ]) || IsPlayerInRangeOfPoint(playerid, 2, House[i][IntPosX], House[i][IntPosY], House[i][IntPosZ]))
            {
                if(Player[playerid][HouseID] == House[i][hID])
                {
                    if(House[i][hLocked] == 0)
                    {
                        House[i][hLocked] = 1;
                        ApplyAnimation(playerid, "BD_FIRE", "wash_up", 4.0, 0, 0, 0, 0, 1);
                                            ApplyAnimation(playerid, "BD_FIRE", "wash_up", 4.0, 0, 0, 0, 0, 1);//If I repeated this code, it will work
                        format(string, sizeof(string), " * %s locks the door to the house.", GetName(playerid));
                        SetPlayerChatBubble(playerid, string, COLOR_LIGHTPURPLE, 10, 7000);
                        SendClientMessage(playerid, COLOR_LIGHTPURPLE, string);
                    }
                    else
                    {
                        House[i][hLocked] = 0;
                        ApplyAnimation(playerid, "BD_FIRE", "wash_up", 4.0, 0, 0, 0, 0, 1);
                                           vApplyAnimation(playerid, "BD_FIRE", "wash_up", 4.0, 0, 0, 0, 0, 1); // same here
                        format(string, sizeof(string), " * %s unlocks the door to the house.", GetName(playerid));
                        SetPlayerChatBubble(playerid, string, COLOR_LIGHTPURPLE, 10, 7000);
                        SendClientMessage(playerid, COLOR_LIGHTPURPLE, string);
                    }
                }
                else return SendClientMessage(playerid, COLOR_GREY, "You don't own this house.");
            }
        }
    }
    return 1;
}
This didn't work sadly, the skin just twitches slightly to show that it's trying to execute.
Reply
#6

Your code won't work because you are using 'if' instead of 'else if'. It would work like this:

pawn Код:
new variable = 0;
if(variable == 0) //Gets called because variable is equal to 0
{
    variable = 1; //variable is now equal to 1
}
else //Gets called because variable is no longer equal to 0
{
    variable = 0; //variable is equal to 0 again, nothing changes.
}
One solution is to use 'else if' rather than and 'if' statement. Or you can use the following code:
pawn Код:
CMD:lock(playerid, params[])
{
    if(!GetPVarInt(playerid, "LoggedIn")) return SendClientMessage(playerid, COLOR_RED, "[ERROR]: You need to be logged in to use this command.");
    for(new i = 0; i < MAX_HOUSES; i++)
    {
        if(!fexist(HousePath(i))) continue;
        if(IsPlayerInRangeOfPoint(playerid, 2, House[i][ExtPosX], House[i][ExtPosY], House[i][ExtPosZ]) || IsPlayerInRangeOfPoint(playerid, 2, House[i][IntPosX], House[i][IntPosY], House[i][IntPosZ]))
        {
            if(Player[playerid][HouseID] != House[i][hID]) return SendClientMessage(playerid, COLOR_GREY, "You don't own this house.");
            new string[60];
            ApplyAnimation(playerid, "BD_FIRE", "wash_up", 4.0, 0, 0, 0, 0, 1);
            format(string, sizeof(string), (House[i][hLocked]) ? (" * %s unlocks the door to the house.") : (" * %s locks the door to the house."), GetName(playerid));
            SetPlayerChatBubble(playerid, string, COLOR_LIGHTPURPLE, 10, 7000);
            SendClientMessage(playerid, COLOR_LIGHTPURPLE, string);
            House[i][hLocked] = (House[i][hLocked]) ? (0) : (1);
            break;
        }
    }
    return 1;
}
Reply
#7

Quote:
Originally Posted by Threshold
Посмотреть сообщение
Your code won't work because you are using 'if' instead of 'else if'. It would work like this:

pawn Код:
new variable = 0;
if(variable == 0) //Gets called because variable is equal to 0
{
    variable = 1; //variable is now equal to 1
}
else //Gets called because variable is no longer equal to 0
{
    variable = 0; //variable is equal to 0 again, nothing changes.
}
One solution is to use 'else if' rather than and 'if' statement. Or you can use the following code:
pawn Код:
CMD:lock(playerid, params[])
{
    if(!GetPVarInt(playerid, "LoggedIn")) return SendClientMessage(playerid, COLOR_RED, "[ERROR]: You need to be logged in to use this command.");
    for(new i = 0; i < MAX_HOUSES; i++)
    {
        if(!fexist(HousePath(i))) continue;
        if(IsPlayerInRangeOfPoint(playerid, 2, House[i][ExtPosX], House[i][ExtPosY], House[i][ExtPosZ]) || IsPlayerInRangeOfPoint(playerid, 2, House[i][IntPosX], House[i][IntPosY], House[i][IntPosZ]))
        {
            if(Player[playerid][HouseID] != House[i][hID]) return SendClientMessage(playerid, COLOR_GREY, "You don't own this house.");
            new string[60];
            ApplyAnimation(playerid, "BD_FIRE", "wash_up", 4.0, 0, 0, 0, 0, 1);
            format(string, sizeof(string), (House[i][hLocked]) ? (" * %s unlocks the door to the house.") : (" * %s locks the door to the house."), GetName(playerid));
            SetPlayerChatBubble(playerid, string, COLOR_LIGHTPURPLE, 10, 7000);
            SendClientMessage(playerid, COLOR_LIGHTPURPLE, string);
            House[i][hLocked] = (House[i][hLocked]) ? (0) : (1);
            break;
        }
    }
    return 1;
}
It's not that the command doesn't work, it works as intended functionally, but the animation won't play no matter what I try.
Reply
#8

No... the command will work, but not the way you want it to.

Try the code I gave you and see if anything changes.
Reply
#9

Quote:
Originally Posted by Threshold
Посмотреть сообщение
No... the command will work, but not the way you want it to.

Try the code I gave you and see if anything changes.
Still doesn't play
Reply
#10

Oh my god... I don't know how I missed it... you were putting the 'forcesync' parameter in place of the 'timer' parameter.
Код:
ApplyAnimation(playerid, animlib[], animname[], Float:fDelta, loop, lockx, locky, freeze, time, forcesync)
pawn Код:
ApplyAnimation(playerid, "BD_FIRE", "wash_up", 4.0, 0, 0, 0, 0, 0, 1);
Meaning time = 1, which means the animation would stop playing after 1 millisecond...

Use this:
pawn Код:
CMD:lock(playerid, params[])
{
    if(!GetPVarInt(playerid, "LoggedIn")) return SendClientMessage(playerid, COLOR_RED, "[ERROR]: You need to be logged in to use this command.");
    for(new i = 0; i < MAX_HOUSES; i++)
    {
        if(!fexist(HousePath(i))) continue;
        if(IsPlayerInRangeOfPoint(playerid, 2, House[i][ExtPosX], House[i][ExtPosY], House[i][ExtPosZ]) || IsPlayerInRangeOfPoint(playerid, 2, House[i][IntPosX], House[i][IntPosY], House[i][IntPosZ]))
        {
            if(Player[playerid][HouseID] != House[i][hID]) return SendClientMessage(playerid, COLOR_GREY, "You don't own this house.");
            new string[60];
            ApplyAnimation(playerid, "BD_FIRE", "wash_up", 4.0, 0, 0, 0, 0, 0, 1);
            format(string, sizeof(string), (House[i][hLocked]) ? (" * %s unlocks the door to the house.") : (" * %s locks the door to the house."), GetName(playerid));
            SetPlayerChatBubble(playerid, string, COLOR_LIGHTPURPLE, 10, 7000);
            SendClientMessage(playerid, COLOR_LIGHTPURPLE, string);
            House[i][hLocked] = (House[i][hLocked]) ? (0) : (1);
            break;
        }
    }
    return 1;
}
References:
https://sampwiki.blast.hk/wiki/ApplyAnimation
Reply
#11

Quote:
Originally Posted by Threshold
Посмотреть сообщение
Oh my god... I don't know how I missed it... you were putting the 'forcesync' parameter in place of the 'timer' parameter.
Код:
ApplyAnimation(playerid, animlib[], animname[], Float:fDelta, loop, lockx, locky, freeze, time, forcesync)
pawn Код:
ApplyAnimation(playerid, "BD_FIRE", "wash_up", 4.0, 0, 0, 0, 0, 0, 1);
Meaning time = 1, which means the animation would stop playing after 1 millisecond...

Use this:
pawn Код:
CMD:lock(playerid, params[])
{
    if(!GetPVarInt(playerid, "LoggedIn")) return SendClientMessage(playerid, COLOR_RED, "[ERROR]: You need to be logged in to use this command.");
    for(new i = 0; i < MAX_HOUSES; i++)
    {
        if(!fexist(HousePath(i))) continue;
        if(IsPlayerInRangeOfPoint(playerid, 2, House[i][ExtPosX], House[i][ExtPosY], House[i][ExtPosZ]) || IsPlayerInRangeOfPoint(playerid, 2, House[i][IntPosX], House[i][IntPosY], House[i][IntPosZ]))
        {
            if(Player[playerid][HouseID] != House[i][hID]) return SendClientMessage(playerid, COLOR_GREY, "You don't own this house.");
            new string[60];
            ApplyAnimation(playerid, "BD_FIRE", "wash_up", 4.0, 0, 0, 0, 0, 0, 1);
            format(string, sizeof(string), (House[i][hLocked]) ? (" * %s unlocks the door to the house.") : (" * %s locks the door to the house."), GetName(playerid));
            SetPlayerChatBubble(playerid, string, COLOR_LIGHTPURPLE, 10, 7000);
            SendClientMessage(playerid, COLOR_LIGHTPURPLE, string);
            House[i][hLocked] = (House[i][hLocked]) ? (0) : (1);
            break;
        }
    }
    return 1;
}
References:
https://sampwiki.blast.hk/wiki/ApplyAnimation
....I can't believe it either lol, thanks for the help :P
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)