SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 13/06/2018, 04:02 PM   #1
AlfaSufaIndo
Big Clucker
 
Join Date: Oct 2016
Location: Jombang, East Java, Indonesia
Posts: 96
Reputation: 0
Default BUG /DRAG COMMAND

So i make a /drag and /undrag command and it's not working, there is no error. But when i drag other player, that player is not following me


PHP Code:
public OnPlayerUpdate(playerid)
{
    
//DRAG
    
new ID;
    if(
Drag[ID] != -1)
    {
        new 
string[128];
        if(
IsPlayerConnected(Drag[ID]))
        {
            new 
Float:dXFloat:dYFloat:dZ;
            
SetPlayerVirtualWorld(playeridGetPlayerVirtualWorld(Drag[ID]));
            
SetPlayerInterior(playeridGetPlayerInterior(Drag[ID]));
            
GetPlayerPos(Drag[ID], dXdYdZ);
            
SetPlayerPos(playeriddX+1dYdZ);
        }
        else
        {
            
Drag[ID] = -1;
            
format(stringsizeof(string), "{B0C4DE}DRAGINFO: {FFFFFF}Player yang menyeretmu ({00FF00}%s{FFFFFF}) telah keluar dari server! Kamu tidak lagi di seret."GetPlayerNameEx(playerid));
            
SendClientMessage(playeridCOLOR_WHITEstring);
        }
    }
    return 
1;
}

CMD:drag(playeridparams[])
{
    new 
IDstring[26+MAX_PLAYER_NAME], string2[20+MAX_PLAYER_NAME];
    if(
sscanf(params"u"ID)) return SendClientMessage(playeridCOLOR_WHITE"CMD:/drag [playerid] NOTE: /undrag [playerid] untuk berhenti menyeret player.");
    if(
ID == playerid) return SendClientMessage(playeridCOLOR_WHITE"Kamu tidak bisa menyeret dirimu sendiri!");
    if(
IsPlayerConnected(ID))
    {
        if(
Drag[ID] == 1)
        {
            
SendClientMessage(playeridCOLOR_WHITE"Player tersebut telah kamu seret!");
        }
        if(
GetDistanceBetweenPlayers(playeridID) > 2)
        {
            
SendClientMessage(playeridCOLOR_WHITE"Kalian terlalu jauh!" );
            return 
1;
        }
        if(
GetPVarInt(ID"Injured") == 1)
        {
            
format(stringsizeof(string), "You are being dragged by %s."RemoveUnderScore(playerid));
            
format(string2sizeof(string2), " You are dragging %s."RemoveUnderScore(ID));
            
SCM(playeridCOLOR_PURPLEstring2);
            
SCM(IDCOLOR_PURPLEstring);
            
TogglePlayerControllable(ID0);
            
ApplyAnimation(ID"ped""KO_skid_front"4.0111101);
            
Drag[ID] = playerid;
        }
        else return 
SendClientMessage(playeridCOLOR_WHITE"Player itu tidak Injured / Terluka");
    }
    else return 
SendClientMessageEx(playeridCOLOR_WHITE"Player tidak bisa ditemukan.");
    return 
1;
}

CMD:undrag(playeridparams[])
{
    new 
ID;
    if(
sscanf(params"u"ID)) return SendClientMessage(playeridCOLOR_WHITE"CMD: /undrag [playerid]");
    if(
ID == playerid) return SendClientMessage(playeridCOLOR_WHITE"Kamu tidak bisa menggunakan perintah ini kepada dirimu sendiri!");
    if(
IsPlayerConnected(ID))
    {
        if(
Drag[ID] = 0)
        {
            
SendClientMessage(playeridCOLOR_WHITE"Player tersebut tidak sedang kamu seret");
        }
        for(new 
0MAX_PLAYERSi++)
        {
            if(
IsPlayerConnected(i) && Drag[i] == playerid)
            {
                
TogglePlayerControllable(i1);
                
ApplyAnimation(i"PED""BIKE_fall_off"4.1011101);
                
SCM(playeridCOLOR_PURPLE"You have stopped drag your target.");
                
SCM(iCOLOR_PURPLE"You aren't being dragged anymore.");
                
Drag[i] = -1;
                
ClearAnimations(playerid);
            }
        }
    }
    else return 
SendClientMessage(playeridCOLOR_WHITE"Player tidak bisa ditemukan!");
    return 
1;

AlfaSufaIndo is offline   Reply With Quote
Old 13/06/2018, 04:16 PM   #2
Sew_Sumi
Banned
 
Join Date: Jun 2008
Location: Azerbaijan
Posts: 6,469
Reputation: 525
Default Re: BUG /DRAG COMMAND

Code:
public OnPlayerUpdate(playerid) 
{ 
    //DRAG 
    new ID; 
    if(Drag[ID] != -1)
This is a problem.

You likely meant to be using playerid, as ID is a fresh variable, and has no value, so the array will always reference ID, which will probably be 0.


Considering that within 4 lines I've already noticed a real issue with your code, it should be a given you're going to have to review your code and actually understand script.
Sew_Sumi is offline   Reply With Quote
Old 13/06/2018, 08:18 PM   #3
AlfaSufaIndo
Big Clucker
 
Join Date: Oct 2016
Location: Jombang, East Java, Indonesia
Posts: 96
Reputation: 0
Default Re: BUG /DRAG COMMAND

SOLVED
AlfaSufaIndo is offline   Reply With Quote
Old 13/06/2018, 10:45 PM   #4
Sew_Sumi
Banned
 
Join Date: Jun 2008
Location: Azerbaijan
Posts: 6,469
Reputation: 525
Default Re: BUG /DRAG COMMAND

Just beware, and check, that this hasn't happened elsewhere, and that because of this sort of error, it hasn't been picked up because you're using ID 0, and it just 'happened' to get the right ID for the scenario.

Also, OnPlayerUpdate is very much like OnPlayerKeystateChange, where if you've used these callbacks, you REALLY have to be CAUTIOUS with things such as condition checks(if statements, and case structures), especially considering both of these callbacks can fire at millisecond spacing.

TL:DR; Check over the rest of your code for similar situations.

Good to hear you got it working, but just don't assume it's completely fixed just because of this find.
Sew_Sumi is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need /drag command. UnKnownEgyptain Scripting Help 4 13/03/2015 11:25 PM
Drag Command Kindred Scripting Help 10 02/04/2014 08:13 PM
I need Drag and stop drag command Jizz Scripting Help 5 24/02/2014 12:08 PM
/drag command nickdadon Help Archive 0 30/01/2011 04:51 AM
Drag command kman Help Archive 1 21/10/2009 12:30 AM


All times are GMT. The time now is 05:44 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.