Jump to content

[Help] Blending with the environment resource


JanKy

Recommended Posts

So, i've been working on this resource, and i want it to do the following thing : when a player wears a ghillie suit and stands still for 3 seconds, his player model goes a little bit transparent, like "blending with the environment".

Here is the code :

Client Side :

function getPlayerStance () 
	currentskin = getElementData (localPlayer, "skin") 
	if currentskin == 285 then 
		if getPedMoveState (localPlayer) == "stand" or getPedMoveState (localPlayer) == "crouch" then 
			triggerServerEvent ("onPlayerGhillieStateOn", localPlayer) 
		else 
			triggerServerEvent ("onPlayerGhillieStateOff", localPlayer) 
		end 
	else 
		triggerServerEvent ("onPlayerGhillieStateOff", localPlayer) 
	end 
end 
setTimer (getPlayerStance, 3000,0) 

Server Side :

function onPlayerGhillieStateOn () 
	setElementAlpha (client, 50) 
end 
addEvent ("onPlayerGhillieStateOn" , true)
addEventHandler ("onPlayerGhillieStateOn", root, onPlayerGhillieStateOn) 

function onPlayerGhillieStateOff () 
	setElementAlpha (client, 255) 
end 
addEvent ("onPlayerGhillieStateOff", true) 
addEventHandler ("onPlayerGhillieStateOff", root, onPlayerGhillieStateOff)

And i managed to only get this working : 

Spoiler

 

Thanks in advance ^^

Link to comment
setTimer(function()
	for _,player in ipairs(getElementsByType("player")) do
		if getElementModel(player) == 285 then
			if getPlayerIdleTime(player) >= 3000 then
				setElementAlpha(player, 50)
			else
				setElementAlpha(player, 255)
			end
		else
			setElementAlpha(player, 255)
		end
	end
end, 1000, 0)

 

Edited by #َxLysandeR
  • Like 1
  • Thanks 1
Link to comment

Absolutely no error in the debugscript. It is server sided, and all looks right. I changed the timer from "1000" which is a second to "100" ( which i believe it's the minimum ) and it almost works, but still flickers. But i don't think this is the right thing to do, tho'.

Link to comment

You probably have some resource running that sets back the alpha of the player. In your first code you set it every 3 seconds even when it's already 50, then it's being set back, that is why it flickers every 3 seconds. In Lysanders code it sets it every 1 second that is why it flickers even faster. Search for the keyword setElementAlpha in your resources folder using Notepad++ or similar. 

  • Thanks 1
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...