Jump to content

Brak plecaków DAYZ


Recommended Posts

Witam, mam pewien problem mianowicie na serwerze lokalnym plecaki na plecach mi działają i jest wszystko ok, ale jak wrzucę core.lua na serwer "żywy" to plecaki nie pokazują się na plecach. Proszę o pomoc : tutaj jest core.lua Dodam, że błąd wyskakuje w linicje 485

local weaponAmmoTable = {
	["Weapons"] ={
		{"M1911 Mag", "M1911", 22, 346},
		{"M9 SD Mag", "M9 SD", 23, 347},
		{"Desert Eagle Mag", "Desert Eagle", 24, 348},
		{"PDW Mag", "PDW", 28, 352},
		{"MP5A5 Mag", "MP5A5", 29, 353},
		{"AKS-74U Mag", "AKS-74U", 31, 1839},
		{"AK-107 Mag", "AK-107", 31, 1834},
		{"AKS Gold Mag", "AKS Gold", 31, 1835},
		{"M4A1 Holo Mag", "M4A1 Holo", 31, 1830},
		{"MK 48 Mod 0 Mag", "MK 48 Mod 0", 30, 1880},
		{"MG36 Mag", "MG36", 30, 1832},
		{"PKP Mag", "PKP", 30, 1833},
		{"SA-58V ACOG Mag", "SA-58V ACOG", 31, 1838},
		{"1866 Slug", "Winchester 1866", 25, 349},
		{"2Rnd. Slug", "Sawn-Off Shotgun", 26, 350},
		{"SPAZ-12 Pellet", "SPAZ-12 Combat Shotgun", 27, 351},
		{"DMR Mag", "DMR", 34, 1869},
		{"KVSK Mag", "KVSK", 34, 1870},
		{"AS50 Mag", "AS50", 34, 1871},
		{"CZ550 Mag", "CZ550", 34, 1872},
		{"Mosin 9130 Mag", "Mosin 9130", 34, 1873},
		{"M24 Mag", "M24", 34, 1874},
		{"M107 Mag", "M107", 34, 1875},
		{"SVD Dragunov Camo Mag", "SVD Dragunov Camo", 34, 1876},
		{"SKS-45 Mag", "SKS-45", 33, 357}
	},
	["others"] = {
		{"Tear Gas", 17, 343, "Tear Gas"},
		{"Grenade", 16, 342, "Grenade"},
		{"Hunting Knife", 4, 335, "Hunting Knife"},
		{"Hatchet", 8, 339, "Hatchet"},
		{"Binoculars", 43, 367, "Binoculars"},
		{"Baseball Bat", 5, 336, "Baseball Bat"},
		{"Shovel", 6, 337, "Shovel"},
		{"Golf Club", 2, 333, "Golf Club"}
	}
};

function getWeaponAmmoType(name)
	for _,v in ipairs(weaponAmmoTable["Weapons"]) do
		if (name == v[2]) then return v[1], v[3], v[4]; end
	end
	for _,v in ipairs(weaponAmmoTable["others"]) do
		if (name == v[1]) then return v[4], v[2], v[3]; end
	end
	return false, false, false;
end

local skinTable = {
	{"Camouflage Clothing", 287},
	{"Civilian Clothing", 179},
	{"Ghillie Suit", 285},
	{"Survivor Clothing", 73},
	{"Rebel Clothing",18},
	{"Ghost Clothing",37},
	{"Bandit Clothing",302},
	{"Woman Clothing",303},
	{"S.T.A.L.K.E.R.",19},
	{"Sniper Bandit",304},
        {"WomanMilitary Clothing",89}
};



local weatherTable = {
	[1] = 5,
	[2] = 8,
	[3] = 7,
	[4] = 10
};

local backpackSlots = {
	["NTS"] = {
		["Coyote Backpack"] = 74,
		["Czech Backpack"] = 64,
		["Alice Pack"] = 46,
		["Assault Pack (ACU)"] = 24,
		["Military Backpack"] = 86,
		["The Backpack"] = 112
	},
	["STN"] = {
		[74] = "Coyote Backpack",
		[64] = "Czech Backpack",
		[46] = "Alice Pack",
		[24] = "Assault Pack (ACU)",
		[86] = "Military Backpack",
		[112] = "The Backpack"
	}
};

local elementBackpack = {};
local elementWeaponBack = {};
local elementWeaponBack2 = {};
local elementWeaponRaplace = {};
local handsUp = false;
local siting = false;
local lying = false;

addEvent("relWep", true);
addEvent("onPlayerHideBody", true);
addEvent("onPlayerRearmWeapon", true);
addEvent("removeBackWeaponOnDrop", true);
addEvent("kilLDayZPlayer", true);
addEvent("onPlayerRequestChangingStats", true);
addEvent("onPlayerUseMedicObject", true);
addEvent("onPlayerGiveMedicObject", true);
addEvent("onPlayerChangeSkin", true);
addEvent("onPlayerRefillWaterBottle", true);
addEvent("onPlayerPitchATent", true);
addEvent("onPlayerBuildAWireFence", true);
addEvent("removeWirefence", true);
addEvent("addPlayerCookMeat", true);
addEvent("removeTent" ,true);
addEvent("onPlayerMakeAFire", true);
addEvent("onPlayerPlaceRoadflare", true);
addEvent("kickPlayerOnHighPing", true);
addEvent("onPlayerEquipBackpack", true);
addEvent("onPlayerUnequipWeapon", true);

