Jump to content

restrict vehicles to acl


monamour

Recommended Posts

am trying to make script that allows only staffs(or acl i chose) to enter such vehicles 
and it would be great if somone teach me how to make players pays amount of money to spawn them
this is what i made but it's not working  
SCRIPT ERROR: carpriv\server.lua:4: ')' expected near 'then'     }

script:

staffcar = { [432]=true,[425]=true,[520]=true,[599]=true }

function enterVehicle ( player, seat, jacked )
    if ( staffcar[getElementModel(source)] ) and ( not isObjectInACLGroup ( "user." .. getAccountName(getPlayerAccount(source)), aclGetGroup ("Admin") ) then
        cancelEvent()
        outputChatBox ( "only acl can enter this!", player ) 
    end
end
addEventHandler ( "onVehicleStartEnter", getRootElement(), enterVehicle )
Link to comment
  • Moderators
if ( staffcar[getElementModel(source)] ) and ( not isObjectInACLGroup ( "user." .. getAccountName(getPlayerAccount(source)), aclGetGroup ("Admin") )) then

Or even better if you do not want to be confused:

if staffcar[getElementModel(source)] and not isObjectInACLGroup ( "user." .. getAccountName(getPlayerAccount(source)), aclGetGroup ("Admin") ) then

I prefer the last one. Only wrapping code between (...) when really needed.

Link to comment
  • Moderators

To be able to do that, you have to learn how to communicate between client(player his pc) and the server(can also be the player his pc or another computer).

GUI = clientside.

Giving weapons, take money away(synced) = serverside


You need to be able to understand this, even if you run your server on your own machine:

Figure_3.jpg

The fibreculture journal. (z.d.). Architecting Cheating in MMORPGs [Foto]. Geraadpleegd van http://sixteen.fibreculturejournal.org/files/2010/07/Figure_3.jpg

 

 

This tutorial might be handy.

 

  • Like 1
Link to comment
5 hours ago, IIYAMA said:

To be able to do that, you have to learn how to communicate between client(player his pc) and the server(can also be the player his pc or another computer).

GUI = clientside.

Giving weapons, take money away(synced) = serverside


You need to be able to understand this, even if you run your server on your own machine:

Figure_3.jpg

The fibreculture journal. (z.d.). Architecting Cheating in MMORPGs [Foto]. Geraadpleegd van http://sixteen.fibreculturejournal.org/files/2010/07/Figure_3.jpg

 

 

This tutorial might be handy.

 

yeah i understand the diffrence betwen server and client .

freeroam has server and,client side, of course , so i need to edit the server side defently 

but how could i make them spawn them and able to enter them if i have staffcar script(the one you helpt me with) running in same time !!

Link to comment
  • Moderators

By making exceptions

local vehicleEnterExceptions = {}

-- function
if vehicleEnterExceptions[player] or (staffcar[getElementModel(source)] and not isObjectInACLGroup ( "user." .. getAccountName(getPlayerAccount(source)), aclGetGroup ("Admin") )) then
 
-- end
  
function addPlayerToException (player)
	vehicleEnterExceptions[player] = true
	return true
end
  
function removePlayerFromException (player)
	vehicleEnterExceptions[player] = nil
	return true
end
  
addEventHandler("onPlayerQuit", root,
function ()
	removePlayerFromException (source)
end)

 

 

addPlayerToException (player)

-- DO > https://wiki.multitheftauto.com/wiki/WarpPedIntoVehicle

setTimer(removePlayerFromException, 50, 1, player) -- Events are afaik async, so must this function call.

 

You could try something like this. (untested)

 

 

Edited by IIYAMA
Link to comment
13 hours ago, IIYAMA said:

if ( staffcar[getElementModel(source)] ) and ( not isObjectInACLGroup ( "user." .. getAccountName(getPlayerAccount(source)), aclGetGroup ("Admin") )) then

Or even better if you do not want to be confused:


if staffcar[getElementModel(source)] and not isObjectInACLGroup ( "user." .. getAccountName(getPlayerAccount(source)), aclGetGroup ("Admin") ) then

I prefer the last one. Only wrapping code between (...) when really needed.

btw its still not working :(

new error :  

WARNING: server.lua:4: Bad argument @ 'getAccountName' [Expected account at argument 1, got boolean]
ERROR: server.lua:4: attempt to concatenate a boolean value

and the error show every time (non admin) enter Vehichle (staffcar) 

Edited by monamour
Link to comment
  • Moderators

it means that the variable which should contain the player isn't containing it.

 

If you use the event onVehicleStartEnter, use the first parameter for the player.

https://wiki.multitheftauto.com/wiki/OnVehicleStartEnter

 

Parameters:

player enteringPlayer, int seat, player jacked, int door

Source:

The source is in this event the vehicle.

Example:

function enterVehicle ( player, seat, jacked )

 

if vehicleEnterExceptions[player] or (staffcar[getElementModel(player)] and not isObjectInACLGroup ( "user." .. getAccountName(getPlayerAccount(player)), aclGetGroup ("Admin") )) then
 

 

Edited by IIYAMA
Link to comment
35 minutes ago, IIYAMA said:

it means that the variable which should contain the player isn't containing it.

 

If you use the event onVehicleStartEnter, use the first parameter for the player.

https://wiki.multitheftauto.com/wiki/OnVehicleStartEnter

 

Parameters:


 
  1. player enteringPlayer, int seat, player jacked, int door

Source:

The source is in this event the vehicle.

Example:


function enterVehicle ( player, seat, jacked )

 


if vehicleEnterExceptions[player] or (staffcar[getElementModel(player)] and not isObjectInACLGroup ( "user." .. getAccountName(getPlayerAccount(player)), aclGetGroup ("Admin") )) then
 

 

but its exactly what i did like you see in the start of topic :

script:

staffcar = { [432]=true,[425]=true,[520]=true,[599]=true } 

function enterVehicle ( player, seat, jacked )  ------- exactly like you said
    if ( staffcar[getElementModel(source)] ) and  not isObjectInACLGroup ( "user." .. getAccountName(getPlayerAccount(source)), aclGetGroup ("Admin") ) then
        cancelEvent()
        outputChatBox ( "only acl can enter this!", player ) 
    end
end
addEventHandler ( "onVehicleStartEnter", getRootElement(), enterVehicle )

but what happening is even normal player can enter them and i have the error message in the console  which is : 

WARNING: server.lua:4: Bad argument @ 'getAccountName' [Expected account at argument 1, got boolean]
ERROR: server.lua:4: attempt to concatenate a boolean value

*i think the problem is somewhere in the red code

Edited by monamour
*
Link to comment
  • Moderators

"user." .. getAccountName(getPlayerAccount(source)), aclGetGroup ("Admin") )

Indeed.

 

What was source again in this event?

Spoiler

Vehicle

 

Can you get the account from a ... ?

Spoiler

vehicle

 

Answer:

Spoiler

No

 

What happens when you do that?

Spoiler

Wiki: https://wiki.multitheftauto.com/wiki/GetPlayerAccount

 

Returns

Returns the player's account object, or false if the player passed to the function is invalid.

 

Can you get the accountname of the value false?

Spoiler

No

 

 

So:

Spoiler

"user." .. getAccountName(getPlayerAccount(player)), aclGetGroup ("Admin") )

 

 

Link to comment
6 minutes ago, IIYAMA said:

"user." .. getAccountName(getPlayerAccount(source)), aclGetGroup ("Admin") )

Indeed.

 

What was source again in this event?

  Hide contents

Vehicle

 

Can you get the account from a ... ?

  Hide contents

vehicle

 

Answer:

  Hide contents

No

 

What happens when you do that?

  Hide contents

Wiki: https://wiki.multitheftauto.com/wiki/GetPlayerAccount

 

Returns

Returns the player's account object, or false if the player passed to the function is invalid.

 

Can you get the accountname of the value false?

  Hide contents

No

 

 

So:

  Hide contents


 
"user." .. getAccountName(getPlayerAccount(player)), aclGetGroup ("Admin") )

 

 

OH bro i am so stupid that i didn't realized it!!

now i understand , by your favor!

thank you so much , i really appreicate that you spent time to teach and correct me , not only replaying with the correct code but with explaying and its so kindly!!

 

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