Jump to content

Vehicle removing script - problems


dn83

Recommended Posts

Especially freeroam spawnpoints can get pretty chaotic after a while when players create vehicles near the spawn, and those vehicles later respawn after being destroyed somewhere else. And some players just create alot of vehicles they never intend to use.. :) I thought, isn't there an easy way for admins to get rid of them vehicles? Oh wait, this is mta:dm, I can script that myself! :D

Now, this is not a release, but rather a problem!

You see, most of the time this script works perfectly! Sometimes though it might just say that the vehicle is removed, but it is still visible.. Thing is, I cannot get into the vehicle anymore, trying to re-remove it doesn't work.. And if I was driving it when I removed it, I cannot get out anymore! After a while being locked into that vehicle it might say 'Network trouble' (and I've only tested it on 127.0.0.1).. Can such a simple script have bugs, or are we looking at a bug in mta itself? I cannot exactly recreate the problem, it just happens - if it happens.. :?

So here's mY 1sT sCrIpT: Vehicle removing script 1.0

- Just press and hold 'K' (default button), click on a vehicle with your mouse, and it is gone!

The client part:

local removeActive = 0 
local localPlayer = getLocalPlayer() 
  
outputChatBox( "Vehicle removing script 1.0 loaded!\nHold 'K' and click on a vehicle to remove it." ) 
  
function activateRemoveCar() 
    if ( removeActive == 0 ) then 
        removeActive = 1 
        showCursor( true ) 
        --outputChatBox( "Click on a vehicle to remove it" ) 
    else 
        removeActive = 0 
        showCursor( false ) 
    end 
end 
  
bindKey( "k" , "down" , activateRemoveCar ) 
bindKey( "k" , "up" , activateRemoveCar ) 
  
  
function removeCar( button , state , absX , absY , wX , wY , Wz , theElement ) 
    if ( removeActive == 1 and state == "up" ) then 
        if ( theElement ) then 
            local elementType = getElementType( theElement ) 
            if ( elementType == "vehicle" ) then 
                --outputChatBox( "Removing vehicle..." ) 
                triggerServerEvent( "removeCar" , localPlayer , theElement ) 
            else 
                outputChatBox( "You can only remove vehicles" ) 
            end 
        else 
            outputChatBox( "No vehicle selected" ) 
        end 
    end 
end 
  
addEventHandler( "onClientClick" , getRootElement() , removeCar ) 

And the server part:

function removeCar( theVehicle ) 
    if ( theVehicle ) then 
        local removed = destroyElement( theVehicle ) 
        if removed then 
            outputChatBox( "Vehicle removed!" , source ) 
        else 
            outputChatBox( "Failed to remove vehicle." , source ) 
        end 
    end 
end 
  
addEvent( "removeCar" , true ) 
addEventHandler( "removeCar" , getRootElement() , removeCar ) 

What needs to be done:

- Make it admin only! Someone show me how? :)

Questions:

- destroyElement has to be run on the server for this to work, right?

- client-side outputChatBox is only shown to the local player, right?

Link to comment
Especially freeroam spawnpoints can get pretty chaotic after a while when players create vehicles near the spawn, and those vehicles later respawn after being destroyed somewhere else. And some players just create alot of vehicles they never intend to use.. :) I thought, isn't there an easy way for admins to get rid of them vehicles? Oh wait, this is mta:dm, I can script that myself! :D

Now, this is not a release, but rather a problem!

You see, most of the time this script works perfectly! Sometimes though it might just say that the vehicle is removed, but it is still visible.. Thing is, I cannot get into the vehicle anymore, trying to re-remove it doesn't work.. And if I was driving it when I removed it, I cannot get out anymore! After a while being locked into that vehicle it might say 'Network trouble' (and I've only tested it on 127.0.0.1).. Can such a simple script have bugs, or are we looking at a bug in mta itself? I cannot exactly recreate the problem, it just happens - if it happens.. :?

So here's mY 1sT sCrIpT: Vehicle removing script 1.0

- Just press and hold 'K' (default button), click on a vehicle with your mouse, and it is gone!

The client part:

local removeActive = 0 
local localPlayer = getLocalPlayer() 
  
outputChatBox( "Vehicle removing script 1.0 loaded!\nHold 'K' and click on a vehicle to remove it." ) 
  
function activateRemoveCar() 
    if ( removeActive == 0 ) then 
        removeActive = 1 
        showCursor( true ) 
        --outputChatBox( "Click on a vehicle to remove it" ) 
    else 
        removeActive = 0 
        showCursor( false ) 
    end 
end 
  
bindKey( "k" , "down" , activateRemoveCar ) 
bindKey( "k" , "up" , activateRemoveCar ) 
  
  
function removeCar( button , state , absX , absY , wX , wY , Wz , theElement ) 
    if ( removeActive == 1 and state == "up" ) then 
        if ( theElement ) then 
            local elementType = getElementType( theElement ) 
            if ( elementType == "vehicle" ) then 
                --outputChatBox( "Removing vehicle..." ) 
                triggerServerEvent( "removeCar" , localPlayer , theElement ) 
            else 
                outputChatBox( "You can only remove vehicles" ) 
            end 
        else 
            outputChatBox( "No vehicle selected" ) 
        end 
    end 
end 
  
addEventHandler( "onClientClick" , getRootElement() , removeCar ) 

And the server part:

function removeCar( theVehicle ) 
    if ( theVehicle ) then 
        local removed = destroyElement( theVehicle ) 
        if removed then 
            outputChatBox( "Vehicle removed!" , source ) 
        else 
            outputChatBox( "Failed to remove vehicle." , source ) 
        end 
    end 