addEventHandler("onResourceStart", resourceRoot, function()
	setGameType("The-DayZ 2.0"); --[[ Multi Theft Auto DayZ Revision 3 ]]
	local realTime = getRealTime();
	setTime(realTime.hour, realTime.minute);
	setMinuteDuration(60000);
	setWeaponProperty(30, "pro", "maximum_clip_ammo", 100);
	setWeaponProperty(30, "std", "maximum_clip_ammo", 100);
	setWeaponProperty(30, "poor", "maximum_clip_ammo", 100);
	setWeaponProperty(31, "pro", "maximum_clip_ammo", 30);
	setWeaponProperty(31, "std", "maximum_clip_ammo", 30);
	setWeaponProperty(31, "poor", "maximum_clip_ammo", 30);
	setWeaponProperty(29, "pro", "maximum_clip_ammo", 20);
	setWeaponProperty(29, "std", "maximum_clip_ammo", 20);
	setWeaponProperty(29, "poor", "maximum_clip_ammo", 20);
	setWeaponProperty("34", "poor", "weapon_range", 500);
	setWeaponProperty("34", "std", "weapon_range", 500);
	setWeaponProperty("34", "pro", "weapon_range", 500);
	setWeaponProperty("30", "poor", "weapon_range", 150);
	setWeaponProperty("30", "std", "weapon_range", 150);
	setWeaponProperty("30", "pro", "weapon_range", 150);
	setWeaponProperty("31", "poor", "weapon_range", 150);
	setWeaponProperty("31", "std", "weapon_range", 150);
	setWeaponProperty("31", "pro", "weapon_range", 150);
	setWeaponProperty("31", "poor", "accuracy", 0.08);
	setWeaponProperty("31", "std", "accuracy", 0.8);
	setWeaponProperty("31", "pro", "accuracy", 0.8);
	setWeaponProperty("30", "poor", "accuracy", 11);
	setWeaponProperty("30", "std", "accuracy", 11);
	setWeaponProperty("30", "pro", "accuracy", 11);
setWeaponProperty("mp5", "poor", "weapon_range", 200);
setWeaponProperty("mp5", "std", "weapon_range", 200);
setWeaponProperty("mp5", "pro", "weapon_range", 200);
setWeaponProperty("mp5", "poor", "accuracy", 0.8);
setWeaponProperty("mp5", "std", "accuracy", 0.8);
setWeaponProperty("mp5", "pro", "accuracy", 0.8);
end);

function getBackpackNameFromSlots(slots)
	if (slots > 8) then
		return backpackSlots["STN"][slots];
	end
	return "None";
end

function getBackpackSlotsFromName(name)
	if name then
		return backpackSlots["NTS"][name];
	end
	return false;
end

function removeBackpack(source)
	if elementBackpack[source] then
		detachElementFromBone(elementBackpack[source]);
		destroyElement(elementBackpack[source]);
		elementBackpack[source] = false;
		setElementData(source, "tohide2", "NONE");
	end
end

function removeWeaponBack(source)
	if elementWeaponBack[source] then
		detachElementFromBone(elementWeaponBack[source]);
		destroyElement(elementWeaponBack[source]);
		elementWeaponBack[source] = false;
		setElementData(source, "tohide3", "NONE");
	end
end

function removeWeaponBack2(source)
	if elementWeaponBack2[source] then
		detachElementFromBone(elementWeaponBack2[source]);
		destroyElement(elementWeaponBack2[source]);
		elementWeaponBack2[source] = false;
		setElementData(source, "tohide4", "NONE");
	end
end

function removeWeaponReplace(source)
	if elementWeaponRaplace[source] then
		detachElementFromBone(elementWeaponRaplace[source]);
		destroyElement(elementWeaponRaplace[source]);
		elementWeaponRaplace[source] = false;
		setElementData(source, "tohide1", "NONE");
	end
end

addEventHandler("onPlayerEquipBackpack", root, function(backpack)
	local nSlots = getBackpackSlotsFromName(backpack);
	local oSlots = getElementData(source, "MAX_Slots");
	if (nSlots > oSlots) then
		setElementData(source, "MAX_Slots", nSlots);
		setElementData(source, backpack, getElementData(source, backpack) - 1);
		local oName = getBackpackNameFromSlots(oSlots);
		triggerClientEvent(source, "refreshInventoryManual", source);
	else
		triggerClientEvent(source, "displayClientInfo", source, "You already have a biger or equal backpack!", 255, 22, 0);
	end
end);

addEventHandler("onPlayerUnequipWeapon", root, function(eweapon, slot)
	local weap = getElementData(source, "currentweapon_"..tostring(slot));
	local name,id,model = getWeaponAmmoType(weap);
	takeWeapon(source, id);
	if (slot < 3) then
		setElementData(source, weap, getElementData(source, weap) + 0);
		setElementData(source, eweapon, getElementData(source, eweapon) - 0);
		setElementData(source, "currentweapon_"..tostring(slot), "");
		if (slot == 1) then
			removeWeaponBack(source);
			removeWeaponReplace(source);
		else
			removeWeaponBack2(source);
		end
	else
		setElementData(source, weap, getElementData(source, weap.." (Equipped)"));
		setElementData(source, eweapon, 0);
		setElementData(source, "currentweapon_"..tostring(slot), "");
	end
	triggerClientEvent(source, "refreshInventoryManual", source);
end);

