EditDynamicObject Calls both OnPlayerEdits! -
grymtn - 23.09.2017
Hello im trying to write a furniture system, i thought i did everything right but this is confusing..
This will be a long thread, sorry in advance.
first my object load save create and all stocks:
Код:
stock createobject(model,Float:obx,Float:oby,Float:obz,Float:orbx,Float:orby,Float:orbz,obvir,obint)
{
new os[20];
format(os,sizeof(os),"Furnitures/%d.ini",ocnt);
dini_Create(os);
dini_IntSet(os,"mdl",model);
dini_IntSet(os,"oint",obint);
dini_IntSet(os,"ovir",obvir);
dini_FloatSet(os,"ox",obx);
dini_FloatSet(os,"oy",oby);
dini_FloatSet(os,"oz",obz);
dini_FloatSet(os,"orx",orbx);
dini_FloatSet(os,"ory",orby);
dini_FloatSet(os,"orz",orbz);
dini_IntSet(os,"id",ocnt);
ocnt++;
return 1;
}
stock saveobject(oids,model,Float:obx,Float:oby,Float:obz,Float:orbx,Float:orby,Float:orbz,obvir,obint)
{
new os[20];
format(os,sizeof(os),"Furnitures/%d.ini",oids);
dini_IntSet(os,"mdl",model);
dini_IntSet(os,"oint",obint);
dini_IntSet(os,"ovir",obvir);
dini_FloatSet(os,"ox",obx);
dini_FloatSet(os,"oy",oby);
dini_FloatSet(os,"oz",obz);
dini_FloatSet(os,"orx",orbx);
dini_FloatSet(os,"ory",orby);
dini_FloatSet(os,"orz",orbz);
return 1;
}
stock loadobject()
{
new ostr[40];
ocnt=1;
for(new g=1; g<MAX_OBJECT; g++)
{
format(ostr,sizeof(ostr),"Furnitures/%d.ini",g);
if(!dini_Exists(ostr))
{
for(new p=0;p<MAX_PLAYERS;p++)
{
Streamer_Update(p,-1);
}
return 0;
}
objinfo[g][oid]=dini_Int(ostr,"id");
objinfo[g][ox]=dini_Float(ostr,"ox");
objinfo[g][oy]=dini_Float(ostr,"oy");
objinfo[g][oz]=dini_Float(ostr,"oz");
objinfo[g][orx]=dini_Float(ostr,"orx");
objinfo[g][ory]=dini_Float(ostr,"ory");
objinfo[g][orz]=dini_Float(ostr,"orz");
objinfo[g][oint]=dini_Int(ostr,"oint");
objinfo[g][ovir]=dini_Int(ostr,"ovir");
objinfo[g][omdl]=dini_Int(ostr,"mdl");
objinfo[g][oid] = CreateDynamicObject(objinfo[g][omdl],objinfo[g][ox],objinfo[g][oy],objinfo[g][oz],objinfo[g][orx],objinfo[g][ory],objinfo[g][orz],objinfo[g][ovir],objinfo[g][oint],-1,50.0,50.0,-1,0);
ocnt++;
new ltext[100];
format(ltext,sizeof(ltext),"Loaded object id %d at %f,%f,%f",objinfo[g][omdl],objinfo[g][ox],objinfo[g][oy],objinfo[g][oz]);
printf(ltext);
}
return 1;
}
stock countobject()
{
new ostr[40];
ocnt=1;
for(new g=1; g<MAX_OBJECT; g++)
{
format(ostr,sizeof(ostr),"Furnitures/%d.ini",g);
if(!dini_Exists(ostr))
{
for(new p=0;p<MAX_PLAYERS;p++)
{
Streamer_Update(p,-1);
}
return 0;
}
ocnt++;
}
return 1;
}
now my buyfurniture and its ondialogresponse:
Код:
CMD:buyfurniture(playerid,params[])
{
if(inhouse[playerid]==0) return SCM(playerid,COLOR_RED,"You need to be in a house to do this command.");
new numara=0;
for(new say=0;say<MAX_OBJECTS;say++)
{
if(objinfo[say][ovir]==inhouse[playerid])
{
numara++;
}
}
if(numara >= 15) return SCM(playerid,COLOR_RED,"You have already reached maximum furnitures you can own in this house.(Max 15)");
ShowPlayerDialog(playerid,1400,DIALOG_STYLE_LIST,"Furnitures","Chairs\nBeds\nTables\nTvs\nCabinets\nMiscalenous","See","Cancel");
return 1;
}
///bla bla bla
case 0:
{
new Float:tpx,Float:tpy,Float:tpz;
GetPlayerPos(playerid,tpx,tpy,tpz);
countobject();
objinfo[ocnt][omdl]=2297;
objinfo[ocnt][orx]=0.0;
objinfo[ocnt][ory]=0.0;
objinfo[ocnt][orz]=0.0;
objinfo[ocnt][oid] = CreateObject(objinfo[ocnt][omdl],tpx+2,tpy,tpz,objinfo[ocnt][orx],objinfo[ocnt][ory],objinfo[ocnt][orz]);
EditObject(playerid,objinfo[ocnt][oid]);
}
now onplayereditobject:
Код:
public OnPlayerEditObject(playerid, playerobject, objectid, response, Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ)
{
new Float:oldX, Float:oldY, Float:oldZ,
Float:oldRotX, Float:oldRotY, Float:oldRotZ;
GetObjectPos(objectid, oldX, oldY, oldZ);
GetObjectRot(objectid, oldRotX, oldRotY, oldRotZ);
new Float:OX, Float:OY, Float:OZ, Float:ORX, Float:ORY, Float:ORZ, OVW, OINT;
if(!playerobject) // If this is a global object, move it for other players
{
if(!IsValidObject(objectid)) return;
MoveObject(objectid, fX, fY, fZ, 10.0, fRotX, fRotY, fRotZ);
}
if(response == EDIT_RESPONSE_FINAL)
{
new string[254];
OVW = GetPlayerVirtualWorld(playerid);
OINT = GetPlayerInterior(playerid);
GetObjectPos(objectid, OX, OY, OZ);
GetObjectRot(objectid, ORX, ORY, ORZ);
SendClientMessage(playerid, COLOR_BLUE, "Object Saved, Please add more if you wish");
format(string, sizeof(string), "Object model %i spawned at %f, %f, %f, with rotation %f, %f, %f,", objinfo[ocnt][omdl], OX, OY, OZ, ORX, ORY, ORZ);
SendClientMessage(playerid, 0xD8D8D8FF, string);
format(string, sizeof(string), "Object world %i interior id %i", OVW, OINT);
SendClientMessage(playerid, 0xD8D8D8FF, string);
DestroyObject(objectid);
objinfo[ocnt][oid]=CreateDynamicObject(objinfo[ocnt][omdl],OX,OY,OZ,ORX,ORY,ORZ,OVW,OINT);
Streamer_Update(playerid,-1);
new chcstr[200];
format(chcstr,sizeof(chcstr),"Furnitures/%d.ini",ocnt);
if(!dini_Exists(chcstr))
{
createobject(objinfo[ocnt][omdl],OX,OY,OZ,ORX,ORY,ORZ,OVW,OINT);
}
else
{
saveobject(objinfo[ocnt][oid],objinfo[ocnt][omdl],OX,OY,OZ,ORX,ORY,ORZ,OVW,OINT);
}
}
if(response == EDIT_RESPONSE_CANCEL)
{
//The player cancelled, so put the object back to it's old position
if(!playerobject) //Object is not a playerobject
{
SetObjectPos(objectid, oldX, oldY, oldZ);
SetObjectRot(objectid, oldRotX, oldRotY, oldRotZ);
}
else
{
SetPlayerObjectPos(playerid, objectid, oldX, oldY, oldZ);
SetPlayerObjectRot(playerid, objectid, oldRotX, oldRotY, oldRotZ);
}
}
}
until here. everthing works great. now my problem starts on editing the furnitures
Код:
CMD:editfurniture(playerid,params[])
{
if(inhouse[playerid]==0) return SCM(playerid,COLOR_RED,"You need to be in a house to do this command.");
else
{
new ih=inhouse[playerid];
if(strcmp(hInfo[ih][howner],GetName(playerid))==0)
{
new listtext[1000];
for(new q=1;q<MAX_OBJECT;q++)
{
if(objinfo[q][ovir]==ih)
{
format(listtext,sizeof(listtext),"%s\n%d\t%d",listtext,q,objinfo[q][omdl]);
}
}
ShowPlayerDialog(playerid,1440,DIALOG_STYLE_LIST,"Current Furnitures",listtext,"Ok","Cancel");
}
else
{
SCM(playerid,COLOR_RED,"You need to be in your house to do this command.");
}
}
return 1;
}
ONDIALOG RESPONSE PART:
case 0:
{
if(inhouse[playerid]==0) return SCM(playerid,COLOR_RED,"You need to be in a house to do this command.");
new numara=0;
for(new say=0;say<MAX_OBJECTS;say++)
{
if(objinfo[say][ovir]==inhouse[playerid])
{
numara++;
if(numara==1)
{
ocnt=say;
EditDynamicObject(playerid,ocnt);
}
}
}
}
case 1:
{
if(inhouse[playerid]==0) return SCM(playerid,COLOR_RED,"You need to be in a house to do this command.");
new numara=0;
for(new say=0;say<MAX_OBJECTS;say++)
{
if(objinfo[say][ovir]==inhouse[playerid])
{
numara++;
if(numara==2)
{
ocnt=say;
EditDynamicObject(playerid,ocnt);
}
}
}
}
///blablabla goes on
OnPlayerEditDynamicObject:
Код:
public OnPlayerEditDynamicObject(playerid, objectid, response, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz)
{
new Float:oldX, Float:oldY, Float:oldZ,
Float:oldRotX, Float:oldRotY, Float:oldRotZ;
GetDynamicObjectPos(objectid, oldX, oldY, oldZ);
GetDynamicObjectRot(objectid, oldRotX, oldRotY, oldRotZ);
new Float:OX, Float:OY, Float:OZ, Float:ORX, Float:ORY, Float:ORZ, OVW, OINT;
if(response == EDIT_RESPONSE_FINAL)
{
new string[254];
OVW = GetPlayerVirtualWorld(playerid);
OINT = GetPlayerInterior(playerid);
GetDynamicObjectPos(objectid, OX, OY, OZ);
GetDynamicObjectRot(objectid, ORX, ORY, ORZ);
SendClientMessage(playerid, COLOR_BLUE, "Object Saved, Please add more if you wish");
format(string, sizeof(string), "Object model %i spawned at %f, %f, %f, with rotation %f, %f, %f,", objinfo[ocnt][omdl], OX, OY, OZ, ORX, ORY, ORZ);
SendClientMessage(playerid, 0xD8D8D8FF, string);
format(string, sizeof(string), "Object world %i interior id %i", OVW, OINT);
SendClientMessage(playerid, 0xD8D8D8FF, string);
DestroyDynamicObject(objectid);
objinfo[ocnt][oid]=CreateDynamicObject(objinfo[ocnt][omdl],OX,OY,OZ,ORX,ORY,ORZ,OVW,OINT);
Streamer_Update(playerid,-1);
new chcstr[200];
format(chcstr,sizeof(chcstr),"Furnitures/%d.ini",ocnt);
if(!dini_Exists(chcstr))
{
createobject(objinfo[ocnt][omdl],OX,OY,OZ,ORX,ORY,ORZ,OVW,OINT);
}
else
{
saveobject(objinfo[ocnt][oid],objinfo[ocnt][omdl],OX,OY,OZ,ORX,ORY,ORZ,OVW,OINT);
}
}
if(response == EDIT_RESPONSE_CANCEL)
{
SetPlayerObjectPos(playerid, objectid, oldX, oldY, oldZ);
SetPlayerObjectRot(playerid, objectid, oldRotX, oldRotY, oldRotZ);
}
}
when i edit furniture old furnitures despawn and the one i wanna edit spawns in old position(not even new position) and i recieve both OnPlayerEditObject and OnPlayerEditDynamicObject's SendClientMessages. and it doesnt change the save.
anybody can help ?
Re: EditDynamicObject Calls both OnPlayerEdits! -
grymtn - 24.09.2017
bump
Re: EditDynamicObject Calls both OnPlayerEdits! -
raydx - 24.09.2017
Why you are mixing createobject with createdynamicobject? Choose one.
Re: EditDynamicObject Calls both OnPlayerEdits! -
grymtn - 24.09.2017
on buying i create object then destroy object and create dynamic object there are more than one house that uses one interior i need to set virtual worlds
Re: EditDynamicObject Calls both OnPlayerEdits! -
raydx - 24.09.2017
Ok, nevermind.
So your problem is in OnPlayerEditDynamicObject, lines:
GetDynamicObjectPos(objectid, OX, OY, OZ);
GetDynamicObjectRot(objectid, ORX, ORY, ORZ);
It is taking the old position.
You have to use variables built in callback - OnPlayerEditDynamicObject(playerid, objectid, response,
Float, Float:y, Float:z, Float:rx, Float:ry, Float:rz)
for new position.
So, use x, y, z, rx, ry, rz instead of your ox, oy, oz etc.
Re: EditDynamicObject Calls both OnPlayerEdits! -
grymtn - 24.09.2017
OX doesnt mean OLDX it is OX in meaning of OBJECTX because i have different variable that named oldX if you mean that. it is shown in [/CODE/] blocks
Re: EditDynamicObject Calls both OnPlayerEdits! -
raydx - 24.09.2017
Name doesn't matter, you don't understand.
GetDynamicObjectPos(objectid, OX, OY, OZ); is not working while editing object, it is returning old position.
Fixed code:
Код:
public OnPlayerEditDynamicObject(playerid, objectid, response, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz)
{
new Float:oldX, Float:oldY, Float:oldZ,
Float:oldRotX, Float:oldRotY, Float:oldRotZ;
GetDynamicObjectPos(objectid, oldX, oldY, oldZ);
GetDynamicObjectRot(objectid, oldRotX, oldRotY, oldRotZ);
new OVW, OINT;
if(response == EDIT_RESPONSE_FINAL)
{
new string[254];
OVW = GetPlayerVirtualWorld(playerid);
OINT = GetPlayerInterior(playerid);
SendClientMessage(playerid, COLOR_BLUE, "Object Saved, Please add more if you wish");
format(string, sizeof(string), "Object model %i spawned at %f, %f, %f, with rotation %f, %f, %f,", objinfo[ocnt][omdl], x, y, z, rx, ry, rz);
SendClientMessage(playerid, 0xD8D8D8FF, string);
format(string, sizeof(string), "Object world %i interior id %i", OVW, OINT);
SendClientMessage(playerid, 0xD8D8D8FF, string);
DestroyDynamicObject(objectid);
objinfo[ocnt][oid]=CreateDynamicObject(objinfo[ocnt][omdl],x,y,z,rx,ry,rz,OVW,OINT);
Streamer_Update(playerid,-1);
new chcstr[200];
format(chcstr,sizeof(chcstr),"Furnitures/%d.ini",ocnt);
if(!dini_Exists(chcstr))
{
createobject(objinfo[ocnt][omdl],x,y,z,rx,ry,rz,OVW,OINT);
}
else
{
saveobject(objinfo[ocnt][oid],objinfo[ocnt][omdl],x,y,z,rx,ry,rz,OVW,OINT);
}
}
if(response == EDIT_RESPONSE_CANCEL)
{
SetPlayerObjectPos(playerid, objectid, oldX, oldY, oldZ);
SetPlayerObjectRot(playerid, objectid, oldRotX, oldRotY, oldRotZ);
}
}
Re: EditDynamicObject Calls both OnPlayerEdits! -
grymtn - 24.09.2017
ok now it works thanks a lot! forget about theother issue it was my picking the wrong object now it works like a charm