BUG /DRAG COMMAND -
AlfaSufaIndo - 13.06.2018
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:dX, Float:dY, Float:dZ;
SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(Drag[ID]));
SetPlayerInterior(playerid, GetPlayerInterior(Drag[ID]));
GetPlayerPos(Drag[ID], dX, dY, dZ);
SetPlayerPos(playerid, dX+1, dY, dZ);
}
else
{
Drag[ID] = -1;
format(string, sizeof(string), "{B0C4DE}DRAGINFO: {FFFFFF}Player yang menyeretmu ({00FF00}%s{FFFFFF}) telah keluar dari server! Kamu tidak lagi di seret.", GetPlayerNameEx(playerid));
SendClientMessage(playerid, COLOR_WHITE, string);
}
}
return 1;
}
CMD:drag(playerid, params[])
{
new ID, string[26+MAX_PLAYER_NAME], string2[20+MAX_PLAYER_NAME];
if(sscanf(params, "u", ID)) return SendClientMessage(playerid, COLOR_WHITE, "CMD:/drag [playerid] NOTE: /undrag [playerid] untuk berhenti menyeret player.");
if(ID == playerid) return SendClientMessage(playerid, COLOR_WHITE, "Kamu tidak bisa menyeret dirimu sendiri!");
if(IsPlayerConnected(ID))
{
if(Drag[ID] == 1)
{
SendClientMessage(playerid, COLOR_WHITE, "Player tersebut telah kamu seret!");
}
if(GetDistanceBetweenPlayers(playerid, ID) > 2)
{
SendClientMessage(playerid, COLOR_WHITE, "Kalian terlalu jauh!" );
return 1;
}
if(GetPVarInt(ID, "Injured") == 1)
{
format(string, sizeof(string), "You are being dragged by %s.", RemoveUnderScore(playerid));
format(string2, sizeof(string2), " You are dragging %s.", RemoveUnderScore(ID));
SCM(playerid, COLOR_PURPLE, string2);
SCM(ID, COLOR_PURPLE, string);
TogglePlayerControllable(ID, 0);
ApplyAnimation(ID, "ped", "KO_skid_front", 4.0, 1, 1, 1, 1, 0, 1);
Drag[ID] = playerid;
}
else return SendClientMessage(playerid, COLOR_WHITE, "Player itu tidak Injured / Terluka");
}
else return SendClientMessageEx(playerid, COLOR_WHITE, "Player tidak bisa ditemukan.");
return 1;
}
CMD:undrag(playerid, params[])
{
new ID;
if(sscanf(params, "u", ID)) return SendClientMessage(playerid, COLOR_WHITE, "CMD: /undrag [playerid]");
if(ID == playerid) return SendClientMessage(playerid, COLOR_WHITE, "Kamu tidak bisa menggunakan perintah ini kepada dirimu sendiri!");
if(IsPlayerConnected(ID))
{
if(Drag[ID] = 0)
{
SendClientMessage(playerid, COLOR_WHITE, "Player tersebut tidak sedang kamu seret");
}
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i) && Drag[i] == playerid)
{
TogglePlayerControllable(i, 1);
ApplyAnimation(i, "PED", "BIKE_fall_off", 4.1, 0, 1, 1, 1, 0, 1);
SCM(playerid, COLOR_PURPLE, "You have stopped drag your target.");
SCM(i, COLOR_PURPLE, "You aren't being dragged anymore.");
Drag[i] = -1;
ClearAnimations(playerid);
}
}
}
else return SendClientMessage(playerid, COLOR_WHITE, "Player tidak bisa ditemukan!");
return 1;
}
Re: BUG /DRAG COMMAND -
Sew_Sumi - 13.06.2018
Код:
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.
Re: BUG /DRAG COMMAND -
AlfaSufaIndo - 13.06.2018
SOLVED
Re: BUG /DRAG COMMAND -
Sew_Sumi - 13.06.2018
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.