Jump to content

OnPlayerWantedLevelChange


Recommended Posts

Hi , i want to make a function excute when the player wanted level change
my objective is to make when the player gets 2 stars wanted level , his nametag color become red
If you want to suggest on me to use a Timer checks if the player has wanted level ,
i know this but i want another way to avoid timers as possible and there is no OnPlayerWantedLevelChange soo that's the problem

Link to comment

Well if you have your own system to give player wanted level, you can do it easily put triggerEvent like such.

function yourOwnGivePlayerWantedLevel(player, wl)
	local lastWl = getPlayerWantedLevel(player)
  	if wl then
		local newWl = wl + lastWl -- Can be minus can be plus
    	setPlayerWantedLevel(player, newWl)
    	triggerEvent("onPlayerWantedLevelChange", player, lastWl, newWl)
    end
end

 

Link to comment
8 hours ago, NeverGiveup said:

Well if you have your own system to give player wanted level, you can do it easily put triggerEvent like such.

function yourOwnGivePlayerWantedLevel(player, wl)
	local lastWl = getPlayerWantedLevel(player)
  	if wl then
		local newWl = wl + lastWl -- Can be minus can be plus
    	setPlayerWantedLevel(player, newWl)
    	triggerEvent("onPlayerWantedLevelChange", player, lastWl, newWl)
    end
end

 

I Like your idea but can you help me in creating the event function
my object is to create a blip attached to the player that has wanted levels
and to remove the blip when the player wanted level are clear
I want a help because i don't work with blips too much
That's my idea right now:

function checkCriminals()
local cr,cg,cb = getPlayerNametagColor(source)
if getPlayerWantedLevel(source) >= 1 and cr,cg,cb ~= 255,0,0 then
setPlayerNametagColor(source,255,0,0)
for index, element in ipairs ( getAttachedElements ( source ) ) do
if ( getElementType ( element ) ~= "blip" )  then 
			createBlipAttachedTo(source,0,25,255,0,0)
            end 
if not element then
createBlipAttachedTo(source,0,25,255,0,0)
end
end
end
end
addEvent("onPlayerWantedLevelChange",true)
addEventHandler("onPlayerWantedLevelChange",root,checkCriminals)

 

Link to comment
local criminals = {}
function checkCriminals()
    local cr, cg, cb = getPlayerNametagColor(source)
    if getPlayerWantedLevel(source) >= 1 and cr, cg, cb ~= 255, 0, 0 then
        setPlayerNametagColor(source, 255, 0, 0)
        criminals[source] = createBlipAttachedTo(source,0, 25, 255, 0, 0)
    else
        setPlayerNametagColor(source, 0, 255, 0)
        if criminals[source] and isElement(criminals[source]) then
            destroyElement(criminals[source])
            criminals[source] = nil
        end
    end
end
addEvent("onPlayerWantedLevelChange", true)
addEventHandler("onPlayerWantedLevelChange", root, checkCriminals)

untested i guess it works..

Edited by NeverGiveup
Link to comment
20 hours ago, NeverGiveup said:
local criminals = {}
function checkCriminals()
    local cr, cg, cb = getPlayerNametagColor(source)
    if getPlayerWantedLevel(source) >= 1 and cr, cg, cb ~= 255, 0, 0 then
        setPlayerNametagColor(source, 255, 0, 0)
        criminals[source] = createBlipAttachedTo(source,0, 25, 255, 0, 0)
    else
        setPlayerNametagColor(source, 0, 255, 0)
        if criminals[source] and isElement(criminals[source]) then
            destroyElement(criminals[source])
            criminals[source] = nil
        end
    end
end
addEvent("onPlayerWantedLevelChange", true)
addEventHandler("onPlayerWantedLevelChange", root, checkCriminals)

untested i guess it works..

I didn't test urs but i used the same "If" like you previously and i got a error reported in Debug on "cr, cg, cb ~= 255, 0, 0"
i think it should be "(cr ~= 255 and cg ~= 0 and cb ~= 0 ) then"
Anyways thanks for your help and i think i can continue now ,

Soo Thanks again<3

  • Like 1
Link to comment

Hi again , i want a help in this
if cr, cg, cb ~= 255, 0, 0 then
so thats didn't work but that works without any errors in debug
if ( cr ~= 255 and cg ~= 0 and cb ~= 0 ) then
but what i want is to check if the player nametag is red or no
but it's not happening sometimes if the player is yellow sometimes
so i want help in checking if the player nametag is red or no


EDIT: I found a solution so i used this

  local cr, cg, cb = getPlayerNametagColor(args[1])
    local crcgcb = tostring(cr)..tostring(cg)..tostring(cb)

if ( crcgcb ~= "25500" ) then

i know it's pretty weird but that what i have found
But of course if there is another solution tell me

Edited by MouNiR.Dz
Link to comment
  • Moderators
12 minutes ago, MouNiR.Dz said:

so i want help in checking if the player nametag is red or no

This is red:

 (cr == 255 and cg == 0 and cb == 0) -- red

 

This is not red:

 not (cr == 255 and cg == 0 and cb == 0) -- not red

 

if not (cr == 255 and cg == 0 and cb == 0) then

end

 

 

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