Jump to content

can't compare


Deep thinker

Recommended Posts

hello i was working on a small script which attach the star icon if the player is wanted but i got a debug output it said that there is a bug in the compare in line #3

here is the script ,i think i should change the Event "onResourceStart"

function wanted()
local wanted = getPlayerWantedLevel(player)
if ( wanted > 0 ) then
x, y, z = getElementPosition(player)
i = getElementInterior(player)
d = getElementDimension(player)
wantedpickup = createObject( 1247, x, y, z+1, i, d )
attachElements( wanted , player )
end
end
addEventHandler("onResourceStart",root,wanted)

also i had anther script which can't find a file in its meta file "saur.png"

<meta>
	<info author="ProMax" type="script" version="2.0" name="staff-tag" description="Simple Staff Tag Script" />
	<script src="client.lua" type="client"/>
	
	<file src="saur.png"/>
</meta>
function renderStaffTag()
    local streamedPlayers = getElementsByType ("player", root, true)
        local lpos = {getElementPosition(localPlayer)}
        for _,p in ipairs (streamedPlayers) do
            if p and isElement (p) then
                if not getPlayerTeam(p) or getPlayerTeam(p) ~= getTeamFromName("Staff") then return end
    if streamedPlayers and #streamedPlayers ~= 0 then
                    local ppos = {getElementPosition(p)}
                    if getDistanceBetweenPoints3D (lpos[1], lpos[2], lpos[3], ppos[1], ppos[2], ppos[3]) <= 20 then
                        local x, y = getScreenFromWorldPosition (ppos[1], ppos[2], ppos[3]+1.2)
                        if x and y then
                            dxDrawText ("Staff Member", x+1, y+1, x, y, tocolor (0, 0, 0), 1, "pricedown", "center")
                            dxDrawText ("Staff Member", x, y, x, y, tocolor (52, 0, 66), 1, "pricedown", "center")
                        end
                    end
                end
            end
        end
    end

addEventHandler ("onClientRender", root, renderStaffTag)

also if someone can add a part which draw an image in the game attached to the player with name "saur.png"

Thanks

Link to comment
  • Administrators
function wanted()
	local players = getElementsByType ( "player" )
	for theKey,thePlayer in ipairs(players) do -- use a generic for loop to step through each player
		local wantedLevel = getPlayerWantedLevel ( thePlayer ) -- get the wanted level of the player
		if ( wantedLevel > 0 ) then
			x, y, z = getElementPosition(thePlayer)
			i = getElementInterior(thePlayer)
			d = getElementDimension(thePlayer)
			wantedpickup = createObject( 1247, x, y, z, i, d )
			attachElements( wantedpickup , thePlayer, 0, 0, 1.5 ) -- we can use the z offset here to put it above the player
		end
	end
end
addEventHandler("onResourceStart",getRootElement(),function()
setTimer(wanted, 5000, 0) -- when the resource starts, run every 5 seconds
end)

-- assume that there exists a collision shape named 'policeStation'
function addWantedLevel ( player, command, level ) 
   setPlayerWantedLevel ( player, level ) -- set the player's wanted level to 6 stars
   outputChatBox ( getPlayerName ( player ) .. " entered the police station!" )
end
addCommandHandler("cops", addWantedLevel) -- command to give yourself a wanted level, /cops <1-6>

Here you go. See if you can make sense of this, it's pretty simple.

Edited by LopSided_
Link to comment
  • Administrators

Can't edit my post, oops, doublepost!

Here's an updated version which is more efficient, instead of creating a star object for wanted players every 5 seconds, we'll check if the star exists first.

Also, the other one didn't delete the star once you weren't wanted anymore, so that's fixed.

starSpawned = 0

function wanted()
	local players = getElementsByType ( "player" )
	for theKey,thePlayer in ipairs(players) do -- use a generic for loop to step through each player
		local wantedLevel = getPlayerWantedLevel ( thePlayer ) -- get the wanted level of the player
		if starSpawned == 0 then
		wantedpickup = createObject( 1247, 0, 0, 0, i, d )
		starSpawned = 1
		end
		if ( wantedLevel > 0 ) then
			x, y, z = getElementPosition(thePlayer)
			i = getElementInterior(thePlayer)
			d = getElementDimension(thePlayer)
				setObjectScale(wantedpickup, 0.5)
				attachElements( wantedpickup , thePlayer, 0, 0, 1.5 ) -- we can use the z offset here to put it above the player
		else
		    -- get the elements attached to the vehicle
		local attachedElements = getAttachedElements ( thePlayer )
		-- loop through the table of elements
		for i,v in ipairs ( attachedElements ) do
        -- detach the element from the vehicle
        detachElements ( v, thePlayer )
		destroyElement(v)
		starSpawned = 0
		end
		end
	end
end
addEventHandler("onResourceStart",getRootElement(),function()
setTimer(wanted, 1000, 0) -- when the resource starts, run every 5 seconds
end)

-- assume that there exists a collision shape named 'policeStation'
function addWantedLevel ( player, command, level ) 
   setPlayerWantedLevel ( player, level ) -- set the player's wanted level to 6 stars
   outputChatBox ( getPlayerName ( player ) .. " entered the police station!" )
end
addCommandHandler("cops", addWantedLevel) -- command to give yourself a wanted level, /cops <1-6>

 

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