SwiZzoR

Money Ship Dynamic | y_ini / y_commands |

May 1st, 2014
1,320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.99 KB | None | 0 0
  1. #include <a_samp>
  2. #include <YSI\y_commands>
  3. #include <YSI\y_ini>
  4.  
  5. // Defines Dialog
  6. #define Dialog_ShipMenu (121)
  7. #define Dialog_CreateShip (122)
  8. #define Dialog_EditShip (123)
  9. #define Dialog_EditMoney (124)
  10. #define Dialog_DeleteShip (125)
  11. // Defines Dialog
  12. #define SendFormatMessage(%0,%1,%2,%3) format(M_str,sizeof(M_str),%2,%3); SendClientMessage(%0,%1,M_str)
  13. // -------------------------------------------------
  14. #define MAX_SHIP 500
  15. enum Data_Ship
  16. {
  17.     MID,
  18.     Money,
  19.     SFile[60],
  20.     Float:Pos[6],
  21.     Float:MPos[3]
  22. };
  23.  
  24. new Ships[MAX_SHIP][Data_Ship],
  25.         Float:pPos[3],
  26.             LastId,
  27.                 M_str[128],
  28.                     TimerShips,
  29.                         Count = 0;
  30.  
  31. CMD:menuship(playerid,params[])
  32. {
  33.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,0xFF0000FF,"ERROR: You are not admin !");
  34.     ShowPlayerDialog(playerid,Dialog_ShipMenu,DIALOG_STYLE_LIST,"Money Ship - by I Love it","Create Ship\nEdit Ship","OK","Cancel");
  35.     return 1;
  36. }
  37.  
  38. public OnFilterScriptInit()
  39. {
  40.     TimerShips = SetTimer("MoneyShips",1000*3,true);
  41.     for(new i = 0, j = sizeof(Ships); i != j;i++)
  42.     {
  43.         format(Ships[i][SFile],60,"Ships/%d.ini",i);
  44.         if(fexist(Ships[i][SFile])) INI_ParseFile(Ships[i][SFile], "LoadShips", .bExtra = true, .extra = i);
  45.         if(Ships[i][MID] <= 0 || Ships[i][Pos][0] == 0.0) continue;
  46.         CreateObject(8493,Ships[i][Pos][0],Ships[i][Pos][1],Ships[i][Pos][2],Ships[i][Pos][3],Ships[i][Pos][4],Ships[i][Pos][5]) ,Count ++;
  47.     }
  48.     return 1;
  49. }
  50.  
  51. public OnFilterScriptExit()
  52. {
  53.     for(new i, j = sizeof(Ships); i != j;i++)
  54.     {
  55.         DestroyObject(Ships[i][MID]);
  56.         if(Ships[i][MID] <= 0 || Ships[i][Pos][0] == 0.0) continue;
  57.         format(Ships[i][SFile],60,"Ships/%d.ini",i);
  58.         new INI:ini = INI_Open(Ships[i][SFile]);
  59.         INI_WriteInt(ini,"ID",Ships[i][MID]);
  60.         INI_WriteInt(ini,"Money",Ships[i][Money]);
  61.         INI_WriteFloat(ini,"Pos0",Ships[i][Pos][0]);
  62.         INI_WriteFloat(ini,"Pos1",Ships[i][Pos][1]);
  63.         INI_WriteFloat(ini,"Pos2",Ships[i][Pos][2]);
  64.         INI_WriteFloat(ini,"Pos3",Ships[i][Pos][3]);
  65.         INI_WriteFloat(ini,"Pos4",Ships[i][Pos][4]);
  66.         INI_WriteFloat(ini,"Pos5",Ships[i][Pos][5]);
  67.         INI_WriteFloat(ini,"MPos0",Ships[i][Pos][0]);
  68.         INI_WriteFloat(ini,"MPos1",Ships[i][Pos][1]);
  69.         INI_WriteFloat(ini,"MPos2",Ships[i][Pos][2]);
  70.         INI_Close(ini);
  71.     }
  72.     KillTimer(TimerShips);
  73.     return 1;
  74. }
  75.  
  76. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  77. {
  78.     if(dialogid == Dialog_ShipMenu && response)
  79.     {
  80.         switch(listitem)
  81.         {
  82.             case 0:
  83.             {
  84.            
  85.                 GetPlayerPos(playerid,pPos[0],pPos[1],pPos[2]);
  86.                 new id = CreateObject(8493,pPos[0],pPos[1],pPos[2],0.0,0.0,0.0);
  87.                 Count++;
  88.                 if(Count > MAX_SHIP) return SendClientMessage(playerid,0xFF0000FF,"You have reached the maximum ships Money"),DestroyObject(id);
  89.                 Ships[Count][MID] = id;
  90.                 Ships[Count][Pos][0] = pPos[0];
  91.                 Ships[Count][Pos][1] = pPos[1];
  92.                 Ships[Count][Pos][2] = pPos[2];
  93.                 EditObject(playerid,id);
  94.                
  95.             }
  96.             case 1: SelectObject(playerid), SendClientMessage(playerid,0xFF0000FF,"Select Ship to edit !");
  97.         }
  98.     }
  99.    
  100.     if(dialogid == Dialog_EditShip && response)
  101.     {
  102.         switch(listitem)
  103.         {
  104.             // Edit Pos of Ship
  105.             case 0: EditObject(playerid,Ships[LastId][MID]);
  106.             case 1: // Change the area for to get the money
  107.             {
  108.                 GetPlayerPos(playerid,pPos[0],pPos[1],pPos[2]);
  109.                 Ships[LastId][MPos][0] = pPos[0];
  110.                 Ships[LastId][MPos][1] = pPos[1];
  111.                 Ships[LastId][MPos][2] = pPos[2];
  112.                 SendClientMessage(playerid,0xFF0000FF,"Changed the area for to get the money for where you stand");
  113.             }
  114.             // Edit Money
  115.             case 2: ShowPlayerDialog(playerid,Dialog_EditMoney,DIALOG_STYLE_INPUT,"Edit Money","Write the money for receive every 3 seconds","OK","Cancel");
  116.             // Delete Ship
  117.             case 3: ShowPlayerDialog(playerid,Dialog_DeleteShip,DIALOG_STYLE_INPUT,"Delete Ship","For delete this ship, type \"Yes\"","OK","Cancel");
  118.         }
  119.     }
  120.    
  121.     if(dialogid == Dialog_EditMoney && response)    // Edit Money
  122.     {
  123.         if(!IsNumeric(inputtext)) return  ShowPlayerDialog(playerid,Dialog_EditMoney,DIALOG_STYLE_INPUT,"Edit Money","Write the money for receive every 3 seconds\n Error : Write Only Numbers !","OK","Cancel");
  124.         Ships[LastId][Money] = strval(inputtext);
  125.         SendFormatMessage(playerid,0xFF0000FF,"You Are Changed the Money for recive every 3 seconds to : %d",strval(inputtext));
  126.     }
  127.  
  128.     if(dialogid == Dialog_DeleteShip && response) // Delete Ship
  129.     {
  130.         if(!strcmp(inputtext,"Yes",true))
  131.         {
  132.             SendClientMessage(playerid,0xFF0000FF,"You Are Delete this ship");
  133.             format(Ships[LastId][SFile],60,"Ships/%d.ini",LastId);
  134.             if(fexist(Ships[LastId][SFile])) fremove(Ships[LastId][SFile]);
  135.             DestroyObject(Ships[LastId][MID]);
  136.             Ships[LastId][MID] = -1;
  137.             Ships[LastId][Money] = 0;
  138.         }
  139.     }
  140.     return 1;
  141. }
  142.  
  143. public OnPlayerSelectObject(playerid, type, objectid, modelid, Float:fX, Float:fY, Float:fZ)
  144. {
  145.     for(new i = 0,j = sizeof(Ships);i != j;i++) if(objectid == Ships[i][MID]) LastId = i;
  146.     if(type == SELECT_OBJECT_GLOBAL_OBJECT && modelid == 8493 && Ships[LastId][MID] == objectid)
  147.     {
  148.         ShowPlayerDialog(playerid,Dialog_EditShip,DIALOG_STYLE_LIST,"Edit Ship - By I Love it","Edit Pos of Ship\nChange the area for to get the money\nEdit Money\nDelete Ship","OK","Cancel");
  149.        
  150.         CancelSelectTextDraw(playerid);
  151.     }
  152.     return 1;
  153. }
  154.  
  155. public OnPlayerEditObject(playerid, playerobject, objectid, response, Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ)
  156. {
  157.  
  158.     if(response == EDIT_RESPONSE_FINAL)
  159.     {
  160.         Ships[LastId][Pos][0] = fX;
  161.         Ships[LastId][Pos][1] = fY;
  162.         Ships[LastId][Pos][2] = fZ;
  163.         Ships[LastId][Pos][3] = fRotX;
  164.         Ships[LastId][Pos][4] = fRotY;
  165.         Ships[LastId][Pos][5] = fRotZ;
  166.     }
  167.     if(response == EDIT_RESPONSE_CANCEL)
  168.     {
  169.         SetObjectPos(Ships[LastId][MID], Ships[LastId][Pos][0], Ships[LastId][Pos][1], Ships[LastId][Pos][2]);
  170.         SetObjectRot(Ships[LastId][MID],Ships[LastId][Pos][3],Ships[LastId][Pos][4],Ships[LastId][Pos][5]);
  171.     }
  172. }
  173.  
  174. forward LoadShips_data(Ship, name[], value[]);
  175. public LoadShips_data(Ship, name[], value[])
  176. {
  177.     INI_Int("ID",Ships[Ship][MID]);
  178.     INI_Int("Money",Ships[Ship][Money]);
  179.     INI_Float("Pos0",Ships[Ship][Pos][0]);
  180.     INI_Float("Pos1",Ships[Ship][Pos][1]);
  181.     INI_Float("Pos2",Ships[Ship][Pos][2]);
  182.     INI_Float("Pos3",Ships[Ship][Pos][3]);
  183.     INI_Float("Pos4",Ships[Ship][Pos][4]);
  184.     INI_Float("Pos5",Ships[Ship][Pos][5]);
  185.     INI_Float("MPos0",Ships[Ship][Pos][0]);
  186.     INI_Float("MPos1",Ships[Ship][Pos][1]);
  187.     INI_Float("MPos2",Ships[Ship][Pos][2]);
  188.     return 1;
  189. }
  190.  
  191. forward MoneyShips(playerid);
  192. public MoneyShips(playerid)
  193. {
  194.     for(new i, j = sizeof(Ships); i != j;i++)
  195.     {
  196.         if(Ships[i][MID] <= 0 || Ships[i][Pos][0] == 0.0) continue;
  197.         if(IsPlayerInRangeOfPoint(playerid, 10, Ships[i][MPos][0], Ships[i][MPos][1], Ships[i][MPos][2]))
  198.             GivePlayerMoney(playerid,Ships[i][Money]);
  199.  
  200.     }
  201.     return 1;
  202. }
  203.  
  204. stock IsNumeric(string[])
  205. {
  206.  for(new i = 0; i < strlen(string); i++) if(string[i] > '9' || string[i] < '0') return false;
  207.  return true;
  208. }
Advertisement
Add Comment
Please, Sign In to add comment