Advertisement
Guest User

By iRaiDeN

a guest
Apr 28th, 2014
938
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.04 KB | None | 0 0
  1. #include <a_samp>
  2. #include <a_mysql>
  3. #include <zcmd>
  4. //#include <sscanf2>
  5.  
  6. #define     MAX_GANG        (1) //Change this!
  7.  
  8. #define     DB_SERVER       "127.0.0.1"
  9. #define     DB_USER         "root"
  10. #define     DB_DB           "samp"
  11. #define     DB_PASS         ""
  12.  
  13. enum gangEnum {
  14.     g_name[27],
  15.     g_motd[128],
  16.     g_leader[27],
  17.     Float:g_pos_hq[3],
  18.     Float:g_pos_hq_int[3],
  19.     g_tier
  20. };
  21.  
  22. new
  23.     dbHandle,
  24.     gInfo[MAX_GANG][gangEnum],
  25.     bool: pInvited[MAX_PLAYERS],
  26.     g_name_2[MAX_PLAYERS][27];
  27.  
  28. public OnGameModeInit()
  29. {
  30.     dbHandle = mysql_connect(DB_SERVER,DB_USER,DB_DB,DB_PASS);
  31.     mysql_function_query(dbHandle,"SELECT * FROM gangs",true,"loadGangs","");
  32.     return 1;
  33. }
  34.  
  35. public OnPlayerSpawn(playerid)
  36.     return SetPlayerPos(playerid,gInfo[playerid][g_pos_hq_int][0],gInfo[playerid][g_pos_hq_int][1],gInfo[playerid][g_pos_hq_int][2]);
  37.  
  38. public OnPlayerRequestSpawn(playerid)
  39. {
  40.     new localString[128];
  41.     format(localString,128,"[Gang MOTD]: %s",gInfo[playerid][g_motd]);
  42.     SendClientMessage(playerid,-1,localString);
  43. }
  44.  
  45. COMMAND:gang(playerid,params[])
  46. {
  47.     new param[128];
  48.     if(gInfo[playerid][g_tier] != 3)
  49.     {
  50.         if(sscanf(params,"s[128]",param))
  51.             return SendClientMessage(playerid,-1,"[Usage]: /gang [invite | kick | motd | hq | tier]");
  52.     } else {
  53.         if(sscanf(params,"s[128]",param))
  54.             return SendClientMessage(playerid,-1,"[Usage]: /gang [accept | leave]");
  55.     }
  56.     if(!strcmp(param,"invite",true,6))
  57.     {
  58.         if(gInfo[playerid][g_tier] != 3) return 0;
  59.         if(sscanf(param,"u",params[0]))
  60.             return SendClientMessage(playerid,-1,"[Usage Command(Invite)]: [ID]");
  61.         if(!IsPlayerConnected(params[0]))
  62.             return SendClientMessage(playerid,-1,"[Error]: invaild player ID");
  63.         if(strcmp(gInfo[playerid][g_name],gInfo[params[0]][g_name],true))
  64.             return SendClientMessage(playerid,-1,"[Error]: this player in gang!");
  65.         strcat(gInfo[params[0]][g_name],gInfo[playerid][g_name]);
  66.         pInvited[params[0]] = true;
  67.         g_name_2[params[0]] = gInfo[playerid][g_name];
  68.         SetTimerEx("EndInvited",5*1000*60,false,"d",playerid);
  69.         new localString[128];
  70.         format(localString,128,"[Gang]: hello, you been invited to the GANG: %s | /gang accept");
  71.         SendClientMessage(params[0],-1,localString);
  72.     }
  73.     if(!strcmp(param,"kick",true,4))
  74.     {
  75.         if(gInfo[playerid][g_tier] != 3) return 0;
  76.         if(sscanf(param,"u",params[1]))
  77.             return SendClientMessage(playerid,-1,"[Usage Command(Kick)]: [ID]");
  78.         if(!IsPlayerConnected(params[1]))
  79.             return SendClientMessage(playerid,-1,"[Error]: invaild player ID");
  80.         if(strcmp(gInfo[playerid][g_name],gInfo[params[0]][g_name],true))
  81.             return SendClientMessage(playerid,-1,"[Error]: this player not in your's gang!");
  82.         new localString[128];
  83.         format(localString,128,"[Gang]: you have been un-invited to the GANG: %s",gInfo[playerid][g_name]);
  84.         SendClientMessage(playerid,-1,localString);
  85.         strcat(gInfo[params[1]][g_name],"\0");
  86.         SpawnPlayer(params[1]);
  87.     }
  88.     if(!strcmp(param,"motd",true,4))
  89.     {
  90.         if(gInfo[playerid][g_tier] != 3) return 0;
  91.         if(sscanf(param,"u",params[2]))
  92.             return SendClientMessage(playerid,-1,"[Usage Command]: [MOTD]");
  93.         strcat(gInfo[playerid][g_motd],"\0");
  94.         gInfo[playerid][g_motd] = params[2];
  95.         new localString[128];
  96.         format(localString,128,"[Gang]: the gang MOTED by changed to: %s",params[2]);
  97.         SendClientMessage(playerid,-1,localString);
  98.     }
  99.     if(!strcmp(param,"hq",true,2))
  100.     {
  101.         if(gInfo[playerid][g_tier] != 3) return 0;
  102.         new Float:gPos[MAX_PLAYERS][3];
  103.         GetPlayerPos(playerid,gPos[playerid][0],gPos[playerid][1],gPos[playerid][2]);
  104.         gInfo[playerid][g_pos_hq][0] = gPos[playerid][0],gInfo[playerid][g_pos_hq][1] = gPos[playerid][1],gInfo[playerid][g_pos_hq][2] = gPos[playerid][2];
  105.         new localString[128];
  106.         format(localString,128,"[Gang]: the HQ Pos changed successufly to: %f,%f,%f",gPos[playerid][0],gPos[playerid][1],gPos[playerid][2]);
  107.         SendClientMessage(playerid,-1,localString);
  108.     }
  109.     if(!strcmp(param,"tier",true,4))
  110.     {
  111.         if(gInfo[playerid][g_tier] != 3) return 0;
  112.         if(sscanf(param,"ud",params[3],params[4]))
  113.             return SendClientMessage(playerid,-1,"[Usage Command]: [ID] [tier]");
  114.         if(!IsPlayerConnected(params[3]))
  115.             return SendClientMessage(playerid,-1,"[Error]: invaild player ID");
  116.         if(strcmp(gInfo[playerid][g_name],gInfo[params[3]][g_name],true))
  117.             return SendClientMessage(playerid,-1,"[Error]: this player not in your gang!");
  118.         gInfo[playerid][g_tier] = params[4];
  119.         new localString[128];
  120.         format(localString,128,"[Gang]: you tier now is: %d",params[4]);
  121.         SendClientMessage(params[4],-1,localString);
  122.     }
  123.     if(!strcmp(param,"accept",true,6))
  124.     {
  125.         if(!pInvited[playerid]) return 0;
  126.         gInfo[playerid][g_name] = g_name_2[playerid];
  127.         new localString[128];
  128.         format(localString,128,"[Gang]: you successuflly accept the invited to the GANG: %s",gInfo[playerid][g_name]);
  129.         SendClientMessage(playerid,-1,localString);
  130.     }
  131.     if(!strcmp(param,"leave",true,5))
  132.     {
  133.         if(!strlen(gInfo[playerid][g_name])) return 0;
  134.         new localString[128];
  135.         format(localString,128,"[Gang]: you are successuflly leaved the GANG: %s",gInfo[playerid][g_name]);
  136.         SendClientMessage(playerid,-1,localString);
  137.         strcat(gInfo[playerid][g_name],"\0");
  138.         strcat(gInfo[playerid][g_motd],"\0");
  139.     }
  140.     return 1;
  141. }
  142.  
  143. COMMAND:makeleader(playerid,params[])
  144. {
  145.     if(gInfo[playerid][g_tier] != 3) return 0;
  146.     if(sscanf(params,"u",params[1]))
  147.         return SendClientMessage(playerid,-1,"[Usage]: /makeleader [ID]");
  148.     new pName[MAX_PLAYER_NAME];
  149.     GetPlayerName(params[1],pName[params[1]],24);
  150.     gInfo[params[1]][g_leader] = pName[params[1]];
  151.     new localString[128];
  152.     format(localString,128,"[Gang]: you now the leader of the GANG: %s",gInfo[playerid][g_name]);
  153.     SendClientMessage(params[1],-1,localString);
  154.     return 1;
  155. }
  156.  
  157. forward loadGangs();
  158. public loadGangs()
  159. {
  160.     for(new i; i != MAX_GANG; i++)
  161.     {
  162.         cache_get_field_content(0,"g_name",gInfo[i][g_name],dbHandle);
  163.         cache_get_field_content(0,"g_motd",gInfo[i][g_motd],dbHandle);
  164.         cache_get_field_content(0,"g_leader",gInfo[i][g_leader],dbHandle);
  165.         gInfo[i][g_pos_hq][0] = cache_get_field_content_float(0,"g_hq_x",dbHandle);
  166.         gInfo[i][g_pos_hq][1] = cache_get_field_content_float(0,"g_hq_y",dbHandle);
  167.         gInfo[i][g_pos_hq][2] = cache_get_field_content_float(0,"g_hq_z",dbHandle);
  168.         gInfo[i][g_pos_hq_int][0] = cache_get_field_content_float(0,"g_hq_int_x",dbHandle);
  169.         gInfo[i][g_pos_hq_int][1] = cache_get_field_content_float(0,"g_hq_int_y",dbHandle);
  170.         gInfo[i][g_pos_hq_int][2] = cache_get_field_content_float(0,"g_hq_int_z",dbHandle);
  171.     }
  172.     SetTimer("loadAllGangs",2000,false);
  173.     return 1;
  174. }
  175.  
  176. forward loadAllGangs();
  177. public loadAllGangs()
  178. {
  179.     for(new i; i != MAX_GANG; i++)
  180.     {
  181.         CreatePickup(1239,2,gInfo[i][g_pos_hq][0],gInfo[i][g_pos_hq][1],gInfo[i][g_pos_hq][2]);
  182.         new localString[128];
  183.         format(localString,128,"This the HQ of the GANG: %s",gInfo[i][g_name]);
  184.         Create3DTextLabel(localString,-1,30.0,40.0,50.0,40.0,0,0);
  185.     }
  186.     return 1;
  187. }
  188.  
  189. forward EndInvited(playerid);
  190. public EndInvited(playerid)
  191.     return pInvited[playerid] = false,strcat(g_name_2[playerid],"\0"),1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement