· 8 years ago · Jul 09, 2018, 07:58 PM
1local Entity = FindMetaTable("Entity")
2local Player = FindMetaTable("Player")
3
4local itemListToSend = {}
5local itemProperties = {}
6itemProperties.BaseItem = "None"
7itemProperties.Name = "None"
8itemProperties.Owner = 0
9itemProperties.Description = "None"
10itemProperties.Prefix = "None"
11itemProperties.PrefixValue = 0
12itemProperties.RefinementValue = 0
13
14function DeriveNewTable(tblWantedTable)
15 local tblNewTable = {}
16 for k, v in pairs(tblWantedTable) do
17 if type(v) != "table" then
18 tblNewTable[k] = v
19 else
20 tblNewTable[k] = table.Copy(v)
21 end
22 end
23 return tblNewTable
24end
25
26function QuickCreateItemToSend(tblDeriveTable, strBaseItem)
27 PrintMessage(2,"Received " .. strBaseItem)
28 PrintMessage(2,"Trying to retrieve table template")
29 local tblNewItem = DeriveNewTable(tblDeriveTable)
30 PrintMessage(2,"Table template successfully retrieved")
31 PrintMessage(2,"Trying to set baseitem to " .. GAMEMODE.DataBase.Items[strBaseItem].BaseItem)
32 tblNewItem.BaseItem = GAMEMODE.DataBase.Items[strBaseItem].BaseItem
33 PrintMessage(2,"BaseItem set")
34 tblNewItem.Name = GAMEMODE.DataBase.Items[strBaseItem].Name
35 PrintMessage(2,"Name set")
36 tblNewItem.Owner = GAMEMODE.DataBase.Items[strBaseItem].Owner
37 PrintMessage(2,"Owner set")
38 tblNewItem.Description = GAMEMODE.DataBase.Items[strBaseItem].Desc
39 PrintMessage(2,"Description set")
40 tblNewItem.Prefix = GAMEMODE.DataBase.Items[strBaseItem].Prefix
41 PrintMessage(2,"Prefix set")
42 --PrintMessage(2,type(GAMEMODE.DataBase.Items[strBaseItem].PrefixValue))
43 tblNewItem.PrefixValue = GAMEMODE.DataBase.Items[strBaseItem].PrefixValue
44 PrintMessage(2,"Prefix value set")
45 tblNewItem.RefinementValue = GAMEMODE.DataBase.Items[strBaseItem].RefinementValue
46 PrintMessage(2,"ref value set")
47 return tblNewItem
48end
49
50
51function Entity:AddSpecialItem(strItem, intAmount, boolDelete, boolAuction, boolUpdate)
52 if !IsValid(self) then return false end
53
54 PrintMessage(2,"TRYING TO ADD " .. strItem)
55 PrintMessage(2,"Checking if " .. strItem .. " is a special item and if it is a default item.")
56 PrintMessage(2,"Comparing " .. strItem .. " against " .. ItemTable(strItem).BaseItem .. " .")
57 if ItemTable(strItem).SpecialItem == 1 and strItem == ItemTable(strItem).BaseItem then
58 PrintMessage(2,"It is a default item, creating new unique item")
59 strItem = self:CreateNewSpecialItem(strItem, "None", 0, 0, self.PlayerID)
60 PrintMessage(2,"Checking " .. strItem .. " against the database.")
61
62 --Check if item exists in the database.
63 if GAMEMODE.DataBase.Items[strItem] then
64 PrintMessage(2,strItem .. " EXISTS ON SERVER! SHOULD NOW SEND TO CLIENT!")
65
66 else
67 PrintMessage(2,strItem .. " did not exist.")
68 return false
69 end
70 elseif ItemTable(strItem).SpecialItem == 1 then
71 PrintMessage(2,"The item is a special item but not a default item.")
72
73 else
74 PrintMessage(2,"The item was not a special item.")
75 PrintMessage(2,"Sending the item to the AddItem function.")
76 self:AddItem(strItem, intAmount)
77 PrintMessage(2,"-------------------------------------------------")
78 PrintMessage(2,"=================================================")
79 PrintMessage(2,"------------ " .. strItem .. " added ------------")
80 PrintMessage(2,"=================================================")
81 PrintMessage(2,"-------------------------------------------------")
82 self:SaveGame()
83 return false
84 end
85 local tblItemTable = GAMEMODE.DataBase.Items[strItem]
86 if !tblItemTable then return false end
87 intAmount = tonumber(intAmount) or 1
88 self.Data = self.Data or {}
89 self.Data.Inventory = self.Data.Inventory or {}
90
91 self.Data.Inventory[strItem] = self.Data.Inventory[strItem] or 0
92 self.Weight = self.Weight or 0
93 local intMaxItems = math.Clamp(math.floor((self:GetMaxWeight() - self.Weight) / tblItemTable.Weight), 0, intAmount)
94 intAmount = math.Clamp(intAmount, -self.Data.Inventory[strItem], intMaxItems)
95 if intAmount == 0 then return false end
96 PrintMessage(2,"Checking if boolDelete is false")
97 if boolDelete == false then
98 PrintMessage(2,"boolDelete is false")
99 PrintMessage(2,"Checking if boolAuction is true")
100 if boolAuction == true then
101 PrintMessage(2,"boolAuction is true.")
102 PrintMessage(2,"Adding " .. strItem .. " to auction")
103 SLAddToAuction(strItem)
104 return true
105 else
106 PrintMessage(2,"boolAuction is false")
107 PrintMessage(2,"Adding " .. strItem .. " to inventory")
108 if SERVER then
109 if self.Data.Paperdoll && intAmount < 0 then
110 if self.Data.Inventory[strItem] == 1 && self.Data.Paperdoll[tblItemTable.Slot] == strItem then
111 self:UseItem(strItem)
112 end
113 end
114 end
115
116 self.Data.Inventory[strItem] = self.Data.Inventory[strItem] + intAmount
117 --PrintMessage(2, "There is now " .. self.Data.Inventory[strItem] .. " registered in inventory")
118 self.Weight = self.Weight + (tblItemTable.Weight * intAmount)
119 --local tablleeee = self.Data.Inventory
120 if SERVER && self:GetClass() == "player" then
121 SendUsrMsg("UD_UpdateItem", self, {strItem, intAmount})
122 --PrintMessage(2,"Owner attribute on item set to current player")
123 tblItemTable.Owner = self.PlayerID
124 GAMEMODE.DataBase.Items[strItem] = tblItemTable
125
126
127 PrintMessage(2,"-------------------------------------------------")
128 PrintMessage(2,"=================================================")
129 PrintMessage(2,"------------ " .. strItem .. " added ------------")
130 PrintMessage(2,"=================================================")
131 PrintMessage(2,"-------------------------------------------------")
132 self:SaveGame()
133 end
134 if CLIENT then
135 --print(table.ToString(tablleeee, "Inventory: ", false))
136 if GAMEMODE.MainMenu then GAMEMODE.MainMenu.InventoryTab:LoadInventory() end
137 if GAMEMODE.ShopMenu then GAMEMODE.ShopMenu:LoadShop() end
138 if GAMEMODE.ShopMenu then GAMEMODE.ShopMenu:LoadPlayer() end
139 if GAMEMODE.BankMenu then GAMEMODE.BankMenu:LoadPlayer() end
140 if GAMEMODE.UpdateHotBar then GAMEMODE:UpdateHotBar() end
141 end
142 return true
143 end
144
145 if boolUpdate == true then
146 if boolAuction == true then
147 SLAddToAuction(strItem)
148 else
149 SLUpdatePlayerOwned(strItem, GAMEMODE.DataBase.Items[strItem].Owner)
150 end
151
152 end
153
154 else
155 PrintMessage(2,"boolDelete is true")
156 if SERVER then
157 PrintMessage(2,"Deleting item from database.")
158 DeleteSpecialItemFromDB(tblItemTable)
159
160 if self.Data.Paperdoll && intAmount < 0 then
161 if self.Data.Inventory[strItem] == 1 && self.Data.Paperdoll[tblItemTable.Slot] == strItem then
162 self:UseItem(strItem)
163 end
164 end
165 end
166
167 self.Data.Inventory[strItem] = self.Data.Inventory[strItem] + intAmount
168 --PrintMessage(2,table.ToString(self.Data.Inventory, "Inventory: ", false))
169 self.Weight = self.Weight + (tblItemTable.Weight * intAmount)
170 if SERVER && self:GetClass() == "player" then
171 SendUsrMsg("UD_UpdateItem", self, {strItem, intAmount})
172
173 tblItemTable.Owner = self.PlayerID
174 GAMEMODE.DataBase.Items[strItem] = tblItemTable
175
176 if self.Data.Inventory[strItem] < 1 then
177 itemListToSend[strItem] = nil
178 end
179
180 PrintMessage(2,"-------------------------------------------------")
181 PrintMessage(2,"=================================================")
182 PrintMessage(2,"------------ " .. strItem .. " removed ------------")
183 PrintMessage(2,"=================================================")
184 PrintMessage(2,"-------------------------------------------------")
185 self:SaveGame()
186 end
187 if CLIENT then
188 if GAMEMODE.MainMenu then GAMEMODE.MainMenu.InventoryTab:LoadInventory() end
189 if GAMEMODE.ShopMenu then GAMEMODE.ShopMenu:LoadShop() end
190 if GAMEMODE.ShopMenu then GAMEMODE.ShopMenu:LoadPlayer() end
191 if GAMEMODE.BankMenu then GAMEMODE.BankMenu:LoadPlayer() end
192 if GAMEMODE.UpdateHotBar then GAMEMODE:UpdateHotBar() end
193 end
194
195 return true
196
197 end
198
199
200end
201
202
203function Entity:AddItem(strItem, intAmount)
204 if !IsValid(self) then return false end
205 local tblItemTable = GAMEMODE.DataBase.Items[strItem]
206 if !tblItemTable then return false end
207 intAmount = tonumber(intAmount) or 1
208 self.Data = self.Data or {}
209 self.Data.Inventory = self.Data.Inventory or {}
210 self.Data.Inventory[strItem] = self.Data.Inventory[strItem] or 0
211 self.Weight = self.Weight or 0
212 local intMaxItems = math.Clamp(math.floor((self:GetMaxWeight() - self.Weight) / tblItemTable.Weight), 0, intAmount)
213 intAmount = math.Clamp(intAmount, -self.Data.Inventory[strItem], intMaxItems)
214 if intAmount == 0 then return false end
215 if SERVER then
216 if self.Data.Paperdoll && intAmount < 0 then
217 if self.Data.Inventory[strItem] == 1 && self.Data.Paperdoll[tblItemTable.Slot] == strItem then
218 self:UseItem(strItem)
219 end
220 end
221 end
222 self.Data.Inventory[strItem] = self.Data.Inventory[strItem] + intAmount
223 self.Weight = self.Weight + (tblItemTable.Weight * intAmount)
224 if SERVER && self:GetClass() == "player" then
225 SendUsrMsg("UD_UpdateItem", self, {strItem, intAmount})
226 self:SaveGame()
227 end
228 if CLIENT then
229 if GAMEMODE.MainMenu then GAMEMODE.MainMenu.InventoryTab:LoadInventory() end
230 if GAMEMODE.ShopMenu then GAMEMODE.ShopMenu:LoadShop() end
231 if GAMEMODE.ShopMenu then GAMEMODE.ShopMenu:LoadPlayer() end
232 if GAMEMODE.BankMenu then GAMEMODE.BankMenu:LoadPlayer() end
233 if GAMEMODE.UpdateHotBar then GAMEMODE:UpdateHotBar() end
234 end
235 return true
236end
237
238function Entity:RemoveItem(strItem, intAmount)
239 return self:AddItem(strItem, -intAmount)
240end
241
242function Entity:RemoveSpecialItem(strItem, intAmount, boolAuction)
243 if GAMEMODE.DataBase.Items(strItem).SpecialItem and GAMEMODE.DataBase.Items(strItem).SpecialItem == 1 then
244 return self:AddSpecialItem(strItem, -intAmount, false, boolAuction, boolAuction)
245 else
246 return self:AddItem(strItem, -intAmount)
247 end
248end
249
250function Entity:DeleteSpecialItem(strItem, intAmount)
251 if GAMEMODE.DataBase.Items(strItem).SpecialItem and GAMEMODE.DataBase.Items(strItem).SpecialItem == 1 then
252 return self:AddSpecialItem(strItem, -intAmount, true, false, false)
253 else
254 return self:AddItem(strItem, -intAmount)
255 end
256
257end
258
259function Entity:GetItem(strItem)
260 if !IsValid(self) then return 0 end
261 self.Data.Inventory = self.Data.Inventory or {}
262 return self.Data.Inventory[strItem] or 0
263end
264
265function Entity:TransferItem(objTarget, strItem1, intAmount1, strItem2, intAmount2)
266 intAmount1 = tonumber(intAmount1) or 1
267 intAmount2 = tonumber(intAmount2) or 0
268 if strItem1 then if !objTarget:HasItem(strItem1, intAmount1) then return false end end
269 if strItem2 then if !self:HasItem(strItem2, intAmount2) then return false end end
270 if strItem1 then if self:AddSpecialItem(strItem1, intAmount1, false, false, true) then objTarget:AddSpecialItem(strItem1, -intAmount1, false, false, false) end end
271 if strItem2 then if objTarget:AddSpecialItem(strItem2, intAmount2) then self:AddSpecialItem(strItem2, -intAmount2, false, false, false) end end
272end
273
274function Entity:HasItem(strItem, intAmount)
275 if !self.Data.Inventory then return false end
276 intAmount = tonumber(intAmount) or 1
277 return (self:GetItem(strItem) or 0) - intAmount >= 0 && intAmount > 0
278end
279
280
281function Entity:GetQuestItem(strItem)
282 if !IsValid(self) then return 0 end
283 self.Data.Inventory = self.Data.Inventory or {}
284 return self.Data.Inventory[strItem] or 0
285end
286
287function Entity:HasQuestItem(strItem, intAmount)
288 if !self.Data.Inventory then return false end
289 intAmount = tonumber(intAmount) or 1
290 return (self:GetItem(strItem) or 0) - intAmount >= 0 && intAmount > 0
291end
292
293
294
295function Entity:HasRoomFor(tblItems, intAddtionalConstant)
296 local intWeight = self:TotalWeightOf(tblItems)
297 local spaceleft = self:GetMaxWeight()
298 if intWeight + (intAddtionalConstant or 0) <= spaceleft then return true end
299end
300
301function Entity:TotalWeightOf(tblItems)
302 local intWeight = self.Weight or 0
303 for strItem, intAmount in pairs(tblItems or {}) do
304 local tblItemTable = ItemTable(strItem)
305 intWeight = intWeight + (tblItemTable.Weight * intAmount)
306 end
307 return intWeight
308end
309
310function Entity:GiveItems(tblItems)
311 PrintMessage(2,"Entered give items function")
312 if tblItems then
313 PrintMessage(2,"The item table has items")
314 PrintMessage(2,"" .. table.ToString(tblItems, "tblItems container", false))
315 else
316 PrintMessage(2,"The item table is empty")
317 end
318 for strItem, intAmount in pairs(tblItems or {}) do
319 PrintMessage(2,"Found " .. intAmount .. " " .. strItem .. ".")
320 if GAMEMODE.DataBase.Items[strItem].SpecialItem == 1 then
321 PrintMessage(2,strItem .. " is a special item.")
322 PrintMessage(2,"Adding " .. intAmount .. " " .. strItem .. " to inventory.")
323 self:AddSpecialItem(strItem, intAmount, false, false, false)
324 else
325 PrintMessage(2,strItem .. " is not a special item.")
326 PrintMessage(2,"Adding " .. intAmount .. " " .. strItem .. " to inventory.")
327 self:AddItem(strItem, intAmount)
328 end
329 end
330end
331
332
333--This function serves the purpose of creating a single special item throughout the game.
334function updateSpecialItem(tblItem, strPrefix, value, refAmount)
335 --This function is to quickly create a unique special copy of one weapon
336
337
338 --Declare and initialise variables
339 local strDescStat = ""
340 local boolRef = false
341 local boolPref = false
342 local boolIncrease = false
343 local boolDamage = false
344 local boolSpeed = false
345 local boolArmor = false
346 local boolSuper = false
347
348 --Set boolRef to true if the weapon is to be refined.
349 if refAmount > 0 then
350 boolRef = true
351 end
352
353 if strPrefix != "None" then
354 boolPref = true
355 --Set the descriptive stat string to the english - readable equivalent of the stat changed.
356 if(strPrefix == "Strong" or strPrefix == "Powerful" ) then
357 strDescStat = "Strength"
358 boolDamage = true
359 boolIncrease = true
360 strStatType = "stat_strength"
361
362 elseif(strPrefix == "Weak" or strPrefix == "Impotent" ) then
363 strDescStat = "Strength"
364 boolDamage = true
365 boolIncrease = false
366 strStatType = "stat_strength"
367
368 elseif(strPrefix == "Accurate" or strPrefix == "Dexterous" ) then
369 strDescStat = "Dexterity"
370 boolDamage = true
371 boolIncrease = true
372 strStatType = "stat_dexterity"
373
374 elseif(strPrefix == "Inaccurate" or strPrefix == "Unskilled" ) then
375 strDescStat = "Dexterity"
376 boolDamage = true
377 boolIncrease = false
378 strStatType = "stat_dexterity"
379
380 elseif(strPrefix == "Agile" or strPrefix == "Energetic" ) then
381 strDescStat = "Agility"
382 boolDamage = true
383 boolIncrease = true
384 strStatType = "stat_agility"
385
386 elseif(strPrefix == "Sluggish" or strPrefix == "Lifeless" ) then
387 strDescStat = "Agility"
388 boolDamage = true
389 boolIncrease = false
390 strStatType = "stat_agility"
391
392 elseif(strPrefix == "Fortunate" or strPrefix == "Lucky" ) then
393 strDescStat = "Luck"
394 boolDamage = true
395 boolIncrease = true
396 strStatType = "stat_luck"
397
398 elseif(strPrefix == "Unfortunate" or strPrefix == "Unlucky" ) then
399 strDescStat = "Luck"
400 boolDamage = true
401 boolIncrease = false
402 strStatType = "stat_luck"
403
404 elseif(strPrefix == "Fresh" or strPrefix == "Healthy" ) then
405 strDescStat = "Health"
406 boolDamage = true
407 boolIncrease = true
408 strStatType = "stat_maxhealth"
409
410 elseif(strPrefix == "Infected" or strPrefix == "Diseased" ) then
411 strDescStat = "Health"
412 boolDamage = true
413 boolIncrease = false
414 strStatType = "stat_maxhealth"
415
416 elseif(strPrefix == "Metal Seeker" or strPrefix == "Gem Hunter" ) then
417 strDescStat = "Mining Expertise"
418 boolDamage = true
419 boolIncrease = true
420 strStatType = "stat_miningexpertise"
421
422 elseif(strPrefix == "Dirt Finder" or strPrefix == "Hopeless" ) then
423 strDescStat = "Mining Expertise"
424 boolDamage = true
425 boolIncrease = false
426 strStatType = "stat_miningexpertise"
427
428 elseif(strPrefix == "Expert" or strPrefix == "Efficient" ) then
429 strDescStat = "Processing Expertise"
430 boolDamage = true
431 boolIncrease = true
432 strStatType = "stat_processingexpertise"
433
434 elseif(strPrefix == "Incapable" or strPrefix == "Inefficient" ) then
435 strDescStat = "Processing Expertise"
436 boolDamage = true
437 boolIncrease = false
438 strStatType = "stat_processingexpertise"
439
440 elseif(strPrefix == "Wise" or strPrefix == "Experienced" ) then
441 strDescStat = "Expertise"
442 boolDamage = true
443 boolIncrease = true
444 strStatType = "stat_expertise"
445
446 elseif(strPrefix == "Incompetent" or strPrefix == "Inexperienced" ) then
447 strDescStat = "Expertise"
448 boolDamage = true
449 boolIncrease = false
450 strStatType = "stat_expertise"
451
452 elseif(strPrefix == "Clever" or strPrefix == "Intelligent" ) then
453 strDescStat = "Intellect"
454 boolDamage = true
455 boolIncrease = true
456 strStatType = "stat_intellect"
457
458 elseif(strPrefix == "Ignorant" or strPrefix == "Stupid" ) then
459 strDescStat = "Intellect"
460 boolDamage = true
461 boolIncrease = false
462 strStatType = "stat_intellect"
463
464 elseif(strPrefix == "Hurtful" or strPrefix == "Sharpened" ) then
465 strDescStat = "Damage"
466 boolDamage = true
467 boolIncrease = true
468
469 elseif(strPrefix == "Blunt" or strPrefix == "Ticklish" ) then
470 strDescStat = "Damage"
471 boolDamage = true
472 boolIncrease = false
473
474 elseif(strPrefix == "Quick" or strPrefix == "Fast" ) then
475 strDescStat = "Attack Speed"
476 boolDamage = true
477 boolIncrease = true
478
479 elseif(strPrefix == "Dull" or strPrefix == "Slow" ) then
480 strDescStat = "Attack Speed"
481 boolDamage = true
482 boolIncrease = false
483
484
485 elseif(strPrefix == "Armored" or strPrefix == "Defensive" ) then
486 strDescStat = "Armor"
487 boolDamage = true
488 boolIncrease = true
489
490 elseif(strPrefix == "Ripped" or strPrefix == "Fragile" ) then
491 strDescStat = "Armor"
492 boolDamage = true
493 boolIncrease = false
494
495 elseif(strPrefix == "Godlike" or strPrefix == "Legendary" or strPrefix == "Epic" or strPrefix == "Deity" ) then
496 boolSuper = true
497 boolIncrease = true
498 end
499
500 strPrefix = "'" .. strPrefix .. "' "
501 else
502 boolPref = false
503 strPrefix = ""
504 end
505
506
507
508 --Special Item
509 --Copy the item into the temp variable
510 local temp = table.Copy(tblItem)
511
512 if boolPref == true then
513 if boolSuper == false then
514 -----------------------------------------------------------If it is effecting a stat
515 if (boolSpeed == false and boolDamage == false and boolArmor == false) then
516 --Set extrastat to the result of the effected stat increased by the percentage of the current loop index value
517 local extrastat = ((tblItem.Buffs[strStatType] / 100)*value)
518
519 --If the current effect to be made is a negative effect
520 if (boolIncrease == false) then
521 --Reduce the effected stat by the extrastat calculated beforehand
522 temp.Buffs[strStatType] = tblItem.Buffs[strStatType] - extrastat
523 temp.SellPrice = temp.SellPrice - ((temp.SellPrice / 100)*value)
524 end
525
526 --If the current effect to me made is a positive effect
527 if (boolIncrease == true) then
528 --Increase the effected stat by the extrastat calculated beforehand
529 temp.Buffs[strStatType] = tblItem.Buffs[strStatType] + extrastat
530 temp.SellPrice = temp.SellPrice + ((temp.SellPrice / 100)*(value*1.75))
531 end
532
533 ---------------------------------------------------------If it is effecting attack speed
534 elseif (boolSpeed == true) then
535 --Set extrastat to the result of the attack speed increased by the percentage of the current loop index value
536 local extrastat = ((tblItem.FireRate / 100)*value)
537
538 --If the current effect to be made is a negative effect
539 if (boolIncrease == false) then
540 --Reduce the attack speed by the extrastat calculated beforehand
541 temp.FireRate = tblItem.FireRate - extrastat
542 temp.SellPrice = temp.SellPrice - ((temp.SellPrice / 100)*(value*1.75))
543 end
544
545 --If the current effect to me made is a positive effect
546 if (boolIncrease == true) then
547 --Increase the attack speed by the extrastat calculated beforehand
548 temp.FireRate = tblItem.FireRate + extrastat
549 temp.SellPrice = temp.SellPrice + ((temp.SellPrice / 100)*(value*2.25))
550 end
551
552 -----------------------------------------------------------If it is effecting attack damage
553 elseif (boolDamage == true) then
554 --Set extrastat to the result of the attack damage increased by the percentage of the current loop index value
555 local extrastat = ((tblItem.Power / 100)*value)
556
557 --If the current effect to be made is a negative effect
558 if (boolIncrease == false) then
559 --Reduce the attack damage by the extrastat calculated beforehand
560 temp.Power = tblItem.Power - extrastat
561 temp.SellPrice = temp.SellPrice - ((temp.SellPrice / 100)*(value*2.5))
562 end
563
564 --If the current effect to me made is a positive effect
565 if (boolIncrease == true) then
566 --Increase the attack damage by the extrastat calculated beforehand
567 temp.Power = tblItem.Power + extrastat
568 temp.SellPrice = temp.SellPrice + ((temp.SellPrice / 100)*(value*3.25))
569 end
570
571 -----------------------------------------------------------If it is effecting armor
572 elseif (boolArmor == true) then
573 --Set extrastat to the result of the attack damage increased by the percentage of the current loop index value
574 local extrastat = ((tblItem.Armor / 100)*value)
575
576 --If the current effect to be made is a negative effect
577 if (boolIncrease == false) then
578 --Reduce the armor by the extrastat calculated beforehand
579 temp.Armor = tblItem.Armor - extrastat
580 temp.SellPrice = temp.SellPrice - ((temp.SellPrice / 100)*(value*2.25))
581 end
582
583 --If the current effect to me made is a positive effect
584 if (boolIncrease == true) then
585 --Increase the armor by the extrastat calculated beforehand
586 temp.Armor = tblItem.Armor + extrastat
587 temp.SellPrice = temp.SellPrice + ((temp.SellPrice / 100)*(value*2.6))
588 end
589 end
590
591 --If the current effect to be made is a negative effect.
592 if (boolIncrease == false) then
593 --Append the description of the changes to the items description.
594 temp.Desc2 = tblItem.Desc2 .. "\n (" .. strDescStat .. " decreased by " .. value .."%)"
595 --Set the weapons degraded property to true
596 temp.Degraded = true
597 end
598
599 --If the current effect to be made is a positive effect.
600 if (boolIncrease == true) then
601 --Append the description of the changes to the items description.
602 temp.Desc2 = tblItem.Desc2 .. "\n (" .. strDescStat .. " increased by " .. value .."%)"
603 --Set the weapons improved property to true
604 temp.Improved = true
605 end
606
607 --Else if boolSuper is true
608 else
609 --Determine the percentage change
610 local extrastat = 0
611
612 --Create a table of stats
613 local tblStatList = {}
614 local tblStatDesc = {}
615 tblStatList[1] = "stat_strength"
616 tblStatDesc[1] = "Strength"
617 tblStatList[2] = "stat_dexterity"
618 tblStatDesc[2] = "Dexterity"
619 tblStatList[3] = "stat_luck"
620 tblStatDesc[3] = "Luck"
621 tblStatList[4] = "stat_agility"
622 tblStatDesc[4] = "Agility"
623 tblStatList[5] = "stat_maxhealth"
624 tblStatDesc[5] = "Max Health"
625 tblStatList[6] = "stat_intellect"
626 tblStatDesc[6] = "Intellect"
627 tblStatList[7] = "stat_miningexpertise"
628 tblStatDesc[7] = "Mining Expertise"
629 tblStatList[8] = "stat_processingexpertise"
630 tblStatDesc[8] = "Processing Expertise"
631 tblStatList[9] = "stat_expertise"
632 tblStatDesc[9] = "Expertise"
633 local tblSize = 9
634 local priceChange = 1
635
636 --If the current effect to be made is a positive effect
637 if (boolIncrease == true) then
638 --start a loop counting from 1 to the end of the table
639 for statIndex = 1, tblSize do
640 --Set stattype to the start in the table using statIndex as the table index offset
641 strStatType = tblStatList[statIndex]
642 --If the current stat exists as a buff
643 if temp.Buffs[strStatType] then
644 --Calculate extrastat
645 extrastat = ((tblItem.Buffs[strStatType] / 100)*value)
646 --Increase the effected stat by the extrastat calculated beforehand
647 temp.Buffs[strStatType] = tblItem.Buffs[strStatType] + extrastat
648 --Append the description of the changes to the items description.
649 temp.Desc2 = temp.Desc2 .. "\n (" .. tblStatDesc[statIndex] .. " increased by " .. value .."%)"
650 priceChange = priceChange + 1
651 end
652 end
653
654 if temp.Power and (temp.Power > 0) then
655 --Calculate extrastat
656 extrastat = ((tblItem.Power / 100)*value)
657 --Increase the attack damage by the extrastat calculated beforehand
658 temp.Power = tblItem.Power + extrastat
659 --Append the description of the changes to the items description.
660 temp.Desc2 = temp.Desc2 .. "\n (Damage increased by " .. value .."%)"
661 priceChange = priceChange + 1
662 end
663
664 if temp.FireRate and (temp.FireRate > 0) then
665 --Calculate extrastat
666 extrastat = ((tblItem.FireRate / 100)*value)
667 --Increase the attack speed by the extrastat calculated beforehand
668 temp.FireRate = tblItem.FireRate + (extrastat/2)
669 --Append the description of the changes to the items description.
670 temp.Desc2 = temp.Desc2 .. "\n (Attack Speed increased by " .. (value/2) .."%)"
671 priceChange = priceChange + 1
672 end
673
674 if temp.Armor and (temp.Armor > 0) then
675 --Calculate extrastat
676 extrastat = ((tblItem.Armor / 100)*value)
677 --Increase the armor by the extrastat calculated beforehand
678 temp.Armor = tblItem.Armor + extrastat
679 --Append the description of the changes to the items description.
680 temp.Desc2 = temp.Desc2 .. "\n (Armor increased by " .. value .."%)"
681 priceChange = priceChange + 1
682 end
683
684
685 --Set the weapons improved property to true
686 if strPrefix == "Godlike" then
687 temp.Godlike = true
688 elseif strPrefix == "Legendary" then
689 temp.Legendary = true
690 elseif strPrefix == "Epic" then
691 temp.Epic = true
692 elseif strPrefix == "Deity" then
693 temp.Deity = true
694 end
695 temp.SellPrice = temp.SellPrice + ((temp.SellPrice / 100)*((value*2)*priceChange))
696 temp.Desc2 = temp.Desc2 .. "\n (Cannot be used for crafting unless forced)"
697
698 end
699
700 end
701
702
703 --Change the name of the item to include the prefix before it's name
704 temp.PrintName = strPrefix .. tblItem.PrintName
705 --Round the items value to ensure it is not in decimals
706 temp.SellPrice = math.Round(temp.SellPrice, 0)
707 if temp.SellPrice < 1 then
708 temp.SellPrice = 1
709 end
710 end
711
712
713 if boolRef == true then
714 local temp2 = table.Copy(temp)
715 for refLevel = 1, refAmount do
716 local locValue = 0
717
718 temp2.SellPrice = temp2.SellPrice + (((temp2.SellPrice / (90-refLevel))*refLevel)*refLevel)
719
720 if temp2.Power and (temp2.Power > 0) then
721 --Set the locValue to the items damage divided by 8.65 multiplied by the refLevel
722 locValue = ((temp2.Power / (26.65 - refLevel))*refLevel)*1.5
723 locValue = math.Round(locValue, 0)
724 --Increase the damage by the locValue calculated beforehand
725 temp2.Power = temp.Power + locValue
726 --Append the description of the changes to the items description.
727 temp2.Desc2 = temp.Desc2 .. "\n \n +" .. refLevel .. "(Damage increased by " .. string.Comma(locValue) ..".)\n \n"
728 end
729
730 if temp2.Armor and (temp2.Armor > 0) then
731 --Set the locValue to the items armor divided by 8.65 multiplied by the refLevel
732 locValue = ((temp2.Armor / (26.65 - refLevel))*refLevel)*1.5
733 locValue = math.Round(locValue, 0)
734 --Increase the armor by the locValue calculated beforehand
735 temp2.Armor = temp.Armor + locValue
736 --Append the description of the changes to the items description.
737 temp2.Desc2 = temp.Desc2 .. "\n \n +" .. refLevel .. "(Armor increased by " .. string.Comma(locValue) ..".) \n \n"
738 end
739
740 --Change the name of the item to include the prefix before it's name
741 temp2.PrintName = temp.PrintName .. " +" .. refLevel
742 --Round the items value to ensure it is not in decimals
743 temp2.SellPrice = math.Round(temp.SellPrice, 0)
744 if temp2.SellPrice < 1 then
745 temp2.SellPrice = 1
746 end
747
748 end
749
750
751 --Save the new generated item in the database.
752 GAMEMODE.DataBase.Items[tblItem.Name] = temp2
753 else
754 --Save the new generated item in the database.
755 GAMEMODE.DataBase.Items[tblItem.Name] = temp
756 end
757
758
759end
760
761function renameSpecialItem(tblItem,newName)
762 PrintMessage(2,"Creating new item ")
763 local newTbl = table.Copy(tblItem)
764 PrintMessage(2,"Changing item name")
765 newTbl.Name = newName
766 PrintMessage(2,"Saving item to db")
767 GAMEMODE.DataBase.Items[newTbl.Name] = newTbl
768 PrintMessage(2," not Removing old table (can't find a solution to do so.)")
769 --table.Remove(GAMEMODE.DataBase.Items,tblItem)
770 PrintMessage(2,"Returning new table")
771 return newTbl
772end
773
774function Entity:PrintItemTable(itemTab)
775 PrintMessage(2,"The Item is as follows : " )
776 PrintMessage(2,"{ " )
777 PrintMessage(2,"Lua DB Name : " .. itemTab.Name)
778 PrintMessage(2,"BaseItem : " .. itemTab.BaseItem)
779 PrintMessage(2,"Print Name : " .. itemTab.PrintName)
780 PrintMessage(2,"Description : " .. itemTab.Desc)
781 PrintMessage(2,"Prefix : " .. itemTab.Prefix)
782 PrintMessage(2,"Prefix Value : " .. itemTab.PrefixValue)
783 PrintMessage(2,"Refinement Value : " .. itemTab.RefinementValue)
784 PrintMessage(2,"Owner ID : " .. itemTab.Owner)
785 PrintMessage(2,"Special Item : " .. itemTab.SpecialItem)
786 PrintMessage(2,"Sell Price : " .. itemTab.SellPrice)
787 PrintMessage(2,"Weight : " .. itemTab.Weight)
788 if itemTab.Power and (itemTab.Power > 0) then
789 PrintMessage(2,"Attack Power : " .. itemTab.Power)
790 end
791 if itemTab.Armor and (itemTab.Armor > 0) then
792 PrintMessage(2,"Armor : " .. itemTab.Armor)
793 end
794 if itemTab.FireRate and (itemTab.FireRate > 0) then
795 PrintMessage(2,"Attack Rate : " .. itemTab.FireRate)
796 end
797 if itemTab.Icon and (itemTab.Icon != "") then
798 PrintMessage(2,"Icon : " .. itemTab.Icon)
799 end
800 PrintMessage(2,"} " )
801end
802
803function writeItemToClient(itemParsed, boolToggle)
804
805 PrintMessage(2,"Preparing to send net message")
806 if boolToggle == true then
807
808 PrintMessage(2, "Trying to store newly created " .. itemParsed .. " in a table")
809 itemListToSend[itemParsed] = QuickCreateItemToSend(itemProperties, itemParsed)
810 PrintMessage(2, itemParsed .. " Stored in itemToCreateList")
811 end
812
813 if SERVER then
814 PrintMessage(2,"Starting message broadcast")
815 net.Start( "AddNewUniqueItem" )
816 PrintMessage(2,"Started a new message called : AddNewUniqueItem")
817 PrintMessage(2,"Attempting to add itemToCreateList to message")
818 PrintTable(itemListToSend)
819 net.WriteTable( itemListToSend )
820 PrintMessage(2,"itemToCreateList added to message")
821 net.Broadcast()
822 PrintMessage(2,"Message Broadcast Successful")
823 end
824
825end
826
827function Entity:CreateNewSpecialItem(strItem, strPrefix, intPrefValue, intRefValue, plyID)
828 PrintMessage(2,"Entered the createnewspecialitem function with player ID : " .. plyID)
829 PrintMessage(2,"Attempting to generate a new UID for items.")
830 local itemID = SLGenerateItemUID()
831 PrintMessage(2,"Success, new item UID is : " .. itemID)
832 local tempItem = table.Copy(GAMEMODE.DataBase.Items[strItem])
833 if tempItem then
834 PrintMessage(2,strItem .. " exists in local lua DB")
835 PrintMessage(2,"Creating a copy of : " .. strItem .. " from local lua DB")
836 if type(tempItem) == "table" then
837 PrintMessage(2,"The item was : " .. strItem)
838 tempItem.Name = tempItem.BaseItem .. "_" .. itemID
839 local tempName = tempItem.BaseItem .. "_" .. itemID
840 tempItem.Owner = plyID
841 tempItem.Prefix = strPrefix
842 tempItem.PrefixValue = intPrefValue
843 tempItem.RefinementValue = intRefValue
844 PrintMessage(2,"Trying to update/create item into lua DB : ")
845 self:PrintItemTable(tempItem)
846 updateSpecialItem(tempItem, strPrefix, intPrefValue, intRefValue)
847
848 local doubleCheckID = SLSaveItemToDB(tempItem.Name)
849 PrintMessage(2,itemID)
850 if doubleCheckID != itemID then
851 PrintMessage(2,"ID MISMATCH, Id was actually " .. doubleCheckID .. " instead of " .. itemID)
852 --DeleteSpecialItemFromDB(tempItem.Name)
853 PrintMessage(2,"ID needs changing")
854 local newID = tempItem.BaseItem .. "_" .. (doubleCheckID)
855 PrintMessage(2,"New ID Set to " .. newID .. " ... Attempting to update")
856 GAMEMODE.DataBase.Items[tempName].Name = newID
857 tempItem = table.Copy(GAMEMODE.DataBase.Items[tempName])
858 updateSpecialItem(tempItem, strPrefix, intPrefValue, intRefValue)
859 PrintMessage(2,"Lua Update Successful, Item is now : ")
860 self:PrintItemTable(tempItem)
861 PrintMessage(2,"Sending to sql name update function. : ")
862 PrintMessage(2,"New ID : " .. newID)
863 PrintMessage(2,"Old ID : " .. tempName)
864 PrintMessage(2,"Player ID : " .. plyID)
865 SLUpdateItemNameInDB(newID, tempName, plyID)
866 PrintMessage(2,"SQL Update Successful")
867 end
868
869
870 writeItemToClient(tempItem.Name, true)
871
872 PrintMessage(2,"Returning : " .. tempItem.Name)
873
874 return tempItem.Name
875 else
876 PrintMessage(2,"Failed.")
877 end
878 end
879end
880
881function Entity:CreateItemsFromDBTable(plyID, tblItems)
882
883 PrintMessage(2,"Entered items table creation function. The items are : ")
884 for i, tblData in pairs(tblItems) do
885 PrintMessage(2,"Item " .. i .. ": " .. tblData.Name .. ".")
886 end
887 for i,tblData in pairs(tblItems) do
888 local tempItem = table.Copy(GAMEMODE.DataBase.Items[tblData.BaseItem])
889 tempItem.Name = tblData.Name
890 tempItem.Owner = plyID
891 tempItem.Prefix = tblData.Prefix
892 tempItem.Desc = tblData.Description
893 tempItem.PrefixValue = tblData.Prefix_Value
894 tempItem.RefinementValue = tblData.Refinement_Level
895 updateSpecialItem(tempItem, tblData.Prefix, tblData.Prefix_Value, tblData.Refinement_Level)
896
897 PrintMessage(2, "Trying to store pre-existing " .. tempItem.Name .. " in a table")
898 self:PrintItemTable(tempItem)
899 itemListToSend[tempItem.Name] = QuickCreateItemToSend(itemProperties, tempItem.Name)
900
901
902 PrintMessage(2, tempItem.Name .. " Stored in itemToCreateList")
903
904 end
905
906 writeItemToClient("",false)
907
908end
909
910
911
912----------------##################################### Tables declared outside of function, so they are declared only once, and not resetting each time function is called. (Process/Run-time efficiency)
913
914local tblSuperList = {}
915tblSuperList[1] = "Godlike"
916tblSuperList[2] = "Legendary"
917tblSuperList[3] = "Epic"
918tblSuperList[4] = "Deity"
919
920
921
922function Entity:SearchForItem(strItem, intAmount, boolSuper, boolNoRefPref)
923
924
925 --Ensure player and inventory is valid
926 if !IsValid(self) or !self.Data.Inventory then return false end
927 --ensure inventory is inventory OR empty table
928 self.Data.Inventory = self.Data.Inventory or {}
929 --Create an empty table
930 local tempTbl = {}
931 --set amount found to 0
932 local amountFound = 0
933
934
935
936
937 --Start a loop counting from 1 to the size of the table
938 --print("Starting loop counting from 1 to the size of the table which is " .. table.Count(self.Data.Inventory) .. " .\n")
939 --print("The table contains " .. self.Data.Inventory .. " .\n")
940
941 for i,v in pairs(self.Data.Inventory) do
942 --If the item is found inside the table of this index
943 --print("Searching for " .. strItem .. " in " .. i .. " .\n")
944 if string.find(i, strItem) then
945 local tblItemTable = ItemTable(i)
946 --if bool super is false
947 --print("Item recognised, there are " .. v .. "x" .. i .. " .\n")
948 if boolNoRefPref == true then
949 if tblItemTable.SpecialItem == 1 then
950 if tblItemTable.Prefix == "None" and tblItemTable.RefinementValue == 0 then
951 amountFound = amountFound + v
952 end
953 else
954 amountFound = amountFound + v
955 end
956
957 else
958 if boolSuper == false then
959 --print("Checking if the item does not contain any super prefixes")
960 --if this item DOES NOT CONTAIN any of the super prefixes
961 if tblItemTable.SpecialItem == 1 then
962 if (tblItemTable.Prefix != tblSuperList[1]) and (tblItemTable.Prefix != tblSuperList[2]) and (tblItemTable.Prefix != tblSuperList[3]) and (tblItemTable.Prefix != tblSuperList[4]) then
963 --print("amount found incremented by the amount of items present")
964 --increment Amount found
965 amountFound = amountFound + v
966 end
967 else
968 amountFound = amountFound + v
969 end
970 --Else if boolSuper is true
971 else
972 --print("amount found incremented by the amount of items present")
973 --increment amountFound
974 amountFound = amountFound + v
975 end
976 end
977 end
978 end
979
980 --print("Checking if " .. amountFound .. " is greater than or equal to " .. intAmount .. " .\n")
981 --If amount found is greater than or equal to the amount needed
982 if amountFound >= intAmount then
983 --return true
984 --print("There are enough items, so returning true.\n")
985 return true
986 else
987 --else if there isn't enough, return false
988 --print("There are not enough items, so returning false.\n")
989 return false
990 end
991
992
993end
994
995
996
997function Entity:SearchRemoveItem(strItem, intAmount, boolSuper, boolNoRefPref)
998
999
1000 --Ensure player and inventory is valid
1001 if !IsValid(self) or !self.Data.Inventory then return false end
1002 --ensure inventory is inventory OR empty table
1003 self.Data.Inventory = self.Data.Inventory or {}
1004 --Create an empty table
1005 local tempTbl = {}
1006 --set amount found to 0
1007 local amountFound = 0
1008 --Declare local counter
1009 local amountAdded = 0
1010
1011
1012
1013 --Start a loop counting from 1 to the size of the table
1014 --print("Starting loop counting from 1 to the size of the table which is " .. table.Count(self.Data.Inventory) .. " .\n")
1015 --print("The table contains " .. self.Data.Inventory .. " .\n")
1016
1017 for i,v in pairs(self.Data.Inventory) do
1018 --If the item is found inside the table of this index
1019 --print("Searching for " .. strItem .. " in " .. i .. " .\n")
1020 if string.find(i, strItem) then
1021 local tblItemTable = ItemTable(i)
1022 if boolNoRefPref == true then
1023 if tblItemTable.SpecialItem == 1 then
1024 if tblItemTable.Prefix == "None" and tblItemTable.RefinementValue == 0 then
1025 --print("amount found incremented by the amount of items present")
1026 --increment amountFound
1027 amountFound = amountFound + v
1028 if table.Count(tempTbl) < intAmount and v > 0 then
1029 --if the amountFound is greater than the amount required
1030 if amountFound > intAmount then
1031 --Set amountFound to the amount required
1032 amountFound = intAmount
1033 end
1034
1035 --loop for while the table has less entries thn the amount required and amountAdded is less than the amount found.
1036 while( table.Count(tempTbl) < intAmount and amountAdded < amountFound ) do
1037 --increment amountAdded
1038 amountAdded = amountAdded + 1
1039 --add the item to the temptable to the index of amountAdded
1040 tempTbl[amountAdded] = i
1041 end
1042 end
1043 end
1044 else
1045 amountFound = amountFound + v
1046 if table.Count(tempTbl) < intAmount and v > 0 then
1047 --if the amountFound is greater than the amount required
1048 if amountFound > intAmount then
1049 --Set amountFound to the amount required
1050 amountFound = intAmount
1051 end
1052
1053 --loop for while the table has less entries thn the amount required and amountAdded is less than the amount found.
1054 while( table.Count(tempTbl) < intAmount and amountAdded < amountFound ) do
1055 --increment amountAdded
1056 amountAdded = amountAdded + 1
1057 --add the item to the temptable to the index of amountAdded
1058 tempTbl[amountAdded] = i
1059 end
1060 end
1061 end
1062 else
1063 --if bool super is false
1064 --print("Item recognised, there are " .. v .. "x" .. i .. " .\n")
1065 if boolSuper == false then
1066 --print("Checking if the item does not contain any super prefixes")
1067 --if this item DOES NOT CONTAIN any of the super prefixes
1068 if tblItemTable.SpecialItem == 1 then
1069 if (tblItemTable.Prefix != tblSuperList[1]) and (tblItemTable.Prefix != tblSuperList[2]) and (tblItemTable.Prefix != tblSuperList[3]) and (tblItemTable.Prefix != tblSuperList[4]) then
1070 --print("amount found incremented by the amount of items present")
1071 --increment Amount found
1072 amountFound = amountFound + v
1073 --If the table has less entries than the amount required and the amount found is greater than 0
1074 if table.Count(tempTbl) < intAmount and v > 0 then
1075 --if the amountFound is greater than the amount required
1076 if amountFound > intAmount then
1077 --Set amountFound to the amount required
1078 amountFound = intAmount
1079 end
1080
1081 --loop for while the table has less entries thn the amount required and amountAdded is less than the amount found.
1082 while( table.Count(tempTbl) < intAmount and amountAdded < amountFound ) do
1083 --increment amountAdded
1084 amountAdded = amountAdded + 1
1085 --add the item to the temptable to the index of amountAdded
1086 tempTbl[amountAdded] = i
1087 end
1088 end
1089 end
1090 else
1091 amountFound = amountFound + v
1092 if table.Count(tempTbl) < intAmount and v > 0 then
1093 --if the amountFound is greater than the amount required
1094 if amountFound > intAmount then
1095 --Set amountFound to the amount required
1096 amountFound = intAmount
1097 end
1098
1099 --loop for while the table has less entries thn the amount required and amountAdded is less than the amount found.
1100 while( table.Count(tempTbl) < intAmount and amountAdded < amountFound ) do
1101 --increment amountAdded
1102 amountAdded = amountAdded + 1
1103 --add the item to the temptable to the index of amountAdded
1104 tempTbl[amountAdded] = i
1105 end
1106 end
1107 end
1108 --Else if boolSuper is true
1109 else
1110 --print("amount found incremented by the amount of items present")
1111 --increment amountFound
1112 amountFound = amountFound + v
1113 if table.Count(tempTbl) < intAmount and v > 0 then
1114 --if the amountFound is greater than the amount required
1115 if amountFound > intAmount then
1116 --Set amountFound to the amount required
1117 amountFound = intAmount
1118 end
1119
1120 --loop for while the table has less entries thn the amount required and amountAdded is less than the amount found.
1121 while( table.Count(tempTbl) < intAmount and amountAdded < amountFound ) do
1122 --increment amountAdded
1123 amountAdded = amountAdded + 1
1124 --add the item to the temptable to the index of amountAdded
1125 tempTbl[amountAdded] = i
1126 end
1127 end
1128 end
1129 end
1130 end
1131 end
1132
1133 --print("Checking if " .. amountFound .. " is greater than or equal to " .. intAmount .. " .\n")
1134 --If amount found is greater than or equal to the amount needed
1135 if amountFound >= intAmount then
1136 --return true
1137 --print("There are enough items, so returning true.\n")
1138 --start loop counting from i = 1 , where v is the content throughout the table
1139 for i,v in pairs(tempTbl) do
1140 local tblItemTable = ItemTable(v)
1141 --remove the item from the inventory
1142 if tblItemTable.SpecialItem == 1 then
1143 self.DeleteSpecialItem(v, 1)
1144 else
1145 self:RemoveItem(v, 1)
1146 end
1147 end
1148 return true
1149 else
1150 --else if there isn't enough, return false
1151 --print("There are not enough items, so returning false.\n")
1152 return false
1153 end
1154
1155
1156end
1157
1158function Entity:RemoveSoldItem(strItem, intAmount)
1159 if ItemTable(strItem).SpecialItem == 1 then
1160 if !self:DeleteSpecialItem(strItem, intAmount) then return false end
1161 else
1162 if !self:RemoveItem(strItem, intAmount) then return false end
1163 end
1164end
1165
1166function Entity:GiveBoughtItem(strItem)
1167 local tblItemTable = ItemTable(strItem)
1168 --self:CreateNotification("Item distribution")
1169 if tblItemTable.SpecialItem == 1 then
1170 local strItem2
1171 strItem2 = CreateNewSpecialItem(strItem, "None", 0, 0, self.PlayerID)
1172 self:AddSpecialItem(strItem2, 1, false, false, false)
1173 else
1174 self:AddItem(strItem, intAmount)
1175 end
1176
1177end
1178
1179function Entity:GiveCraftedItems(tblItems)
1180 for strItem, intAmount in pairs(tblItems or {}) do
1181 local tblItemTable = ItemTable(strItem)
1182 --self:CreateNotification("Item distribution")
1183 if tblItemTable.SpecialItem == 1 then
1184 for intIndex = 1, intAmount do
1185 local strItem2
1186 strItem2 = chooseSpecialStats(strItem, self, 2)
1187 self:AddSpecialItem(strItem2, 1, false, false, false)
1188 end
1189 else
1190 self:AddItem(strItem, intAmount)
1191 end
1192
1193 end
1194end
1195
1196
1197function Entity:TakeCraftedItems(tblItems, boolSuper)
1198 for strItem, intAmount in pairs(tblItems or {}) do
1199 if !self:SearchRemoveItem(strItem, intAmount, boolSuper, false) then return false end
1200 end
1201end
1202
1203function Entity:GiveQuestItems(tblItems)
1204 for strItem, intAmount in pairs(tblItems or {}) do
1205 local tblItemTable = ItemTable(strItem)
1206 --self:CreateNotification("Item distribution")
1207 if tblItemTable.SpecialItem == 1 then
1208 for intIndex = 1, intAmount do
1209 local strItem2
1210 strItem2 = CreateNewSpecialItem(strItem, "None", 0, 0, self.PlayerID)
1211 self:AddSpecialItem(strItem2, 1, false, false, false)
1212 end
1213 else
1214 self:AddItem(strItem, intAmount)
1215 end
1216
1217 end
1218end
1219
1220function Entity:TakeQuestItems(tblItems)
1221 for strItem, intAmount in pairs(tblItems or {}) do
1222 if !self:SearchRemoveItem(strItem, intAmount, false, true) then return false end
1223 end
1224end
1225
1226function Entity:TakeItems(tblItems)
1227 for strItem, intAmount in pairs(tblItems or {}) do
1228 if ItemTable(strItem).SpecialItem == 1 then
1229 if !self:DeleteSpecialItem(strItem, intAmount) then return false end
1230 else
1231 if !self:RemoveItem(strItem, intAmount) then return false end
1232 end
1233 end
1234end
1235
1236
1237if CLIENT then
1238 usermessage.Hook("UD_UpdateItem", function(usrMsg)
1239 LocalPlayer():AddItem(usrMsg:ReadString(), usrMsg:ReadLong())
1240 end)
1241 net.Receive("AddNewUniqueItem", function()
1242 print("Message broadcast recieved")
1243 local newItemList = net.ReadTable()
1244 PrintTable(newItemList)
1245 for itemTable, item in pairs(newItemList or {}) do
1246 --PrintTable(itemTable[item])
1247 --print(item.Name)
1248 if item.Name != false then
1249 print("Item recieved is not false")
1250 if !GAMEMODE.DataBase.Items[item.Name] then
1251 print("Item does not yet exist, now creating item.")
1252 local newItem = table.Copy(GAMEMODE.DataBase.Items[item.BaseItem])
1253 newItem.Name = item.Name
1254 newItem.Owner = item.Owner
1255 newItem.Desc = item.Description
1256 newItem.Prefix = item.Prefix
1257 newItem.PrefixValue = item.PrefixValue
1258 newItem.RefinementValue = item.RefinementValue
1259 updateSpecialItem(newItem, item.Prefix, item.PrefixValue, item.RefinementValue)
1260 print("Item " .. item.Name .. " should now exist.")
1261 else
1262 print("Item " .. item.Name .. " already exists!")
1263 print("Use the update net message to update an item if the item needs updating.")
1264 end
1265 end
1266 end
1267 end)
1268end
1269
1270if SERVER then
1271 util.AddNetworkString("AddNewUniqueItem")
1272end