end 
  
addEvent( "removeCar" , true ) 
addEventHandler( "removeCar" , getRootElement() , removeCar ) 

What needs to be done:

- Make it admin only! Someone show me how? :)

Questions:

- destroyElement has to be run on the server for this to work, right?

- client-side outputChatBox is only shown to the local player, right?

You "might" have a look at the script I built for the same issue. It's called "vrdelay", or it's full, very unlogical name: Delayed Vehicle Despawn.

What it currently does is removing any abandonded vehicle after a set amount of time (default 10 minutes).

One known issue however is that it currently doesn't remove vehicles that were never entered.

If you are an administrator you can soft-enable/disable the script using the commands it supplies. There is a help.xml file included that is supported by the help manager to give you some detail. There's also a command that let's you show all vehicles that are on a timer for destruction.

You are free to copy code from it for use in your script, if you put in my credits at some visible spot. If you wish to edit the code and redistribute it, please ask me first, as I want to know where and how my stuff is used :)

link: viewtopic.php?f=91&t=21102 (scroll to last posts for latest version)

-My script has a "sneaky" way to identify users as admins or non-admins, you might use that.

-destroyElement is a server-only operation I think yes.

-client-side outputChatBox... I have no clue tbh, try it :), it's much more obvious to use: outputChatBox("sometext", thePlayer) to send the text "sometext" to a player object: thePlayer.

Link to comment

Yes I noticed your script, Rabbit. My script was never intended for an actual release, I don't even have a public server.. I'm just trying to learn scripting on my own :) So don't feel threatened that I'm trying to take over your business :lol:

My real question however was why the vehicles aren't always completely removed..

Seems like you have also encountered this (quoted from your help.xml):

"-During our last tests it seemed that sometimes a vehicle really gets destroyed, but the model doesn't get despawned. We think however this is an external issue from another resource probably, but just to put this to your notice."

Btw, pretty sneaky way to identify admins :) But can the script/resource itself be limited (through acl?) so only moderators or admins can use it? Acl is still unexplored territory for me..

Link to comment
Yes I noticed your script, Rabbit. My script was never intended for an actual release, I don't even have a public server.. I'm just trying to learn scripting on my own :) So don't feel threatened that I'm trying to take over your business :lol:

My real question however was why the vehicles aren't always completely removed..

Seems like you have also encountered this (quoted from your help.xml):

"-During our last tests it seemed that sometimes a vehicle really gets destroyed, but the model doesn't get despawned. We think however this is an external issue from another resource probably, but just to put this to your notice."

Btw, pretty sneaky way to identify admins :) But can the script/resource itself be limited (through acl?) so only moderators or admins can use it? Acl is still unexplored territory for me..

The fact the vehicle sometimes does not appear I cannot explain also, it also happens with my version of the solution to the problem.

I ran it with multiple PC's at the same time, and on one PC the car was really visually removed, while on the other PC it was still there, but not possible to interact with the car anymore (the element was really destroyed along with it's timer). I think it may be a client-side problem perhaps.

As for the admin-access thing. What I basically do is, to gather all players who are on the server and are logged in to the server account system (they must have used /login username password in-game), and out of that select of players I match their accounts against the admin-data I retrieved from the ACL. If a match is found and that player is the player in question, then my script says he/she is an admin.

Same can be done for moderators, where you can match useraccounts against the acl-data of admins united with the acl-data of moderators :)

PS. you can also use the ACL and limit access to a command for example, through the ACL. One issue which was a disadvantage for me, is that you need to setup this specific access, on the server in the ACL... This means server adminitrators have extra work, and the correct configuration is not that obvious also.

An example, if you would limit access for the resource "test" to the command "testcommand", through the webadmin resource:

- first problem is that the webadmin resource does not have permissions to change the ACL by default (the in-game admin-panel does, but I am lazy and I do not wish to boot up the game everytime to add, remove, or change the ACL. So let's open: acl.xml inside your deathmatch mod map on the server.

Scroll down until you find something like:

<group name="Admin"> 
      <acl name="Moderator"/> 
      <acl name="SuperModerator"/> 
      <acl name="Admin"/> 
      <acl name="RPC"/> 
      <object name="resource.admin"/> 
   </group> 

Add the webadmin resourcee to this "admin-node", above the admin resource:

<group name="Admin"> 
      <acl name="Moderator"/> 
      <acl name="SuperModerator"/> 
      <acl name="Admin"/> 
      <acl name="RPC"/> 
[b]      <object name="resource.webadmin"/>[/b] 
      <object name="resource.admin"/> 
   </group> 

Alright, now reboot your server to active this, you don't need reboots after this anymore.

Now let's get to the real stuff, open your webbrowser and go to http://serveraddress:22005 and login with any admin-account from your server.

If you do not get a response, check if the resources: "webadmin" and "resourcebrowser" are running, and whether you use a different port (default is 22005) for your webadmin resource (mtaserver.conf).

You should see a menu-section for ACL management, click on GROUPS and add a new group, for example "testgroup". After that add the resource "test" to this group.

Now head over to the ACLs menu, and add a new ACL, let's call it "testACL", after this add the command "testcommand", with ALLOW ACCESS to the ACL you just created.

After that, add the same command to the ACL "Default", but this time leave ALLOW ACCESS unchecked (meaning disallow access).

Right now, nobody, except objects in the ACL "testACL" can use the command. If you would have put the command into the ACL "moderator" instead of testACL, then moderators would be able to use it (and also admins, because moderator rights is a part of administrator rights)

Hope that clearifies something at least :)

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