addEventHandler("onPlayerRearmWeapon", root, function(weapon, slot)
	takeAllWeapons(source);
	local wAmmo,id,_ = getWeaponAmmoType(weapon);
	local ammos = wAmmo;
	if (id ~= 8 or id ~= 5 or id ~= 6 or id ~= 2) then
		ammos = 1;
	end
	if (slot < 3 and ammos < 1) then
		triggerClientEvent(source, "displayClientInfo", source, "No mags left for this weapon!", 255, 22, 0);
	else
		local old = getElementData(source, "currentweapon_"..tostring(slot));
		if (weapon == old) then
			equipThem(source, slot);
			return;
		end
		if (slot < 3) then
			if (old ~= "") then
				setElementData(source, old, getElementData(source, old));
				setElementData(source, old.." (Equipped)", 0);
			end
			setElementData(source, weapon, getElementData(source, weapon));
			setElementData(source, weapon.." (Equipped)", 1);
			setElementData(source, "currentweapon_"..tostring(slot), weapon);
		else
			if (old ~= "") then
				local oldq = getElementData(source, old);
				if (oldq > 0) then
					setElementData(source, old, oldq);
				end
			end
			setElementData(source, weapon.." (Equipped)", getElementData(source, weapon));
			setElementData(source, "currentweapon_"..tostring(slot), weapon);
			setElementData(source, weapon, 0);
		end
	end
	triggerClientEvent(source, "refreshInventoryManual", source);
	equipThem(source, slot);
end);

function equipThem(player, slot)
	removeWeaponBack(player);
	removeWeaponBack2(player);
	removeWeaponReplace(player);
	for i = 1, 3 do
		local weapon = getElementData(player, "currentweapon_"..tostring(i));
		if (weapon ~= "") then
			if (i == slot) then bool = true; else bool = false; end
			local ammo,id,_ = getWeaponAmmoType(weapon);
			if (i == 3) then
				giveWeapon(player, id, getElementData(player, weapon.." (Equipped)"), bool);
			else
				if (id == 8) then
					giveWeapon(player, id, 1, bool);
				else
					local wam = getElementData(player, ammo);
					giveWeapon(player, id, wam, bool);
					setWeaponAmmo(player, id, wam);
				end
			end
		end
	end
	if (slot == 1) then
		local weap2 = getElementData(player, "currentweapon_2");
		if (weap2 ~= "") then
			local _,id,model2 = getWeaponAmmoType(weap2);
			if model2 then
				attachWeaponBack2(player, model2, id);
			end
		end
	elseif (slot == 2) then
		local weap1 = getElementData(player, "currentweapon_1");
		if (weap1 ~= "") then
			local _,_,model1 = getWeaponAmmoType(weap1);
			if model1 then
				attachWeaponBack(player, model1);
			end
		end
	else
		local weap1 = getElementData(player, "currentweapon_1");
		if (weap1 ~= "") then
			local _,_,model1 = getWeaponAmmoType(weap1);
			if model1 then
				attachWeaponBack(player, model1);
			end
		end
		local weap2 = getElementData(player, "currentweapon_2");
		if (weap2 ~= "") then
			local _,id,model2 = getWeaponAmmoType(weap2);
			if model2 then
				attachWeaponBack2(player, model2, id);
			end
		end
		if (slot == 0) then
			setPedWeaponSlot(player, 0);
		end
	end
end


function attachWeaponReplace(source, model)
	removeWeaponReplace(source);
	local x,y,z = getElementPosition(source);
	if (model > 1000) then
		elementWeaponRaplace[source] = createObject(model, x, y, z);
		if elementWeaponRaplace[source] then
			setElementData(source, "tohide1", elementWeaponRaplace[source]);
		end
		if elementBackpack[source] then
			attachElementToBone(elementWeaponRaplace[source], source, 12, 0, 0, 0, 180, 90, 180);
		else
			attachElementToBone(elementWeaponRaplace[source], source, 12, 0, 0, 0, 180, 90, 180);
		end
	end
end

function attachWeaponBack(source, model)
	removeWeaponBack(source);
	local x,y,z = getElementPosition(source);
	elementWeaponBack[source] = createObject(model, x, y, z);
	if elementWeaponBack[source] then
		setObjectScale(elementWeaponBack[source], 0.8);
		setElementData(source, "tohide3", elementWeaponBack[source]);
	end
	if elementBackpack[source] then
		attachElementToBone(elementWeaponBack[source], source, 3, 0.19, -0.31, -0.1, 0, 270, -90);
	else
		attachElementToBone(elementWeaponBack[source], source, 3, 0.19, -0.11, -0.1, 0, 270, 10);
	end
end

