SA-MP Forums Archive
Random Animation - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Random Animation (/showthread.php?tid=628261)



Random Animation - aoky - 08.02.2017

Is there anyone to make it so any player that is spawned in will do an animation of my choice? I'm new to scripting and looking to learn. Basically, I want this:

Random player does the animation: CS_DEAD_GUY at any random time or w/e. I will rep you for the help!


Re: Random Animation - Abagail - 08.02.2017

If you're using foreach, you can use the Iter_Random function to get a random player ID. Example:
pawn Код:
ApplyAnimation(Iter_Random(Player), "WUZI", "CS_Dead_Guy", 4.1, 1, 0, 0, 0, 1, 1);



Re: Random Animation - aoky - 08.02.2017

Hi, thanks for the reply. I did that but now I get these errors:.
Quote:

C:\Users\Aoky\Desktop\Stuff\Server\pawno\include\Y SI\..\YSI_Data\..\YSI_Internal\..\YSI_Core\y_utils .inc(254) : warning 202: number of arguments does not match definition
C:\Users\Aoky\Desktop\Stuff\Server\pawno\include\Y SI\..\YSI_Data\..\YSI_Internal\..\YSI_Core\y_utils .inc(267) : error 025: function heading differs from prototype
C:\Users\Aoky\Desktop\dildo.pwn(6 : warning 209: function "ScriptInit_OnGameModeInit" should return a value
C:\Users\Aoky\Desktop\dildo.pwn(395) : error 021: symbol already defined: "ApplyAnimation"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


2 Errors.




Re: Random Animation - aoky - 08.02.2017

Is there anyway to do this without foreach?


Re: Random Animation - Abagail - 08.02.2017

Quote:
Originally Posted by aoky
Посмотреть сообщение
Is there anyway to do this without foreach?
It's possible without foreach, however is less optimized. This might work, I haven't tested it though.
pawn Код:
new RandomPlayer = INVALID_PLAYER_ID, TempIndex;
while(RandomPlayer == INVALID_PLAYER_ID)
{
    TempIndex = random(GetPlayerPoolSize() + 1);
    if(TempIndex != INVALID_PLAYER_ID)
        RandomPlayer = TempIndex;
}
This continues the code block until a random player has been selected.


Re: Random Animation - aoky - 08.02.2017

So I do this:
Quote:

new RandomPlayer = INVALID_PLAYER_ID, TempIndex;
while(RandomPlayer == INVALID_PLAYER_ID)
{
TempIndex = random(GetPlayerPoolSize() + 1);
if(TempIndex != INVALID_PLAYER_ID)
RandomPlayer = TempIndex;
ApplyAnimation(playerid, "WUZI", "CS_Dead_Guy", 4.1, 1, 0, 0, 0, 1, 1);
}




Re: Random Animation - Abagail - 08.02.2017

Not nessacarily like that, you could do something like this:
pawn Код:
new RandomPlayer = INVALID_PLAYER_ID, TempIndex;
while(RandomPlayer == INVALID_PLAYER_ID)
{
    TempIndex = random(GetPlayerPoolSize() + 1);
    if(TempIndex != INVALID_PLAYER_ID)
        RandomPlayer = TempIndex;
}

ApplyAnimation(RandomPlayer, "WUZI", "CS_Dead_Guy", 4.1, 1, 0, 0, 0, 1, 1);
Alternatively, you could just do this with foreach if you want more optimization:
pawn Код:
ApplyAnimation(Iter_Random(Player), "WUZI", "CS_Dead_Guy", 4.1, 1, 0, 0, 0, 1, 1);



Re: Random Animation - aoky - 08.02.2017

Hey, thanks.
Quote:

C:\Users\Aoky\Desktop\dildo.pwn(411) : error 010: invalid function or declaration
C:\Users\Aoky\Desktop\dildo.pwn(414) : error 010: invalid function or declaration
C:\Users\Aoky\Desktop\dildo.pwn(41 : warning 203: symbol is never used: "RandomPlayer"
C:\Users\Aoky\Desktop\dildo.pwn(41 : warning 203: symbol is never used: "TempIndex"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


2 Errors.

I get 2 errors now.


Re: Random Animation - Abagail - 08.02.2017

What's line 411?


Re: Random Animation - aoky - 08.02.2017

while(RandomPlayer == INVALID_PLAYER_ID)