Jump to content

Character Tokens: Saving server specific data to an object on a player.


RAINBOW

Recommended Posts

Came up with some code that checks for a custom item I've modded in called "Ctoken".  Have a look if you like, I have gotten to the point where I access the server specific item, then realised I don't have a clue if I can just 'add' in values to it.

 

The idea behind storing it on an item is for our persistent server, each character will get the item when they join (If they don't already possess one that is!).  The event OnGameStart is serving fine for this purpose, anyway, boolean (true or false) values such as "Trusted Player" and custom player factions such as "Trader" are going to be set on this wonderific "do it all" item.

 

Here's my code:

 

--+ Raenbow +----+ 9th May 2014 +-- --+ CHARACTER TOKEN HANDLER. +---- function loadToken(_player)local player = _player;local token = player:getInventory():FindAndReturn("Raenbow.Ctoken");--local string sDebug = token:getName(); --returns "Character Token" --How can I add in 'another' value to the object token? end function raenbow_ctoken() local player = getPlayer(); --Check if a ctoken exists in inventory or not here:if player:getInventory():contains("Item_Ctoken") == false then--No Ctoken exists, create one and move on:print("Raenbow: No CTOKEN FOUND.  CREATING ONE:");getPlayer():getInventory():AddItem("Raenbow.Ctoken");elseprint("Raenbow: CTOKEN FOUND!");end --to do here, Check there is not more than one ctoken here: --Execute next part here:loadToken(player);end Events.OnGameStart.Add(raenbow_ctoken);

 

 

I'm entirely unsure if I can just 'add' in a value somehow, like with a simple "SetValue()" command or whatever, all I managed to trawl up from the javadocs and gleaming the forums was these:

 

setScriptItem(token);
ScriptManager():getItem();
 
But from what I see on the forums, the scripting stuff is getting binned or whatever anyway.  Surely there must be a simple way to attach a bunch of string/int/bools to an inventory item object? 
 
Thanks in advance!  This one has me stumped :(
Link to comment
Share on other sites

I wasn't too sure about this script business.  I read This and I'm beginning to wonder.  

 

"Is creating my own custom variable and attaching it to an item, as simple as adding a line of code in here?"

 

For example:

item EnergyDrink{HungerChange = 10,Weight = 1.0,Type = Food,UnhappyChange = 10,ThirstChange = -5,DisplayName = Energy drink,ReplaceOnUse = PopBottleEmpty,Icon = Pop4,CustomContextMenu = Drink,}

Can I just 'add' in a line here? such as

 

item EnergyDrink{HungerChange = 10," "    " "    " "CharacterTokenFaction = Bandit," "    " "    " "CustomContextMenu = Drink,}

 

 
Surely it can't be that simple?
Link to comment
Share on other sites

Dude.  Totally fucking works.  Hard to believe someone who created a "Pillow Case silencer" could stumble upon this beauty!

 

Also, that is the most horrendously commented tutorial I've ever read! :)

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
×
×
  • Create New...