OnPlayerEditObject

From SA-MP Wiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 16:27, 27 May 2015
Pottus (Talk | contribs)

← Previous diff
Current revision
OstGot (Talk | contribs)

Line 17: Line 17:
{{Param|Float:fRotZ|The Z rotation for the object that was edited}} {{Param|Float:fRotZ|The Z rotation for the object that was edited}}
-{{NoReturnCallback}}+{{Returns|
 +* '''1''' - Will prevent other scripts from receiving this callback.
 +* '''0''' - Indicates that this callback will be passed to the next script.
 +* It is always called first in filterscripts.}}
{{Warning|When using 'EDIT_RESPONSE_UPDATE' be aware that this callback will not be called when releasing an edit in progress resulting in the last update of 'EDIT_RESPONSE_UPDATE' being out of sync of the objects current position.}} {{Warning|When using 'EDIT_RESPONSE_UPDATE' be aware that this callback will not be called when releasing an edit in progress resulting in the last update of 'EDIT_RESPONSE_UPDATE' being out of sync of the objects current position.}}
 +{{Example}}
<pawn> <pawn>
public OnPlayerEditObject(playerid, playerobject, objectid, response, Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ) public OnPlayerEditObject(playerid, playerobject, objectid, response, Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ)
Line 31: Line 35:
if(!IsValidObject(objectid)) return 1; if(!IsValidObject(objectid)) return 1;
SetObjectPos(objectid, fX, fY, fZ); SetObjectPos(objectid, fX, fY, fZ);
- SetObjectRot(objectid, fRotX, fRotY, fRotZ);+ SetObjectRot(objectid, fRotX, fRotY, fRotZ);
} }

Current revision



OnPlayerEditObject was added in SA-MP 0.3e This callback was added in SA-MP 0.3e and will not work in earlier versions!


Description:

This callback is called when a player finishes editing an object (EditObject/EditPlayerObject).


Parameters:
(playerid, playerobject, objectid, response, Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ)
playeridThe ID of the player that edited an object
playerobject0 if it is a global object or 1 if it is a playerobject.
objectidThe ID of the edited object
responseThe type of response
Float:fXThe X offset for the object that was edited
Float:fYThe Y offset for the object that was edited
Float:fZThe Z offset for the object that was edited
Float:fRotXThe X rotation for the object that was edited
Float:fRotYThe Y rotation for the object that was edited
Float:fRotZThe Z rotation for the object that was edited


Return Values:

  • 1 - Will prevent other scripts from receiving this callback.
  • 0 - Indicates that this callback will be passed to the next script.
  • It is always called first in filterscripts.


Image:32px-Circle-style-warning.png

Warning

When using 'EDIT_RESPONSE_UPDATE' be aware that this callback will not be called when releasing an edit in progress resulting in the last update of 'EDIT_RESPONSE_UPDATE' being out of sync of the objects current position.


Example Usage:

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);
	if(!playerobject) // If this is a global object, sync the position for other players
	{
	    if(!IsValidObject(objectid)) return 1;
	    SetObjectPos(objectid, fX, fY, fZ);		          
	    SetObjectRot(objectid, fRotX, fRotY, fRotZ);
	}
 
	if(response == EDIT_RESPONSE_FINAL)
	{
		// The player clicked on the save icon
		// Do anything here to save the updated object position (and rotation)
	}
 
	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);
		}
	}
}


Related Functions

The following functions might be useful, as they're related to this callback in one way or another.

Personal tools
In other languages