Headache

[FS] Tirar y recoger dinero al suelo (zcmd & sscanf)

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