• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Using Table to save player state

Status
Not open for further replies.
Level 19
Joined
Aug 8, 2007
Messages
2,765
Im trying to use Table for a quest system and to add rewards would be to save the player state and the amount. However, hashtables have no way to save player state. Does anyone know a workaround?
 
how about something like this

this way they could set there own numbers by setting the array values

then when u load the integer just use the array to set it

JASS:
globals
    playerstate array playStateIntegers
endglobals

function setPlayerStateNumbers takes nothing returns nothing
    set playStateIntegers[0] = PLAYER_STATE_RESOURCE_GOLD
    set playStateIntegers[1] = PLAYER_STATE_RESOURCE_LUMBER
endfunction
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
how about something like this

this way they could set there own numbers by setting the array values

then when u load the integer just use the array to set it

JASS:
globals
    playerstate array playStateIntegers
endglobals

function setPlayerStateNumbers takes nothing returns nothing
    set playStateIntegers[0] = PLAYER_STATE_RESOURCE_GOLD
    set playStateIntegers[1] = PLAYER_STATE_RESOURCE_LUMBER
endfunction
Maybe could work, but making seperate for gold/wood seems more friendly to use than that, i want to stay away from array lookup
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
well if u do it this way all u would have to do is something like this
JASS:
local integer pS = Table[0]
call SetPlayerState(( Player(p), playerStateIntegers[pS], load ur other value)

i cant think of any easier way.

Cant give rep to you? :(

Anyway, something tells me i just dont want to add it and if theres an easier way to do it without lookup than id do it, but for now im just gonna do two seperates for gold/wood. Ty though
 
Type casting : http://www.hiveworkshop.com/forums/tutorial-submission-283/typecasting-232039/

You can also use these libraries :
JASS:
library Handle
/**************************************************************************************************************
 *  Handle API
 *  ¯¯¯¯¯¯¯¯¯¯
 *  You can now save <every type> into hashtables and load almost** everything, thanks to these functions.
 *  
 *  Since many JASS types extend a handle instead of an agent, this library enables some very useful commands.
 *  Thanks to KingKing for the "ConvertFogState" trick used in many of these functions and for inspiration.
 *  Thanks to Vexorian for the awesome JassHelper; any/all of these functions will inline when you use them.
 *
 *
 *  Example Useage
 *  ¯¯¯¯¯¯¯¯¯¯¯¯¯¯
 *  call SaveHandle(hash, 0, 0, CreateTextTag())
 *  call SaveHandle(hash, 0, 1, TriggerAddAction(t, function thistype.onLoop))
 *
 *  call SetPlayerState(u, LoadPlayerStateHandle(hash, 0, 2), GetPlayerState(u, LoadPlayerStateHandle(hash, 0, 3)))
 *  call SetUnitState(p, LoadUnitStateHandle(hash, 0, 4), 9001)
 *
 *
 *  function SaveHandle takes hashtable table, integer parentKey, integer childKey, handle h returns boolean
 * 
 *  ->  This is basically the same thing as SaveAgentHandle, only it saves *any handle* -- it does not have to
 *      be an agent-type.  This is extremely useful for many reasons like generic saves and for saving types
 *      which could never be saved before (attacktype, damagetype, pathingtype, etc.)
 *  
 *  function SaveHandleId takes hashtable table, integer parentKey, integer childKey, handle h returns nothing
 * 
 *  ->  This is pretty much a shortcut from typing GetHandleId() each time you just want to save a handle's
 *      integer reference.
 *  
 *  function Load$NAME$Handle takes hashtable table, integer parentKey, integer childKey returns $TYPE$
 *  
 *  ->  Loads the handle of almost everything that wasn't in the hashtable API natives.
 *   
 *  function Load$NAME$HandleEx takes hashtable table, integer parentKey, integer childKey returns $TYPE$
 *   
 *  ->  If you saved the handle as an integer, this will load/typecast the desired handle from that integer.
 *      I recommend using this method instead of simple Load$NAME$Handle because it's faster to do it this way.
 *      Just keep in mind that you can't use this function for types that were already in the hashtable native
 *      API functions - they must be loaded normally or from KingKing's typecasting library.
 */
    
    function SaveHandle takes hashtable table, integer parentKey, integer childKey, handle h returns boolean
        return SaveFogStateHandle(table, parentKey, childKey, ConvertFogState(GetHandleId(h)))
    endfunction
        
    function SaveHandleId takes hashtable table, integer parentKey, integer childKey, handle h returns nothing
        call SaveInteger(table, parentKey, childKey, GetHandleId(h))
    endfunction
    
    
    //! textmacro ConvertHandleType takes NAME, TYPE
    function Load$NAME$Handle takes hashtable table, integer parentKey, integer childKey returns $TYPE$
        return Convert$NAME$(GetHandleId(LoadFogStateHandle(table, parentKey, childKey)))
    endfunction
    
    function Load$NAME$HandleEx takes hashtable table, integer parentKey, integer childKey returns $TYPE$
        return Convert$NAME$(LoadInteger(table, parentKey, childKey))
    endfunction
    //! endtextmacro
    
    //! runtextmacro ConvertHandleType("Race", "race")
    //! runtextmacro ConvertHandleType("AllianceType", "alliancetype")
    //! runtextmacro ConvertHandleType("RacePref", "racepreference")
    //! runtextmacro ConvertHandleType("IGameState", "igamestate")
    //! runtextmacro ConvertHandleType("FGameState", "fgamestate")
    //! runtextmacro ConvertHandleType("PlayerState", "playerstate")
    //! runtextmacro ConvertHandleType("PlayerScore", "playerscore")
    //! runtextmacro ConvertHandleType("PlayerGameResult", "playergameresult")
    //! runtextmacro ConvertHandleType("UnitState", "unitstate")
    //! runtextmacro ConvertHandleType("AIDifficulty", "aidifficulty")
    //! runtextmacro ConvertHandleType("GameEvent", "gameevent")
    //! runtextmacro ConvertHandleType("PlayerEvent", "playerevent")
    //! runtextmacro ConvertHandleType("PlayerUnitEvent", "playerunitevent")
    //! runtextmacro ConvertHandleType("WidgetEvent", "widgetevent")
    //! runtextmacro ConvertHandleType("DialogEvent", "dialogevent")
    //! runtextmacro ConvertHandleType("UnitEvent", "unitevent")
    //! runtextmacro ConvertHandleType("LimitOp", "limitop")
    //! runtextmacro ConvertHandleType("UnitType", "unittype")
    //! runtextmacro ConvertHandleType("GameSpeed", "gamespeed")
    //! runtextmacro ConvertHandleType("Placement", "placement")
    //! runtextmacro ConvertHandleType("StartLocPrio", "startlocprio")
    //! runtextmacro ConvertHandleType("GameDifficulty", "gamedifficulty")
    //! runtextmacro ConvertHandleType("GameType", "gametype")
    //! runtextmacro ConvertHandleType("MapFlag", "mapflag")
    //! runtextmacro ConvertHandleType("MapVisibility", "mapvisibility")
    //! runtextmacro ConvertHandleType("MapSetting", "mapsetting")
    //! runtextmacro ConvertHandleType("MapDensity", "mapdensity")
    //! runtextmacro ConvertHandleType("MapControl", "mapcontrol")
    //! runtextmacro ConvertHandleType("PlayerColor", "playercolor")
    //! runtextmacro ConvertHandleType("PlayerSlotState", "playerslotstate")
    //! runtextmacro ConvertHandleType("VolumeGroup", "volumegroup")
    //! runtextmacro ConvertHandleType("CameraField", "camerafield")
    //! runtextmacro ConvertHandleType("BlendMode", "blendmode")
    //! runtextmacro ConvertHandleType("RarityControl", "raritycontrol")
    //! runtextmacro ConvertHandleType("TexMapFlags", "texmapflags")
    //! runtextmacro ConvertHandleType("EffectType", "effecttype")
    //! runtextmacro ConvertHandleType("Version", "version")
    //! runtextmacro ConvertHandleType("ItemType", "itemtype")
    //! runtextmacro ConvertHandleType("AttackType", "attacktype")
    //! runtextmacro ConvertHandleType("DamageType", "damagetype")
    //! runtextmacro ConvertHandleType("WeaponType", "weapontype")
    //! runtextmacro ConvertHandleType("SoundType", "soundtype")
    //! runtextmacro ConvertHandleType("PathingType", "pathingtype")
/*
*   Handles that were already in the hashtable API but cannot be saved with <SaveAgentHandle>:
*
*   triggeraction   ->  LoadTriggerActionHandle
*   texttag         ->  LoadTextTagHandle
*   unitpool        ->  LoadUnitPoolHandle
*   itempool        ->  LoadItemPoolHandle
*
* **Things which still cannot be typecasted:
*
*   terraindeformation
*   weathereffect
*   camerasetup
*/
//*************************************************************************************************************
endlibrary
JASS:
//////////////////////////////////////////
//       Typecasting 2.0.1
//       by kingking
//  
//  This library provides some type
//  converting functions.
//
//  ====================================
//   Functions provided :
//  ====================================
//  Agent2Widget(agent) -> widget
//  Agent2Group(agent) -> group
//  Agent2Trigger(agent) -> trigger
//  Agent2Timer(agent) -> timer
//  Agent2Location(agent) -> location
//  Agent2Effect(agent) -> effect
//  Agent2Unit(agent) -> unit
//  Agent2Item(agent) -> item
//  Widget2Unit(widget) -> unit
//  Widget2Destructable(widget) -> destructable
//  Widget2Item(widget) -> item
//
//  Due to the usage of CovertFogState in hashtable, I2X
//  is available again.
//  
//  Int2Widget(integer) -> widget
//  Int2Destructable(integer) -> destructable
//  Int2Item(integer) -> item
//  Int2Unit(integer) -> unit
//  Int2Ability(integer) -> ability
//  Int2Timer(integer) -> timer
//  Int2Trigger(integer) -> trigger
//  Int2TriggerCondition(integer) -> triggercondition
//  Int2TriggerAction(integer) -> triggeraction
//  Int2Force(integer) -> force
//  Int2Group(integer) -> group
//  Int2Location(integer) -> location
//  Int2Rect(integer) -> rect
//  Int2Sound(integer) -> sound
//  Int2Effect(integer) -> effect
//  Int2UnitPool(integer) -> unitpool
//  Int2ItemPool(integer) -> itempool
//  Int2Quest(integer) -> quest
//  Int2QuestItem(integer) -> questitem
//  Int2DefeatCondition(integer) -> defeatcondition
//  Int2TimerDialog(integer) -> timerdialog
//  Int2Leaderboard(integer) -> leaderboard
//  Int2Multiboard(integer) -> multiboard
//  Int2MultiboardItem(integer) -> multiboarditem
//  Int2Trackable(integer) -> trackable
//  Int2Dialog(integer) -> dialog
//  Int2Button(integer) -> button
//  Int2TextTag(integer) -> texttag
//  Int2Ubersplat(integer) -> ubersplat
//  Int2Region(integer) -> region
//  Int2FogState(integer) -> fogstate
//  Int2FogModifier(integer) -> fogmodifier
//
//  Requirement :
//  Wc3 1.24b or newer
//  Jasshelper 0.A.2.9 or newer
///////////////////////////////////////
library Typecasting

    globals
        private hashtable Data = InitHashtable()
    endglobals

    //! textmacro Typecasting takes ParentName, parenttype, TypeName, type
    function $ParentName$2$TypeName$ takes $parenttype$ object returns $type$
        call Save$ParentName$Handle(Data,0,0,object)
        return Load$TypeName$Handle(Data,0,0)
    endfunction
    //! endtextmacro
    //! runtextmacro Typecasting ("Agent","agent","Widget","widget")
    //! runtextmacro Typecasting ("Agent","agent","Group","group")
    //! runtextmacro Typecasting ("Agent","agent","Trigger","trigger")
    //! runtextmacro Typecasting ("Agent","agent","Timer","timer")
    //! runtextmacro Typecasting ("Agent","agent","Location","location")
    //! runtextmacro Typecasting ("Agent","agent","Effect","effect")
    //! runtextmacro Typecasting ("Agent","agent","Unit","unit")
    //! runtextmacro Typecasting ("Agent","agent","Item","item")
    //! runtextmacro Typecasting ("Widget","widget","Unit","unit")
    //! runtextmacro Typecasting ("Widget","widget","Destructable","destructable")
    //! runtextmacro Typecasting ("Widget","widget","Item","item")

    //! textmacro Typecasting_I2X takes TypeName, type
    function Int2$TypeName$ takes integer id returns $type$
        call SaveFogStateHandle(Data,0,0,ConvertFogState(id))
        return Load$TypeName$Handle(Data,0,0)
    endfunction
    //! endtextmacro
    //! runtextmacro Typecasting_I2X("Unit", "unit")
    //! runtextmacro Typecasting_I2X("Effect", "effect")
    //! runtextmacro Typecasting_I2X("Trigger", "trigger")
    //! runtextmacro Typecasting_I2X("Timer", "timer")
    //! runtextmacro Typecasting_I2X("Widget", "widget")
    //! runtextmacro Typecasting_I2X("Group", "group")
    //! runtextmacro Typecasting_I2X("Location", "location")
    //! runtextmacro Typecasting_I2X("Item", "item")
    //! runtextmacro Typecasting_I2X("Destructable", "destructable")
    //! runtextmacro Typecasting_I2X("Ability", "ability")
    //! runtextmacro Typecasting_I2X("TriggerCondition", "triggercondition")
    //! runtextmacro Typecasting_I2X("TriggerAction", "triggeraction")
    //! runtextmacro Typecasting_I2X("Force", "force")
    //! runtextmacro Typecasting_I2X("Rect", "rect")
    //! runtextmacro Typecasting_I2X("Sound", "sound")
    //! runtextmacro Typecasting_I2X("UnitPool", "unitpool")
    //! runtextmacro Typecasting_I2X("ItemPool", "itempool")
    //! runtextmacro Typecasting_I2X("Quest", "quest")
    //! runtextmacro Typecasting_I2X("QuestItem", "questitem")
    //! runtextmacro Typecasting_I2X("DefeatCondition", "defeatcondition")
    //! runtextmacro Typecasting_I2X("TimerDialog", "timerdialog")
    //! runtextmacro Typecasting_I2X("Leaderboard", "leaderboard")
    //! runtextmacro Typecasting_I2X("Multiboard", "multiboard")
    //! runtextmacro Typecasting_I2X("MultiboardItem", "multiboarditem")
    //! runtextmacro Typecasting_I2X("Trackable", "trackable")
    //! runtextmacro Typecasting_I2X("Dialog", "dialog")
    //! runtextmacro Typecasting_I2X("Button", "button")
    //! runtextmacro Typecasting_I2X("TextTag", "texttag")
    //! runtextmacro Typecasting_I2X("Image", "image")
    //! runtextmacro Typecasting_I2X("Ubersplat", "ubersplat")
    //! runtextmacro Typecasting_I2X("Region", "region")
    //! runtextmacro Typecasting_I2X("FogState", "fogstate")
    //! runtextmacro Typecasting_I2X("FogModifier", "fogmodifier")
endlibrary

The link i gave you contains these.

Because of that libraries, i can now save DamageTypes and AttackTypes :D
But because you want a Table mode, you should code it yourself.
 
Status
Not open for further replies.
Top