function attachWeaponBack2(source, model, id)
	removeWeaponBack2(source);
	local x,y,z = getElementPosition(source);
	elementWeaponBack2[source] = createObject(model, x, y, z);
	if elementWeaponBack2[source] then
		setObjectScale(elementWeaponBack2[source], 1);
		if (id == 6) then
			setObjectScale(elementWeaponBack2[source], 0.7);
		elseif (id == 8) then
			setObjectScale(elementWeaponBack2[source], 0.8);
		end
		setElementData(source, "tohide4", elementWeaponBack2[source]);
	end
	if elementBackpack[source] then
		if (id == 8) then
			attachElementToBone(elementWeaponBack2[source], source, 3, -0.18, -0.12, 0.22, 180, 0, -90);
		elseif (id == 2 or id == 4 or id == 6 or id == 5) then
			attachElementToBone(elementWeaponBack2[source], source, 3, -0.18, -0.18, -0.1, 0, 0, -90);
		else
			attachElementToBone(elementWeaponBack2[source], source, 3, -0.18, -0.31, -0.1, 0, 270, -90);
		end
	else
		if (id == 8) then
			attachElementToBone(elementWeaponBack2[source], source, 3, -0.07 -0.14, -0.1, -0.1, 0, -8);
		elseif (id == 2 or id == 4) then
			attachElementToBone(elementWeaponBack2[source], source, 3, -0.20, -0.11, -0.1, -0.1, 0, -11);
		elseif (id == 6 or id == 5) then
			attachElementToBone(elementWeaponBack2[source], source, 3, -0.15, -0.11, -0.1, -0.1, 0, 70);
		else
			attachElementToBone(elementWeaponBack2[source], source, 3, -0.22, -0.11, -0.1, -0.1, -270, -11);
		end
	end
end


addEventHandler("onPlayerWeaponSwitch", root, function(previousWeaponID, currentWeaponID)
	local weapon = getElementData(source, "currentweapon_1");
	local weapon2 = getElementData(source, "currentweapon_2");
	if not weapon then return; end
	local _,weapID,model = getWeaponAmmoType(weapon);
	if (currentWeaponID == weapID) then
		removeWeaponBack(source);
		attachWeaponReplace(source, model);
	elseif (previousWeaponID == weapID) then
		removeWeaponReplace(source);
	end
	if not weapon2 then return; end
	local _,id2,model2 = getWeaponAmmoType(weapon2);
	if (previousWeaponID == id2) then
	elseif (currentWeaponID == id2) then
		removeWeaponBack2(source);
	end
end);


addEventHandler("removeBackWeaponOnDrop", root, function(check, slot)
	if (slot == 1) then
		removeWeaponBack(source);
		removeWeaponReplace(source);
	elseif (slot == 2) then
		removeWeaponBack2(source);
	end
	if check then
		local weapon = getElementData(source, "currentweapon_"..tostring(slot));
		local _,id,_ = getWeaponAmmoType(weapon);
		takeWeapon(source, id);
		if (slot == 3) then
			takeWeapon(client, id);
			local weapon = getElementData(client, "currentweapon_3");
			if weapon then
				setElementData(client, weapon.." (Equipped)", getElementData(client, weapon.." (Equipped)") - 1);
				setElementData(client, "currentweapon_3", "");
			end
		end
		setElementData(source, "currentweapon_"..tostring(slot), "");
		triggerClientEvent(source, "refreshInventoryManual", source);
	end
end);

addEventHandler("onPlayerQuit", root, function()
	removeBackpack(source);
	removeWeaponBack(source);
	removeWeaponReplace(source);
	removeWeaponBack2(source);
end);

addEventHandler("kilLDayZPlayer", root, function()
	removeBackpack(source);
	removeWeaponBack(source);
	removeWeaponReplace(source);
	removeWeaponBack2(source);
end);

