SA-MP Forums Archive
Magic Wand fail - 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: Magic Wand fail (/showthread.php?tid=634072)



Magic Wand fail - ProBro - 12.05.2017

When I press ALT,It's supposed to stomp the player near me...

Ofcourse it does! but It ALSO STOMPS ME! :'v

I can't find the problem here,Can anyone help me?


PHP код:
public OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    if(
PRESSED(newkeys KEY_WALK))
    {
        if(
gettime() - Abilitys[playerid][SuperPower])return GameTextForPlayer(playerid,"~w~ Power Recharging!",1000,5);
        
ApplyAnimation(playerid,"ped","Shove_Partial",3.9,0,1,1,1,1,1);
        
SetPlayerAttachedObject(playerid,0,18683,6);
        
SetPlayerAttachedObject(playerid,1,18728,6);
        
SetPlayerAttachedObject(playerid,2,338,6);
        new 
Float:x,Float:y,Float:z,Float:Angle;
        
GetPlayerPos(playerid,Float:x,Float:y,Float:z);
        
GetPlayerFacingAngle(playerid,Float:Angle);
        
Abilitys[playerid][SuperPower] = gettime();
        for(new 
0MAX_PLAYERSi++)
        {
            if(
GetDistanceBetweenPlayers(playerid,i) < 6.0)
            {
                new 
Float:vec[4];
                
GetPlayerFacingAngle(i,Float:Angle);
                
GetPlayerVelocity(i,Float:x,Float:y,Float:z);
                
SetPlayerVelocity(i,Float:x+0.3,Float:y+0.3,Float:z+0.2);
                
SetPlayerFacingAngle(i,Float:Angle);
                
GetPlayerVelocity(i,vec[0],vec[1],vec[2]); GetPlayerFacingAngle(i,vec[3]);
            }
        }
    }
    return 
1;

Video on the bug

https://*********/E0-SsHDsGMg


Re: Magic Wand fail - Kane - 12.05.2017

Try removing the GetPlayerPos and FacingAngle from playerid and ony have it for the distance player.


Re: Magic Wand fail - ProBro - 12.05.2017

Quote:
Originally Posted by Arthur Kane
Посмотреть сообщение
Try removing the GetPlayerPos and FacingAngle from playerid and ony have it for the distance player.
tried
PHP код:
public OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    if(
PRESSED(newkeys KEY_WALK))
    {
        if(
gettime() - Abilitys[playerid][SuperPower])return GameTextForPlayer(playerid,"~w~ Power Recharging!",1000,5);
        
ApplyAnimation(playerid,"ped","Shove_Partial",3.9,0,1,1,1,1,1);
        
SetPlayerAttachedObject(playerid,0,18683,6);
        
SetPlayerAttachedObject(playerid,1,18728,6);
        
SetPlayerAttachedObject(playerid,2,338,6);
        new 
Float:x,Float:y,Float:z,Float:Angle;
        
Abilitys[playerid][SuperPower] = gettime();
        for(new 
0MAX_PLAYERSi++)
        {
            if(
GetDistanceBetweenPlayers(playerid,i) < 6.0)
            {
                new 
Float:vec[4];
                
GetPlayerVelocity(i,Float:x,Float:y,Float:z);
                
SetPlayerVelocity(i,Float:x+0.3,Float:y+0.3,Float:z+0.2);
                
GetPlayerVelocity(i,vec[0],vec[1],vec[2]); GetPlayerFacingAngle(i,vec[3]);
            }
        }
    }
    return 
1;

Still doesn't work.
It's the same


Re: Magic Wand fail - Antenastyle - 12.05.2017

Can you show us the GetDistanceBetweenPlayers?


Re: Magic Wand fail - DarkSkull - 13.05.2017

You're not checking if the loop is finding your playerid or not. This should fix it.

PHP код:
for(new 0MAX_PLAYERSi++)
{
    if(
i==playerid) continue;
    if(
GetDistanceBetweenPlayers(playerid,i) < 6.0)
    {
        new 
Float:vec[4];
        
GetPlayerFacingAngle(i,Float:Angle);
        
GetPlayerVelocity(i,Float:x,Float:y,Float:z);
        
SetPlayerVelocity(i,Float:x+0.3,Float:y+0.3,Float:z+0.2);
        
SetPlayerFacingAngle(i,Float:Angle);
        
GetPlayerVelocity(i,vec[0],vec[1],vec[2]); GetPlayerFacingAngle(i,vec[3]);
    }




Re: Magic Wand fail - Kubko - 13.05.2017

It is logical that your magic wand effect will apply to all players involved as you're checking distance between them inside the loop.

If you want to apply the effect only to the targets, you have to add extra check into your loop. Also using tags in function's parametres is actually not neccesary here.

Here's a code which should fix your bug:
PHP код:
for(new iMAX_PLAYERSi++)
{
    if(
!= playerid && GetDistanceBetweenPlayers(playeridi) < 6.0)
    {
        new
            
Float:vec[4]
        ;
        
GetPlayerVelocity(ixyz);
        
SetPlayerVelocity(i0.30.30.2);
        
GetPlayerVelocity(ivec[0], vec[1], vec[2]);
        
GetPlayerFacingAngle(ivec[3]);
    }

//Oh I didn't notice that the solution has already been posted above, my bad.


Re: Magic Wand fail - ProBro - 13.05.2017

Quote:
Originally Posted by DarkSkull
Посмотреть сообщение
You're not checking if the loop is finding your playerid or not. This should fix it.

PHP код:
for(new 0MAX_PLAYERSi++)
{
    if(
i==playerid) continue;
    if(
GetDistanceBetweenPlayers(playerid,i) < 6.0)
    {
        new 
Float:vec[4];
        
GetPlayerFacingAngle(i,Float:Angle);
        
GetPlayerVelocity(i,Float:x,Float:y,Float:z);
        
SetPlayerVelocity(i,Float:x+0.3,Float:y+0.3,Float:z+0.2);
        
SetPlayerFacingAngle(i,Float:Angle);
        
GetPlayerVelocity(i,vec[0],vec[1],vec[2]); GetPlayerFacingAngle(i,vec[3]);
    }

lemme try


Re: Magic Wand fail - ProBro - 13.05.2017

Fixed,Thanks ALL!