16.04.2019, 20:25
I am creating a dynamic gate system and placing them works. Opening works and the automatic closing after x seconds also works.
Now when I instantly edit the gate after creating it, it is fine. But when I restart the server and the gates are loaded by the script, I can edit them, but after clicking save, it doesn't call OnPlayerEditDynamicObject. Then if I create a new gate next to it, I can still edit it and OnPlayerEditDynamicObject is getting called. Until server restart.
This is my code:
What is causing this? The object is there, I can edit it's position and it even saves it position after saving but OnPlayerEditDynamicObject is not getting called.
Now when I instantly edit the gate after creating it, it is fine. But when I restart the server and the gates are loaded by the script, I can edit them, but after clicking save, it doesn't call OnPlayerEditDynamicObject. Then if I create a new gate next to it, I can still edit it and OnPlayerEditDynamicObject is getting called. Until server restart.
This is my code:
PHP Code:
//Adding a gate:
ServerGates[id][GateObject] = CreateDynamicObject(ServerGates[id][GateModel], ServerGates[id][GatePosX]-1.0, ServerGates[id][GatePosY]-1.0, ServerGates[id][GatePosZ], ServerGates[id][GateRotX], ServerGates[id][GateRotY], ServerGates[id][GateRotZ]);
EditDynamicObject(playerid, ServerGates[id][GateObject]);
//Editing a gate uses this line
EditDynamicObject(playerid, ServerGates[id][GateObject]);
//Loading gates
LoadServerGates()
{
new DBResult:LOAD_GATES_RESULTS;
new szQuery[256], gatecount = 0;
for(new d = 0;d<MAX_GATES;d++)
{
new id = d;
format(szQuery, sizeof(szQuery), "SELECT * FROM `GATES` WHERE `ID` = '%d'", id);
LOAD_GATES_RESULTS = db_query(ZARP_DATABASE, szQuery);
if(db_num_rows(LOAD_GATES_RESULTS))
{
ServerGates[id][GateWorld] = db_get_field_assoc_int(LOAD_GATES_RESULTS, "WORLD");
ServerGates[id][GateInterior] = db_get_field_assoc_int(LOAD_GATES_RESULTS, "INTERIOR");
ServerGates[id][GateModel] = db_get_field_assoc_int(LOAD_GATES_RESULTS, "MODELID");
ServerGates[id][GatePosX] = db_get_field_assoc_float(LOAD_GATES_RESULTS, "POSX");
ServerGates[id][GatePosY] = db_get_field_assoc_float(LOAD_GATES_RESULTS, "POSY");
ServerGates[id][GatePosZ] = db_get_field_assoc_float(LOAD_GATES_RESULTS, "POSZ");
ServerGates[id][GateRotX] = db_get_field_assoc_float(LOAD_GATES_RESULTS, "ROTX");
ServerGates[id][GateRotY] = db_get_field_assoc_float(LOAD_GATES_RESULTS, "ROTY");
ServerGates[id][GateRotZ] = db_get_field_assoc_float(LOAD_GATES_RESULTS, "ROTZ");
ServerGates[id][GateOPosX] = db_get_field_assoc_float(LOAD_GATES_RESULTS, "OPOSX");
ServerGates[id][GateOPosY] = db_get_field_assoc_float(LOAD_GATES_RESULTS, "OPOSY");
ServerGates[id][GateOPosZ] = db_get_field_assoc_float(LOAD_GATES_RESULTS, "OPOSZ");
ServerGates[id][GateORotX] = db_get_field_assoc_float(LOAD_GATES_RESULTS, "OROTX");
ServerGates[id][GateORotY] = db_get_field_assoc_float(LOAD_GATES_RESULTS, "OROTY");
ServerGates[id][GateORotZ] = db_get_field_assoc_float(LOAD_GATES_RESULTS, "OROTZ");
ServerGates[id][GateObject] = CreateDynamicObject(ServerGates[id][GateModel], ServerGates[id][GatePosX], ServerGates[id][GatePosY], ServerGates[id][GatePosZ], ServerGates[id][GateRotX], ServerGates[id][GateRotY], ServerGates[id][GateRotZ]);
gatecount++;
}
}
printf("Gates loaded: %d out of %d", gatecount, MAX_GATES);
db_free_result(LOAD_GATES_RESULTS);
return 1;
}