YSI:Using Objects

From SA-MP Wiki

Jump to: navigation, search

Creation

The YSI object system is very similar to the default SA:MP object system, it just supports more objects. In the normal system if you wanted to create an object you would do:

CreateObject(model, x, y, z, rx, ry, rz);

This is VERY similar to what you do in YSI:

CreateDynamicObject(model, x, y, z, rx, ry, rz);

Simple as, all you need to do to convert your code is add the word "Dynamic", which is dead easy with the find and replace feature.

In SA:MP if you want to create an object for just one player you would do:

CreatePlayerObject(playerid, model, x, y, z, rx, ry, rz);

Again, this is VERY similar in YSI, just add "Dynamic" again and you're done:

CreatePlayerDynamicObject(playerid, model, x, y, z, rx, ry, rz);

One thing SA:MP doesn't provide by default is support for objects only appearing in certain virtual worlds, this is achieved in YSI with:

CreateVWDynamicObject(world, model, x, y, z, rx, ry, rz);

Again, a very simple function.

Note: You don't have to put the rotation if they're all 0.0:

CreateDynamicObject(model, x, y, z);

These functions will return the objectid, this is used to access the object from other functions and is the parameter in OnDynamicObjectMoved:

new
    objectid = CreateDynamicObject(1337, 10.0, 10.0, 10.0);

That will create a wheely bin near the center of San Andreas (in the area known as the GTAHost farm).

Movement

Now we've covered creating your object lets move it about. This is again very similar to the default ways of doing things, to set an object's position in SA:MP you would use SetObjectPos, in YSI you use SetDynamicObjectPos with exactly the same parameters as SetObjectPos:

SetDynamicObjectPos(objectid, x, y, z);

Same for the new versions of GetObjectPos, SetObjectRot and GetObjectRot:

GetDynamicObjectPos(objectid, x, y, z);
SetDynamicObjectRot(objectid, rx, ry, rz);
GetDynamicObjectRot(objectid, rx, ry, rz);

There are also movement functions, these operate exactly the same as the normal versions but will still work even if no-one can see the object. This also has a new callback: OnDynamicObjectMoved, this is exactly the same as OnObjectMoved (which you now shouldn't use) but is called even when an object no-one can see reaches it's destination. There is no OnPlayerObjectMoved equivalent because of the way objects are handled for individuals, they all use the same callback.

public OnDynamicObjectMoved(objectid)
{
    printf("Object %d moved", objectid);
	return 1;
}
Personal tools
Navigation
Toolbox