Jump to content
Sign in to follow this  

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

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:


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 :(

Share this post

Link to post
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?

Share this post

Link to post
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! :)

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...