Guest User

Untitled

a guest
Apr 27th, 2014
631
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.53 KB | None | 0 0
  1. #include    <a_samp>
  2. #include    <a_mysql>
  3. #include    <zcmd>
  4. #include    <sscanf2>
  5.  
  6. #define     DB_SERVER       "127.0.0.1"
  7. #define     DB_USER         "root"
  8. #define     DB_DB           "samp"
  9. #define     DB_PASS         ""
  10.  
  11. #define     MAX_BUILDING        (100)
  12.  
  13. enum buildingEnum {
  14.     b_name[27],
  15.     Float:b_pos[3],
  16.     Float:b_i_pos[3],
  17.     b_interior,
  18.     b_virtuall
  19. };
  20.  
  21. new
  22.     dbHandle,
  23.     bInfo[MAX_BUILDING][buildingEnum];
  24.  
  25.  
  26. public OnGameModeInit()
  27. {
  28.     mysql_function_query(dbHandle,"SELECT * FROM building",false,"loadBuildings","");
  29.     return 1;
  30. }
  31.  
  32. COMMAND:addbuilding(playerid,params[])
  33. {
  34.     if(sscanf(params,"s[26]dd",params[0],params[1],params[2]))
  35.         return SendClientMessage(playerid,-1,"[Usage]: /addbuilding [building name] [building interior] [building virtual]");
  36.     new
  37.         gQuery[246],
  38.         Float:gPos[MAX_PLAYERS][3];
  39.     GetPlayerPos(playerid,gPos[playerid][0],gPos[playerid][1],gPos[playerid][2]);
  40.     format(gQuery,246,"INSERT INTO building (b_name,b_int,b_virtual,b_x,b_y,b_z,b_i_x,b_i_y,b_i_z) VALUES(%s,%d,%d,%f,%f,%f,0.0,0.0,0.0)",params[0],params[1],params[2],gPos[playerid][0],gPos[playerid][1],gPos[playerid][2]);
  41.     mysql_function_query(dbHandle,gQuery,246,"","");
  42.     new localString[246];
  43.     CreatePickup(1239,2,bInfo[playerid][b_pos][0],bInfo[playerid][b_pos][1],bInfo[playerid][b_pos][2]);
  44.     format(localString,128,"Building Name: %s",bInfo[playerid][b_name]);
  45.     Create3DTextLabel(localString, -1, 30.0, 40.0, 50.0, 40.0, 0, 0);
  46.     format(localString,124,"[Success]: you successufulli created a build, continnue fun game!");
  47.     SendClientMessage(playerid,-1,localString);
  48.     return 1;
  49. }
  50.  
  51. COMMAND:enter(playerid,params[])
  52. {
  53.     for(new i; i != MAX_BUILDING; i++)
  54.     {
  55.         if(!IsPlayerInRangeOfPoint(playerid,2.0,bInfo[i][b_pos][0],bInfo[i][b_pos][1],bInfo[i][b_pos][2])) continue;
  56.         SetPlayerPos(playerid,bInfo[i][b_i_pos][0],bInfo[i][b_i_pos][1],bInfo[i][b_i_pos][2]);
  57.         SetPlayerInterior(playerid,bInfo[i][b_interior]);
  58.         SetPlayerVirtualWorld(playerid,bInfo[i][b_virtuall]);
  59.     }
  60.     return 1;
  61. }
  62.  
  63. COMMAND:exit(playerid,params[])
  64. {
  65.     for(new i; i != MAX_BUILDING; i++)
  66.     {
  67.         if(!IsPlayerInRangeOfPoint(playerid,2.0,bInfo[i][b_i_pos][0],bInfo[i][b_i_pos][1],bInfo[i][b_i_pos][2])) continue;
  68.         SetPlayerPos(playerid,bInfo[i][b_pos][0],bInfo[i][b_pos][1],bInfo[i][b_pos][2]);
  69.         SetPlayerInterior(playerid,0);
  70.         SetPlayerVirtualWorld(playerid,0);
  71.     }
  72.     return 1;
  73. }
  74.  
  75. forward loadBuildings();
  76. public loadBuildings()
  77. {
  78.     for(new i; i != MAX_BUILDING; i++)
  79.     {
  80.         cache_get_field_content(0,"b_name",bInfo[i][b_name],dbHandle);
  81.         bInfo[i][b_pos][0] = cache_get_field_content_float(0,"b_x",dbHandle);
  82.         bInfo[i][b_pos][1] = cache_get_field_content_float(0,"b_y",dbHandle);
  83.         bInfo[i][b_pos][2] = cache_get_field_content_float(0,"b_z",dbHandle);
  84.         bInfo[i][b_i_pos][0] = cache_get_field_content_float(0,"b_i_x",dbHandle);
  85.         bInfo[i][b_i_pos][1] = cache_get_field_content_float(0,"b_i_y",dbHandle);
  86.         bInfo[i][b_i_pos][2] = cache_get_field_content_float(0,"b_i_z",dbHandle);
  87.         bInfo[i][b_interior] = cache_get_field_content_int(0,"b_int",dbHandle);
  88.         bInfo[i][b_virtuall] = cache_get_field_content_int(0,"b_virtual",dbHandle);
  89.     }
  90.     SetTimer("loadAllBuilding",2000,false);
  91.     return 1;
  92. }
  93.  
  94. forward loadAllBuilding();
  95. public loadAllBuilding()
  96. {
  97.     new localString[128];
  98.     for(new i; i != MAX_BUILDING; i++)
  99.     {
  100.         CreatePickup(1239,2,bInfo[i][b_pos][0],bInfo[i][b_pos][1],bInfo[i][b_pos][2]);
  101.         format(localString,128,"Building Name: %s",bInfo[i][b_name]);
  102.     }
  103.     Create3DTextLabel(localString, -1, 30.0, 40.0, 50.0, 40.0, 0, 0);
  104. }
Advertisement
Add Comment
Please, Sign In to add comment