addEventHandler("onElementDataChange", root, function(dataName, oldValue)
	if not oldValue then oldValue = 0; end
	if (getElementType(source) == "player") then
		if (dataName == "MAX_Slots") then
			local newValue = getElementData(source, dataName);
			removeBackpack(source);
			local x,y,z = getElementPosition(source);
			if (newValue == 12) then elementBackpack[source] = createObject(3026, x, y, z); -- Assault Pack (ACU)
			elseif (newValue == 16) then elementBackpack[source] = createObject(1248, x, y, z); -- Alice Pack
			elseif (newValue == 26) then elementBackpack[source] = createObject(1575, x, y, z); -- Czech Backpack
			elseif (newValue >= 36) then elementBackpack[source] = createObject(1252, x, y, z); -- Coyote Backpack
			elseif (newValue == 8) then return; end
			if elementBackpack[source] then
				setElementData(source, "tohide2", elementBackpack[source]);
				if (newValue >= 36) then
					setObjectScale(elementBackpack[source], 0.95);
				end
			end
			if (newValue == 12) then
				attachElementToBone(elementBackpack[source], source, 3, 0, -0.16, 0.05, 270, 0, 180);
			else
				attachElementToBone(elementBackpack[source], source, 3, 0, -0.225, 0.05, 90, 0, 0);
			end	
			addCommandHandler ( "createObject", consoleCreateObject )	
		elseif (dataName == "Map") then
			if (getElementData(source, "Map") >= 1) then
				toggleControl(source, "radar", true);
			else
				toggleControl(source, "radar", false);
			end

		elseif (dataName == "GPS") then
			if (getElementData(source, "GPS") >= 1) then
				setPlayerHudComponentVisible(source, "radar", true);
			else
				setPlayerHudComponentVisible(source, "radar", false);
			end
		end
		local weapon1 = getElementData(source, "currentweapon_1");
		local weapon2 = getElementData(source, "currentweapon_2");
		local weapon3 = getElementData(source, "currentweapon_3");
		if (dataName == weapon1 or dataName == weapon2 or dataName == weapon3) then
			if (getElementData(source, dataName) == 0) then
				local ammoData,weapID = getWeaponAmmoType(dataName);
				takeWeapon(source, weapID);
			end
		end
		local ammoData1,weapID1 = getWeaponAmmoType(weapon1);
		if (dataName == ammoData1) then
			local newammo = (oldValue-getElementData(source, dataName));
			if (newammo == 1) then return; end
			if (getElementData(source, dataName) < oldValue) then
				takeWeapon(source, weapID1, newammo);
				removeWeaponBack(source);
			elseif (getElementData(source, dataName) > oldValue) then
				giveWeapon(source, weapID1, getElementData(source, dataName)-oldValue, false);
			end
		end
		local ammoData2,weapID2 = getWeaponAmmoType(weapon2);
		if (dataName == ammoData2) then
			local newammo = oldValue-getElementData(source, dataName);
			if (newammo == 1) then return; end
			if (getElementData(source, dataName) < oldValue) then
				takeWeapon(source, weapID2, newammo);
			elseif (getElementData(source,dataName) > oldValue) then
				giveWeapon(source, weapID2, getElementData(source, dataName)-oldValue, false);
			end
		end
		local ammoData3,weapID3 = getWeaponAmmoType(weapon3);
		if (dataName == ammoData3) then
			local newammo = oldValue-getElementData(source, dataName);
			if (newammo == 1) then return; end
			if (getElementData(source, dataName) < oldValue) then
				takeWeapon(source, weapID3, newammo);
			elseif (getElementData(source, dataName) > oldValue) then
				giveWeapon(source, weapID3, getElementData(source, dataName)-oldValue, false);
			end
		end
	end
end);

addEventHandler("onPlayerStealthKill", root, function(target)
	if (target and getElementType(target) == "player") then
		triggerEvent("kilLDayZPlayer", target, source, false, false);
	end
end);

function addPlayerStats(player, data, value)
	if (data == "food") then
		local current = getElementData(player, data);
		if (current + value > 100) then
			setElementData(player, data, 100);
		elseif (current + value < 1) then
			setElementData(player, data, 0);
			setElementData(player, "blood", (getElementData(player, "blood") - math.random(50, 120)));
		else
			setElementData(player, data, (current + value));
		end
	elseif (data == "thirst") then
		local current = getElementData(player, data);
		if (current + value > 100) then
			setElementData(player, data, 100);
		elseif (current + value < 1) then
			setElementData(player, data, 0);
			setElementData(player, "blood", (getElementData(player, "blood") - math.random(50, 120)));
		else
			setElementData(player, data, (current + value));
		end
	elseif (data == "blood") then
		local current = getElementData(player, data);
		if (current + value > 12000) then
			setElementData(player, data, 12000);
		elseif (current + value < 1) then
			setElementData(player, data, 0);
		else
			setElementData(player, data, (current + value));
		end
	elseif (data == "temperature") then
		local current = getElementData(player, data);
		if (current + value > 41) then
			setElementData(player, data, 41);
		elseif (current + value <= 31) then
			setElementData(player, data, 31);
		else
			setElementData(player, data, (current + value));
		end
	elseif (data == "humanity") then
		local current = getElementData(player, data);
		local new = current + value;
		if (new > 5000) then
			setElementData(player, data, 5000);
			setElementData(player, "htype", "Hero");
		else
			setElementData(player, data, new);
			if (new <= 0) then
				setElementData(player, "htype", "Bandit");
			elseif new >= 2000 then
				setElementData(player, "htype", "Survivor");
			end
		end
	end
end

setTimer(function()
	for _,v in ipairs(getElementsByType("player")) do
		if getElementData(v, "logedin") then
			local value = 0;
			if isElementInWater(v) then
				value = -0.01;
			end
			if getControlState(v, "sprint") then
				value = (value + 0.005);
				addPlayerStats(v, "thirst", -0.2);
			end
			local weather = getWeather();
			if (weather == 5) then
				value = (value + 0.005);
			elseif (weather == 8) then
				value = (value - 0.05);
			elseif (weather == 7) then
				value = (value - 0.01);
			elseif (weather == 10) then
				value = (value + 0.05);
			end
			addPlayerStats(v, "temperature", value);
			addPlayerStats(v, "food", -1.5);
			addPlayerStats(v, "thirst", -1.5);
		end 
	end
end, 60000, 0);

