Jump to content

Custom Loadouts (using database)


Recommended Posts

Hey all :)

 

How about the ability to create custom loadouts and assign them to specific players, via the database?

 

I would love this, as it would allow us to give custom loadouts to folks that donate :D

 

Similar to the 'custom_loadout' and 'custom_loadout_profile' in Reality/Bliss databases.

 

 

Link to comment
Share on other sites

If we did it this way then it would break male/female selection. We could easily add a way to do this via the mission file that wont break anything however the playerUID's would need to be in the mission file. I am not sure if it is acceptable to have playerUID's in the mission file.

Link to comment
Share on other sites

I have accomplished this successfully on our own server at ForsakenDayZ.com.  Here is it's current capabilities

 

1.) Custom Spawn Locations based upon each character

2.) Custom Inventory, Backpack, and Backpack content

3.) Custom Skin

 

This is not accomplished via ANY DAYZ game coding.  It is 100% SQL and windows task scheduler (Ghetto Custom Loadout!)

 

1.) Build a Table in MySQL (I use NaviCat or SQLYOG) called character_custom in EPOCH database

- PlayerName (varchar(25))

- PlayerUID (varchar(20))

- Inventory (longtext(0)) - allow null

- Backpack (longtext(0) - allow null

- Worldspace (varchar(128)) - default value []

- CurrentState (varchar(200) - default value []

- Model (varchar(50)) - default value Survivor2_DZ

 

 

** This table shares similar structure of Character_Data in the EPOCH Database.

 

2.) Simply copy the table field elements from a specific character for testing.  the key field is PLAYERUID, this is what we key off.  The PlayerName is simply for friendly reference so you know which loadout is related to which player. 

 

3.) Install MySQL 5.1 ODBC Driver.  This is important so we can directly hit the MySQL DB through various forms. This must be installed wherever you run the script below

- http://dev.mysql.com/downloads/connector/odbc/5.1.html

 

4.) Create a .VBS file and save it to a good reference location. ex: C:\Scripts\loadout.vbs

 

Here is the code, see comments and edit as needed:

 

' ================================================================================

 

' VBS Script for Custom Load-out and Base Location Regeneration
' This script analyzes an ON-DEATH event and pulls Custom Loadout
' and Base Location information.
'
' Few things to understand.
' If the Player attempts to enter the game with a Character_data.Alive=0 value, the system
' will create a new Character with the same UID.  It is important that this script is ran prior
' to the character joining the game.
'
' Worldspace = Spawn Location
'
' #7/5/2013# - JB
' Added refresher of Trader stock Items

 

 

' Define DSN

' Edit the <username> and <password> below to reflect your SQL settings.  You may also have to alter port and server location as

' well.  This is configured to run on local server in which your DAYZ is hosted.  if you dont have direct access to the server, but

' have MySQL access, this will still work.  keep in mind, it will need to run on something 24/7, otherwise the loadouts wont work!

set ConDayZ = CreateObject("ADODB.Connection")
ConDayZ.open "DRIVER={MySQL ODBC 5.1 Driver}; SERVER=127.0.0.1; PORT=3306; DATABASE=dayz_epoch; USER=<SQLUSERNAME>; PASSWORD=<yourpasswordhere> OPTION=3;"

' Update Traders Inventory

' This function stocks trader inventory as soon as it drops to 1 or below.. nifty feature to keep from manually restocking

' trader items - you can eliminate this if necessary, or comment out if necessary.
SQL = "UPDATE traders_data SET qty=10 WHERE qty <= 1"
ConDayZ.Execute (SQL)

 

' Create a Looper to process this script multiple times during initial run.

' This was important as Windows Task Scheduler only allows a task to run every minute.  Basically I am creating a loop with a

' slight delay to run several times a minute.  about 10 seconds in between.  This was created to not POUND the database

' non-stop. you can modify as necessary, the key thing is that if your "custom loadout guy" dies, he needs to be sure to wait 10

' seconds before respawning.  If he spawns in too quickly, the game will create a NEW FRESH SPAWN and the loadout wont work.

' Like I said, adjust as necessary, but done kill your DB, otherwise other performance issues will creep up!

For i = 0 To 4

' Step one Query Database of Custom Loadouts

SQLa = "SELECT PlayerUID FROM character_custom"
SET RSa = ConDayZ.Execute (SQLa)
WHILE RSa.EOF = FALSE

 SQL = "SELECT CharacterID, PlayerUID FROM character_data WHERE Alive=0 AND PlayerUID=" & RSa(0) & " ORDER BY CharacterID DESC"
 SET RS = ConDayZ.Execute (SQL)
 IF RS.EOF = False THEN
 ' We have found someone that is dead, yo
 
 ' Step1 Bring the original Character to life and reset items like fresh spawn.

' Note: This is a nice feature as it sets the BASE spawn items.  If you have someone that just wants a custom SPAWN location, this

