Jump to content

Wanted Trigger Tiimer


VenomOG

Recommended Posts

Hello so i have done a evade script, if your wanted it triggers a timer, just
check it and see where i went wrong :
CLIENT
 

EVADE
addEvent("StartEvadeTimer",true)

addEventHandler("StartEvadeTimer",root,function()

addEventHandler( "onClientRender", root, showEvadeTime )

Time = 300

tick = getTickCount()

end)



function showEvadeTime( )

	if getElementData( localPlayer, "ArrestedBy" ) or getElementData(localPlayer,"Jailed") == "yes" or isPedDead ( localPlayer ) then 

	removeEventHandler("onClientRender",root,showEvadeTime)


	return end 

    if getTickCount(  )-tick >= 1000 then

	Time = Time -1

	tick = getTickCount()

	end

    dxDrawText(Time.." seconds left ", sx*69, sy*728, sx*187, sy*758, tocolor(255, 255, 255, 255), 1.80, "default-bold", "left", "bottom", false, false, false, false, false)

	if Time <= 0 then 

	removeEventHandler("onClientRender",root,showEvadeTime)

	triggerServerEvent("removeEvadeStars",localPlayer)

	end

end

SERVER
 

function removeEvadeStars(player)
setPlayerWantedLevel(player,0)
exports.SAEGMessages:sendClientMessage("Evade : You have evaded your stars",player,0,255,0)
end
addEvent("removeEvadeStars", true)
addEventHandler("removeEvadeStars", getRootElement(), removeEvadeStars)

function convertNumber ( number )
	local formatted = number
	while true do
		formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
		if ( k==0 ) then
			break
		end
	end
	return formatted
end

setTimer(function trigger(player)
local wantedLvl = getPlayerWantedLevel (root)
   if wantedLvl == 3 then
   triggerClientEvent(player,"StartEvadeTimer",player)
end
end
end, 1000, 0)

addEventHandler("onResourceStop", getResourceRootElement(getThisResource()), function() for k, v in ipairs(getElementsByType("player")) do setElementData(v, "rob", false) end end)

 

Link to comment
  • Moderators

Using a named function directly as  an anonymous function is not allowed in lua:

setTimer(function trigger(player)

(So remove trigger)

 

 

local wantedLvl = getPlayerWantedLevel (root)

Getting the wanted level of the root element, Hmm, is the root that evil?

Maybe you would have more luck if you get it from each player?

 

 

triggerClientEvent(player,"StartEvadeTimer",player)

Triggering to a player in the server every 1 second? Should be fine if everybody does have fast internet and ping under the 50... but we both know that isn't the case in MTA.

(No UDP trigger event support, /me crying...)

Link to comment
function removeEvadeStars(player)
setPlayerWantedLevel(player,0)
exports.SAEGMessages:sendClientMessage("Evade : You have evaded your stars",player,0,255,0)
end
addEvent("removeEvadeStars", true)
addEventHandler("removeEvadeStars", getRootElement(), removeEvadeStars)

function convertNumber ( number )
	local formatted = number
	while true do
		formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
		if ( k==0 ) then
			break
		end
	end
	return formatted
end

setTimer(function(player)
for k, v in ipairs(getElementsByType("player")) do 
local wantedLvl = getPlayerWantedLevel (v)
   if (wantedLvl == 1) then
   triggerClientEvent(v,"StartEvadeTimer",v)
end
end
end, 1000,0)

addEventHandler("onResourceStop", getResourceRootElement(getThisResource()), function() for k, v in ipairs(getElementsByType("player")) do setElementData(v, "rob", false) end end)

It constantly restarted the timer how can i stop that @IIYAMA

Link to comment
  • Moderators

Line 26:

end, 1000, 0)

The 0 at the end means infinity.

 

If you write it like this:

end, 1000, 1)

It will only execute the code one time.

 

If that is not the solution you want, then how about use element data to prevent re-triggering? Which you are already familiar with.(line 28)

Link to comment
2 minutes ago, IIYAMA said:

Line 26:

end, 1000, 0)

The 0 at the end means infinity.

 

If you write it like this:


end, 1000, 1)

It will only execute the code one time.

 

If that is not the solution you want, then how about use element data to prevent re-triggering? Which you are already familiar with.(line 28)

Example.

16 minutes ago, IIYAMA said:

Line 26:

end, 1000, 0)

The 0 at the end means infinity.

 

If you write it like this:


end, 1000, 1)

It will only execute the code one time.

 

If that is not the solution you want, then how about use element data to prevent re-triggering? Which you are already familiar with.(line 28)

How can i make it only starts trigger. if wanted, like once player get wanted then start timer

Link to comment
  • Moderators
55 minutes ago, Knuck said:

Example.

How can i make it only starts trigger. if wanted, like once player get wanted then start timer

There are no events for wanted levels.

But you can make them manually by triggering an event at the moment you set the player his wanted level in the gamemode.(this has to be done in the gamemode)

 

You can also use this line there:

triggerClientEvent(v,"StartEvadeTimer", v)

(Just make sure to match the variable names with the gamemode)

Edited by IIYAMA
Link to comment
2 minutes ago, IIYAMA said:

There are no events for wanted levels.

But you can make them manually by triggering an event at the moment you set the player his wanted level in the gamemode.

 

You can also use this line there:


triggerClientEvent(v,"StartEvadeTimer", v)

(Just make sure to match the variable names with the gamemode)

Fixed thanks, 
how can i disable a weapon while a weapon is beeing used

Link to comment
  • Moderators
7 hours ago, Knuck said:

Fixed thanks, 
how can i disable a weapon while a weapon is beeing used

Are you looking for this?

Disable: https://wiki.multitheftauto.com/wiki/ToggleControl

Weapon use: https://wiki.multitheftauto.com/wiki/OnClientPlayerWeaponFire

Or weapon switch: https://wiki.multitheftauto.com/wiki/OnClientPlayerWeaponSwitch

(With matching example from your current request)

 

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