addEventHandler("onPlayerRequestChangingStats", root, function(itemName, itemInfo, data)
	if (data == "food") then
		if (itemName == "Burger") then blood = math.random(200, 300);
		elseif (itemName == "Pizza") then blood = math.random(300, 350);
		elseif (itemName == "Cooked Meat") then blood = math.random(600, 800);
		elseif (itemName == "Beans Can") then blood = math.random(150, 250);
		elseif (itemName == "Pasta Can") then blood = math.random(320, 400); end
		setPedAnimation(source, "FOOD", "EAT_Burger", -1, false, false, nil, false);
		setElementData(source, itemName, getElementData(source, itemName)-1);
		addPlayerStats(source, "blood", blood);
		addPlayerStats(source, data, math.random(60, 100));
	elseif (data == "thirst") then
		setElementData(source, itemName, getElementData(source, itemName)-1);
		addPlayerStats(source, data, math.random(60, 100));
		setPedAnimation(source, "VENDING", "VEND_Drink2_P", -1, false, false, nil, false);
		if (itemName == "Water Bottle") then
			setElementData(source, "Empty Water Bottle", getElementData(source, "Empty Water Bottle") + 1);
		end
	end
	triggerClientEvent(source, "displayClientInfo", source, "You consumed "..itemName, 22, 255, 0);
	triggerClientEvent(source, "refreshInventoryManual", source);
end);

addEventHandler("onPlayerUseMedicObject", root, function(itemName)
	setPedAnimation(source, "BOMBER", "BOM_Plant", -1, false, false, nil, false);
	setTimer(function(source)
		if (itemName == "Bandage") then
			setElementData(source, "bleeding", 0);
			setElementData(source, itemName, getElementData(source, itemName) - 1);
		elseif (itemName == "Medic Kit") then
			addPlayerStats(source, "blood", 7000);
			setElementData(source, "bleeding", 0);
			setElementData(source, itemName, getElementData(source, itemName) - 1);
		elseif (itemName == "Heat Pack") then
			setElementData(source, "cold", false);
			setElementData(source, "temperature", 37);
			setElementData(source, itemName, getElementData(source, itemName) - 1);
		elseif (itemName == "Painkiller") then
			setElementData(source, "pain", false);
			setElementData(source, itemName, getElementData(source, itemName) - 1);
		elseif (itemName == "Morphine") then
			setElementData(source, "brokenbone", false)
			setElementData(source, itemName, getElementData(source, itemName) - 1);
		elseif (itemName == "Blood Bag") then
			addPlayerStats(source, "blood", 12000);
			setElementData(source, itemName, getElementData(source, itemName) - 1);
		end
		triggerClientEvent(source, "refreshInventoryManual", source);
	end, 1000, 1, source);
end);

addEventHandler("onPlayerGiveMedicObject", root, function(itemName, player)
	setPedAnimation(source, "BOMBER", "BOM_Plant", -1, false, false, nil, false);
	setTimer(function(source)
		if (itemName == "givebandage") then
			setElementData(player, "bleeding", 0);
			setElementData(source, "Bandage", getElementData(source, "Bandage") - 1);
			addPlayerStats(source, "humanity", 40);
		elseif (itemName == "giveblood") then
			addPlayerStats(player, "blood", 12000);
			setElementData(source, "Blood Bag", getElementData(source, "Blood Bag") - 1);
			addPlayerStats(source, "humanity", 250);
		end
		triggerClientEvent(source, "refreshInventoryManual", source);
	end, 1000, 1, source);
end);

function getSkinIDFromName(name)
	for _,v in ipairs(skinTable) do
		if (name == v[1]) then return v[2]; end
	end
end

function getSkinNameFromID(id)
	for _,v in ipairs(skinTable) do
		if (id == v[2]) then return v[1]; end
	end
end

addEventHandler("onPlayerChangeSkin", root, function(skin)
	local name = getSkinNameFromID(getElementData(source, "skin"));
	setElementData(source, name, getElementData(source, name)+1);
	setElementData(source, skin, getElementData(source, skin)-1);
	local id = getSkinIDFromName(skin);
	setElementData(source, "skin", id);
	setElementModel(source, id);
	triggerClientEvent(source, "refreshInventoryManual", source);
end);

addEventHandler("onPlayerRefillWaterBottle", root, function(itemName)
	if isElementInWater(source) then
		setElementData(source, "Water Bottle", getElementData(source, "Water Bottle") + 1);
		setElementData(source, itemName, getElementData(source, itemName) - 1);
		triggerClientEvent(source, "refreshInventoryManual", source);
		triggerClientEvent(source, "displayClientInfo", source, "You filled 1 x "..itemName, 22, 255, 0);
	else
		triggerClientEvent(source, "displayClientInfo", source, "You must be in water!", 255, 22, 0);
	end 
end);

addEventHandler("onPlayerPitchATent", root, function(itemName)
	setElementData(source, itemName, getElementData(source, itemName) - 1);
	setPedAnimation(source, "BOMBER", "BOM_Plant", -1, false, false, nil, false);
	setTimer(function(source)
		local x,y,z = getElementPosition(source);
		local xr,yr,zr = getElementRotation(source);
		local offsetRot = math.rad(zr+90);
		local vx = x+5*math.cos(offsetRot);
		local vy = y+5*math.sin(offsetRot);
		local vrot = zr+180;
		local tent = createObject(3243, vx, vy, (z-1), 0, 0, vrot);
		setObjectScale(tent, 1.3);
		local tentCol = createColSphere(x, y, z, 4);
		attachElements(tentCol, tent, 0, 0, 0);
		setElementData(tentCol, "parent", tent);
		setElementData(tent, "parent", tentCol);
		setElementData(tentCol, "tent", true);
		setElementData(tentCol, "MAX_Slots", 500);
		triggerClientEvent(source, "refreshInventoryManual", source);
	end, 1000, 1, source);
end);