' ensures that they have the basic loadout.  Adjust as you see fit!
 SQL1 =  "UPDATE character_data SET Inventory='[[""ItemFlashlight""],[""ItemBandage"",""ItemPainkiller""]]', " &_
  "Backpack='[""DZ_Patrol_Pack_EP1"",[[],[]],[[],[]]]', CurrentState='["""",""amovpercmstpsnonwnondnon_zevl"",36]', Alive=1, " &_
  "medical='[false,false,false,false,false,false,false,12000,[],[0,0],0,[0,0]]'" &_
  ",LastAte='" & now() & "', LastDrank='" & now() & "', KillsZ=0, HeadshotsZ=0, DistanceFoot=0, KillsH=0, Model='Survivor2_DZ', KillsB=0, Humanity=2500, Infected=0 " &_
  "WHERE CharacterID=" & RS(0)
 ConDayZ.Execute (SQL1)
 SQL1 = ""
 

 ' Step2 Build Custom Loadout, if exists
 SQL2 = "SELECT Inventory, Backpack, Worldspace, CurrentState, Model FROM character_custom WHERE PlayerUID=" & RS(1)
 SET RS2 = ConDayZ.Execute (SQL2)
 IF RS2.EOF = False THEN
  ' We have found a custom loadout
  SQL3 =  "UPDATE character_data SET "&_
   "Inventory='" & Replace(RS2(0),Chr(34),"""") &_
   "', Backpack='" & Replace(RS2(1),Chr(34),"""") &_
   "', Worldspace='" & Replace(RS2(2),Chr(34),"""") &_
   "', Currentstate='" & Replace(RS2(3),Chr(34),"""") &_
   "', Model='" & Replace(RS2(4),Chr(34),"""") & "' WHERE CharacterID=" & RS(0)
  ConDayZ.Execute (SQL3)
  SQL3 = ""

 END IF
 RS2.Close
 SQL2 = ""

END IF
RS.Close

' Loop to next record
RSa.MoveNext
WEND
RSa.Close

' Having to run this script multiple times in 1 minute period due to Windows
' inability to schedule less than 1 minute.
WScript.sleep 10000

' Loop back to process it again.
Next

 

 

 

 

' Alright, lets end this beast
 
SQL = ""
ConDayZ.Close

 

' ==========================================================================

 

 

 

5.) Now simply save the file and have it scheduled to run via Windows Task Scheduler EVERY Minute.  I would of course run it a few times to ensure it works.  All you need to do is DIE in the game, or "UPDATE Character_Data SET alive=0 WHERE PlayerUID=xxxxxx"  - this will kill you, and you can test how it works.

 

 

Few disclaimers

 

1.) No warranty or guarantee. use at your own risk

2.) The field contents are very sensitive, the best action is to copy it directly from the character_data table.  If you jack up the syntax of the inventory you will cause your character to spawn without essential items.

3.) Worldspace is best determined when your character is at the location- however, if you must deal with coords, here is the math and format:

 

format: [ Angle, [ X, -Z, Y ]

math: X = X / 100, Z = 153 - ( Z / 100 ), Y = Y

Angle = direction you're facing

X = Horizontal position across the map,

-Z = Inverted vertical position down the map

Y = Height above sea level

 

4.) The Custom Loadout doesn't allow the creation of new "spawns".  It simply revives you if you die.  This is nice as it will keep you ALIVE for longer periods and build your stats.  if you dont like it, modify the SQL to adjust the data parameters on Character_Data table. 

 

5.) Due to issue # 4, you cannot revive a previous state of your survivors.  For example, say someone says there was a bug and they just died and lost all their possessions - sucks for them because we dont retain dead survivors in the DB, we simply revive them and then adjust their inventory.

 

6.) Dont make fun of me code, ya haters... use it, modify it, and show some love!  if you would like any other custom modifiers to the DB, I am available for Hire!

 

 

A few features coming to the code or custom scripts...

 

1.) Fresh Spawn custom loadout.  No need to modify mission file or game code. We can modify users loadouts by detecting fresh spawns and adjust immediately.

 

2.) Spawn with your buddy.  Custom spawn locations follow your best buddy wherever he or she may go!

 

3.) Clan Packs or Gift Packages for contributors (will require mission restart).  Drop a Shed with SAFE, Fencing, canvas, tents, etc. pretty much any item that is supported in game.

 

 

 

Much appreciation goes to my fellow admins on ForsakenDayZ: Ghost and Aixelsyd - ya'll rock.

-JB

 

 

 

 

 

Link to comment
Share on other sites

Whilst I don't like having PlayerUID's in the mission files if there is no alternative for now other than setting up another/extended DB like above I can live with it. (As its currently used for the admin menu)

 

I would imagine the code would be very similar to the admin menu?

 

if ((getPlayerUID player) in ["######","######"]) then {

// Custom Loadout 
DefaultMagazines = [];
DefaultWeapons = [];
DefaultBackpack = "";
DefaultBackpackWeapon = "";
};
else

// Default Loadout 

DefaultMagazines = [];
DefaultWeapons = [];
DefaultBackpack = "";
DefaultBackpackWeapon = "";
Link to comment
Share on other sites

We have had a better more efficient system working on our server for a couple months now, when there were less than 50 epoch servers out there. You would have to ask nOeViL to release it for everyone, but I doubt it as he made it specifically custom for our server.

 

You can tidy this up, make it 100% server side, and not have the slight performance this will have when the database gets very large due to high populations. It also allows those who do not have a dedibox or VM, to execute it if they have access to the DB, no outside script needed. However, this release would work nicely for anyone who doesn't have performance issues when near capacity all the time, kudos on the release.

 

PM me if you want a few suggestions to expand further with more options!

Link to comment
Share on other sites

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

×
×
  • Create New...