This seems soooooo circumvoluted, to give some random XPs to the player....
So, the script:
INIT
ITEM:__Me
EXTERN CHARACTERTEMPLATE:%animalToSpawn=null
EVENTS
EVENT onuseitem
VARS
FLOAT3:_trackspositions
FLOAT3:_spawnDestination
CHARACTER:_Source
INT:_GainedXP
ON
OnUseItem(_Source,__Me)
ACTIONS
IF "c1"
IsRandom(0.4)
THEN
GetRandom(_spawnDestination,{-2;0;2},{2;0;-2},{2;0;2},{-2;0;-2},{-2;0;0},{2;0;0},{0;0;-2},{0;0;2})
GetPosition(__Me,_trackspositions)
Add(_trackspositions,_spawnDestination)
SpawnCharacter(_,%animalToSpawn,_trackspositions,0)
DisplayText(_Source,"You successfully follow the tracks",3)
//DialogStart(_,"dialog_tracks",__Me,_Source)
SetUserFlag(_Source,"usedtrackssuccess")
ELSE
GetRandomBetween(_GainedXP,1,5)
SetVar(_Source,"xpgainedfromfailure",_GainedXP)
SetUserFlag(_Source,"usedtracksfailure")
DisplayText(_Source,"You fail to follow the tracks",3)
ENDIF
ClearUserFlag(_Source,"usedtrackssuccess")
ClearUserFlag(_Source,"usedtracksfailure")
ItemDestroy(__Me)In order to give the XPs to the player, I define a tag that is different whether the player succeeds or fails.
Then, I randomized an int variable:
GetRandomBetween(_GainedXP,1,5))
that I set as a Variable on the user:
SetVar(_Source,"xpgainedfromfailure",_GainedXP)
then, to the story code:
IF
ObjectFlagSet("usedtracksfailure",_Source,_)
AND
GetVarInteger(_Source,"xpgainedfromfailure",_Value)
THEN
PartyAddActualExperience((CHARACTERGUID)_Source,_Value);so, this story waits for the flag to be set. I then get the Var that holds the random int.
Then, I add that random int to the player.
GOOOOOOOOOOOOOD, please tell me there is a cleaner, easier, smoother, nicer, better way to do this, like a "giveXP" function that I can call within a script.
btw, how do I create a function ? because there is a 'callfunction" script thingy that might be handy.
And this is only randomizing the gained XPs. I can't imagine when I will have to get more variables, and use them for some stuff...