Jump to content
Sign in to follow this  
ToejaM

How would I do I make a user fortress that is protected when the user is offline

Recommended Posts

I've got an idea, what I want to do is make it so that in persistent game types (DayZ for example or Wasteland Hive..) that if you make a base, you can have a script teleport people away or to the entrance if you're not on the server.. but if you're on, then the script is disabled meaning your base is open to be raided so while you're out foraging your house might be burgled.

Currently the script I'm running, you edit it with playerUIDs and those are then allowed into the protected circle. I feel this takes alot away from the game it would be much more fun if people could raid your base while you're on the server.. but as we have lives, it sucks for people to spend alot of time to get jacked when they arent even around to see it happen.

Any ideas on how to go about this?

Share this post


Link to post
Share on other sites
You could use onPlayerConnected and onPlayerDisconnected to execute scripts which will teleport away all people if the owner of the fortress is not online, easy as that :D

What about if the base has more than one person in the list? If one person in the clan disconnects and there are still others online it would still teleport everyone in the area away?

Share this post


Link to post
Share on other sites

Well that's for you to decide :D

As always there are several ways how to implement this, but you need at least these details:

  • assign the fortresses an unique identifier, something like a name which begins with "fortress_" and a number as a suffix (this could be advantageous for your database, just create a table named "fortresses" or something and the primary key could be used to suffix the unique identifier ingame. You could easily link the UserID in the database with the fortress to create an affiliation).
  • In the init.sqf, check if it's the server and fetch all fortresses plus the users affiliated with it from the database and save it in a multidimensional array or any other data structure you see fit. As may best put this into a function so you can call it everytime you need to update the affiliations.
  • create a global array which holds the unique identifiers of the fortresses and will be used as a condition for your triggers (we'll name it "empty_fortresses" for this example).
  • Place a trigger for each fortress into their center and set the condition like this:
    "fortress_ID" in empty_fortresses


    Replace fortress_ID with the specific unique identifier of that fortress.

Now you could use onPlayerConnected and onPlayerDisconnected to check if all players affiliated with a specific fortress are disconnected and if they are, add the unique identifier of that fortress into "empty_fortresses". This would trigger the scripts you put into the activation field of the trigger you created after fetching the fortress list and execute whatever you had in mind.

Just a suggestion though: Teleporting players for this purpose seems to be a bit improper, because teleporting is something you'd never have in a "real" enviroment. Something like placing barricades around the fortress or even a gate which can be locked is more appropriate :D

Share this post


Link to post
Share on other sites

Wow thats all a bit over my head dealing with the databases and scripting and such.

The teleport to the entrance idea is basically acting as an invisible impenetrable barricade. Not so bothered about the realism aspect and realistically... people wouldnt have proper jobs and they'd sleep in their fortress so they could wake up if they get attacked haha! Someone needs to code it so it sends a text to people sleeping so they can get up lol.

Thanks for the help, is there a simpler way for this?

Share this post


Link to post
Share on other sites

Everything relating to persistance will make your overall code managment much more complex, there is no way out of it I'm afraid.

Because there is persistance, you have to fetch all the data and prevent any inconsistencies which can occur if ingame events aren't handled the right way and written back into the database.

As always my disclaimer follows: I don't have THE answer, just a suggestion how you could - or rather how I would - do it.

Let's wait for some other answers and suggestions and if nothing useful turns up, just PM me and I'll fix you the code (expect for the persistance part...)

Share this post


Link to post
Share on other sites

Your idea of isconnected/isdisconnected...

Say there are three people allowed access to a base, none are online = the teleport script is in force.

If one person joins, the teleport script is then disabled.. another person joins that has access.. the script is obviously still disabled.

Now, if one of the two people with access disconnects... does that re-enable the teleport script or does it require all people offline on the access list for the teleport script to come back up?

Share this post


Link to post
Share on other sites

The latter one obviously :D You have to check if all players in the access list for a specific fortress are gone on every disconnect-event, if they are, re-enable the teleport script, else do nothing.

Basically it is:

  • onPlayerConnected: is the player in the access list and the teleport script is enabled? Disable it!
  • onPlayerDisconnected: Are all players in the access list offline and the teleport script is disabled? Enable it!

The real hurdle will be creating the access list for each fortress and keep track of every change made in the database as well as ingame.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×