Advertisement
garfield

[FS]: Carregar posição do jogador

Dec 27th, 2012
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 1.94 KB | None | 0 0
  1. #include a_samp
  2.  
  3. new
  4.     bool: Salvou[ MAX_PLAYERS char]
  5. ;
  6.  
  7. public OnPlayerConnect(playerid){
  8.     return Salvou{playerid} = !true, !false;
  9. }
  10.  
  11. static stock Carregar(playerid){
  12.  
  13.     if(Salvou{playerid})
  14.         return SendClientMessage(playerid, -1, "Você não salvou sua posição!");
  15.        
  16.     static str[100],Nome[30],File: fil;
  17.     strcat(Nome, ".ips");
  18.     fil = fopen(Nome, io_read);
  19.     fread(fil, str);
  20.     SetPlayerPos(playerid, floatstr(getParam(str, 0, '|')), floatstr(getParam(str, 1, '|')), floatstr(getParam(str, 2, '|')));
  21.    
  22.    
  23.     return true;
  24. }
  25.  
  26.  
  27. static stock Salvar(playerid){
  28.  
  29.     if(Salvou{playerid})
  30.         return SendClientMessage(playerid, -1, "Você já salvou sua posição!");
  31.        
  32.        
  33.     static Float: Pos[3], str[100], File: fil, Nome[30];
  34.     strcat(Nome, ".ips");
  35.     GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
  36.     format(str, 100, "%f|%f|%f|", Pos[0], Pos[1], Pos[2]);
  37.     fil = fopen(Nome, io_write);
  38.     fwrite(fil, str);
  39.     fclose(fil);
  40.    
  41.     Salvou{playerid} = true;
  42.     return true;
  43. }
  44.  
  45.  
  46.  
  47. stock getParam(intstring[], parameter, delim){ //
  48.  
  49.     static
  50.         szStringOut[128],
  51.         Loop_Interator,
  52.         LastWorldSize,
  53.         String_Size,
  54.         Parameters
  55.     ;
  56.  
  57.     // Setting:
  58.     String_Size     = strlen(intstring);
  59.  
  60.     // Resetting:
  61.     szStringOut[0]  = EOS;
  62.     Loop_Interator  = 0 ;
  63.     LastWorldSize   = 0 ;
  64.     Parameters      = 0 ;
  65.  
  66.  
  67.     for ( ; Loop_Interator  !=  String_Size; ++Loop_Interator){
  68.  
  69.         if(intstring[Loop_Interator] == delim){
  70.             if(Parameters == parameter){
  71.                 strmid(szStringOut,  intstring,(parameter != 0 ? (LastWorldSize + 1) : (LastWorldSize)), Loop_Interator);
  72.                 break;
  73.             }
  74.             Parameters ++;
  75.             LastWorldSize = Loop_Interator;
  76.         }
  77.     }
  78.     return szStringOut;
  79. }
  80.  
  81.  
  82. public OnPlayerCommandText(playerid, cmdtext[]){
  83.  
  84.     if(!strcmp(cmdtext, "/salvar", true)){
  85.         Salvar(playerid);
  86.         return true;
  87.     }
  88.     if(!strcmp(cmdtext, "/carregar", true)){
  89.         Carregar(playerid);
  90.         return true;
  91.     }
  92.     return false;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement