Rynet Posted January 5, 2008 Share Posted January 5, 2008 (edited) I am updating this to [email protected]'s current status on the vehicle despawner and doing a little topic cleaning UPDATE: newest version uploaded to: http://www.colips.nl/files/vrdelay0.2b2.zip Newest version also has a help-tab on the help-manager resource now, describing what it does and the known issues we've discovered while testing it locally, debug output is suppressed in this version. One major change in this version is the structure of the destruction queue. Instead of holding vehicles in it, it holds arrays of vehicles, combined with timers. That way the timer is guaranteed to be bound to the vehicle on the queue, and can easily be destroyed with it's vehicle. The structure now looks like: { { vehicle1, timer1 }, { vehicle2, timer2 }, { vehicle3, timer3 }, etc.. } Plan for next version is to make it more configurable, hopefully with an included GUI Edited January 12, 2008 by Guest Link to comment
[email protected] Posted January 5, 2008 Share Posted January 5, 2008 I guess you can build a script that uses the destroyElement ( element elementToDestroy ) function to destroy the vehicle itself. To find the vehicle you can use the event handler onExitVehicle, which triggers your function to destroy the vehicle, passing the vehicle element to the triggered function as source. Inside that triggered function you can add a timer which triggers a second function actually destroying the vehicle after a certain amount of time, let's say 10 minutes. I will script an example in some moments and verify if that works Link to comment
[email protected] Posted January 6, 2008 Share Posted January 6, 2008 Hi again, apologies for doubleposting, seemed I couldn't edit my own post EDIT: and for a weird reason I can edit this post, but not my previous one... Anyway Rynet, I created a resource-script, of what I think you meant the script should do. You can download it currently from: http://www.colips.nl/files/vrdelay.zip (forum doesn't allow me to put it as attachment, for a reason I suppose ) Put the zipfile in your /mods/deathmatch/resources/ directory, and load the resource in the server ( servercommand for this is: start vrdelay ) The default vehicle despawn delay-time is set to 10 minutes. Currently this is hardcoded in the .lua scriptfile, but if you unzip the contents of the zipfile into your /mods/deathmatch/resources/ directory, you can open the .lua script with a text editor (even notepad would do), and manually set the delay-time of the vehicles. if you open the delayedVehicleDestroy.lua file, you should change the line in bold-style, as shown below. For instance: if you want the vehicles to disappear after 45 minutes, after the player left the vehicle, then you should change the "10" in the bold-styled line in the code, to "45". Note that that line is not typed in bold in the actual .lua file. ---------------------------------------------- -- Delayed Vehicle Removal Script -- Author: [email protected] -- Date: 6 january 2008 -- Description: This resource removes any -- abandoned vehicle on the map after a -- certain amount of time. Abandoned -- means a player leaving the vehicle. ---------------------------------------------- -- Configurable, set your despawndelay here! -- [b]local removeDelay = 10 [/b] -- The amount of minutes to wait before removing an abandonded vehicle ---------------------------------------------- -- Description of the implementation: ---------------------------------------------- -- -- We record a queue that holds all vehicles that are about to be removed from the game, within a certain amount of time. -- A vehicle that has been abandonded is added to this queue and will remain on the queue until the vehicle gets removed, or a player enters the vehicle again. -- When the timer has been expired for that specific vehicle, the vehicle will be removed from the game. -- If the vehicle is removed, it will never respawn again. It can only be recovered by restarting the map on the server. -- Ofcourse spawning a new vehicle is an option also ..... One last note: I haven't specified exactly what happens when there are several players in a vehicle and only 1 of them leaves the vehicle. My guess is that the vehicle despawn timer will start anyway then, and when that timer expires it probably kicks out all "passengers" and removing the vehicle. As soon as another player enters the vehicle the vehicle will not despawn though. I will look into that later One more last last note : You are free to use this script for non-commercial purposes. You can modify the script if you wish to. You cannot remove my credits from the script though. Link to comment
Rynet Posted January 6, 2008 Author Share Posted January 6, 2008 Thanks mate! I will test it out and see what I can add into the script. Link to comment
[email protected] Posted January 6, 2008 Share Posted January 6, 2008 I was trying to add a command that would enable/disable the script's functionality during runtime. That means: admins would be able to stop the vehicles from despawning by typing: "vrdelay stop" in the console (or "/vrdelay stop" in the chatbox), and type "vrdelay start" to resume vehicles despawning again. But I had some issues by making this an admin-exclusive command (everyone was basically able to use it which you probably don't want ) If anyone can get me a hint on making that command accessible to server admins only that would be very sweet The command is disabled for now, but was implemented through a command handler, calling a function that starts and stops the script, based on what it's argument was. Code below: function startStopHandler( playerObj, cmd, arg ) -- function to start/stop the script functionality, currently disabled. if isGuestAccount( getClientAccount( playerObj )) then outputChatBox("You do not have permission to use this command!", playerObj, 255, 0, 0) else if( arg == "start" ) and not sEnabled then sEnabled = true outputChatBox("#00FF00Delayed Vehicle Despawn #FFFF00is enabled now", playerObj, 255, 255, 0, true) else if( arg =="stop") and sEnabled then local numQueued = #markedVehicles for i = 1,numQueued do table.remove( markedVehicles, i ) end sEnabled = false outputChatBox("#00FF00Delayed Vehicle Despawn #FFFF00is disabled now", playerObj, 255, 255, 0, true) end end end end addCommandHandler("vrdelay", startStopHandler) -- command handler to enable/disable the script Additional notes: -sEnabled is a global variable, which is true or false. the other main functions read from this variable. -this function works for all registered players currently. Unregistered players (players without accounts on the server) cannot use the command, but I want it to be an admin/moderator-only command. -I have been experimenting with the ACL, concerning this problem but it seems quite hard to add the permission for this command from inside the script itself, as the whole resource doesn't seem to have permission to edit the ACL. Link to comment
eAi Posted January 6, 2008 Share Posted January 6, 2008 I was trying to add a command that would enable/disable the script's functionality during runtime.That means: admins would be able to stop the vehicles from despawning by typing: "vrdelay stop" in the console (or "/vrdelay stop" in the chatbox), and type "vrdelay start" to resume vehicles despawning again. But I had some issues by making this an admin-exclusive command (everyone was basically able to use it which you probably don't want ) If anyone can get me a hint on making that command accessible to server admins only that would be very sweet The command is disabled for now, but was implemented through a command handler, calling a function that starts and stops the script, based on what it's argument was. Code below: function startStopHandler( playerObj, cmd, arg ) -- function to start/stop the script functionality, currently disabled. if isGuestAccount( getClientAccount( playerObj )) then outputChatBox("You do not have permission to use this command!", playerObj, 255, 0, 0) else if( arg == "start" ) and not sEnabled then sEnabled = true outputChatBox("#00FF00Delayed Vehicle Despawn #FFFF00is enabled now", playerObj, 255, 255, 0, true) else if( arg =="stop") and sEnabled then local numQueued = #markedVehicles for i = 1,numQueued do table.remove( markedVehicles, i ) end sEnabled = false outputChatBox("#00FF00Delayed Vehicle Despawn #FFFF00is disabled now", playerObj, 255, 255, 0, true) end end end end addCommandHandler("vrdelay", startStopHandler) -- command handler to enable/disable the script Additional notes: -sEnabled is a global variable, which is true or false. the other main functions read from this variable. -this function works for all registered players currently. Unregistered players (players without accounts on the server) cannot use the command, but I want it to be an admin/moderator-only command. -I have been experimenting with the ACL, concerning this problem but it seems quite hard to add the permission for this command from inside the script itself, as the whole resource doesn't seem to have permission to edit the ACL. You generally shouldn't be coding scripts that modify the ACL unless that is their main purpose. You should rely on the server admin to do that. You can use hasObjectPermissionTo if you want to check if you have the correct rights and warn the admin if need be. If you have a setting the admin can change, use the settings system, namely get. This allows the admin to change this setting 'on the fly' and without editing your zip file. If you want to prevent users being able to call your console command by default, specify 'true' as the last boolean for the addCommandHandler call: bool addCommandHandler ( string commandName, function handlerFunction, [bool restricted = false] ) If restricted is true, by default nobody can call the command, the admin will have to add it to the ACL for the users they want to be able to access it. Link to comment
Rynet Posted January 6, 2008 Author Share Posted January 6, 2008 Does this still remove the vehicle if it is created but never entered by a player? Does it also add it to the despawn timer if a player quits while in a vehicle and doesn't exit it? Just seeing if it has it all covered. Link to comment
Rynet Posted January 6, 2008 Author Share Posted January 6, 2008 Update: Upon testing the script does not remove vehicles that nobody entered nor does it remove vehicles that someone died in and didn't exit. I am guessing the script needs another event handler for on the use of /createvehicle that it either gives the ownership to the player or starts a decaying timer as soon as it is created rather then entered. Then have the event on player death to start the decay timer on the vehicle? not sure how that would work because once the player died it wouldn't be attached to the vehicle anymore without continuously polling to see if that character is still in that vehicle. Link to comment
[email protected] Posted January 6, 2008 Share Posted January 6, 2008 Update: Upon testing the script does not remove vehicles that nobody entered nor does it remove vehicles that someone died in and didn't exit. I am guessing the script needs another event handler for on the use of /createvehicle that it either gives the ownership to the player or starts a decaying timer as soon as it is created rather then entered. Then have the event on player death to start the decay timer on the vehicle? not sure how that would work because once the player died it wouldn't be attached to the vehicle anymore without continuously polling to see if that character is still in that vehicle. Hi Ryzel, I read the following as "when a player abandons/leaves his car": that despawn them selfs after a certain amount of time when no one is using them anymore It seems you meant when there is no player in the car. I will look into that tomorrow afternoon, or earlier if time allows it. and thanks for the reaction on permissions eAi. I have been trying to mess around with hasObjectPermissionsTo, but I do not have anything yet that does what it should do EDIT: the in-game command "/vrdelay start|stop" works as it was meant to work now. Admins using "/vrdelay start" and "/vrdelay stop" (in the console window without the slashes), can respectively enable or disable the scripts functionality now. Upon using the stop command, no more vehicles will despawn by this script and the queue holding all vehicles that were about to removed is emptied. Every player on the server will also be updated if the script is started/stopped The updated version is located at: http://www.colips.nl/files/vrdelay.zip and the despawn timer is again set to 10 minutes by default. TODO: -vehicles despawning, even if nobody ever entered the vehicle -vehicles despawning when the vehicle explodes -vehicle despawning when the last player occupying the vehicle died -vehicle despawning currently does not look if the player who left the vehicle was the ONLY player inside that vehicle, in other words: If there was more than 1 player in the vehicle, the despawn timer will still be started. *I forgot to update the implementation description with the vrdelay command-related details, and some comments related to the vrdelay command aren't updated also, in the current resource package Feedback on bugs, positive reactions, suggestions are welcome ofcourse Link to comment
Rynet Posted January 6, 2008 Author Share Posted January 6, 2008 Not sure if this will help but seems console once in awhile outputs a debug problem. here is the log file. I didn't notice any problems with it removing the cars we already used, not sure however if it still removes it if the player has logged out? 10:10:12] JOIN: JJ joined the game (IP: 192.168.15.6) [10:11:01] CONNECT: Rynet connected (IP: 127.0.0.1) [10:11:09] JOIN: Rynet joined the game (IP: 127.0.0.1) [10:20:41] WARNING: ctvdebug.lua: Bad argument @ 'createVehicle' - Line: 189 [10:20:54] WARNING: ctvdebug.lua: Bad argument @ 'createVehicle' - Line: 189 [10:28:42] WARNING: delayedVehicleDestroy.lua: Bad 'vehicle' pointer @ 'getVehicleOccupant'(1) - Line: 123 [10:28:42] WARNING: delayedVehicleDestroy.lua: Bad 'element' pointer @ 'destroyElement'(1) - Line: 113 [10:32:49] WARNING: delayedVehicleDestroy.lua: Bad 'vehicle' pointer @ 'getVehicleOccupant'(1) - Line: 123 [10:32:49] WARNING: delayedVehicleDestroy.lua: Bad 'element' pointer @ 'destroyElement'(1) - Line: 113 [10:35:28] WARNING: delayedVehicleDestroy.lua: Bad 'vehicle' pointer @ 'getVehicleOccupant'(1) - Line: 123 [10:35:28] WARNING: delayedVehicleDestroy.lua: Bad 'element' pointer @ 'destroyElement'(1) - Line: 113 [10:57:14] WARNING: delayedVehicleDestroy.lua: Bad 'vehicle' pointer @ 'getVehicleOccupant'(1) - Line: 123 [10:57:14] WARNING: delayedVehicleDestroy.lua: Bad 'element' pointer @ 'destroyElement'(1) - Line: 113 [10:58:57] QUIT: JJ left the game [Quit] [10:59:04] QUIT: Rynet left the game [Quit] [11:01:26] WARNING: delayedVehicleDestroy.lua: Bad 'vehicle' pointer @ 'getVehicleOccupant'(1) - Line: 123 [11:01:26] WARNING: delayedVehicleDestroy.lua: Bad 'element' pointer @ 'destroyElement'(1) - Line: 113 as for the script not checking which player left the vehicle I think there is an event handler for the driver position in the vehicle. It has some ID attached to it which is global so could grab the ID and look for the onplayerexit of the position of that car. Link to comment
Rynet Posted January 6, 2008 Author Share Posted January 6, 2008 I have also found that running /vrdelay start when it is already running gives you a invalid syntax because it doesn't check to see if it is already started and I'm guessing it doesn't run a check if it is already stopped when you run the command itself. So you would need to add a check for that and then output that it is already running or it is already stopped if the command issued is in direct contradiction to its current state. Might as well add a /vrdelay status or something to output if it is already running or disabled. Link to comment
[email protected] Posted January 6, 2008 Share Posted January 6, 2008 Not sure if this will help but seems console once in awhile outputs a debug problem.[10:28:42] WARNING: delayedVehicleDestroy.lua: Bad 'vehicle' pointer @ 'getVehicleOccupant'(1) - Line: 123 [10:28:42] WARNING: delayedVehicleDestroy.lua: Bad 'element' pointer @ 'destroyElement'(1) - Line: 113 [10:32:49] WARNING: delayedVehicleDestroy.lua: Bad 'vehicle' pointer @ 'getVehicleOccupant'(1) - Line: 123 [10:32:49] WARNING: delayedVehicleDestroy.lua: Bad 'element' pointer @ 'destroyElement'(1) - Line: 113 as for the script not checking which player left the vehicle I think there is an event handler for the driver position in the vehicle. It has some ID attached to it which is global so could grab the ID and look for the onplayerexit of the position of that car. getVehicleOccupant( vehicleObj ) in the script should return the driver of the vehicle and getVehicleOccupant( vehicleObj, i ) in the loop should check every seat of a vehicle for the condition that there's a player on the seat. However: Between the start of the destroy vehicle timer and the actual destruction of the vehicle, it can happen the vehicle does not exist at the moment when the timer for that vehicle expires. (for example, when the vehicle got blown up but has not yet respawned). This should be fixed once the vehicle will be removed if it explodes. But I haven't had the time to create that properly. You can probably do it yourself easily, by adding an event handler for the server event "onVehicleExplode", which calls the function destroyVehicle. I still have an issue with removing the vehicle if a player dies inside the vehicle though. Trying to work that out for tomorrow. As for that syntax message for the start/stop command. The script does check if it is running or not, but the condition of the output of that message is not correct. It doesn't start the script if it was already running. I will make sure this inconsistency is not present in the next update. Link to comment
Rynet Posted January 6, 2008 Author Share Posted January 6, 2008 Alright, I am working on a portion of this that will also create a menu based list of the cars that are abandoned that an admin can bring and manually select abandoned cars to remove. Just adding some more functionality to it. I will post here when I have completed the scripting for that portion and merged it with yours. Probably could even add a function to destroy all cars in the queue at once via a command even tho the script is running it will destroy them all and remove them from the queue for a very populated server and you want a instant performance boost Link to comment
[email protected] Posted January 6, 2008 Share Posted January 6, 2008 Alright, I am working on a portion of this that will also create a menu based list of the cars that are abandoned that an admin can bring and manually select abandoned cars to remove. Just adding some more functionality to it. I will post here when I have completed the scripting for that portion and merged it with yours.Probably could even add a function to destroy all cars in the queue at once via a command even tho the script is running it will destroy them all and remove them from the queue for a very populated server and you want a instant performance boost Adding a GUI would be very cool I'm not sure about a performance boost for the server if you remove all queued vehicles instantly. If the list of queued vehicles is pretty large, then the server may need some time to despawn every vehicle on that queue, thus creating more likely something like extra latency for 1 second, after which you can start with a clean desk again To be honest I haven't analyzed what kind of impact the server would get if you would need to destroy, let's say 500 vehicles instantly. In theory this is possible if you have a very populated server, with many people switching cars all the time and a large timer delay. Question should then be: what is the best possible case to maximize overall server performance? Ofcourse a very bad scenario is to have more and more vehicles being stacked up in the server until it crashes because it ran out of system resources, so that's not an option. Another bad scenario can be the case where you need to instantly remove 500 vehicles (because an admin wanted to clear the queue), this can, depending on your server machine take up to seconds. Which might be enough to disconnect a lot of players. I'd say that is not a solution also. A 3rd possibility could be that if an admin wishes to clear the queue and destroy all vehicles on the queue, to destroy every car on the queue with a 500ms delay between the destroy of a vehicle and the next vehicle on the queue. An extra concern would be the time it would take to clear the queue then, and what would happen if you stop clearing the queue halfway. Also what would happen with vehicles being added to the queue, while the queue is being cleared. A 4th option could be to clear the queue automatically every x minutes. By adding a function that starts a timer, which calls the function itself again (recursively). This function should only be running if the global variable sEnabled (which holds the state of the script) is true, if it is false it should not execute the timer anymore, but it should resume executing again if an admin uses /vrdelay start for example. Oh my, what a block of text was that Link to comment
Rynet Posted January 6, 2008 Author Share Posted January 6, 2008 The solution would be to create two queues. You would add a global timer to take all the information from queue one and transfer it into queue 2. Queue 2 would then start removing the vehicles lets say 10 by 10 or something? Would have to see exactly how many cars can be removed simultaneously without impacting server performance. I would guess that it would need to parse the queue one file and not transfer any cars that have been left abandoned for less than 30 seconds so if someone just created a car and went to jump into it and it poofed because it was moved to queue two during the global timer. A variable adjuster perhaps? A line that is modifiable or set by server workloads. Example: It would check the total cars on the server amount and if there is x amount of cars compared to x amount to players. 100 cars and 20 players it would dynamically adjust the vehicle decay timer from 10 minutes to every 1 minute? Then it would revert back to 10 minutes if lets say 20 players and 30 cars or what have you? Link to comment
Rynet Posted January 6, 2008 Author Share Posted January 6, 2008 I have another solution why didn't I think about it before? Why not also add a function that destroys a players vehicle if he creates another vehicle or if he enters a different vehicle? It would need to run a check to see if his previous vehicle has occupants still in it or what not but that wouldn't be too hard to add with an event handler that the script already uses. This would lessen the queue tremendously. This would work in conjunction with people quitting, dieing, and what have you? Sometimes easier is better. lol Link to comment
[email protected] Posted January 6, 2008 Share Posted January 6, 2008 I think I get your idea, but storing the same data on 2 places, in this case all queued cars at a specific moment are present in both queues, can be dangerous. You should be absolutely sure that, if a car gets removed from queue1, then it should also be removed from queue2, and also the other direction: car removed from queue2, then it should also be removed from queue1. If this cannot be guaranteed you actually can't say if the script always does the same thing. An example: queues: Q1 and Q2 2 cars are being removed every time-tick when we start, Q1 contains 3 cars and Q2 has not yet copied the contents of Q1. Q1 = {car1, car2, car3} Q2 = {} Q2 copies from Q1: Q1 = {car1, car2, car3} Q2 = {car1, car2, car3} A vehicle is added to the realtime queue Q1: Q1 = {car1, car2, car3, car4} Q2 = {car1, car2, car3} time-tick occurs, 2 cars being removed: Q1 = {car1, car2, car3, car4} Q2 = {car3} *exploded* the timers for car1 and car2 are still running, and will attempt to destroy a vehicle that doesn't exist anymore (because it was removed by the regular cleanup), but Q1 wasn't updated also during the operation, where 2 cars were removed). And an update: I have updated the output when issuing the /vrdelay command, to match the situation. The message that says that the script is enabled now or disabled now is also sent to every player on the server now, as I intended at first. I haven't added any comments and implementation descriptions still. Current changes are updated in the zip: http://www.colips.nl/files/vrdelay.zip Link to comment
Rynet Posted January 6, 2008 Author Share Posted January 6, 2008 (edited) Ya you are right, but adding in this will lighten the queue up id think. I have another solution why didn't I think about it before? Why not also add a function that destroys a players vehicle if he creates another vehicle or if he enters a different vehicle? It would need to run a check to see if his previous vehicle has occupants still in it or what not but that wouldn't be too hard to add with an event handler that the script already uses. This would lessen the queue tremendously. This would work in conjunction with people quitting, dieing, and what have you? Sometimes easier is better. lol This would have to be used in conjunction with a timer because if someone quit then it would remain because they didn't create a new vehicle. This would be a new circumstantial addition. Edited January 6, 2008 by Guest Link to comment
[email protected] Posted January 6, 2008 Share Posted January 6, 2008 Ya you are right, but adding in this will lighten the queue up id think. I have another solution why didn't I think about it before? Why not also add a function that destroys a players vehicle if he creates another vehicle or if he enters a different vehicle? It would need to run a check to see if his previous vehicle has occupants still in it or what not but that wouldn't be too hard to add with an event handler that the script already uses. This would lessen the queue tremendously. This would work in conjunction with people quitting, dieing, and what have you? Sometimes easier is better. lol I wonder what happens if 2 players have the same previously used vehicle If 2 players have been in the same vehicle and both of them left the vehicle, but did not create/enter another one yet Then player 1 enters another vehicle and his previous vehicle gets destroyed.(eventually players in it are kicked out) After that player 2 anters a different vehicle than player 1 is in. Both players are drivers in this case, not passengers. Then there is an attempt to destroy a vehicle that doesn't exist anymore I would guess... Link to comment
Rynet Posted January 6, 2008 Author Share Posted January 6, 2008 If occupants do exist in his old vehicle or someone else is using the vehicle then if scenario a: occupants exist and no driver exists then it will put it in a separate array till they exit and wait so and so time before manually destroying it. Scenario B: give ownership of the car to the new driver and destroy the drivers old vehicle not the previous owners. Link to comment
Rynet Posted January 6, 2008 Author Share Posted January 6, 2008 Can't it be made to have some form of ownership recorded. We could use the players id and the vehicles ID and attach them if he leaves and creates a vehicle and no one entered his previous vehicles then it will destroy his previous vehicle. If occupants exist in the vehicle then it will not destroy the vehicle until all occupants have either left the vehicle or it will be put on a timer then remove the car after the occupants leave or die or log out. If someone takes control of the car via stealing it then they become the owner of the vehicle and it will not be destroyed till they log, die, or create another vehicle. I think I have that right not sure lol I sound like a lawyer! Link to comment
[email protected] Posted January 6, 2008 Share Posted January 6, 2008 Not sure if I got your words there, but the script actually does: event | action --------------------------------------------------------------------- player leaves vehicle | vehicle is put on destructionqueue player enters vehicle | if the vehicle was on the destruction queue, it's taken out of the queue vehicle on destruction queue is being despawned | remove vehicle from queue and physically destroy it vehicle explodes | instantly physically destroy vehicle So basically it looks currently the easiest to me, to simply change event 1, so that the vehicle is put on the destruction queue, ONLY if the player was the only player inside that vehicle. You can do this by looping through all seats of the vehicle and check if all seats are empty when the player left. If so, then put the vehicle on the queue. physically this means you need to add this check in the "function delayVehicleDestroy()" function. EDIT: I also noticed I uploaded a zipfile, which still had most debugging output enabled. re-uploaded it now. Link to comment
[email protected] Posted January 6, 2008 Share Posted January 6, 2008 A variable adjuster perhaps? A line that is modifiable or set by server workloads. Example: It would check the total cars on the server amount and if there is x amount of cars compared to x amount to players. 100 cars and 20 players it would dynamically adjust the vehicle decay timer from 10 minutes to every 1 minute? Then it would revert back to 10 minutes if lets say 20 players and 30 cars or what have you? this is possible: The script sets the timer variable using set("vrdelaytime", value), where value is the configurable varible removeDelay to set the delay in minutes, but in milliseconds. You can read from this using get("vrdelaytime") If you want to change the delay while the script is running, you can do that by issueing: set("vrdelay", newDelay), where newDelay is the new delaytime in milliseconds (x minutes = x * 60000 ms) When a new car is put on the queue then, it will be despawned faster/slower(depending on the new delay) than before the change of this value. The script should have no problem with searching the correct car in the queue to remove. It can remove items from inside the middle of the queue, etc. Link to comment
ChrML Posted January 6, 2008 Share Posted January 6, 2008 You can do an isElement followed by a getElementType call to check if the vehicle is still valid in the timer functions . Link to comment
[email protected] Posted January 7, 2008 Share Posted January 7, 2008 (edited) You can do an isElement followed by a getElementType call to check if the vehicle is still valid in the timer functions . Thanks for that hint, I had forgotten that isElement() excepts not just elements as it's argument, but obviously that should be the case or the function would be worthless after all I actually worked it out by simply destroying the vehicle element when the vehicle explodes in an earlier version though, and removing the vehicle from the queue manually then if it was on the queue, by just performing my destroyVehicle function, which has an optional argument whether or not it should try to remove a vehicle from the queue when the function is called. Update note: I noticed that the script as it is available for download currently (vrdelay.zip), contains a flaw when the resource cannot set a register-setting on the server. This can sometimes be avoided by removing your settings.xml file on windows dedicated servers. The developement version I currently got checks for this and disables script execution on scriptloadtime (setting sEnabled to false) if it cannot write the register variable containing the delaytime-amount. Further, the script could send a message that says the script has been unloaded or loaded inconsitantly: When a different resource was loaded or a game-mode was stopped for example. In the next version, this will only happen for the vrdelay resource, to restore consistancy on this message again. Last major change is that most debug output will now be output to the server window instead of sending it back to the player who initiated the event. I will be uploading my next update, once I have updated all implementation details and comments. EDIT: does anyone have a suggestion on executing a function whenever a vehicle is created/spawned, no matter which resources was responsible for it? Something like the onVehicleRespawn event, but not just when it respawns, simply whenever it spawns. This is to set start the vehicle destruction timer, whenever a vehicle is spawned. If anyone figured it out, let me know What I'm affraid of is that I need to add a custom event, that does this and build a vehicle spawn function inside the script myself, and export this function via the meta-file, for it to be available to other resources through the call() function. (Silently hoping on an easier way though ) EDIT: 8 january 2008, 1:35AM CET: vehicle destruction timers are now ONLY started when the player who left a vehicle was the last player (= vehicle is then empty). Also fixed some typos in text output and the script doesn't think it is unloaded anymore whenever a different resource is unloaded. Added a check whether the started/stopped resource is the vrdelay script itself or not. Made some major changes in the onVehicleStartExit handler, in order to suit some new requirements. Added a function that checks whether a vehicle is empty or not and updated a serious amount of implementation details and descriptions. Bed time I have uploaded a newer dev version of the script to: http://www.colips.nl/files/vrdelay_dev.zip This version has all debug-output still enabled. I wouldn't recommend to use this version on a server that is not meant for developing scripts/code. If you have a server for players to have fun on and you use this script version on it, you probably get spammed by debug messages Alright, so what has changed in this version: - Vehicles no longer respawn when they exploded. - Vehicles that respawned will get on the destruction queue, to be removed after the specified amount of time. (this can happen when a vehicle respawned, but did not explode before, mostly caused by external scripts) - Vehicles that explode will instantly be destroyed, and will not respawn anymore. - Added a new argument to the command /vrdelay, called "status". When an admin types: "/vrdelay status", then a debug message will be returned to the console and the server-console-window, showing all active timers and which vehicle they belong to. - When a vehicle is removed from the destruction queue, it's timer will get destroyed also (using the function removeVehicleFromDestructionQueue for that). - When a vehicle is directly destroyed, using the function destroyVehicle, and supplying the optional attribute (to also remove the vehicle from the queue), then also it's timer will be destroyed. - Updated some implementation details, but it is currently not up-to-date. Edited January 9, 2008 by Guest Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now