Jump to content

simple freeroam resource


Deep thinker

Recommended Posts

hello,today i had to learn how make the freeroam (F1) only for ACL admin , but it output a debug notice

Error: freeroam\fr_client.lua:1596: attempt to call global 'getPlayerAccount' (a nil value)

addEventHandler('onClientResourceStart', g_ResRoot,
    function()
     local accName = getAccountName ( getPlayerAccount ( thePlayer ) ) -- get his account name
     if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then -- Does he have access to Admin functions?
    fadeCamera(true)
        setTimer(getPlayers, 1000, 1)
        bindKey('f1', 'down', toggleFRWindow)
        createWindow(wndMain)
        hideAllWindows()
        guiCheckBoxSetSelected(getControl(wndMain, 'jetpack'), doesPedHaveJetPack(g_Me))
        guiCheckBoxSetSelected(getControl(wndMain, 'falloff'), canPedBeKnockedOffBike(g_Me))
        setJetpackMaxHeight ( 9001 )
        
        triggerServerEvent('onLoadedAtClient', g_ResRoot)
        end
    end
)

thank you for reading ,

  • Like 1
Link to comment

You are mixing up client side and server side functions so much.

#1: onClientResourceStart is obviously a client sided event but -->
#2: getAccountName is a server sided function.

So, you must do the whole script server side I guess, I'm not sure what do you want to do, but if you want to get the account name of the player you must do it server side.

#3: Who is thePlayer? You must define it somewhere and somehow on server side, on client side you can simply just use localPlayer in some scenarios.
#4: On server side you must specify the player whose camera you want to be faded. So you can't just use fadeCamera(true), instead you must use fadeCamera(thePlayer, true), in this case thePlayer is the player.
#5: On server side, if you are triggering an event from client side, you must obviously use triggerClientEvent, not triggerServerEvent.
#6: You can't use gui or draw functions on server side, and I assume that you did because of the createWindow() and hideAllWindows() functions, you must use triggerClientEvent for that.
#7: Is g_ResRoot defined somewhere?

Client Scripting Functions

Client Scripting Events

Server Scripting Functions

Server Scripting Events

  • Like 1
Link to comment

oh yea about the server and client functions ,i do mix between them a lot ,thank you for noticing i will edit it and contact you with news.

now i have added these functions to the server side and triggered it ,now every one can use F1 also it created a bug and now i can't spawn anything

-- server part
addEvent("onPlayerJoin",true)
addEventHandler("onPlayerJoin",g_root,
function ()
    if not player then
        player = source
    end
    local accName = getAccountName ( getPlayerAccount ( thePlayer ) ) -- get his account name
     if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then -- Does he have access to Admin functions?
    g_PlayerData[player] = { vehicles = {} }
    g_PlayerData[player].blip = createBlipAttachedTo(player, 0, 2, r, g, b)
    if g_FrozenTime then
        clientCall(player, 'setTimeFrozen', true, g_FrozenTime[1], g_FrozenTime[2], g_FrozenWeather)
    end
    end
    end)
addEventHandler('onClientResourceStart', g_ResRoot,
    function()
        triggerServerEvent("onPlayerJoin", g_root) 
        setTimer(getPlayers, 1000, 1)
        bindKey('f1', 'down', toggleFRWindow)
        createWindow(wndMain)
        hideAllWindows()
        guiCheckBoxSetSelected(getControl(wndMain, 'jetpack'), doesPedHaveJetPack(g_Me))
        guiCheckBoxSetSelected(getControl(wndMain, 'falloff'), canPedBeKnockedOffBike(g_Me))
        setJetpackMaxHeight ( 9001 )
        triggerServerEvent('onLoadedAtClient', g_ResRoot)
            end
)

and this line got a nil value

if i > getOption('vehicles.maxperplayer') then

you will find it in your own freeroam resource in line 344 maybe

  • Like 2
Link to comment

The onPlayerJoin event is a default server sided event of mta, you don't need this, this is not a custom event:

addEvent("onPlayerJoin",true)

The source of the onPlayerJoin event is the player who joined. So it means that the player is defined as source, so instead of "thePlayer" and "player" you must use "source", so it would look like this:

local accName = getAccountName ( getPlayerAccount ( source ) )

Also, what is this for?

if not player then
	player = source
end

Did you define somewhere a table called g_PlayerData?

For the client side, you must create a custom function there, and then trigger it to server. So for example

addEvent("customClientEvent", true)
addEventHandler('customClientEvent', g_ResRoot,
    function()
        setTimer(getPlayers, 1000, 1)
        bindKey('f1', 'down', toggleFRWindow)
        createWindow(wndMain)
        hideAllWindows()
        guiCheckBoxSetSelected(getControl(wndMain, 'jetpack'), doesPedHaveJetPack(g_Me))
        guiCheckBoxSetSelected(getControl(wndMain, 'falloff'), canPedBeKnockedOffBike(g_Me))
        setJetpackMaxHeight ( 9001 )
        triggerServerEvent('onLoadedAtClient', g_ResRoot)
            end
)

And then use triggerClientEvent on server side. Also, I don't think that you have to trigger the onLoadedAtClient event from server to client, just to trigger it back to server side again. Just to make it clear, you can just call the function where you put triggerClientEvent on server side I guess. Hope you understand me.

I would reccomend you to also check some of the tutorials on wiki and the forum.

You can find the tutorials on the right side of the Main Page, and you can find some really helpful tutorials on the forum here.

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