Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #define RV_MAX_PICKUPS 400 // MAXIMAL PICKUPS OF SA:MP
- #define RV_CHECK_TIME 5000 // IN MS
- #define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
- enum PICKUP_DATA
- {
- Float:Range,
- Float:PX,
- Float:PY,
- Float:PZ,
- Float:Healing,
- Float:MaxHealing,
- RespawnTime,
- Price,
- PickupID,
- bool:created,
- bool:spawned,
- };
- new Pickups[RV_MAX_PICKUPS][PICKUP_DATA];
- new TotalPickups;
- forward SpawnPickup(arrayid);
- forward RepairLocCheck();
- // SCRIPT BELOW
- public OnFilterScriptInit()
- {
- print("\n********************************\n[R&V] Repair & Vehicle -- LOADED\n********************************\n BY [MOB]TR1VIUM\n");
- SendClientMessageToAll(0xF0F0F0AA, "_______________________________");
- SendClientMessageToAll(0xF0F0F0AA, "[R&V] Repair & Vehicle -- LOADED");
- SendClientMessageToAll(0xF0F0F0AA, " BY [MOB]TR1VIUM");
- LoadPickupVars();
- SetTimer("RepairLocCheck", RV_CHECK_TIME, 1);
- return 1;
- }
- public OnFilterScriptExit()
- {
- for(new i = 0; i < RV_MAX_PICKUPS; i++)
- if(Pickups[i][created])
- DestroyPickup(Pickups[i][PickupID]);
- return 1;
- }
- dcmd_createrepair(playerid, params[])
- {
- if(!IsPlayerAdmin(playerid))
- return SendClientMessage(playerid, 0xE41E1EAA, "[R&V] Admin only.");
- if(IsPlayerInAnyVehicle(playerid))
- return SendClientMessage(playerid, 0xE41E1EAA, "[R&V] You have to be on foot.");
- if (sscanf(params, "fffii", Pickups[TotalPickups][Range], Pickups[TotalPickups][Healing], Pickups[TotalPickups][MaxHealing], Pickups[TotalPickups][RespawnTime], Pickups[TotalPickups][Price])) return SendClientMessage(playerid, 0x1EE443AA, "[R&V] /createrepair [range] [healing] [maxhealing] [respawntime] [price]");
- else
- {
- if(Pickups[TotalPickups][Range] <= 0.0)
- return SendClientMessage(playerid, 0xE41E1EAA, "[R&V] Don't go below 0.0 || range.");
- if(Pickups[TotalPickups][Healing] <= 0.0)
- return SendClientMessage(playerid, 0xE41E1EAA, "[R&V] Don't go below 0.0 || healing.");
- if(Pickups[TotalPickups][MaxHealing] <= 0.0)
- return SendClientMessage(playerid, 0xE41E1EAA, "[R&V] Don't go below 0.0 || maxhealing.");
- if(Pickups[TotalPickups][RespawnTime] < 0)
- return SendClientMessage(playerid, 0xE41E1EAA, "[R&V] Don't go below 0 || respawn time");
- if(Pickups[TotalPickups][Price] < 0)
- return SendClientMessage(playerid, 0xE41E1EAA, "[R&V] Don't go below 0 || Price");
- GetPlayerPos(playerid, Pickups[TotalPickups][PX], Pickups[TotalPickups][PY], Pickups[TotalPickups][PZ]);
- Pickups[TotalPickups][PickupID] = CreatePickup(3096, 1, Pickups[TotalPickups][PX], Pickups[TotalPickups][PY], Pickups[TotalPickups][PZ]);
- Pickups[TotalPickups][created] = true;
- Pickups[TotalPickups][spawned] = true;
- TotalPickups++;
- SendClientMessage(playerid, 0x1EE443AA, "[R&V] Created repair pickup.");
- SavePickupVars();
- }
- return 1;
- }
- dcmd_deleterepair(playerid, params[])
- {
- if(!IsPlayerAdmin(playerid))
- return SendClientMessage(playerid, 0xE41E1EAA, "[R&V] Admin only.");
- for(new i = 0; i < TotalPickups; i++)
- {
- if(PlayerToPoint(Pickups[i][Range], playerid, Pickups[i][PX], Pickups[i][PY], Pickups[i][PZ]))
- {
- DestroyPickup(Pickups[i][PickupID]);
- Pickups[i][created] = false;
- Pickups[i][spawned] = false;
- SendClientMessage(playerid, 0x1EE443AA, "[R&V] Deleted repair pickup.");
- SavePickupVars();
- return 1;
- }
- }
- SendClientMessage(playerid, 0xE41E1EAA, "[R&V] Not at any repair pickup.");
- #pragma unused params
- return 1;
- }
- dcmd_reloadrepair(playerid, params[])
- {
- if(!IsPlayerAdmin(playerid))
- return SendClientMessage(playerid, 0xE41E1EAA, "[R&V] Admin only.");
- SavePickupVars();
- LoadPickupVars();
- SendClientMessage(playerid, 0x1EE443AA, "[R&V] Reloaded repair pickups.");
- #pragma unused params
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- dcmd(createrepair, 12, cmdtext);
- dcmd(deleterepair, 12, cmdtext);
- dcmd(reloadrepair, 12, cmdtext);
- return 0;
- }
- public SpawnPickup(arrayid)
- {
- Pickups[arrayid][PickupID] = CreatePickup(3096, 1, Pickups[arrayid][PX], Pickups[arrayid][PY], Pickups[arrayid][PZ]);
- Pickups[arrayid][created] = true;
- Pickups[arrayid][spawned] = true;
- return 1;
- }
- public RepairLocCheck()
- {
- for(new i = 0; i < MAX_PLAYERS; i++)
- {
- if(!IsPlayerConnected(i) || !IsPlayerInAnyVehicle(i))
- continue;
- for(new int = 0; int < TotalPickups; int++)
- {
- if(Pickups[int][spawned] && PlayerVehicleToPoint(Pickups[int][Range], i, Pickups[int][PX], Pickups[int][PY], Pickups[int][PZ]))
- {
- if(GetPlayerMoney(i) >= Pickups[int][Price])
- {
- new vehicleid = GetPlayerVehicleID(i), Float:hp;
- GetVehicleHealth(vehicleid, hp);
- if(hp >= Pickups[int][MaxHealing])
- {
- GameTextForPlayer(i, "~w~MORE ~r~DAMAGE ~w~NEEDED", 5000, 3);
- break;
- }
- if(hp + Pickups[int][Healing] > Pickups[int][MaxHealing])
- SetVehicleHealth(vehicleid, Pickups[int][MaxHealing]);
- else
- SetVehicleHealth(vehicleid, hp+Pickups[int][Healing]);
- GivePlayerMoney(i, -Pickups[int][Price]);
- GameTextForPlayer(i, "~w~VEHICLE ~g~REPAIRED", 5000, 3);
- if(Pickups[int][RespawnTime] > 0)
- {
- SetTimerEx("SpawnPickup", Pickups[int][RespawnTime], 0, "i", int);
- DestroyPickup(Pickups[int][PickupID]);
- Pickups[int][spawned] = false;
- }
- break;
- }
- else
- {
- new string[126];
- format(string, 126, "~w~YOU NEED ~r~$%i", Pickups[int][Price]);
- GameTextForPlayer(i, string, 5000, 3);
- }
- }
- }
- }
- return 1;
- }
- LoadPickupVars()
- {
- if(!fexist("repairpickups.txt"))
- {
- new File:File = fopen("repairpickups.txt", io_write);
- fclose(File);
- return 1;
- }
- new i = 0, dude[256], idx, value[64];
- new File:File = fopen("repairpickups.txt", io_read);
- while(fread(File, dude))
- {
- value = strtok(dude, idx);
- Pickups[i][Range] = floatstr(value);
- value = strtok(dude, idx);
- Pickups[i][PX] = floatstr(value);
- value = strtok(dude, idx);
- Pickups[i][PY] = floatstr(value);
- value = strtok(dude, idx);
- Pickups[i][PZ] = floatstr(value);
- value = strtok(dude, idx);
- Pickups[i][Healing] = floatstr(value);
- value = strtok(dude, idx);
- Pickups[i][MaxHealing] = floatstr(value);
- value = strtok(dude, idx);
- Pickups[i][RespawnTime] = strval(value);
- value = strtok(dude, idx);
- Pickups[i][Price] = strval(value);
- Pickups[i][PickupID] = CreatePickup(3096, 1, Pickups[i][PX], Pickups[i][PY], Pickups[i][PZ]);
- Pickups[i][created] = true;
- Pickups[i][spawned] = true;
- i++;
- idx = 0;
- }
- fclose(File);
- TotalPickups = i;
- return 1;
- }
- SavePickupVars()
- {
- new dude[256], File:File = fopen("repairpickups.txt", io_write);
- for(new i = 0; i < TotalPickups; i++)
- {
- if(Pickups[i][created])
- {
- format(dude, 256, "%f %f %f %f %f %f %i %i\r\n", Pickups[i][Range], Pickups[i][PX], Pickups[i][PY], Pickups[i][PZ], Pickups[i][Healing], Pickups[i][MaxHealing], Pickups[i][RespawnTime], Pickups[i][Price]);
- fwrite(File, dude);
- }
- }
- fclose(File);
- return 1;
- }
- PlayerVehicleToPoint(Float:radi, playerid, Float:x, Float:y, Float:z)
- {
- new Float:oldposx, Float:oldposy, Float:oldposz;
- new Float:tempposx, Float:tempposy, Float:tempposz;
- GetVehiclePos(GetPlayerVehicleID(playerid), oldposx, oldposy, oldposz);
- tempposx = (oldposx -x);
- tempposy = (oldposy -y);
- tempposz = (oldposz -z);
- if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
- return true;
- return false;
- }
- PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z)
- {
- if(IsPlayerConnected(playerid))
- {
- new Float:oldposx, Float:oldposy, Float:oldposz;
- new Float:tempposx, Float:tempposy, Float:tempposz;
- GetPlayerPos(playerid, oldposx, oldposy, oldposz);
- tempposx = (oldposx -x);
- tempposy = (oldposy -y);
- tempposz = (oldposz -z);
- //printf("DEBUG: X:%f Y:%f Z:%f",posx,posy,posz);
- if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
- {
- return 1;
- }
- }
- return 0;
- }
- sscanf(string[], format[], {Float,_}:...)
- {
- #if defined isnull
- if (isnull(string))
- #else
- if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
- #endif
- {
- return format[0];
- }
- #pragma tabsize 4
- new
- formatPos = 0,
- stringPos = 0,
- paramPos = 2,
- paramCount = numargs(),
- delim = ' ';
- while (string[stringPos] && string[stringPos] <= ' ')
- {
- stringPos++;
- }
- while (paramPos < paramCount && string[stringPos])
- {
- switch (format[formatPos++])
- {
- case '\0':
- {
- return 0;
- }
- case 'i', 'd':
- {
- new
- neg = 1,
- num = 0,
- ch = string[stringPos];
- if (ch == '-')
- {
- neg = -1;
- ch = string[++stringPos];
- }
- do
- {
- stringPos++;
- if ('0' <= ch <= '9')
- {
- num = (num * 10) + (ch - '0');
- }
- else
- {
- return -1;
- }
- }
- while ((ch = string[stringPos]) > ' ' && ch != delim);
- setarg(paramPos, 0, num * neg);
- }
- case 'h', 'x':
- {
- new
- ch,
- num = 0;
- while ((ch = string[stringPos]) > ' ' && ch != delim)
- {
- switch (ch)
- {
- case 'x', 'X':
- {
- num = 0;
- continue;
- }
- case '0' .. '9':
- {
- num = (num << 4) | (ch - '0');
- }
- case 'a' .. 'f':
- {
- num = (num << 4) | (ch - ('a' - 10));
- }
- case 'A' .. 'F':
- {
- num = (num << 4) | (ch - ('A' - 10));
- }
- default:
- {
- return -1;
- }
- }
- }
- setarg(paramPos, 0, num);
- }
- case 'c':
- {
- setarg(paramPos, 0, string[stringPos++]);
- }
- case 'f':
- {
- setarg(paramPos, 0, _:floatstr(string[stringPos]));
- }
- case 'p':
- {
- delim = format[formatPos++];
- continue;
- }
- case '\'':
- {
- new
- end = formatPos - 1,
- ch;
- while ((ch = format[++end]) && ch != '\'') {}
- if (!ch)
- {
- return -1;
- }
- format[end] = '\0';
- if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
- {
- if (format[end + 1])
- {
- return -1;
- }
- return 0;
- }
- format[end] = '\'';
- stringPos = ch + (end - formatPos);
- formatPos = end + 1;
- }
- case 'u':
- {
- new
- end = stringPos - 1,
- id = 0,
- bool:num = true,
- ch;
- while ((ch = string[++end]) && ch != delim)
- {
- if (num)
- {
- if ('0' <= ch <= '9')
- {
- id = (id * 10) + (ch - '0');
- }
- else
- {
- num = false;
- }
- }
- }
- if (num && IsPlayerConnected(id))
- {
- setarg(paramPos, 0, id);
- }
- else
- {
- #if !defined foreach
- #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
- #define __SSCANF_FOREACH__
- #endif
- string[end] = '\0';
- num = false;
- new
- name[MAX_PLAYER_NAME];
- id = end - stringPos;
- foreach (Player, playerid)
- {
- GetPlayerName(playerid, name, sizeof (name));
- if (!strcmp(name, string[stringPos], true, id))
- {
- setarg(paramPos, 0, playerid);
- num = true;
- break;
- }
- }
- if (!num)
- {
- setarg(paramPos, 0, INVALID_PLAYER_ID);
- }
- string[end] = ch;
- #if defined __SSCANF_FOREACH__
- #undef foreach
- #undef __SSCANF_FOREACH__
- #endif
- }
- stringPos = end;
- }
- case 's', 'z':
- {
- new
- i = 0,
- ch;
- if (format[formatPos])
- {
- while ((ch = string[stringPos++]) && ch != delim)
- {
- setarg(paramPos, i++, ch);
- }
- if (!i)
- {
- return -1;
- }
- }
- else
- {
- while ((ch = string[stringPos++]))
- {
- setarg(paramPos, i++, ch);
- }
- }
- stringPos--;
- setarg(paramPos, i, '\0');
- }
- default:
- {
- continue;
- }
- }
- while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
- {
- stringPos++;
- }
- while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
- {
- stringPos++;
- }
- paramPos++;
- }
- do
- {
- if ((delim = format[formatPos++]) > ' ')
- {
- if (delim == '\'')
- {
- while ((delim = format[formatPos++]) && delim != '\'') {}
- }
- else if (delim != 'z')
- {
- return delim;
- }
- }
- }
- while (delim > ' ');
- 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