20.02.2019, 13:18
How can I update a record if the slot and boneid already exist (for one player)?
At the moment he is constantly adding and not updating.
Table structure:
https://forum.sa-mp.com/showpost.php...postcount=4606 (when I add UNIQUE index on boneid and slot, data don't added)
At the moment he is constantly adding and not updating.
PHP код:
for(new i; i < MAX_PLAYER_ATTACHED_OBJECTS; i++){
if(IsPlayerAttachedObjectSlotUsed(playerid, i)){
if(i != AOP[playerid][i][ao_slot]){
format(query, sizeof(query), "INSERT INTO `"MYSQL_PREFIX"aop` (pid, modelid, slot, boneid, fOffsetX, fOffsetY, fOffsetZ, fRotX, fRotY, fRotZ, fScaleX, fScaleY, fScaleZ) VALUES('%i', '%i', '%i', '%i', '%f', '%f', '%f', '%f', '%f', '%f', '%f', '%f', '%f');",
Player[playerid][PID], AOP[playerid][i][ao_model], i, AOP[playerid][i][ao_bone], AOP[playerid][i][ao_x], AOP[playerid][i][ao_y], AOP[playerid][i][ao_z], AOP[playerid][i][ao_rx],
AOP[playerid][i][ao_ry], AOP[playerid][i][ao_rz], AOP[playerid][i][ao_sx], AOP[playerid][i][ao_sy], AOP[playerid][i][ao_sz]);
SendClientMessage(playerid, -1, "[debug] Added");
} else {
format(query, sizeof(query), "UPDATE `"MYSQL_PREFIX"aop` SET modelid = '%i', slot = '%i', fOffsetX = '%f', fOffsetY = '%f', fOffsetZ = '%f', fRotX = '%f', fRotY = '%f', fRotZ = '%f', fScaleX = '%f', fScaleY = '%f', fScaleZ = '%f' WHERE boneid = '%i' AND pid = '%i'",
AOP[playerid][i][ao_model], i, AOP[playerid][i][ao_x], AOP[playerid][i][ao_y], AOP[playerid][i][ao_z], AOP[playerid][i][ao_rx],
AOP[playerid][i][ao_ry], AOP[playerid][i][ao_rz], AOP[playerid][i][ao_sx], AOP[playerid][i][ao_sy], AOP[playerid][i][ao_sz], AOP[playerid][i][ao_bone], Player[playerid][PID]);
SendClientMessage(playerid, -1, "[debug] Updated");
}
mysql_query(query);
mysql_free_result();
}
}
// AOP - AttachedObjectPlayer
https://forum.sa-mp.com/showpost.php...postcount=4606 (when I add UNIQUE index on boneid and slot, data don't added)