addEventHandler("onPlayerBuildAWireFence", root, function(itemName)
	setElementData(source, itemName, getElementData(source, itemName)-1);
	setPedAnimation(source, "BOMBER", "BOM_Plant", -1, false, false, nil, false);
	setTimer(function(source)
		local x,y,z = getElementPosition(source);
		local xr,yr,zr = getElementRotation(source);
		local offsetRot = math.rad(zr+90);
		local vx = x+1*math.cos(offsetRot);
		local vy = y+1*math.sin(offsetRot);
		local vrot = zr+90;
		local wFence = createObject(983, vx, vy, z, xr, yr, vrot);
		setObjectScale(wFence, 1);
		local wFenceCol = createColSphere(x, y, z, 2);
		attachElements(wFenceCol, wFence, 0, 0, 0);
		setElementData(wFenceCol, "parent", wFence);
		setElementData(wFence, "parent", wFenceCol);
		setElementData(wFenceCol, "wirefence", true);
		triggerClientEvent(source, "refreshInventoryManual", source);
	end, 1000, 1, source);
end);

addEventHandler("removeWirefence", root, function(object)
	setTimer(function(object)
		destroyElement(getElementData(object, "parent"));
		destroyElement(object);
	end, 1000, 1, object);
end);

addEventHandler("removeTent",root, function(object)
	local col = getElementData(object, "parent");
	setTimer(function(col, object)
		local x,y,z = getElementPosition(col);
		local item,itemString = getItemTablePosition("Tent");
		local itemPickup = createItemPickup(item, x, y, (z+1), itemString);
		if col then destroyElement(col); end
		if object then destroyElement(object); end
	end, 1000, 1, col, object);
end);

addEventHandler("addPlayerCookMeat", root, function()
	setPedAnimation(source, "BOMBER", "BOM_Plant", -1, false, false, nil, false);
	local meat = getElementData(source, "Raw Meat");
	setTimer(function(source)
		setElementData(source, "Raw Meat", 0);
		setElementData(source, "Cooked Meat", getElementData(source, "Cooked Meat") + meat);
		triggerClientEvent(source, "displayClientInfo", source, "You cooked "..tostring(meat).." Raw Meat.", 22, 255, 0);
	end, 5000, 1, source);
end);

addEventHandler("onPlayerMakeAFire", root, function(itemName)
	setElementData(source, "Wood Pile", getElementData(source, "Wood Pile")-1);
	local x,y,z = getElementPosition(source);
	local xr,yr,zr = getElementRotation(source);
	local offsetRot = math.rad(zr+90);
	local vx = x+1*math.cos(offsetRot);
	local vy = y+1*math.sin(offsetRot);
	local vrot = zr+90;
	local wood = createObject(1463, vx, vy, (z-0.75), xr, yr, vrot);
	setObjectScale(wood, 0.55);
	setElementCollisionsEnabled(wood, false);
	setElementFrozen(wood, true);
	local fire = createObject(3525, vx, vy, (z-0.75), xr, yr, vrot);
	setObjectScale(fire, 0);
	local fireCol = createColSphere(x, y, z, 2);
	setElementData(fireCol, "parent", wood);
	setElementData(wood, "parent", fireCol);
	setElementData(fireCol, "fireplace", true);
	triggerClientEvent(source, "refreshInventoryManual", source);
	setPedAnimation(source, "BOMBER","BOM_Plant", -1, false, false, nil, false);
	setTimer(function(fireCol, fire, wood)
		if fireCol then destroyElement(fireCol); end
		if fire then destroyElement(fire); end
		if wood then destroyElement(wood); end
	end, (2*60000), 1, fireCol, fire, wood);
end);

addEventHandler("onPlayerPlaceRoadflare", root, function(itemName)
	setElementData(source, itemName, getElementData(source, itemName)-1);
	local x,y,z = getElementPosition(source);
	local object = createObject(354, x, y, (z-0.6));
	setTimer(destroyElement, 300000, 1, object);
	triggerClientEvent(source, "refreshInventoryManual", source);
end);
 
addEventHandler("onPlayerChat", root, function(message, mType)
	if (mType == 0 or mType == 1) then
		cancelEvent();
	end
	if (mType == 0) then
		local x,y,z = getElementPosition(source);
		local chatSphere = createColSphere(x, y, z, 15);
		local nearbyPlayers = getElementsWithinColShape(chatSphere, "player");
		destroyElement(chatSphere);
		for _,v in ipairs(nearbyPlayers) do
			outputChatBox("#D3D3D3[Local] #D3D3D3"..string.gsub((getPlayerName(source).." : #D3D3D3"..message), '#%x%x%x%x%x%x', ''), v, 211, 211, 211, true);
		end
	end 
end);

setTimer(function()
	for _,v in ipairs(getElementsByType("player")) do
		if getElementData(v, "logedin") then
			local current = getElementData(v, "skin");
				if (current == 179 or current == 287) then
					setElementModel(v, 288);
				elseif (current == 73) then
					setElementModel(v, 180);
				end
				if (current == 73 or current == 179 or current == 287) then
					setElementModel(v, 210);
				end
			else
				setElementModel(v, getElementData(v, "skin"));
			end
		end
end, 231321321321321321123321321, 0);

