Jump to content

laser bugged


Deep thinker

Recommended Posts

hello i have a script which is depending on some kind of vip system but it's bugged because there is something wrong in the compare in the line "7" which is a laser script.

 

local laserColor = {[2]={255, 0, 0}, [3]={255, 100, 0}}

addCommandHandler("laser",
function (thePlayer)
	if not exports["(T-RPG)VIP"]:isPlayerVIP(getAccountName(getPlayerAccount(thePlayer))) then return end
	local vip = exports["(T-RPG)VIP"]:isPlayerVIP(thePlayer)
	if vip > 1 then return end
	if getElementData(thePlayer, "laser.on") then
		lState="Disabled" r,g,b=unpack(laserColor[vip])
		setElementData(thePlayer, "laser.on", false)
	else
		lState="Enabled" r,g,b=unpack(laserColor[vip])
		setElementData(thePlayer, "laser.on", true)
	end
	setElementData(thePlayer, "laser.aim", false)
	exports["(T-RPG)Info"]:sendMessage(thePlayer,"Laser: The laser is now ".. lState ..".",r,g,b)
end)

 

Edited by ProMax
Link to comment

Probably  exports["(T-RPG)VIP"]:isPlayerVIP(thePlayer) returns a boolean value, and you can't compare ( > ) a boolean with  1 (a number)

It would be helpful if you posted the error you receive, but if i'm right it should be something like "cannot compare boolean with number".

If i'm wrong then post more info about the problem, starting from the error ;)

Link to comment

I think it too xD but just in case there's more... also the advice is still valid, next time you ask for help copy and paste the error if present, and if not present say there's not. If you don't say anything we don't know if you are omitting or there's nothing to say about it cause there's no error. ;)

Link to comment
19 hours ago, LoPollo said:

I think it too xD but just in case there's more... also the advice is still valid, next time you ask for help copy and paste the error if present, and if not present say there's not. If you don't say anything we don't know if you are omitting or there's nothing to say about it cause there's no error. ;)

actually i would like to thank you for the advice ,i was just copy and paste the full script for 1 point which is that i think that would help the supporter ,but  we went away from the error my only question is : can you fix it ? also i have a secondary question out of the subject how can i make the weapon stop shooting it's own bullets .the weapon id is 42 which is Fire Extinguisher i want it to stop showing that smoke ,and thank you again also i would like to say that you gained me as a fan :D

Link to comment

The (untested) fixed script is here, but make sure you understand the fix otherwise next time you will have to start from 0 with a similar problem

Note that i'm assuming that isPlayerVIP returns a boolean since you didn't negate it when i said it, but following the logic that's how it should be

local laserColor = {
	[true]={255, 0, 0}, 
	[false]={255, 100, 0}
}

addCommandHandler("laser",
	function (thePlayer)
		if not exports["(T-RPG)VIP"]:isPlayerVIP(getAccountName(getPlayerAccount(thePlayer))) then return end
		local isVip = exports["(T-RPG)VIP"]:isPlayerVIP(thePlayer)
		setElementData( thePlayer, "laser.on", not getElementData( thePlayer, "laser.on" ) )
		setElementData(thePlayer, "laser.aim", false)
		exports["(T-RPG)Info"]:sendMessage( thePlayer, "Laser: the laser is now ".. ( getElementData( thePlayer, "laser.on" ) and "enabled" or "disabled") ..".", unpack(laserColor[isVip]))
	end
)

I highlight it's untested, tell us if it works if you have time. 

 

1 hour ago, ProMax said:

how can i make the weapon stop shooting it's own bullets .the weapon id is 42 which is Fire Extinguisher i want it to stop showing that smoke

I'm not sure if i understand: do you mean "disable" that weapon? so even if you have fire extinguisher you can't shoot with it?

If so you can use these:

--server event
"onPlayerWeaponSwitch"
--client event
"onClientPlayerWeaponSwitch"


toggleControl --control name: "fire"

 

Edited by LoPollo
Link to comment

i edited the post above for the functions you can use to solve that problem.

if the current weapon is 42 toggle the control "fire" to false

if the previous weapon is 42 toggle the control "fire" to true

EDIT: keep in mind that usign the client side event will not give you the weapon ID, but the slot. Use getPedWeapon to retrieve the weapon ID knowing the slot

Edited by LoPollo
  • Like 1
Link to comment
41 minutes ago, LoPollo said:

i edited the post above for the functions you can use to solve that problem.

if the current weapon is 42 toggle the control "fire" to false

if the previous weapon is 42 toggle the control "fire" to true

EDIT: keep in mind that usign the client side event will not give you the weapon ID, but the slot. Use getPedWeapon to retrieve the weapon ID knowing the slot

thank you .the laser script worked and i scripted the  fire extinguisher script but i have 1 more question .i want to make a script which makes the nightstick only for teams Police,SWAT,Military.

i need to know what functions to use

Link to comment
12 minutes ago, ProMax said:

thank you .the laser script worked and i scripted the  fire extinguisher script but i have 1 more question .i want to make a script which makes the nightstick only for teams Police,SWAT,Military.

i need to know what functions to use

addEventHandler ( 'onClientPlayerWeaponSwitch' )
getPedWeapon
getPlayerTeam
getTeamFromName
cancelEvent

 

Link to comment

but cancelling the weapon switch will also cause the inability to reach the other weapons "scrolling" in that direction

I would suggest replacing the cancelEvent with a setPedWeaponSlot to simply let "skipping" the weapon instead of blocking... that will require some work through

11 minutes ago, ProMax said:

should i use this with it as the wiki said 


getRandomPlayer

No don't worry, the wiki example was using it because the example outputs the weapon a random player is holding. 

Edited by LoPollo
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...