thank you all for help.
i added setElementData to the functions 'elementHitSafeZone' and 'elementLeaveSafeZone' , shown in first code
then, with the hint of NssoR, i created a clientside file, which is shown in second code
now it functions perfectly. thanks for all replies
if anyone interested in full code im putting serverside file too (third code)
setElementData ( theElement, "inSafezone", true )
function donthurtme ( attacker, weapon, bodypart )
if ( getElementData ( getLocalPlayer(), "inSafezone" ) == true ) then
cancelEvent()
end
end
addEventHandler ( "onClientPlayerDamage", getLocalPlayer(), donthurtme )
local safeZonesTable =
{
{ x = 1578.2421875, y = 1801.248046875, z = 10.8203125, width = 58, depth = 61, height = 100 },
{ x = 1996.958984375, y = -1450.9560546875, z = 13.5546875, width = 100, depth = 55, height = 100 },
{ x = -2740.775390625, y = 577.9326171875, z = 14.5546875, width = 150, depth = 100, height = 100 }
-- you can add the coords for new safe zones, theese three are the main hospitals.
}
local controls = { "fire", "next_weapon", "previous_weapon", "aim_weapon", "sprint" } -- you can edit the controls you want to disable
addEventHandler ( "onResourceStart", resourceRoot,
function ( )
for _, zone in ipairs ( safeZonesTable ) do
local safeZone = createColCuboid ( zone.x, zone.y, zone.z - 30, zone.width, zone.depth, zone.height )
createRadarArea ( zone.x, zone.y, zone.width, zone.depth, 0, 200, 0, 50 )
addEventHandler ( "onColShapeHit", safeZone, elementHitSafeZone )
addEventHandler ( "onColShapeLeave", safeZone, elementLeaveSafeZone )
end
end
)
function elementHitSafeZone ( theElement, mDim )
if isElement ( theElement ) then
if ( getElementType ( theElement ) == "player" ) then
for _, control in ipairs ( controls ) do
toggleControl ( theElement, control, false )
setPlayerWeaponSlot ( theElement, 0 )
end
exports.GTWtopbar:dm ( "You entered the safezone.", theElement, 200, 50, 50 ) -- simply change 'exports.GTWtopbar:dm' to 'outputChatBox' for using it on chatbox
setElementData ( theElement, "inSafezone", true )
elseif ( getElementType ( theElement ) == "vehicle" ) then
local thePlayer = getVehicleController ( theElement )
for _, control in ipairs ( controls ) do
toggleControl ( thePlayer, control, false )
setPlayerWeaponSlot ( thePlayer, 0 )
end
if ( thePlayer ) then
exports.GTWtopbar:dm ( "You can't drive vehicles inside the safezone", thePlayer, 200, 50, 50 )
end
exports.GTWvehicleshop:saveAndRemoveVehicle ( theElement, true ) -- edit or simply change it with the function destroyElement(theElement) for using it on a freeroam server etc
setElementData ( theElement, "inSafezone", true )
end
end
end
function elementLeaveSafeZone ( theElement, mDim )
if ( isElement ( theElement ) and getElementType ( theElement ) == "player" ) then
for _, control in ipairs ( controls ) do
toggleControl ( theElement, control, true )
end
exports.GTWtopbar:dm ( "You left the safe zone.", theElement, 200, 50, 50 )
setElementData ( theElement, "inSafezone", nil )
end
end
have a good day.