BUG /DRAG COMMAND
#1

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 код:
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;

Reply
#2

Код:
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.
Reply
#3

SOLVED
Reply
#4

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)