This repository has been archived by the owner on Nov 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AdminGive.py
77 lines (72 loc) · 2.51 KB
/
AdminGive.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
__author__ = 'Corrosion X'
__version__ = '1.0'
__name__ = 'AdminGive'
import clr
import sys
clr.AddReferenceByPartialName("UnityEngine")
clr.AddReferenceByPartialName("Pluton")
import UnityEngine
import Pluton
import System
from System import *
class AdminGive:
def On_PluginInit(self):
Commands.Register("give")\
.setCallback("giveitem")\
.setDescription("Give a player an item")\
.setUsage("give john hatchet 2")
def giveitem(self, args, player):
if len(args) == 0:
player.Message("How to use /give ex. /give corrosion rock 1")
return
quoted = Util.GetQuotedArgs(args)
itemID = Pluton.InvItem.GetItemID(quoted[1])
try:
amount = int(quoted[2])
except ValueError:
amount = 1
if player.Admin:
playerr = self.CheckV(player, quoted[0])
if playerr is None:
return
else:
playerr.Inventory.Add(itemID, amount)
playerr.Message("You have been given " + str(amount) + itemID)
player.Message("You have given " + name + str(amount) + itemID)
def GetPlayerName(self, namee):
name = namee.lower()
for pl in Server.ActivePlayers:
if pl.Name.lower() == name:
return pl
return None
def CheckV(self, Player, args):
systemname = "AdminGive"
count = 0
if hasattr(args, '__len__') and (not isinstance(args, str)):
p = self.GetPlayerName(String.Join(" ", args))
if p is not None:
return p
for pl in Server.ActivePlayers:
for namePart in args:
if namePart.lower() in pl.Name.lower():
p = pl
count += 1
continue
else:
p = self.GetPlayerName(str(args))
if p is not None:
return p
s = str(args).lower()
for pl in Server.ActivePlayers:
if s in pl.Name.lower():
p = pl
count += 1
continue
if count == 0:
Player.MessageFrom(systemname, "Couldn't find " + String.Join(" ", args) + "!")
return None
elif count == 1 and p is not None:
return p
else:
Player.MessageFrom(systemname, "Found " + str(count) + " player with similar name. Use more correct name!")
return None