Jump to content

Not working :v


Gastonito

Recommended Posts

Hello guys, i made these functions with some help of a friend, but idk why it isnt working, there are no errors, etc ...

Client Side : 

--Flying Car
elseif ( source == vehfly ) then
		triggerServerEvent("toggle_aircars",localPlayer)
		else
		triggerServerEvent("disable_aircars",localPlayer)

addEventHandler ( "onClientGUIClick", root,
 function ( )
  if (source == vehfly) then 
   if (guiGetText (source) == 'Flying On') then
    guiSetText (source,'Flying Off')
   elseif (guiGetText (source) == 'Flying Off') then
    guiSetText (source, 'Flying On')
   end
  end
 end
)

addEvent("toggle_aircars", true)
function toggle_aircars(eventVeh)
	for i, veh in ipairs(getElementsByType("vehicle")) do
			if isWorldSpecialPropertyEnabled("aircars") then
		setWorldSpecialPropertyEnabled("aircars", false, eventVeh)	
	end
end
end
addEventHandler("toggle_aircars", root, toggle_aircars)

addEvent("disable_aircars", true)
function disable_aircars(eventVeh)
	for i, veh in ipairs(getElementsByType("vehicle")) do
			if isWorldSpecialPropertyEnabled("aircars") then
		setWorldSpecialPropertyEnabled("aircars", true, eventVeh)
	end
end
end
addEventHandler("disable_aircars", root, disable_aircars)

Server Side : 


addEvent("toggle_aircars", true)
function toggle_aircars()
for eventPlayers in pairs(WrapedPlayers) do
    local eventManager = getAccountName(getPlayerAccount(source))
    if ( eventVehicles[eventManager] ) then
  for i, eventVeh in ipairs ( eventVehicles[eventManager] ) do
            triggerClientEvent("toggle_aircars", source, eventVeh)
        end
    end
    exports.SAEGcommands:sendMessage("Vehicle Flying has been Enabled by "..getPlayerName(client), 0, 255, 0,eventPlayers)
    end
end
addEventHandler("toggle_aircars", root, toggle_aircars)
 
addEvent("disable_aircars", true)
function disable_aircars()
for eventPlayers in pairs(WrapedPlayers) do
    local eventManager = getAccountName(getPlayerAccount(source))
    if ( eventVehicles[eventManager] ) then
  for i, eventVeh in ipairs ( eventVehicles[eventManager] ) do
            triggerClientEvent("disable_aircars", source, eventVeh)
        end
        end
        exports.SAEGcommands:sendMessage("Vehicle Flying has been Dis  abled by "..getPlayerName(client), 255, 0, 0,eventPlayers)
    end
end
addEventHandler("disable_aircars", root, disable_aircars)

 

Link to comment

there are so many wrong things in your code. first of all, 

 

  1. for i, eventVeh in ipairs ( eventVehicles[eventManager] ) do
  2. triggerClientEvent("disable_aircars", source, eventVeh)
  3. end

this is ok but in client, 

  1. for i, veh in ipairs(getElementsByType("vehicle")) do
  2. if isWorldSpecialPropertyEnabled("aircars") then
  3. setWorldSpecialPropertyEnabled("aircars", true, eventVeh)
  4. end

 this makes it all wrong. there is no 3rd arg in that function so the loop is useless. if you want to make it only enabled when a player gets in the event car, pass the event vehicles to client and check on onClientVehicleEnter and then enable property. 

Link to comment
1 hour ago, Adolfram said:

there are so many wrong things in your code. first of all, 

 

  1. for i, eventVeh in ipairs ( eventVehicles[eventManager] ) do
  2. triggerClientEvent("disable_aircars", source, eventVeh)
  3. end

this is ok but in client, 

  1. for i, veh in ipairs(getElementsByType("vehicle")) do
  2. if isWorldSpecialPropertyEnabled("aircars") then
  3. setWorldSpecialPropertyEnabled("aircars", true, eventVeh)
  4. end

 this makes it all wrong. there is no 3rd arg in that function so the loop is useless. if you want to make it only enabled when a player gets in the event car, pass the event vehicles to client and check on onClientVehicleEnter and then enable property. 

No u dont undrestand, i dont want it when the player enters the car, its a gui ( event panel ) its made so if the event manager clicks the button the flying gets enabled for event vehicles :D

Link to comment
  • Moderators

@Angel02


Why don't place some debuglines in your code?

Simply:

outputDebugString("HEY this **** is actually working!")

(you can view those in your debugscript)

and if it doesn't output, you know you have done something wrong in the code before that message.

 

Easy right?

 

Just fill up your entire code with debug messages and you will know @Angel02 "FFS"!!! what's @Angel02 "f.ing" going on!

 

and after you showed me what's wrong, I am happy to help. :) YES?

Link to comment
14 hours ago, IIYAMA said:

@Angel02


Why don't place some debuglines in your code?

Simply:

 


outputDebugString("HEY this **** is actually working!")

(you can view those in your debugscript)

and if it doesn't output, you know you have done something wrong in the code before that message.

 

Easy right?

 

Just fill up your entire code with debug messages and you will know @Angel02 "FFS"!!! what's @Angel02 "f.ing" going on!

 

and after you showed me what's wrong, I am happy to help. :) YES?

Yeah, Sry for being rue but i was mad cuz none helped me.

Anyways, i tryied that already, the debugging messages showed up, the script is actually working, but the flying isnt working :C

Link to comment

This code is a real mess, wtf should EventPlayers and WrapedPlayers even mean, since i don't see it being defined.

Thanks to this it can be everything or maybe you didn't post the full code.But without that it's not easy to fix this.

 

triggerClientEvent(source, "disable_aircars", source, eventVeh)
triggerClientEvent(source, "toggle_aircars", source, eventVeh)

triggerClientEvent(source, "disable_aircars", source, eventVeh)
triggerClientEvent(source, "toggle_aircars", source, eventVeh)

triggerClientEvent always must be like this triggerClientEvent(element, "exportname", playertorecieve, arguments, ...)

Link to comment
  • Moderators

setWorldSpecialPropertyEnabled doesn't accept specific cars, it is ONLY ON or OFF per player for ALL cars.

You should use(serverside) https://wiki.multitheftauto.com/wiki/OnVehicleEnter to check if he has access to the vehicle. triggerClientEvent > setWorldSpecialPropertyEnabled

And(serverside) https://wiki.multitheftauto.com/wiki/OnVehicleExit + https://wiki.multitheftauto.com/wiki/OnPlayerWasted to disable it: triggerClientEvent > setWorldSpecialPropertyEnabled

With other words, you have to rewrite your code from the start. Although it is written simpler than you have right now :).

Edited by IIYAMA
Link to comment

It got fixed by the :O @Simple01

--SERV SIDE

addEvent("toggle_aircars", true)
function toggle_aircars()
	for eventPlayers in pairs(WrapedPlayers) do
		local eventManager = getAccountName(getPlayerAccount(source))
		if ( eventVehicles[eventManager] ) then
			for eventPlayer in pairs( WrapedPlayers ) do
				triggerClientEvent( eventPlayer, "toggle_client_aircars", eventPlayer )
				exports.SAEGcommands:sendMessage("Vehicle Flying has been Enabled by "..getPlayerName(client), 0, 255, 0,eventPlayers)
			end
		end
    end
end
addEventHandler("toggle_aircars", root, toggle_aircars)
 
addEvent("disable_aircars", true)
function disable_aircars()
	for eventPlayers in pairs(WrapedPlayers) do
		local eventManager = getAccountName(getPlayerAccount(source))
		if ( eventVehicles[eventManager] ) then
			for eventPlayer in pairs( WrapedPlayers ) do
				triggerClientEvent( eventPlayer, "disable_client_aircars", eventPlayer )
			end
			exports.SAEGcommands:sendMessage("Vehicle Flying has been Disabled by "..getPlayerName(client), 255, 0, 0,eventPlayers)
		end
    end
end
addEventHandler("disable_aircars", root, disable_aircars)

--CLIENT SIDE

addEvent("toggle_client_aircars", true)
function toggle_aircars(eventVeh)
	if not ( isWorldSpecialPropertyEnabled("aircars") ) then
		setWorldSpecialPropertyEnabled("aircars", true)	
	end
end
addEventHandler("toggle_client_aircars", root, toggle_aircars)

addEvent("disable_client_aircars", true)
function disable_aircars(eventVeh)
	if isWorldSpecialPropertyEnabled("aircars") then
		setWorldSpecialPropertyEnabled("aircars", false)
	end
end
addEventHandler("disable_client_aircars", root, disable_aircars)

 

Link to comment
  • Moderators

Here you have some more: tips, optimisations and clean up. Good luck!

 

Serverside:

An account name is an 'eventManager'? 'eventVehicles' contains account names? You should name them after what they will contain or what function they have.

 

Also you have now 2 loops per block, only the inner loop is required to operate the system: (if you don't remove this:  playerCount * playerCount = loop length)

for eventPlayers in pairs(WrapedPlayers) do

local eventManager = getAccountName(getPlayerAccount(source))
if ( eventVehicles[eventManager] ) then
for eventPlayer in pairs( WrapedPlayers ) do
triggerClientEvent( eventPlayer, "toggle_client_aircars", eventPlayer )
exports.SAEGcommands:sendMessage("Vehicle Flying has been Enabled by "..getPlayerName(client), 0, 255, 0,eventPlayers)
end
end

end

 

Clientside:

function toggle_aircars(eventVeh)

function toggle_aircars(eventVeh) -- clean up

function disable_aircars(eventVeh)

function disable_aircars(eventVeh) -- clean up

 

 

 

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