addCommandHandler("kickall", function(player)
	if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)), aclGetGroup("Admin")) then
		for _,v in ipairs(getElementsByType("player")) do
			if (v ~= player) then
				kickPlayer(v, "#Hotfix!");
			end
		end
	end
end);

addEventHandler("onPlayerCommand", root, function(cmd)
	if (cmd == "login" or cmd == "logout") then
		cancelEvent();
	end
end);

addEventHandler("kickPlayerOnHighPing", root, function()
	kickPlayer(source, "Ping > 400!");
end);

function funcBindHandsup(player, key, keyState)
	if (handsUp) then
		setPedAnimation(player, false);
		handsUp = false;
	else
		if (getElementData(player, "repairvehicle") == true) then return false; end
		if isPedInVehicle(player) then return false; end
		setPedAnimation(player, "BEACH", "ParkSit_M_loop", -1, true, false, false, false);
		handsUp = true;
	end 
end
function funcBindSit(player, key, keyState)
	if (siting) then
		setPedAnimation(player, false);
		siting = false;
	else
		if (getElementData(player, "repairvehicle") == true) then return false; end
		if isPedInVehicle(player) then return false; end
		setPedAnimation(player, "SHOP", "SHP_Rob_HandsUp", -1, true, true, false, false);
		siting = true
	end 
end
function funcBindLie(player, key, keyState)
	if (lying) then
		setPedAnimation(player, false);
		lying = false;
	else
		if (getElementData(player, "repairvehicle") == true) then return false; end
		if isPedInVehicle(player) then return false; end
		setPedAnimation(player, "WUZI", "CS_Dead_Guy", -1, true, false, false, true);
		lying = true;
	end
end

addEventHandler("relWep", resourceRoot, function()
	reloadPedWeapon(client);
end);

function changeWeather(weather)
	if (weather) then
		setWeather(weather);
		return;
	else
		setWeather(weatherTable[math.random(4)]);
		setTimer(changeWeather, (30*60000), 1);
	end
end
 
addEventHandler("onPlayerLogin", root, function()
	bindKey(source, ",", "down", funcBindHandsup);
	bindKey(source, ".", "down", funcBindSit);
	bindKey(source, "l", "down", funcBindLie);
end);

addEventHandler("onPlayerHideBody", root, function()
	local cCol = getElementData(source, "currentCol");
	if (getElementData(source, "Bandage") >= 1) then
		if cCol then
			if getElementData(cCol, "deadman") then
				setElementData(source, "loot", false);
				setElementData(source, "Bandage", getElementData(source, "Bandage") - 1);
				setElementData(source, "currentCol", false);
				setTimer(function(cCol)
					if cCol then
						destroyElement(getElementData(cCol, "parent"));
					end
					destroyElement(cCol);
				end, 2000, 1, cCol);
			end 
		end
	end
end);


addEventHandler("onPlayerQuit", root, function(quitType, reason)
	if not reason then
		outputChatBox("#FFFFFF"..getPlayerName(source):gsub("#%x%x%x%x%x%x", "").." #FF0000has left the server ["..quitType.."]", root, 255, 255, 255, true);
	else
		outputChatBox("#FFFFFF"..getPlayerName(source):gsub("#%x%x%x%x%x%x", "").." #FF0000has left the server [#FFFFFF"..quitType.."#FF0000, #FFFFFF"..reason.."#FF0000]", root, 255, 255, 255, true);
	end
end);

addEventHandler("onPlayerChangeNick", root, function(oldNick, newNick)
	outputChatBox("#FFFFFF"..oldNick:gsub("#%x%x%x%x%x%x", "").." #FF0000is now known as #FFFFFF"..newNick:gsub("#%x%x%x%x%x%x", ""), root, 255, 255, 255, true);
end);

addEventHandler("onPlayerJoin", root, function()
	setPlayerNametagShowing(source, false);
	outputChatBox("#FFFFFF"..getPlayerName(source):gsub("#%x%x%x%x%x%x", "").." #FF0000has joined the server!", root, 255, 255, 255, true);
	for i = 70, 79 do
		if (i ~= 73) then
			setPedStat(source, i, 999);
		end
	end
end);

addEventHandler("onPlayerLogin", root, function()
	triggerClientEvent("displayClientInfo", root, getPlayerName(source):gsub("#%x%x%x%x%x%x", "").." #FFFFFFhas logged in!", 255, 255, 255);
	setElementData(source, "clientdata", {getServerName(), getMaxPlayers()});
end);

setTimer(function()
	for _,v in ipairs(getElementsByType("ped")) do
		if getElementData(v, "zombie") then
			if getElementData(v, "deadzombie") then return; end
			if isPedDead(v) then return; end
			local x,y,z = getElementPosition(v);
			local path = "sounds/mgroan"..math.random(1, 10)..".ogg";
			triggerClientEvent("playPedSound", root, v, path, x, y, z);
		end
	end
end, 5000, 0);

changeWeather(7); -- '7' means you use the weather 7 delete it to make a random weather.

 

Link to comment
  • 2 weeks later...
  • 1 month later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...