Difference between revisions of "LUA:SetServerVariable"

(Created page with "{{PageHeaderChild|LUA|GetQuestCompleteCount}} == GetQuestCompleteCount() == Gets the number of times the given quest has been completed by the given player == Syntax == var = ...")
 
(SetServerVariable())
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{PageHeaderChild|LUA|GetQuestCompleteCount}}
+
{{PageHeaderChild|LUA|SetServerVariable}}
 
 
== GetQuestCompleteCount() ==
 
Gets the number of times the given quest has been completed by the given player
 
  
 +
== SetServerVariable() ==
 +
Sets the server variable. This will persist when you zone etc., use this in conjunction with [[LUA:GetServerVariable|GetServerVariable()]]. Use sparingly as to prevent clutter in variables table.
  
 
== Syntax ==
 
== Syntax ==
var = GetQuestCompleteCount(param1, param2)
+
SetServerVariable(param1, param2, param3)
  
 
== Parameters ==
 
== Parameters ==
; Required - ''param1'' (Spawn), ''param2'' (int8)
+
; Required - ''param1'' (String), ''param2'' (String)
: ''param1'' is a reference to a player.
+
: ''param1'' is the variable name
: ''param2'' is the quest ID.
+
: ''param2'' is the value to set the variable to
 +
; Optional - ''param3'' (String)
 +
: ''param3'' is the comment for the variable
  
== Returns ==
 
; int16
 
  
 
== Usage ==
 
== Usage ==
 
<pre>
 
<pre>
function hailed(NPC, Spawn)
+
function CompleteQuest(Quest, QuestGiver, Player)
     local count = GetQuestCompleteCount(Spawn, Quest1)
+
    GiveQuestReward(Quest, Player)
     if count <= 4 then
+
   
         OfferQuest(Spawn, Quest1)
+
     local var = tonumber(GetServerVariable("Quest1_Global_Complete_Count"))
 +
     if var == nil then
 +
         SetServerVariable("Quest1_Global_Complete_Count", "1", "Number of times Quest 1 has been completed across the server")
 
     else
 
     else
         OfferQuest(Spawn, Quest2)
+
         var = var + 1
 +
        SetServerVariable("Quest1_Global_Complete_Count", var)
 
     end
 
     end
 
end
 
end
 
</pre>
 
</pre>
  
This will offer the player a different quest if they completed Quest1 4 times
+
Every time this quest is completed it will increment the server variable, if it hasn't been completed yet it will create a new server variable
 +
 
 +
== Notes ==
 +
In the server core "lua_" will automatically be added to the front of the name, you only need to know this if you plan to look the variable up in the DB

Latest revision as of 19:28, 8 August 2016

LUA - SetServerVariable

Return to: LUA | Tutorials | Portal | Forum | Project Manager | Bug Tracker


SetServerVariable()

Sets the server variable. This will persist when you zone etc., use this in conjunction with GetServerVariable(). Use sparingly as to prevent clutter in variables table.

Syntax

SetServerVariable(param1, param2, param3)

Parameters

Required - param1 (String), param2 (String)
param1 is the variable name
param2 is the value to set the variable to
Optional - param3 (String)
param3 is the comment for the variable


Usage

function CompleteQuest(Quest, QuestGiver, Player)
    GiveQuestReward(Quest, Player)
    
    local var = tonumber(GetServerVariable("Quest1_Global_Complete_Count"))
    if var == nil then
        SetServerVariable("Quest1_Global_Complete_Count", "1", "Number of times Quest 1 has been completed across the server")
    else
        var = var + 1
        SetServerVariable("Quest1_Global_Complete_Count", var)
    end
end

Every time this quest is completed it will increment the server variable, if it hasn't been completed yet it will create a new server variable

Notes

In the server core "lua_" will automatically be added to the front of the name, you only need to know this if you plan to look the variable up in the DB