Advertisement
Headache

[FS] Tirar y recoger dinero al suelo (strcmp)

Feb 14th, 2013
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.95 KB | None | 0 0
  1. /* Autor: DeadSkyTkb en SA-MP Forums; Jedashe en PawnoScripting */
  2.  
  3. #include <a_samp>
  4.  
  5. #define MAX_OBJDINERO 100 // El máximo de bolsas de dinero que pueden haber en el suelo.
  6. #define COLOR_VIOLETA 0xC2A2DAAA
  7. #define COLOR_ROJO 0xE60000FF
  8. #define COLOR_GRIS 0xAFAFAFAA
  9. // -----------------------------------------------------------------------------
  10. new Float:CoordsDinero[MAX_OBJDINERO][3];
  11. new TDinero[MAX_OBJDINERO];
  12. new DineroID[MAX_OBJDINERO][1];
  13. new BigEar[MAX_PLAYERS];
  14. // -----------------------------------------------------------------------------
  15. enum jInfo
  16. {
  17.     jDinero
  18. };
  19. new JugadorInfo[MAX_PLAYERS][jInfo];
  20. // -----------------------------------------------------------------------------
  21. public OnPlayerCommandText(playerid, cmdtext[])
  22. {
  23.     new cmd[256];
  24.     new tmp[256];
  25.     new idx;
  26.     cmd = strtok(cmdtext,idx);
  27.    
  28.     if(strcmp(cmd, "/tirardinero", true) == 0 || strcmp(cmd, "/tdinero", true) == 0)
  29.     {
  30.         if(JugadorInfo[playerid][jDinero] != 0)
  31.         {
  32.             new f = MAX_OBJDINERO+1;
  33.             for(new a = 0; a < sizeof(CoordsDinero); a++)
  34.             {
  35.                 if(CoordsDinero[a][0] == 0.0)
  36.                 {
  37.                     f = a;
  38.                     break;
  39.                 }
  40.             }
  41.             tmp = strtok(cmdtext, idx);
  42.             new dinero = strval(tmp);
  43.             if(!strlen(tmp))
  44.             {
  45.                 SendClientMessage(playerid, COLOR_GRIS, "Utilice: /t(irar)dinero [Cantidad]");
  46.                 return 1;
  47.             }
  48.             new string[128];
  49.             if(f > MAX_OBJDINERO) return SendClientMessage(playerid, COLOR_ROJO, "Usted no peude tirar dinero ahora, inténtalo más tarde.");
  50.             DineroID[f][0] = dinero;
  51.  
  52.             JugadorInfo[playerid][jDinero] -= dinero;
  53.             GetPlayerPos(playerid, CoordsDinero[f][0], CoordsDinero[f][1], CoordsDinero[f][2]);
  54.             if(dinero < 1000)
  55.             {
  56.                 TDinero[f] = CreateObject(1212,CoordsDinero[f][0],CoordsDinero[f][1],CoordsDinero[f][2]-1,0.00000000,0.00000000,0.00000000);
  57.                 format(string, sizeof(string), "* %s tira unos billetes de dinero al suelo.", PlayerName(playerid));
  58.                 ProxDetector(30.0, playerid, string, COLOR_VIOLETA,COLOR_VIOLETA,COLOR_VIOLETA,COLOR_VIOLETA,COLOR_VIOLETA);
  59.             }
  60.             else
  61.             {
  62.                 TDinero[f] = CreateObject(1550,CoordsDinero[f][0],CoordsDinero[f][1],CoordsDinero[f][2]-1,0.00000000,0.00000000,0.00000000);
  63.                 format(string, sizeof(string), "* %s tira una bolsa de dinero al suelo.", PlayerName(playerid));
  64.                 ProxDetector(30.0, playerid, string, COLOR_VIOLETA,COLOR_VIOLETA,COLOR_VIOLETA,COLOR_VIOLETA,COLOR_VIOLETA);
  65.             }
  66.         }
  67.         return 1;
  68.     }
  69.    
  70.     if(strcmp(cmd, "/recogerdinero", true) == 0 || strcmp(cmd, "/rdinero", true) == 0)
  71.     {
  72.         new string2[128];
  73.         new f = MAX_OBJDINERO+1;
  74.         for(new a = 0; a < sizeof(CoordsDinero); a++)
  75.         {
  76.             if(IsPlayerInRangeOfPoint(playerid, 5.0, CoordsDinero[a][0], CoordsDinero[a][1], CoordsDinero[a][2]))
  77.             {
  78.                 f = a;
  79.                 break;
  80.             }
  81.         }
  82.         if(f > MAX_OBJDINERO) return SendClientMessage(playerid, COLOR_ROJO, "Usted no está cerca de ninguna bolsa o paquete de dinero.");
  83.         else
  84.         {
  85.             CoordsDinero[f][0] = 0.0;
  86.             CoordsDinero[f][1] = 0.0;
  87.             CoordsDinero[f][2] = 0.0;
  88.  
  89.             JugadorInfo[playerid][jDinero] += DineroID[f][0];
  90.             DestroyObject(TDinero[f]);
  91.             format(string2, sizeof(string2), "* %s recoge dinero del suelo.", PlayerName(playerid));
  92.             ProxDetector(30.0, playerid, string2, COLOR_VIOLETA,COLOR_VIOLETA,COLOR_VIOLETA,COLOR_VIOLETA,COLOR_VIOLETA);
  93.         }
  94.         return 1;
  95.     }
  96.     return 0;
  97. }
  98. // -----------------------------------------------------------------------------
  99. forward ProxDetector(Float:radi, playerid, string[],col1,col2,col3,col4,col5);
  100. public ProxDetector(Float:radi, playerid, string[],col1,col2,col3,col4,col5)
  101. {
  102.     if(IsPlayerConnected(playerid))
  103.     {
  104.         new Float:posx, Float:posy, Float:posz;
  105.         new Float:oldposx, Float:oldposy, Float:oldposz;
  106.         new Float:tempposx, Float:tempposy, Float:tempposz;
  107.         GetPlayerPos(playerid, oldposx, oldposy, oldposz);
  108.         //radi = 2.0; //Trigger Radius
  109.         for(new i = 0; i < MAX_PLAYERS; i++)
  110.         {
  111.             if(IsPlayerConnected(i) && (GetPlayerVirtualWorld(playerid) == GetPlayerVirtualWorld(i)))
  112.             {
  113.                 if(!BigEar[i])
  114.                 {
  115.                     GetPlayerPos(i, posx, posy, posz);
  116.                     tempposx = (oldposx -posx);
  117.                     tempposy = (oldposy -posy);
  118.                     tempposz = (oldposz -posz);
  119.                     if (((tempposx < radi/16) && (tempposx > -radi/16)) && ((tempposy < radi/16) && (tempposy > -radi/16)) && ((tempposz < radi/16) && (tempposz > -radi/16)))
  120.                     {
  121.                         SendClientMessage(i, col1, string);
  122.                     }
  123.                     else if (((tempposx < radi/8) && (tempposx > -radi/8)) && ((tempposy < radi/8) && (tempposy > -radi/8)) && ((tempposz < radi/8) && (tempposz > -radi/8)))
  124.                     {
  125.                         SendClientMessage(i, col2, string);
  126.                     }
  127.                     else if (((tempposx < radi/4) && (tempposx > -radi/4)) && ((tempposy < radi/4) && (tempposy > -radi/4)) && ((tempposz < radi/4) && (tempposz > -radi/4)))
  128.                     {
  129.                         SendClientMessage(i, col3, string);
  130.                     }
  131.                     else if (((tempposx < radi/2) && (tempposx > -radi/2)) && ((tempposy < radi/2) && (tempposy > -radi/2)) && ((tempposz < radi/2) && (tempposz > -radi/2)))
  132.                     {
  133.                         SendClientMessage(i, col4, string);
  134.                     }
  135.                     else if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
  136.                     {
  137.                         SendClientMessage(i, col5, string);
  138.                     }
  139.                 }
  140.                 else
  141.                 {
  142.                     SendClientMessage(i, col1, string);
  143.                 }
  144.             }
  145.         }
  146.     }//not connected
  147.     return 1;
  148. }
  149.  
  150. strtok(const string[], &index)
  151. {
  152.     new length = strlen(string);
  153.     while ((index < length) && (string[index] <= ' '))
  154.     {
  155.         index++;
  156.     }
  157.     new offset = index;
  158.     new result[20];
  159.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  160.     {
  161.         result[index - offset] = string[index];
  162.         index++;
  163.     }
  164.     result[index - offset] = EOS;
  165.     return result;
  166. }
  167.  
  168. stock PlayerName(playerid)
  169. {
  170.     new Nombre[24];
  171.     GetPlayerName(playerid,Nombre,24);
  172.     new N[24];
  173.     strmid(N,Nombre,0,strlen(Nombre),24);
  174.     for(new i = 0; i < MAX_PLAYER_NAME; i++)
  175.     {
  176.         if (N[i] == '_') N[i] = ' ';
  177.     }
  178.     return N;
  179. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement