20.02.2019, 14:25
The UNIQUE KEY must be on two columns together (pid, slot) and not one key for each one of them. This allows you to have unique pairing and use INSERT INTO .. ON DUPLICATE syntax which executes an INSERT query if no records found for the `pid` and `slot` values provided otherwise update what columns you want.
If a player only wants to replace the attached object to another boneid, you should pass the same slot so it will update the data for the already existed record.
If a player only wants to replace the attached object to another boneid, you should pass the same slot so it will update the data for the already existed record.
pawn Код:
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) \
ON DUPLICATE KEY \
UPDATE modelid=%i,boneid=%i,fOffsetX=%f,fOffsetY=%f,fOffsetZ=%f,fRotX=%f,fRotY=%f,fRotZ=%f,fScaleX=%f,fScaleY=%f,fScaleZ=%f \
WHERE pid=%i \
AND slot=%i",
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],
AOP[playerid][i][ao_model], 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], Player[playerid][PID], i);