Advertisement
Guest User

ObjectFunctions (c) by Kaliber

a guest
Mar 3rd, 2015
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.25 KB | None | 0 0
  1. /* SA-MP Include Objects in VirtualWorlds
  2.  *
  3.  * (c) by Kaliber, 2013
  4.  *
  5.  * Version 1.0
  6.  */
  7. #if !defined _samp_included
  8.     #include <a_samp>
  9. #endif
  10. #if defined _objects_worlds
  11.     #endinput
  12. #endif
  13. #define _objects_worlds 1
  14. #define INVALID_REQU 0
  15. #define INVALID_PARAM -1
  16. forward Stream_OnPlayerConnect(playerid);
  17. native Stream__CreateObject(modelid,Float:X,Float:Y,Float:Z,Float:rX,Float:rY,Float:rZ,Float:DrawDistance)=CreateObject;
  18. native Stream__IsValidObject(objectid)=IsValidObject;
  19. native Stream__IsObjectMoving(objectid)=IsObjectMoving;
  20. native Stream__SetObjectPos(objectid,Float:X,Float:Y,Float:Z)=SetObjectPos;
  21. native Stream__SetObjectRot(objectid,Float:rX,Float:rY,Float:rZ)=SetObjectRot;
  22. native Stream__GetObjectRot(objectid,&Float:rX,&Float:rY,&Float:rZ)=GetObjectRot;
  23. native Stream__GetObjectPos(objectid,&Float:X,&Float:Y,&Float:Z)=GetObjectPos;
  24. native Stream__StopObject(objectid)=StopObject;
  25. native Stream__AttachObjectToPlayer(objectid,playerid,Float:OffsetX,Float:OffsetY,Float:OffsetZ,Float:rX,Float:rY,Float:rZ)=AttachObjectToPlayer;
  26. native Stream__AttachObjectToVehicle(objectid,vehicleid,Float:OffsetX,Float:OffsetY,Float:OffsetZ,Float:RotX,Float:RotY,Float:RotZ)=AttachObjectToVehicle;
  27. native Stream__SetObjectMaterialText(objectid, text[], materialindex = 0, materialsize = OBJECT_MATERIAL_SIZE_256x128, fontface[] = "Arial", fontsize = 24, bold = 1, fontcolor = 0xFFFFFFFF, backcolor = 0, textalignment = 0)=SetObjectMaterialText;
  28. native Stream__SetObjectMaterial(objectid, materialindex, modelid, txdname[], texturename[], materialcolor)=SetObjectMaterial;
  29. native Stream__SetPlayerVirtualWorld(playerid, worldid)=SetPlayerVirtualWorld;
  30. native Stream__SetPlayerInterior(playerid, intid)=SetPlayerInterior;
  31. native Stream__MoveObject(objectid,Float:X,Float:Y,Float:Z,Float:Speed,Float:RotX,Float:RotY,Float:RotZ)=MoveObject;
  32. native Stream__DestroyObject(objectid)=DestroyObject;
  33. #define A:: e_F_
  34. enum A::ENUM{ A::model,A::int,Float:A::x,Float:A::y,Float:A::z,Float:A::rx,Float:A::ry,Float:A::rz,Float:A::dis,A::world };
  35. static obj[MAX_OBJECTS][A::ENUM],id,bool:buffer[MAX_PLAYERS][MAX_OBJECTS];
  36. stock Stream_SetObjectMaterial(objectid, materialindex, modelid, txdname[], texturename[], materialcolor) {
  37.     for(new i; i<MAX_PLAYERS; i++) {
  38.         if(!IsPlayerConnected(i)) continue;
  39.         if(!Stream_Check(i,objectid)) continue;
  40.         SetPlayerObjectMaterial(i, objectid+1, materialindex, modelid, txdname, texturename, materialcolor);
  41.     }
  42.     return 1;
  43. }
  44. #if defined _ALS_SetObjectMaterial
  45.     #undef SetObjectMaterial
  46. #else
  47.     #define _ALS_SetObjectMaterial
  48. #endif
  49. #define SetObjectMaterial Stream_SetObjectMaterial
  50. stock Stream_SetObjectMaterialText(objectid, text[], materialindex = 0, materialsize = OBJECT_MATERIAL_SIZE_256x128, fontface[] = "Arial", fontsize = 24, bold = 1, fontcolor = 0xFFFFFFFF, backcolor = 0, textalignment = 0) {
  51.     for(new i; i<MAX_PLAYERS; i++) {
  52.         if(!IsPlayerConnected(i)) continue;
  53.         if(!Stream_Check(i,objectid)) continue;
  54.         SetPlayerObjectMaterialText(i,objectid+1,text,materialindex,materialsize,fontface,fontsize,bold,fontcolor,backcolor,textalignment);
  55.     }
  56.     return 1;
  57. }
  58. #if defined _ALS_SetObjectMaterialText
  59.     #undef SetObjectMaterialText
  60. #else
  61.     #define _ALS_SetObjectMaterialText
  62. #endif
  63. #define SetObjectMaterialText Stream_SetObjectMaterialText
  64. stock Stream_AttachObjectToVehicle(objectid,vehicleid,Float:OffsetX,Float:OffsetY,Float:OffsetZ,Float:rX,Float:rY,Float:rZ) {
  65.     for(new i; i<MAX_PLAYERS; i++) {
  66.         if(!IsPlayerConnected(i)) continue;
  67.         if(!Stream_Check(i,objectid)) continue;
  68.         AttachPlayerObjectToVehicle(i,vehicleid,objectid+1,OffsetX,OffsetY,OffsetZ,rX,rY,rZ);
  69.     }
  70.     return 1;
  71. }
  72. #if defined _ALS_AttachObjectToVehicle
  73.     #undef AttachObjectToVehicle
  74. #else
  75.     #define _ALS_AttachObjectToVehicle
  76. #endif
  77. #define AttachObjectToVehicle Stream_AttachObjectToVehicle
  78.  
  79. stock Stream_AttachObjectToPlayer(objectid,playerid,Float:OffsetX,Float:OffsetY,Float:OffsetZ,Float:rX,Float:rY,Float:rZ) {
  80.     return AttachPlayerObjectToPlayer(playerid,objectid+1,playerid,OffsetX,OffsetY,OffsetZ,rX,rY,rZ);
  81. }
  82. #if defined _ALS_AttachObjectToPlayer
  83.     #undef AttachObjectToPlayer
  84. #else
  85.     #define _ALS_AttachObjectToPlayer
  86. #endif
  87. #define AttachObjectToPlayer Stream_AttachObjectToPlayer
  88. stock Stream_IsValidObject(objectid) {
  89.     if(!obj[objectid][A::model] || objectid > id) return INVALID_REQU;
  90.     return 1;
  91. }
  92. #if defined _ALS_IsValidObject
  93.     #undef IsValidObject
  94. #else
  95.     #define _ALS_IsValidObject
  96. #endif
  97. #define IsValidObject Stream_IsValidObject
  98. stock Stream_IsObjectMoving(objectid) {
  99.     for(new i; i<MAX_PLAYERS; i++) {
  100.         if(!IsPlayerConnected(i)) continue;
  101.         if(IsPlayerObjectMoving(i,objectid+1)) return 1;
  102.     }
  103.     return INVALID_REQU;
  104. }
  105. #if defined _ALS_IsObjectMoving
  106.     #undef IsObjectMoving
  107. #else
  108.     #define _ALS_IsObjectMoving
  109. #endif
  110. #define IsObjectMoving Stream_IsObjectMoving
  111. stock Stream_StopObject(objectid) {
  112.     for(new i; i<MAX_PLAYERS; i++) {
  113.         if(!IsPlayerConnected(i)) continue;
  114.         if(!Stream_Check(i,objectid)) continue;
  115.         StopPlayerObject(i,objectid+1);
  116.     }
  117.     return INVALID_REQU;
  118. }
  119. #if defined _ALS_StopObject
  120.     #undef StopObject
  121. #else
  122.     #define _ALS_StopObject
  123. #endif
  124. #define StopObject Stream_StopObject
  125. stock Stream_SetObjectPos(objectid,Float:X,Float:Y,Float:Z) {
  126.     for(new i; i<MAX_PLAYERS; i++) {
  127.         if(!IsPlayerConnected(i)) continue;
  128.         if(!Stream_Check(i,objectid)) continue;
  129.         SetPlayerObjectPos(i,objectid+1,X,Y,Z);
  130.     }
  131.     obj[objectid][A::x]=X,obj[objectid][A::y]=Y,obj[objectid][A::z]=Z;
  132.     return INVALID_REQU;
  133. }
  134. #if defined _ALS_SetObjectPos
  135.     #undef SetObjectPos
  136. #else
  137.     #define _ALS_SetObjectPos
  138. #endif
  139. #define SetObjectPos Stream_SetObjectPos
  140. stock Stream_SetObjectRot(objectid,Float:X,Float:Y,Float:Z) {
  141.     for(new i; i<MAX_PLAYERS; i++) {
  142.         if(!IsPlayerConnected(i)) continue;
  143.         if(!Stream_Check(i,objectid)) continue;
  144.         SetPlayerObjectRot(i,objectid+1,X,Y,Z);
  145.     }
  146.     obj[objectid][A::rx]=X,obj[objectid][A::ry]=Y,obj[objectid][A::rz]=Z;
  147.     return INVALID_REQU;
  148. }
  149. #if defined _ALS_SetObjectRot
  150.     #undef SetObjectRot
  151. #else
  152.     #define _ALS_SetObjectRot
  153. #endif
  154. #define SetObjectRot Stream_SetObjectRot
  155. stock Stream_GetObjectRot(o,&Float:X,&Float:Y,&Float:Z) {
  156.     return X=obj[o][A::rx],Y=obj[o][A::ry],Z=obj[o][A::rz];
  157. }
  158. #if defined _ALS_GetObjectRot
  159.     #undef GetObjectRot
  160. #else
  161.     #define _ALS_GetObjectRot
  162. #endif
  163. #define GetObjectRot Stream_GetObjectRot
  164. stock Stream_GetObjectPos(o,&Float:X,&Float:Y,&Float:Z) {
  165.     return X=obj[o][A::x],Y=obj[o][A::y],Z=obj[o][A::z];
  166. }
  167. #if defined _ALS_GetObjectPos
  168.     #undef GetObjectPos
  169. #else
  170.     #define _ALS_GetObjectPos
  171. #endif
  172. #define GetObjectPos Stream_GetObjectPos
  173. stock Stream_CreateObject(modelid,Float:X,Float:Y,Float:Z,Float:rX,Float:rY,Float:rZ,Float:DrawDistance=300.0) {
  174.     if(id==MAX_OBJECTS) return INVALID_PARAM;
  175.     obj[id][A::model]=modelid,obj[id][A::x]=X,obj[id][A::y]=Y,obj[id][A::z]=Z,obj[id][A::rx]=rX,obj[id][A::ry]=rY,obj[id][A::rz]=rZ,obj[id][A::dis]=DrawDistance;
  176.     obj[id][A::world]=999,obj[id][A::int]=999,id++;
  177.     return id-1;
  178. }
  179. #if defined _ALS_CreateObject
  180.     #undef CreateObject
  181. #else
  182.     #define _ALS_CreateObject
  183. #endif
  184. #define CreateObject Stream_CreateObject
  185. stock Stream_MoveObject(objectid,Float:X,Float:Y,Float:Z,Float:Speed,Float:RotX=0.0,Float:RotY=0.0,Float:RotZ=0.0) {
  186.     if(objectid > id) return INVALID_PARAM;
  187.     for(new i; i<MAX_PLAYERS; i++) {
  188.         if(!IsPlayerConnected(i)) continue;
  189.         if(!Stream_Check(i,objectid)) continue;
  190.         MovePlayerObject(i,objectid+1,Float:X,Float:Y,Float:Z,Float:Speed,Float:RotX,Float:RotY,Float:RotZ);
  191.     }
  192.     new q=objectid;
  193.     obj[q][A::x]=X,obj[q][A::y]=Y,obj[q][A::z]=Z;
  194.     if(RotX) obj[q][A::rx]=RotX;
  195.     if(RotY) obj[q][A::ry]=RotY;
  196.     if(RotZ) obj[q][A::rz]=RotZ;
  197.     return 1;
  198. }
  199. #if defined _ALS_MoveObject
  200.     #undef MoveObject
  201. #else
  202.     #define _ALS_MoveObject
  203. #endif
  204. #define MoveObject Stream_MoveObject
  205. stock Stream_DestroyObject(objectid) {
  206.     if(objectid > id) return INVALID_PARAM;
  207.     for(new i; i<MAX_PLAYERS; i++) {
  208.         if(!IsPlayerConnected(i)) continue;
  209.         if(!Stream_Check(i,objectid)) continue;
  210.         DestroyPlayerObject(i,objectid+1),buffer[i][objectid]=false;
  211.     }
  212.     return obj[objectid][A::model]=0,1;
  213. }
  214. #if defined _ALS_DestroyObject
  215.     #undef DestroyObject
  216. #else
  217.     #define _ALS_DestroyObject
  218. #endif
  219. #define DestroyObject Stream_DestroyObject
  220. stock Stream_SetPlayerVirtualWorld(playerid, worldid) {
  221.     new intid = GetPlayerInterior(playerid),i;
  222.     for(; i<id; i++) {
  223.         if(World_Check(i,worldid,intid)) {
  224.             if(buffer[playerid][i]) continue;
  225.             buffer[playerid][i]=true;
  226.             CreatePlayerObject(playerid,obj[i][A::model],obj[i][A::x],obj[i][A::y],obj[i][A::z],obj[i][A::rx],obj[i][A::ry],obj[i][A::rz],obj[i][A::dis]);
  227.         } else DestroyPlayerObject(playerid,i+1),buffer[playerid][i]=false;
  228.     }
  229.     return Stream__SetPlayerVirtualWorld(playerid, worldid);
  230. }
  231. #if defined _ALS_SetPlayerVirtualWorld
  232.     #undef SetPlayerVirtualWorld
  233. #else
  234.     #define _ALS_SetPlayerVirtualWorld
  235. #endif
  236. #define SetPlayerVirtualWorld Stream_SetPlayerVirtualWorld
  237. stock Stream_SetPlayerInterior(playerid, intid) {
  238.     new worldid = GetPlayerVirtualWorld(playerid),i;
  239.     for(; i<id; i++) {
  240.         if(World_Check(i,worldid,intid)) {
  241.             if(buffer[playerid][i]) continue;
  242.             buffer[playerid][i]=true;
  243.             CreatePlayerObject(playerid,obj[i][A::model],obj[i][A::x],obj[i][A::y],obj[i][A::z],obj[i][A::rx],obj[i][A::ry],obj[i][A::rz],obj[i][A::dis]);
  244.         } else DestroyPlayerObject(playerid,i+1),buffer[playerid][i]=false;
  245.     }
  246.     return Stream__SetPlayerInterior(playerid, intid);
  247. }
  248. #if defined _ALS_SetPlayerInterior
  249.     #undef SetPlayerInterior
  250. #else
  251.     #define _ALS_SetPlayerInterior
  252. #endif
  253. #define SetPlayerInterior Stream_SetPlayerInterior
  254. public OnPlayerConnect(playerid) {
  255.     for(new i; i<id; i++) {
  256.         if(!Stream_Check(playerid,i)) continue;
  257.         buffer[playerid][i]=true;
  258.         CreatePlayerObject(playerid,obj[i][A::model],obj[i][A::x],obj[i][A::y],obj[i][A::z],obj[i][A::rx],obj[i][A::ry],obj[i][A::rz],obj[i][A::dis]);
  259.     }
  260.     return 1;
  261. }
  262. #if defined _ALS_OnPlayerConnect
  263.     #undef OnPlayerConnect
  264. #else
  265.     #define _ALS_OnPlayerConnect
  266. #endif
  267. #define OnPlayerConnect Stream_OnPlayerConnect
  268. stock SetObjectVirtualWorld(object, worldid) {
  269.     if(object > id) return INVALID_PARAM;
  270.     return obj[object][A::world]=worldid;
  271. }
  272. stock GetObjectVirtualWorld(object) {
  273.     if(object > id) return INVALID_PARAM;
  274.     return obj[object][A::world];
  275. }
  276. stock SetObjectInterior(object, intid) {
  277.     if(object > id) return INVALID_PARAM;
  278.     return obj[object][A::int]=intid;
  279. }
  280. stock GetObjectInterior(object) {
  281.     if(object > id) return INVALID_PARAM;
  282.     return obj[object][A::int];
  283. }
  284. stock Stream_Check(i,q) {
  285.     if(!obj[q][A::model]) return 0;
  286.     if(obj[q][A::int] == 999 && obj[q][A::world] == 999) return 1;
  287.     if(obj[q][A::world] == GetPlayerVirtualWorld(i) && obj[q][A::int] == GetPlayerInterior(i) || obj[q][A::world] == GetPlayerVirtualWorld(i) && obj[q][A::int] == 999 || obj[q][A::world] == 999 && obj[q][A::int] == GetPlayerInterior(i)) return 1;
  288.     return 0;
  289. }
  290. stock World_Check(q,worldid,intid) {
  291.     if(!obj[q][A::model]) return 0;
  292.     if(obj[q][A::int] == 999 && obj[q][A::world] == 999) return 1;
  293.     if(obj[q][A::world] == worldid && obj[q][A::int] == intid || obj[q][A::world] == worldid && obj[q][A::int] == 999 || obj[q][A::world] == 999 && obj[q][A::int] == intid) return 1;
  294.     return 0;
  295. }
  296. #undef INVALID_PARAM
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement