Jump to content

Need help with creating Admins privileges on items.


Matubo

Recommended Posts

The task is: to allow only Admins to enter a specific Car.

I've created a car in MAP file. Created a Flag that this one car is for Admins only. A redirect its value to the IF statement in EVENT function, but I cant check if the entering Player is admin.

Generally speaking:

function onVEnter( player, seat, jacked ) 
    local is_admin_car = getElementData(source, "admin_car")     
     
    if(is_admin_car == "1" and  [RESULT OF ADMIN CHECK HERE]) then 
        cancelEvent()        
    end 
end  
  
addEventHandler( "onVehicleStartEnter", root, onVEnter)  

Link to comment

maybe there's an easier solution but this should work except on your server admins don't have the right to ban ips^^:

  
function onVEnter( player, seat, jacked ) 
    local is_admin_car = getElementData(source, "admin_car")     
     
    if is_admin_car == "1" and  hasObjectPermissionTo ( playerSource, "function.banIP", false)  == false then 
        cancelEvent()        
    end 
end  
  
addEventHandler( "onVehicleStartEnter", root, onVEnter)  
  

Link to comment

I think this should sound like:

function onVEnter( player, seat, jacked ) 
    local is_admin_car = getElementData(source, "admin_car")     
     
    if is_admin_car == "1" and  hasObjectPermissionTo ( player, "function.banIP", false) then 
        cancelEvent()        
    end 
end  
  
addEventHandler( "onVehicleStartEnter", root, onVEnter) 

Well, this should be a trick. But is there any standard tools to make these checkings more standardized?

And where can I find the list of those built-In data members of an element by types? Like this one: "function.banIP". As far as I understand this is a member function of an elementtype "player".

And for "vehicles", "blips", "markers" etc?

Link to comment
Well, this should be a trick. But is there any standard tools to make these checkings more standardized?

And where can I find the list of those built-In data members of an element by types? Like this one: "function.banIP". As far as I understand this is a member function of an elementtype "player".

And for "vehicles", "blips", "markers" etc?

the function privilegs are defined in the acl.xml for each group. For example the default group cant access the function to start a resource:

<right name="function.startResource" access="false"/> 

but the admin group can:

  
<right name="function.startResource" access="true"/> 

i dont know if this answeres your question but that's all i know =)

Link to comment

I see your point. Thanks. But nevertheless your type of check doesnt work. :(

I made several experiments and they show that everyone have the permission to "funtion.banIP".

Like:

local can = hasObjectPermissionTo( player, "function.banIP") 
if can then 
    outputDebugString("He can...", 3) 
else 
    outputDebugString("He cant...", 3) 
  

I tried:

local can = hasObjectPermissionTo( player, "function.banIP")

local can = hasObjectPermissionTo( player, "function.banIP", false)

local can = hasObjectPermissionTo( player, "function.banIP", true)

The result was always: [iNFO] He can...

Regardless of players state. Was it a guest or a logged in player with Admin rights.

The function.banIP is declared in "Moderators" ACL, where coomon players dont have access. So I guess the point is in incorrect function behaviour, or I dont understand something...

Link to comment

You should not rely on existing ACLs like banIP, you should make your own. You should call it resource.YourResourceNameHere.canEnterVehicles or something similar. This makes it much more flexible for admins, though slightly harder. It also makes sure they're aware how it works.

Link to comment

Can you show me how to access this custom data member?

And I didnt clearly catch, how this member can be used to filter plyers. As I understand this flag will indicate "can anyone enter any vehicle". But as I wrote before, I wanted to filter just one precise vehicle. I need more specific filter than a global flag.

If you were so kind to explain how I can arrange the handling of data members like "resource.YourResourceNameHere.canEnterVehicles", this would be great.

Link to comment

Well, using hasObjectPermissionTo. You obviously can't specify a specific vehicle from the ACL, you should choose/set that vehicle elsewhere.

Your previous post with hasObjectPermissionTo, can you post your ACL?

Link to comment

Well, I dont need to jump around "hasObjectPermissionTo" after you said that this is not the point.

I just want to make this filtering mechanism. I dont know how, thats why I'm here. Any advise, help, explanations are welcome. :)

Once more, the idea in brief:

I create a car. I want only Admins to have permission to enter it.

In my idea in event of "onVehicleStartEnter" there should be two conditions in the verifications:

- is this car should be checked at all. In other words is this car has "admin car" flag "on" or "off"

- is the player is a simple player or an Admin

If flag is true and player is not an Admin then "cancelEven()"

The first condition is already done by me. The second - is the topic of this thread.

Link to comment

I do something like :

  
function tuPlayerInACLGroup(player,groupName) 
    local et = getElementType(player) 
  
    if (et == "player") or (et == "console") then 
        local account = getClientAccount(player) 
  
        if not isGuestAccount(account) then 
            local un = "user." .. getAccountName(account) 
     
            for id, object in ipairs(aclGroupListObjects(aclGetGroup(groupName))) do 
                if object == un then 
                    return true 
                end 
            end 
        end 
    end 
  
    return false 
end 
  

I know this is slightly frowned upon for not using the ACL but it's just easier on my server. I know the names of the power user groups (Admin, Moderator etc.) so I just run checks to see if the player is in any of those:

  
function tuPlayerHasPower(player) 
    -- Return true if the player belongs to any of the priveledged users 
  
    for i,groupName in pairs({"Moderator","SuperModerator","Admin","Console"}) do 
        if tuPlayerInACLGroup(player,groupName) then 
            return true 
        end 
    end 
  
    return false 
end 
  

This lets me flick commands on/off and check other things (such as your "admin car") without having to resort to changing the ACL. The only negative to this method is the use of pre-set admin group names. I didn't check if I could determine them programatically.

Link to comment

This seems to work. Thank you.

But there goes next problem.

Let me describe you this malfunction:

Firstly, here is the event declaration and event-function:

function onVEnter( player, seat, jacked ) 
    local is_admin_car = getElementData(source, "admin_car")     
     
    outputChatBox ( "Function is called..." ) 
     
    if is_admin_car == "1" and not PlayerHasPower(player) then 
        outputChatBox ( "Filter worked..." ) 
        cancelEvent()        
    end 
end 
  
addEventHandler( "onVehicleStartEnter", root, onVEnter) 
  

Here how it goes. I join the server as a simple player, I spawn in the game and approach the car. I press "enter the vehicle" button and I receive:

"Function is called...

Filter worked...".

How nice.... Yet everything worked. Now I open the console and see: "Failed to enter/exit vehicle - id: 1"

Then I try to seat down second time, I cant. But now I receive: "Failed to enter/exit vehicle - id: 2".

Third, fourth, fifth attempts give me the same: "Failed to enter/exit vehicle - id: 2".

Well, thats odd but not yet somehow informational.

The script worked somehow till that moment, cause the simple player cound not enter the car.

The interesting part goes next: I login as Admin.

I try to seat in a car, I receive only "Function is called..."... but I cant.

I open console and see: "Failed to enter/exit vehicle - id: 0"

I try to seat the second time, and now I DONT receive ANYTHING. Function didnt call at all.

I open console and see: "Failed to enter/exit vehicle - id: 7"

Every time now I recevie only: "Failed to enter/exit vehicle - id: 7" on every attempt.

But thats not all.

I logout Admin acc, but still function doesnt call and "Failed to enter/exit vehicle - id: 7" occures.

And after that the player CANT enter ANY CAR in the world, till he reenter the server.

So here are the points in brief:

- when player is a simple player everything works somehow fine, except those errors in console

- after login as Admin, first try calls the function but admin doesnt seat in a car

- other attempts doesnt even lauch an event function or event itself, cause player cant enter any car till he rejoins, even after logout to simple player

Something wrong goes with this cancelEvent()... Or something. Need help. I cant handle this myself.

Link to comment
How nice.... Yet everything worked. Now I open the console and see: "Failed to enter/exit vehicle - id: 1"

Then I try to seat down second time, I cant. But now I receive: "Failed to enter/exit vehicle - id: 2".

Third, fourth, fifth attempts give me the same: "Failed to enter/exit vehicle - id: 2".

Yes, I've seen those in my game mode. The logic I've got seems to work to I kinda ignored them TBH (I have a player vehicle lock). I have however noted times when a player couldn't enter a newly created vehicle but I could (enter the same one). Maybe there's an issue with enter/exit in DP2 ?

Note: this was the SAME player coming to my server - on different days ?! He was the only one with the problem of not being able to enter new cars (sometimes). A reconnect sorted. Strange it was just him but similar to your issue.

Link to comment

I'm just saying that I think there's problems with enter/exit (sometimes) ? Different ones maybe - but all connected, and I think unsolvable in the scripts we're coding rather than the actual MTA engine. It's DP2 after all - bug hunting right now can be tricky because you can't be certain (sometimes) who's is the coding error. But looking at your code I can't see why it'd fail in the manner it does.

Link to comment

Me too. That is why, I post here :)

And, being a hardcode programmer myself, I have an inside feeling that something wrong happens on a player object itself. Some triggers, or smth. I dont know the algorithms, implemented in MTA, but there obviously should be such handlers on objects.

And one of them crashes after these manipulations. One of those, who handle car interactions.

Thats are just my thougts. No more.

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