Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //------------------------------------------------------------------------------
- //
- // Celular call Filter Script v1.0
- // Designed for SA-MP v0.2.2
- //
- // http://forum.sa-mp.com/index.php?topic=42009.0
- //
- // Created by zeruel_angel
- //
- //------------------------------------------------------------------------------
- #include <a_samp>
- #define COLOR_CALL 0xBFC0C2FF
- #define COLOR_YELLOW 0xFFFF00AA
- #define DEAD_TIMER_ID -666
- #define LIBRE 0
- #define ESTA_LLAMANDO 1
- #define LO_ESTAN_LLAMANDO 2
- #define ESTA_HABLANDO 3
- //------------------------------------------------------------------------------
- // HOW MUCH MONEY COST A SECOND
- #define PRECIO_FICHA 2
- //------------------------------------------------------------------------------
- new CellState[MAX_PLAYERS];
- new AuxiliarTel[MAX_PLAYERS];
- new CellTime[MAX_PLAYERS];
- new TimerLLamando[MAX_PLAYERS]={DEAD_TIMER_ID,...};
- new TimerCaidaFicha[MAX_PLAYERS];
- forward ColgarTelefonino(playerid);
- forward Llamando(callerid,receiverid);
- forward CaidaDeFicha(playerid);
- //------------------------------------------------------------------------------
- public CaidaDeFicha(playerid)
- {
- CellTime[playerid]++;
- }
- //------------------------------------------------------------------------------
- msgInfo(playerid,text[])
- {
- new msg[255];
- format(msg,255,"- %s",text);
- SendClientMessage(playerid, COLOR_YELLOW, msg);
- return 1;
- }
- //------------------------------------------------------------------------------------------------------
- Float:GetDistanceToPoint(playerid,Float:x2,Float:y2,Float:z2)
- {
- if (IsPlayerConnected(playerid))
- {
- new Float:x1,Float:y1,Float:z1;
- GetPlayerPos(playerid,x1,y1,z1);
- return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
- }
- return 9999.9;
- }
- //------------------------------------------------------------------------------
- AlTelefono(playerid,text[])
- {
- new msg[255];
- format(msg,255,"- [CELULAR]: %s",text);
- SendClientMessage(playerid, COLOR_CALL, msg);
- return 1;
- }
- //------------------------------------------------------------------------------
- public OnFilterScriptInit()
- {
- return 1;
- }
- //------------------------------------------------------------------------------
- public Llamando(callerid,receiverid)
- {
- if ((!IsPlayerConnected(receiverid))&&(IsPlayerConnected(callerid)))
- {
- msgInfo(callerid,"- [CELULAR]: Player offline!");
- if (TimerLLamando[callerid]!=DEAD_TIMER_ID)
- {
- KillTimer(TimerLLamando[callerid]);
- TimerLLamando[callerid]=DEAD_TIMER_ID;
- TimerLLamando[receiverid]=DEAD_TIMER_ID;
- CellState[callerid]=LIBRE;
- CellState[receiverid]=LIBRE;
- }
- return 1;
- }
- if ((IsPlayerConnected(receiverid))&&(!IsPlayerConnected(callerid)))
- {
- msgInfo(receiverid,"- [CELULAR]: Player offline!");
- if (TimerLLamando[receiverid]!=DEAD_TIMER_ID)
- {
- KillTimer(TimerLLamando[receiverid]);
- TimerLLamando[callerid]=DEAD_TIMER_ID;
- TimerLLamando[receiverid]=DEAD_TIMER_ID;
- CellState[callerid]=LIBRE;
- CellState[receiverid]=LIBRE;
- }
- return 1;
- }
- if ((!IsPlayerConnected(receiverid))&&(!IsPlayerConnected(callerid)))
- {
- if (TimerLLamando[callerid]!=DEAD_TIMER_ID)
- {
- KillTimer(TimerLLamando[callerid]);
- }
- if (TimerLLamando[receiverid]!=DEAD_TIMER_ID)
- {
- KillTimer(TimerLLamando[receiverid]);
- }
- TimerLLamando[callerid]=DEAD_TIMER_ID;
- TimerLLamando[receiverid]=DEAD_TIMER_ID;
- CellState[callerid]=LIBRE;
- CellState[receiverid]=LIBRE;
- return 1;
- }
- if ((CellState[callerid] == ESTA_LLAMANDO)&&(CellState[receiverid] == LO_ESTAN_LLAMANDO))
- {
- new msg[256];
- new callerName[MAX_PLAYER_NAME];
- msgInfo(callerid,"- [CELULAR]: Chamando...");
- GetPlayerName(callerid, callerName, sizeof(callerName));
- format(msg, sizeof(msg), "- [CELULAR TOCANDO]: (/a)tender | (/d)esligar, Chamada de: %s", callerName);
- msgInfo(receiverid, msg);
- return 1;
- }
- return 1;
- }
- //------------------------------------------------------------------------------
- public ColgarTelefonino(playerid)
- {
- SetPlayerSpecialAction(playerid,SPECIAL_ACTION_STOPUSECELLPHONE);
- return 1;
- }
- //------------------------------------------------------------------------------
- public OnPlayerText(playerid, text[])
- {
- if (CellState[playerid]==ESTA_HABLANDO)
- {
- new msg[255];
- format(msg,sizeof(msg),"- [CELULAR]: %s",text);
- AlTelefono(AuxiliarTel[playerid],text);
- new Float:x1,Float:y1,Float:z1;
- GetPlayerPos(playerid,x1,y1,z1);
- for (new i=0;i<MAX_PLAYERS;i++)
- {
- if (GetDistanceToPoint(i,x1,y1,z1)<20.0)
- {
- SendPlayerMessageToPlayer(i,playerid,msg);
- }
- }
- return 0;
- }
- return 1;
- }
- //------------------------------------------------------------------------------
- public OnPlayerConnect(playerid)
- {
- CellState[playerid]=LIBRE;
- AuxiliarTel[playerid]=-1;
- CellTime[playerid]=0;
- TimerLLamando[playerid]=DEAD_TIMER_ID;
- TimerCaidaFicha[playerid]=DEAD_TIMER_ID;
- return 1;
- }
- //------------------------------------------------------------------------------
- public OnPlayerDisconnect(playerid)
- {
- OnPlayerCommandText(playerid,"/h");
- return 1;
- }
- //------------------------------------------------------------------------------
- public OnPlayerCommandText(playerid,cmdtext[])
- {
- new cmd[256];
- new tmp[256];
- new idx;
- cmd = strtok(cmdtext, idx);
- if(strcmp(cmd, "/ligar", true) == 0)
- {
- if(IsPlayerConnected(playerid))
- {
- if(CellState[playerid]==ESTA_LLAMANDO)
- {
- msgInfo(playerid, "- [CELULAR]: Voc� est� ligando, voc� pode cancelar, (/d)esligar.");
- return 1;
- }
- if(CellState[playerid]==LO_ESTAN_LLAMANDO)
- {
- msgInfo(playerid, "- [CELULAR TOCANDO]: (/a)tender | (/d)esligar.");
- return 1;
- }
- SetPlayerSpecialAction(playerid,SPECIAL_ACTION_USECELLPHONE);
- tmp = strtok(cmdtext, idx);
- if (!strlen(tmp))
- {
- msgInfo(playerid, "- [CELULAR]: USO: /ligar [id]");
- SetTimerEx("ColgarTelefonino",1200,0,"d",playerid);
- return 1;
- }
- new numTel = strval(tmp);
- if (playerid == numTel)
- {
- msgInfo(playerid,"- [CELULAR]: Ocupado...");
- SetTimerEx("ColgarTelefonino",1200,0,"d",playerid);
- return 1;
- }
- if (!IsPlayerConnected(numTel))
- {
- msgInfo(playerid, "- [CELULAR]: Player offline!");
- SetTimerEx("ColgarTelefonino",1200,0,"d",playerid);
- return 1;
- }
- if (CellState[numTel]==LIBRE)
- {
- CellState[numTel] = LO_ESTAN_LLAMANDO;
- CellState[playerid] = ESTA_LLAMANDO;
- AuxiliarTel[playerid] = numTel;
- AuxiliarTel[numTel] = playerid;
- TimerLLamando[playerid]=SetTimerEx("Llamando",2000,true,"ii",playerid,numTel);
- TimerLLamando[numTel]=TimerLLamando[playerid];
- return 1;
- }
- else
- {
- msgInfo(playerid, "- [CELULAR]: Ocupado...");
- SetTimerEx("ColgarTelefonino",1200,0,"d",playerid);
- return 1;
- }
- }
- return 1;
- }
- if(strcmp(cmd, "/atender", true) == 0 || strcmp(cmd, "/a", true) == 0)
- {
- if(IsPlayerConnected(playerid))
- {
- if(CellState[playerid] != LO_ESTAN_LLAMANDO)
- {
- SendClientMessage(playerid, COLOR_CALL, "- [CELULAR]: N�o tem ningu�m te ligando!");
- return 1;
- }
- SetPlayerSpecialAction(playerid,SPECIAL_ACTION_USECELLPHONE);
- msgInfo(playerid, "- [CELULAR]: Celular atendido...");
- msgInfo(AuxiliarTel[playerid],"- [CELULAR]: Celular atendido...");
- TimerCaidaFicha[AuxiliarTel[playerid]]=SetTimerEx("CaidaDeFicha",500,true,"i",AuxiliarTel[playerid]);
- CellState[playerid]=ESTA_HABLANDO;
- CellState[AuxiliarTel[playerid]]=ESTA_HABLANDO;
- return 1;
- }
- return 1;
- }
- if(strcmp(cmd, "/desligar", true) == 0 || strcmp(cmd, "/d", true) == 0)
- {
- if (CellState[playerid] == LIBRE)
- {
- msgInfo(playerid, "- [CELULAR]: Voc� n�o est� usando o celular!");
- return 1;
- }
- if (CellState[playerid] == ESTA_LLAMANDO)
- {
- msgInfo(playerid, "- [CELULAR]: Desligado, chamada encerrada!");
- msgInfo(AuxiliarTel[playerid], "- [CELULAR]: Desligado, chamada encerrada!");
- SetTimerEx("ColgarTelefonino",500,0,"d",playerid);
- KillTimer(TimerLLamando[playerid]);
- TimerLLamando[playerid]=DEAD_TIMER_ID;
- TimerLLamando[AuxiliarTel[playerid]]=DEAD_TIMER_ID;
- CellState[playerid]=LIBRE;
- CellState[AuxiliarTel[playerid]]=LIBRE;
- return 1;
- }
- if (CellState[playerid] == LO_ESTAN_LLAMANDO)
- {
- msgInfo(playerid, "- [CELULAR]: Desligado, chamada encerrada!");
- msgInfo(AuxiliarTel[playerid], "- [CELULAR]: Desligado, chamada encerrada!");
- SetTimerEx("ColgarTelefonino",500,0,"d",AuxiliarTel[playerid]);
- KillTimer(TimerLLamando[playerid]);
- TimerLLamando[playerid]=DEAD_TIMER_ID;
- TimerLLamando[AuxiliarTel[playerid]]=DEAD_TIMER_ID;
- CellState[playerid]=LIBRE;
- CellState[AuxiliarTel[playerid]]=LIBRE;
- return 1;
- }
- if (CellState[playerid] == ESTA_HABLANDO)
- {
- msgInfo(playerid, "- [CELULAR]: Desligado, chamada encerrada!");
- msgInfo(AuxiliarTel[playerid], "- [CELULAR]: Desligado, chamada encerrada!");
- SetTimerEx("ColgarTelefonino",500,0,"d",playerid);
- SetTimerEx("ColgarTelefonino",500,0,"d",AuxiliarTel[playerid]);
- if (TimerCaidaFicha[playerid]!=DEAD_TIMER_ID)
- {
- KillTimer(TimerLLamando[playerid]);
- TimerCaidaFicha[playerid]=DEAD_TIMER_ID;
- /*new msg[255];
- format(msg,sizeof(msg),"- [CELULAR]: A chamada custou: $%d",CellTime[playerid]*PRECIO_FICHA);
- msgInfo(playerid, msg);*/
- }
- if (TimerCaidaFicha[AuxiliarTel[playerid]]!=DEAD_TIMER_ID)
- {
- KillTimer(TimerLLamando[AuxiliarTel[playerid]]);
- TimerCaidaFicha[AuxiliarTel[playerid]]=DEAD_TIMER_ID;
- /*new msg[255];
- format(msg,sizeof(msg),"- [CELULAR]: A chamada custou: $%d",CellTime[AuxiliarTel[playerid]]*PRECIO_FICHA);
- msgInfo(AuxiliarTel[playerid], msg);*/
- }
- CellState[playerid]=LIBRE;
- CellState[AuxiliarTel[playerid]]=LIBRE;
- }
- return 1;
- }
- return 0;
- }
- //=====================================================================================================
- strtok(const string[], &index)
- {
- new length = strlen(string);
- while ((index < length) && (string[index] <= ' '))
- {
- index++;
- }
- new offset = index;
- new result[20];
- while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
- {
- result[index - offset] = string[index];
- index++;
- }
- result[index - offset] = EOS;
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement