Jump to content

Entering turf doesn't close immortality.


Recommended Posts

As I mentioned in the title, I want immortality to be disabled when entering the Turf area.

Note: The Turf script is located in server\mods\deathmatch\resources[xkzKlan]\TurfSistem folder.

The immortality script is located in server\mods\deathmatch\resources[xkzFreeroamSc]\freeroam folder.

 

Code to disable immortality upon entering Turf (Code block) ;

local turfs = {}

addEvent("TurfSistem:onPlayerEnterTurf",true)
addEvent("TurfSistem:onPlayerExitTurf",true)
addEvent("onGroupColorChange",true)
addEvent("onGroupDelete",true)
addEvent("onGroupNameChange",true)
addEvent("D_Modu",true)

addEventHandler("TurfSistem:onPlayerEnterTurf",root,function(id)
	addEventHandler("onPlayerCommand",source,komutEngel)
	setElementData(source,"Turf",tostring(id))
	toggleControl(source,"vehicle_fire",false)
	toggleControl(source,"vehicle_secondary_fire",false)
	toggleControl(source,"ozellik1",false)
	addEventHandler(source, ozellik1, D_Modu, false) -- Invalid code.
end)
addEventHandler("TurfSistem:onPlayerExitTurf",root,function(id)
	removeEventHandler("onPlayerCommand",source,komutEngel)
	setElementData(source,"Turf",nil)
	toggleControl(source,"vehicle_fire",true)
	toggleControl(source,"vehicle_secondary_fire",true)
	toggleControl(source,"ozellik1",true)
	addEventHandler(source, ozellik1, D_Modu, true) -- Invalid code.
end)

 

Immortality script in Freeroam (Code block) ;

local D_Modu = {}

function D_Modu()
    if guiCheckBoxGetSelected(ozellik1) == true then
        triggerServerEvent("Alpha_Olma", getRootElement(), localPlayer)
        outputChatBox("#0066ffÖlümsüzlük Modu #FFFFFFAktif", 255, 255, 255, true)
        addEventHandler("onClientPlayerDamage", localPlayer, nodamage)
        addEventHandler("onClientRender", root, render)
        triggerServerEvent("Olumsuz_olma", getRootElement(), localPlayer)
    else
        outputChatBox("#0066ffÖlümsüzlük Modu #ffffffKapatıldı", 255, 255, 255, true)
        triggerServerEvent("Alpha_Olmama", getRootElement(), localPlayer)
        removeEventHandler("onClientPlayerDamage", localPlayer, nodamage)
        removeEventHandler("onClientRender", root, render)
        triggerServerEvent("Olumsuz_Olmama", getRootElement(), localPlayer)
    end
end

addEventHandler("onClientGUIClick", ozellik1, D_Modu, false)

function nodamage()
    cancelEvent()
end

function render()
    if getPedWeaponSlot(localPlayer) ~= 0 then
        setPedWeaponSlot(localPlayer,0)
    end	
end

 

The errors I'm encountering right now ;
[00:13:37] WARNING: [umoKlan]\TurfSistem\server.lua:16: Bad argument @ 'addEventHandler' [Expected string at argument 1, got player] 
[00:13:39] WARNING: [umoKlan]\TurfSistem\server.lua:24: Bad argument @ 'addEventHandler' [Expected string at argument 1, got player]

 

It seems like I can resolve the issue by making the function global and calling it in "onPlayerEnterTurf". Can you help me with this?

Update: I merged two different folders into the same directory, but couldn't achieve a result.

 
Link to comment
2 minutes ago, FileEX said:

Show the code where the TurfSistem:onPlayerEnterTurf and TurfSistem:onPlayerExitTurf events are triggered

 

function onColShapeHit(hit,dim)
	if not isElement(hit) or not dim then return end
	if getElementType(hit) ~= "player" then return end
	triggerClientEvent(hit,"TurfSistem:onClientPlayerEnterTurf",hit,id)
	triggerEvent("TurfSistem:onPlayerEnterTurf",hit,id)
	removePedJetPack(hit)
	if isPedInVehicle(hit) then return end
	local klan = getPlayerKlan(hit)
	if not klan then return end
	local data = getElementData(source,"TurfBilgi")
	if not data then return end
	local id = data.id
	local klanlar = turfs[id].klanlar
	if not klanlar[klan] then 
		klanlar[klan] = 1 
	else
		klanlar[klan] = klanlar[klan] +1
	end 
	if not data.saldiran then
		if klan ~= data.sahip then
			data.saldiran = klan
		end
	end	
	-- triggerClientEvent(hit,"TurfSistem:onClientPlayerEnterTurf",hit,id)
	-- triggerEvent("TurfSistem:onPlayerEnterTurf",hit,id)
	if not isTimer(turfs[id].timer) then
		timerOlustur(id,hit)
	end
end

 

function onColShapeLeave(hit,dim)
	if not isElement(hit) or not dim then return end
	if getElementType(hit) ~= "player" then return end
	triggerClientEvent(hit,"TurfSistem:onClientPlayerExitTurf",hit,id)
	triggerEvent("TurfSistem:onPlayerExitTurf",hit,id)
	local klan = getPlayerKlan(hit)
	if not klan then return end
	local data = getElementData(source,"TurfBilgi")
	if not data then return end
	local id = data.id
	local klanlar = turfs[id].klanlar
	if klanlar[klan] then klanlar[klan] = klanlar[klan] -1 end	
end

This exit.

Link to comment
7 minutes ago, FileEX said:

So your source is the player. For addEventHandler the first argument is the event name, but you use the source (player which entering into the colshape)

Do I need to add the 'disable' function to the 'onColShapeHit' section?

 

I'm quite confused about how or where to add it. Please help me get out of this situation.

I updated my code like this. Now it no longer gives the old error. However, it shows another error because it couldn't fetch the 'D_Modu' function correctly. How can I fetch this correctly?

Error: 

[01:14:28] ERROR: [umoKlan]\TurfSistem\server.lua:147: call: failed to call 'freeroam:D_Modu' [(tail call)]
[01:14:29] ERROR: [umoKlan]\TurfSistem\server.lua:178: call: failed to call 'freeroam:D_Modu' [(tail call)]

function onColShapeHit(hit,dim)
	if not isElement(hit) or not dim then return end
	if getElementType(hit) ~= "player" then return end
	triggerClientEvent(hit,"TurfSistem:onClientPlayerEnterTurf",hit,id)
	triggerEvent("TurfSistem:onPlayerEnterTurf",hit,id)
	D_Modu() -- new code
	removePedJetPack(hit)
	if isPedInVehicle(hit) then return end
	local klan = getPlayerKlan(hit)
	if not klan then return end
	local data = getElementData(source,"TurfBilgi")
	if not data then return end
	local id = data.id
	local klanlar = turfs[id].klanlar
	if not klanlar[klan] then 
		klanlar[klan] = 1 
	else
		klanlar[klan] = klanlar[klan] +1
	end 
	if not data.saldiran then
		if klan ~= data.sahip then
			data.saldiran = klan
		end
	end	
	-- triggerClientEvent(hit,"TurfSistem:onClientPlayerEnterTurf",hit,id)
	-- triggerEvent("TurfSistem:onPlayerEnterTurf",hit,id)
	if not isTimer(turfs[id].timer) then
		timerOlustur(id,hit)
	end
end

 

Link to comment
addEventHandler("TurfSistem:onPlayerEnterTurf",root,function(id)
	addEventHandler("onPlayerCommand",source,komutEngel)
	setElementData(source,"Turf",tostring(id))
	toggleControl(source,"vehicle_fire",false)
	toggleControl(source,"vehicle_secondary_fire",false)
	toggleControl(source,"ozellik1",false)
	addEventHandler(source, ozellik1, D_Modu, false) -- Remove this
end)
addEventHandler("TurfSistem:onPlayerExitTurf",root,function(id)
	removeEventHandler("onPlayerCommand",source,komutEngel)
	setElementData(source,"Turf",nil)
	toggleControl(source,"vehicle_fire",true)
	toggleControl(source,"vehicle_secondary_fire",true)
	toggleControl(source,"ozellik1",true)
	addEventHandler(source, ozellik1, D_Modu, true) -- Remove this
end)

From this code, simply remove these lines with addEventHandler. They are wrong and are not needed anywhere from what I see

Link to comment

There's another script file named exports.lua within the TurfSistem module. I attempted to compile it a bit and re-export it, but this time I encountered a different error.

 

My exports.lua codes ;

local klansistem = exports.KlanSistem
local D_Modu = exports["freeroam"]:D_Modu(player)
--local player = player-- oyuncu değişkenini belirtin
--call(getResourceFromName("[umoKlan]"), "freeroam", player, "02")

function D_Modu()
    return exports["freeroam"]:D_Modu()
end

It exports the rank system from there.

 

I updated the server.lua file in the TurfSistem module like this ;

local turfs = {}
local freeroam = exports["freeroam"]

addEvent("TurfSistem:onPlayerEnterTurf",true)
addEvent("TurfSistem:onPlayerExitTurf",true)
addEvent("onGroupColorChange",true)
addEvent("onGroupDelete",true)
addEvent("onGroupNameChange",true)

addEventHandler("TurfSistem:onPlayerEnterTurf",root,function(id)
	addEventHandler("onPlayerCommand",source,komutEngel)
	setElementData(source,"Turf",tostring(id))
	toggleControl(source,"vehicle_fire",false)
	toggleControl(source,"vehicle_secondary_fire",false)
	toggleControl(source,"ozellik1",false)
end)

addEventHandler("TurfSistem:onPlayerExitTurf",root,function(id)
	removeEventHandler("onPlayerCommand",source,komutEngel)
	setElementData(source,"Turf",nil)
	toggleControl(source,"vehicle_fire",true)
	toggleControl(source,"vehicle_secondary_fire",true)
	toggleControl(source,"ozellik1",false)
end)

function onColShapeHit(hit,dim)
	if not isElement(hit) or not dim then return end
	if getElementType(hit) ~= "player" then return end
	triggerClientEvent(hit,"TurfSistem:onClientPlayerEnterTurf",hit,id)
	triggerEvent("TurfSistem:onPlayerEnterTurf",hit,id)
	D_Modu(hitElement, true)
	removePedJetPack(hit)
	if isPedInVehicle(hit) then return end
	local klan = getPlayerKlan(hit)
	if not klan then return end
	local data = getElementData(source,"TurfBilgi")
	if not data then return end
	local id = data.id
	local klanlar = turfs[id].klanlar
	if not klanlar[klan] then 
		klanlar[klan] = 1 
	else
		klanlar[klan] = klanlar[klan] +1
	end 
	if not data.saldiran then
		if klan ~= data.sahip then
			data.saldiran = klan
		end
	end	
	-- triggerClientEvent(hit,"TurfSistem:onClientPlayerEnterTurf",hit,id)
	-- triggerEvent("TurfSistem:onPlayerEnterTurf",hit,id)
	if not isTimer(turfs[id].timer) then
		timerOlustur(id,hit)
	end
end

function onColShapeLeave(hit,dim)
	if not isElement(hit) or not dim then return end
	if getElementType(hit) ~= "player" then return end
	triggerClientEvent(hit,"TurfSistem:onClientPlayerExitTurf",hit,id)
	triggerEvent("TurfSistem:onPlayerExitTurf",hit,id)
	D_Modu(hitElement, false)
	local klan = getPlayerKlan(hit)
	if not klan then return end
	local data = getElementData(source,"TurfBilgi")
	if not data then return end
	local id = data.id
	local klanlar = turfs[id].klanlar
	if klanlar[klan] then klanlar[klan] = klanlar[klan] -1 end	
end

This is my client.lua script in the freeroam module ;

local D_Modu = {}

function D_Modu()
    if guiCheckBoxGetSelected(ozellik1) == true then
        triggerServerEvent("Alpha_Olma", getRootElement(), localPlayer)
        outputChatBox("#0066ffÖlümsüzlük Modu #FFFFFFAktif", 255, 255, 255, true)
        addEventHandler("onClientPlayerDamage", localPlayer, nodamage)
        addEventHandler("onClientRender", root, render)
        triggerServerEvent("Olumsuz_olma", getRootElement(), localPlayer)
    else
        outputChatBox("#0066ffÖlümsüzlük Modu #ffffffKapatıldı", 255, 255, 255, true)
        triggerServerEvent("Alpha_Olmama", getRootElement(), localPlayer)
        removeEventHandler("onClientPlayerDamage", localPlayer, nodamage)
        removeEventHandler("onClientRender", root, render)
        triggerServerEvent("Olumsuz_Olmama", getRootElement(), localPlayer)
    end
end

exports["freeroam"]:D_Modu()

I hope I explained it correctly.

Link to comment

I do not understand what's going on. What exactly is the problem now? Something isn't working or is there an error? These code snippets say nothing about the problem

Link to comment

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...