· 6 years ago · Aug 11, 2019, 08:54 AM
1local dbg_lvl = d_LVL_MAIN + d_LVL_SERVER
2
3local function PlayerSave ( ply )
4 if (!IsValid(ply)) then
5 --timer.Stop(ourID);
6 --timer.Remove(ourID);
7 return;
8 end
9
10 ply:Save();
11end
12
13GM.OrganizationData = {};
14GM.OrganizationMembers = {};
15
16/* The following function is responsible for:
17 - Giving players cityrps variables (Needs to be moved to seperate function and called on join) (Possibly update so it's less data) <- Removed completely; Unneeded>
18 - Attempts to grabs the players info line from the database, upon finding it, it will: <* Changed to grab data from a stored table>
19 - Checks if the player is valid (In the future, will be 'has not disconnected') <* Moved into SQL request function and changed to check for disconnection>
20 - Checks if the player line existed, if it does NOT EXISTS, it will: <* Moved into SQL request function>
21 - Insert new player info lines into the SQL tables pertaining to cityrp data. <* Moved into SQL request function>
22 - Then attempt to call this function again to load the data. <* Moved into SQL request function, but now calls the new load SQL func again>
23 - Checks if the player's name is default, if so, allows them to setup their account. <UNCHANGED>
24 - Set the player's join time on their player entity. <UNCHANGED>
25 - Set UMSG strings for name and ringtone. (Change this and all SetNW* functions into SetNWString, etc...) <* Funcs replaced; ALSO NOTED IN G-DOCS>
26 - Gives the player their saved ammo types. <UNCHANGED>
27 - Set player info using SetNW* functions, including figuring out which licenses to set. <UNCHANGED>
28 - Set the player's appearance variables. <UNCHANGED>
29 - Attempts to send the data already sent earlier due to SetNW*. (NOT NEEDED!) <- Removed completely; Unneeded>
30 -- Disabled: Telling the player what their last car was. (Why is it disabled? Is it no longer needed?) <UNCHANGED; Needs research!>
31 - Attempts to grab the player's extra item data from the database, upon loading it, it will: <* Moved into SQL request function; Now saves to table>
32 - Check if it exists, if not, it will create the new line in the database. <* Moved into SQL request function>
33 - Sends the data the client. (This will be changed to save to a table, for the player to grab from later when loaded.) <Not Moved; Updated to use table>
34 - Parse the player's items and storage strings into a table that is saved to the player, using the parseSaveString funcs. <Not Moved;UNCHANGED>
35 - Send the vehicle line data to the client and then parse it. <UNCHANGED>
36 - Send mixture info. <UNCHANGED>
37 - Setup levels and genes. <UNCHANGED>
38 - Check for a valid RP name, if not valid, forces rename. <UNCHANGED>
39 - Send player org info and get org data. <UNCHANGED>
40 - Spawn the player and equip their weapons. <UNCHANGED>
41 - Send player's website account info. <* Moved to more functional location in info loaded function>
42*/
43
44GM.ConnectingPlayers = GM.ConnectingPlayers or {}
45GM.SavedPlayerInfo = GM.SavedPlayerInfo or {}
46GM.SavedExtraData = GM.SavedExtraData or {}
47
48gameevent.Listen( "player_connect" )
49gameevent.Listen( "player_disconnect" )
50local empty_tbl = util.TableToJSON({})
51function GM.LoadPlayerInfo( Name, SID, IP, ent_id )
52 local UID = util.CRC( "gm_" .. SID .. "_gm" ) d_print(dbg_lvl, "[cityrp][LoadPlayerInfo]", "Player '" .. Name .. "' (" .. SID .. ") has joined! Loading info from database...")
53
54 tmysql.query("SELECT `id`, `rp_name_first`, `rp_name_last`, `time_played`, `cash`, `model`, `items`, `storage`, `skills`, `genes`, `formulas`, `organization`, `bank`, `vehicles`, `blacklists`, `ringtone`, `ammo_pistol`, `ammo_rifle`, `ammo_shotgun`, `fuelleft`, `lastcar`, `license`, `instructor`, `hunger`, `ammo_sniper` FROM `cityrp_users` WHERE `id`='" .. SID .. "'", function ( PlayerInfo )
55 if not GAMEMODE.ConnectingPlayers[SID] and not IsValid(player.GetByID(SID)) then d_print(dbg_lvl, "[cityrp][LoadPlayerInfo]", "Player (" .. SID .. ") was not found! Dropping loading request!") return end
56
57 if (!PlayerInfo || !PlayerInfo[1]) then d_print(dbg_lvl, "[cityrp][LoadPlayerInfo]", "Player '" .. Name .. "' (" .. SID .. ") has no player info row! Creating new rows...")
58 tmysql.query("INSERT INTO `cityrp_users` (`id`, `uid`, `steamid`, `rp_name_first`, `rp_name_last`, `time_played`, `cash`, `model`, `items`, `skills`, `genes`, `formulas`, `organization`, `bank`, `vehicles`, `ringtones`, `ringtone`, `last_played`, `license`, `instructor`, `hunger`) VALUES ('" .. SID .. "', '" .. UID .. "', '" .. SID .. "', 'John', 'Doe', '5', '25000', '', '', '', '5', '', '0', '0', '', '', '1', '0', '1','0','100')", function()
59 d_print(dbg_lvl, "[cityrp][LoadPlayerInfo]", "New rows created successfully for Player '" .. Name .. "' (" .. SID .. ")! Attempting to reload player...")
60 GAMEMODE.LoadPlayerInfo(Name, SID, IP, ent_id)
61 end)
62 tmysql.query("INSERT INTO `cityrp_fuel` (`uid`) VALUES ('" .. UID .. "')");
63 tmysql.query("INSERT INTO `cityrp_item_save` (`uid`,`items`,`storage`) VALUES ('" .. UID .. "','" .. empty_tbl .. "', '" .. empty_tbl .. "')")
64 return
65 end
66
67 tmysql.query("SELECT `uid`, `items`, `storage` FROM `cityrp_item_save` WHERE `uid`='" .. UID .. "'", function(ItemSaveData)
68 if not GAMEMODE.ConnectingPlayers[SID] and not IsValid(player.GetByID(SID)) then d_print(dbg_lvl, "[cityrp][LoadPlayerInfo]", "Player (" .. SID .. ") was not found! Dropping ITEM DATA SAVE loading request!") return end
69
70 if !ItemSaveData[1] or !ItemSaveData[1][1] then
71 tmysql.query("INSERT INTO `cityrp_item_save` (`uid`,`items`,`storage`) VALUES ('" .. UID .. "','" .. empty_tbl .. "', '" .. empty_tbl .. "')")
72 ItemSaveData[1] = {[2] = empty_tbl,[3] = empty_tbl}
73 end
74
75 GAMEMODE.SavedExtraData[SID] = {Inv = ItemSaveData[1][2], Storage = ItemSaveData[1][3]}
76 end)
77
78 d_print(dbg_lvl, "[cityrp][LoadPlayerInfo]", "Player '" .. Name .. "' (" .. SID .. ") Info row successfully loaded!")
79 GAMEMODE.SavedPlayerInfo[SID] = PlayerInfo
80 end)
81
82end
83hook.Add("player_connect", "cityrp_playerinfo_init", function(d)
84 GAMEMODE.ConnectingPlayers[d.networkid] = true
85 GAMEMODE.LoadPlayerInfo(d.name, d.networkid, d.address, d.index)
86end)
87hook.Add("player_disconnect", "cityrp_disconnect_check", function(d)
88 GAMEMODE.ConnectingPlayers[d.networkid] = nil
89 GAMEMODE.SavedPlayerInfo[d.networkid] = nil
90 GAMEMODE.SavedExtraData[d.networkid] = nil
91end)
92
93function GM.LoadPlayerProfile ( Player, attempt )
94 if (Player.AlreadyLoaded) then return end
95
96 local SID = Player:SteamID()
97 Player.SMFID = SID
98 Player.Buddies = Player.Buddies or {}
99
100 MsgC( Color( 170, 65, 219 ), "NETWORKING: Attempting to load " .. Player:Nick() .. "'s player info... ");
101
102 if not GAMEMODE.SavedPlayerInfo[SID] then MsgC( Color( 170, 65, 219 ), "NETWORKING: Player Not Found!\n")
103 timer.Simple(2, function()
104 if not IsValid(Player) then return end
105 if (attempt or 0)>5 then MsgC( Color( 170, 65, 219 ), "NETWORKING: Failed to find data after 5 attempts! Disconnecting player!\n")
106 Player:Kick("Unable to load player data! Please rejoin, this is an issue on our end")
107 return
108 end
109 attempt = attempt or 0
110 MsgC( Color( 170, 65, 219 ), "NETWORKING: Attempt number " .. (attempt + 1) .. " at loading player profile for " .. Player:Nick() .. "\n")
111 GAMEMODE.LoadPlayerProfile(Player, attempt + 1)
112 end)
113 else MsgC( Color( 170, 65, 219 ), "NETWORKING: Found player profile\n")
114 local PlayerInfo = GAMEMODE.SavedPlayerInfo[SID]
115 if (PlayerInfo[1][2] == "John" && PlayerInfo[1][3] == "Doe") then Player.CanSetupPlayer = true end
116
117 if (Player.CanSetupPlayer) then
118 MsgC( Color( 170, 65, 219 ), "NETWORKING: Allowing " .. Player:Nick() .. " to setup new player...\n");
119 umsg.Start("cityrp_newchar", Player);
120 umsg.End();
121 else
122 --Player:DetectBaconBot();
123 end
124
125 Player.joinTime = CurTime();
126
127 // Public Vars
128 Player:SetNWString("rp_fname", PlayerInfo[1][2]);
129 Player:SetNWString("rp_lname", PlayerInfo[1][3]);
130 Player:SetNWInt("ringtone", tonumber(PlayerInfo[1][16]));
131
132 // Ammo
133 Player:GiveAmmo(tonumber(PlayerInfo[1][17]), 'pistol');
134 Player:GiveAmmo(tonumber(PlayerInfo[1][18]), 'ar2');
135 Player:GiveAmmo(tonumber(PlayerInfo[1][19]), 'buckshot');
136 Player:GiveAmmo(tonumber(PlayerInfo[1][25]), 'SnicityrpenetratedRound');
137
138 // Private Vars - This part only sets it for the server. Its also sent to the client via the next section.
139 Player:SetNWInt("time_played", tonumber(PlayerInfo[1][4]));
140 Player:SetNWInt("cash", tonumber(PlayerInfo[1][5]));
141 Player:SetNWInt("bank", tonumber(PlayerInfo[1][13]));
142 Player:SetNWString("blacklists", PlayerInfo[1][15]);
143 Player:SetNWString("lastcar", PlayerInfo[1][21] or "a");
144 Player:SetNWInt("hunger", tonumber(PlayerInfo[1][24]));
145
146 local License = false
147 local Instructor = false
148
149 local dbL = tonumber(PlayerInfo[1][22])
150 local dbD = tonumber(PlayerInfo[1][23])
151
152 if dbL == 1 then
153 License = true
154 end
155 if dbD == 1 then
156 Instructor = true
157 end
158
159 Player:SetNWBool("license", License)
160 Player:SetNWBool("instructor", Instructor)
161
162 if (PlayerInfo[1][15] != "") then
163 Player:RecompileBlacklists();
164 end
165
166 // Model
167 --[[local modelInfo = GAMEMODE.ExplodeModelInfo(PlayerInfo[1][6]) or {};
168 local theirNewModel = Player:GetModelPath(modelInfo.sex or "m", tonumber(modelInfo.face) or 1, tonumber(modelInfo.clothes) or 1);
169 Player:SetModel(theirNewModel);
170 Player:SetNWString("model", theirNewModel);
171 Player.PlayerModel = theirNewModel;
172 Player.PlayerSex = modelInfo.sex or "m";
173 Player.PlayerClothes = modelInfo.clothes;
174 Player.PlayerFace = tonumber(modelInfo.face) or 1;]]
175
176 local split = string.Explode("_", PlayerInfo[1][6]);
177 Player:SetNWInt("PlayerSex", tonumber(split[1]))
178 Player.PlayerSex = tonumber(split[1])
179 Player.ModelID = tonumber(split[2])
180 Player.PlayerClothes = tonumber(split[3])
181 Player.PlayerFace = tonumber(split[4])
182
183 Player.PlayerItems = {}
184 Player.StorageItems = {}
185
186 umsg.Start("cityrp_startup", Player)
187 umsg.Short(GAMEMODE.CurrentTime); // Game Time
188 umsg.Short(GAMEMODE.CurrentDay); // Game Day
189 umsg.Short(GAMEMODE.CurrentMonth); // Game Month
190 umsg.Short(GAMEMODE.CurrentYear); // Game Year
191 umsg.End();
192
193 /*
194 umsg.Start("cityrp_lastcar", Player)
195 umsg.String(tostring(PlayerInfo[1][21]));
196 umsg.End();
197 */
198
199 // Inventory
200 net.Start("ItemHook")
201 net.WriteString(PlayerInfo[1][7])
202 net.Send(Player)
203
204 // Bank Storage
205 net.Start("StorageHook")
206 net.WriteString(PlayerInfo[1][8])
207 net.Send(Player)
208
209 local ExtraData = GAMEMODE.SavedExtraData[SID] or {Inv = "",Storage = ""}
210 Player:parseSaveString(PlayerInfo[1][7], ExtraData.Inv);
211 Player:parseSSaveString(PlayerInfo[1][8], ExtraData.Storage);
212
213 // Vehicles
214 timer.Simple(1, function()
215 if IsValid(Player) then
216 net.Start("cityrp_vehicles_init")
217 net.WriteString(PlayerInfo[1][14])
218 net.Send(Player)
219 end
220 end)
221
222 Player.Vehicles = {}
223 Player:parseVehicleString(PlayerInfo[1][14])
224
225 // Mixtures
226 Player:SetNWString("mixtures", PlayerInfo[1][11])
227
228 // Skills
229 local ExplodeSkills = string.Explode(";", PlayerInfo[1][9])
230 for i = 1, #SKILLS_DATABASE do
231 if ExplodeSkills[i] && (i != #ExplodeSkills) then
232 Player:SetNWInt("s_" .. i, tonumber(ExplodeSkills[i]))
233 local postLevel = Player:GetcityrpLevel(SKILLS_DATABASE[i][1])
234 Player:AchievedLevel(SKILLS_DATABASE[i][1], tonumber(postLevel))
235 end
236 end
237
238 // Genes
239 local ExplodeGenes = string.Explode(";", PlayerInfo[1][10]);
240
241 if (#ExplodeGenes > 1) then
242 for i = 1, #GENES_DATABASE do
243 if ExplodeGenes[i + 1] && (i != #ExplodeGenes) then
244 Player:SetNWInt("g_" .. i, tonumber(ExplodeGenes[i + 1]));
245 local postLevel = Player:GetcityrpLevel(GENES_DATABASE[i][1]);
246 Player:AchievedLevel(GENES_DATABASE[i][1], tonumber(postLevel));
247 end
248 end
249 end
250
251 if (ExplodeGenes[1]) then
252 Player:SetNWInt("gpoints", tonumber(ExplodeGenes[1]));
253 end
254
255 // Check his name...
256 if (!Player.CanSetupPlayer && !GAMEMODE.IsValidName(Player:GetFirstName(), Player:GetLastName())) then
257 Player:ForceRename();
258 end
259
260 // Organization
261 local org = tonumber(PlayerInfo[1][12]);
262 if (org != 0) then
263 Player:SetNWInt("org", org);
264
265 if (!GAMEMODE.OrganizationMembers[org]) then
266 GAMEMODE.FetchOrganizationData(org);
267 end
268 end
269
270 // Set Varaibles
271 Player.AlreadyLoaded = true;
272 timer.Create(SID, 60, 0, PlayerSave, Player);
273
274 tmysql.query("SELECT `member_name`, `id_group`, `email_address` FROM `smf_members` WHERE `aim`='" .. SID .. "'", function ( WebsiteInfo )
275
276 if (!WebsiteInfo[1] || !WebsiteInfo[1][1]) then return; end
277
278 umsg.Start("cityrp_accountinfo", Player);
279 umsg.String(tostring(WebsiteInfo[1][1])); //UserName
280 umsg.String(tostring(WebsiteInfo[1][2])); //Group
281 umsg.String(tostring(WebsiteInfo[1][3])); //Email
282 umsg.End();
283
284 end)
285
286 GAMEMODE.ConnectingPlayers[SID] = nil
287 GAMEMODE.SavedPlayerInfo[SID] = nil
288 GAMEMODE.SavedExtraData[SID] = nil
289 end
290end
291hook.Add('PlayerInitialSpawn', 'cityrp_SetPlayerInfo', GM.LoadPlayerProfile)
292
293function GM.ChangeEmail ( Player, Cmd, Args )
294 if (!Args[1]) then return; end
295 if (Args[2] != Player:UniqueID()) then return; end
296
297 local EMail = Args[1];
298
299 tmysql.query("SELECT `member_name` FROM `smf_members` WHERE `aim`='" .. Player:SteamID() .. "'", function ( MemberName )
300
301 if (!MemberName[1] || !MemberName[1][1]) then return; end
302
303 tmysql.query("UPDATE `smf_members` SET `email_address`='" .. tmysql.escape(EMail) .. "' WHERE `aim`='" .. Player:SteamID() .. "'")
304 tmysql.query("UPDATE `tgbh2_users` SET `email`='" .. tmysql.escape(EMail) .. "' WHERE `username`='" .. MemberName[1][1] .. "'")
305
306 Player:Notify("Email changed to '" .. EMail .. "'");
307
308 GAMEMODE.LoadPlayerProfile(Player)
309
310 end)
311
312end
313concommand.Add("cityrp_changeemail", GM.ChangeEmail)
314--[[
315function GM.NewCharacterCreation ( Player, Cmd, Args )
316 if (!Player.CanSetupPlayer) then return false; end
317
318 Player.CanSetupPlayer = nil;
319
320 local Model = Args[1];
321 local FirstName = string.upper(string.sub(Args[2], 1, 1)) .. string.lower(string.sub(Args[2], 2));
322 local LastName = string.upper(string.sub(Args[3], 1, 1)) .. string.lower(string.sub(Args[3], 2));
323 local UN, PW = Args[4], Args[5];
324
325 if (!Model || !FirstName || !LastName) then
326 Player:ForceRename();
327 return;
328 end
329
330 if (!UN || !PW) then
331 Player:ForceFUN();
332 return;
333 end
334
335 // Model Stuff
336 local modelInfo = GAMEMODE.ExplodeModelInfo(Model) or {};
337 local theirNewModel = Player:GetModelPath(modelInfo.sex or "m", tonumber(modelInfo.face) or 1, tonumber(modelInfo.clothes) or 1);
338
339 Player:SetModel(theirNewModel);
340 Player.PlayerModel = theirNewModel;
341 tmysql.query("UPDATE `cityrp_users` SET `model`='" .. modelInfo.sex .. "_" .. modelInfo.face .. "_" .. modelInfo.clothes .. "' WHERE `id`='" .. Player.SMFID .. "'");
342
343 if (!GAMEMODE.IsValidName(FirstName, LastName)) then
344 Player:ForceRename();
345 return;
346 end
347
348 tmysql.query("SELECT `id` FROM `cityrp_users` WHERE `rp_name_first`='" .. FirstName .. "' AND `rp_name_last`='" .. LastName .. "' LIMIT 1", function ( someoneElseHas )
349 if (!Player or !IsValid(Player) or !Player:IsValid()) then
350 return;
351 end
352
353 if (someoneElseHas && someoneElseHas[1] && someoneElseHas[1][1]) then
354 Player:Notify("That name is already taken.\n");
355 Player:ForceRename();
356 return;
357 end
358
359 tmysql.query("SELECT `id_member` FROM `smf_members` WHERE `member_name`='" .. tmysql.escape(UN) .. "' LIMIT 1", function ( someoneElseHasFun )
360 if (!Player or !IsValid(Player) or !Player:IsValid()) then
361 return;
362 end
363
364
365 tmysql.query("INSERT INTO `smf_members` (`member_name`, `id_group`, `real_name`, `passwd`, `email_address`, `icq`, `aim`, `yim`, `msn`, `member_ip`) VALUES ('" .. tmysql.escape(UN) .. "', '4', '" .. tmysql.escape(UN) .. "', MD5('" .. PW .. "'), '" .. Player:UniqueID() .. "' '@gmail.com', '" .. tmysql.escape(Player:Nick()) .. "', '" .. Player:SteamID() .. "', '" .. FirstName .. "', '" .. LastName .. "', '" .. Player:IPAddress() .. "')");
366 tmysql.query("UPDATE `cityrp_users` SET `rp_name_first`='" .. FirstName .. "',`rp_name_last`='" .. LastName .. "' WHERE `id`='" .. Player.SMFID .. "'");
367
368 //fuckyoukenny
369 tmysql.query("SELECT `id_member` FROM `smf_members` WHERE `aim`='" .. Player:SteamID() .. "'", function ( IDMEMBER )
370
371
372 tmysql.query("INSERT INTO `smf_themes` (`id_member`, `id_theme`, `variable`, `value`) VALUES ('" .. IDMEMBER[1][1] .. "', '1', 'cust_rpname', '" .. FirstName .. "' ' ' '" .. LastName .. "')")
373 tmysql.query("INSERT INTO `smf_themes` (`id_member`, `id_theme`, `variable`, `value`) VALUES ('" .. IDMEMBER[1][1] .. "', '1', 'cust_steami', '" .. Player:SteamID() .. "')")
374
375 end);
376
377
378
379 Player:SetNWString("rp_fname", FirstName);
380 Player:SetNWString("rp_lname", LastName);
381
382 --Player:DetectBaconBot();
383
384 end); end);
385
386end
387concommand.Add('cityrp_nc', GM.NewCharacterCreation);]]
388
389function GM.NewCharacterCreation ( Player, Cmd, Args )
390 if (!Player.CanSetupPlayer) then return false; end
391
392 Player.CanSetupPlayer = nil;
393
394 local FirstName = string.upper(string.sub(Args[1], 1, 1)) .. string.lower(string.sub(Args[1], 2));
395 local LastName = string.upper(string.sub(Args[2], 1, 1)) .. string.lower(string.sub(Args[2], 2));
396
397 local ClothesID = tonumber(Args[3]);
398 local FaceID = tonumber(Args[4])
399 local ModelID = tonumber(Args[5])
400 local Sex = tonumber(Args[6])
401
402 if (!FaceID || !ModelID || !Sex || !ClothesID || !FirstName || !LastName) then
403 return;
404 end
405
406 local NewCloth = Player:GetClothesPath(Sex, ClothesID)
407 local NewFace = Player:GetFacePath(Sex, FaceID, ModelID)
408
409 Player:SetModel(SEX_MODEL[Sex][ModelID]);
410 Player:SetSubMaterial(SEX_SUBCLOTHID[Sex][ModelID],NewCloth)
411 Player:SetSubMaterial(SEX_SUBFACEID[Sex][ModelID],NewFace)
412
413 Player:SetNWInt("PlayerSex", Sex)
414 Player.PlayerSex = Sex;
415 Player.PlayerClothes = ClothesID;
416 Player.PlayerFace = FaceID;
417 Player.ModelID = ModelID
418
419 tmysql.query("UPDATE `cityrp_users` SET `model`='" .. Sex .. "_" .. ModelID .. "_" .. ClothesID .. "_" .. FaceID .. "' WHERE `id`='" .. Player:SteamID() .. "'");
420
421 if (!GAMEMODE.IsValidName(FirstName, LastName)) then
422 Player:ForceRename();
423 return;
424 end
425
426 tmysql.query("SELECT `id` FROM `cityrp_users` WHERE `rp_name_first`='" .. FirstName .. "' AND `rp_name_last`='" .. LastName .. "' LIMIT 1", function ( someoneElseHas )
427 if (!Player or !IsValid(Player) or !Player:IsValid()) then return; end
428
429 if (someoneElseHas && someoneElseHas[1] && someoneElseHas[1][1]) then
430 Player:Notify("That name is already taken.\n");
431 Player:ForceRename();
432 return;
433 end
434
435 Player:SetNWString("rp_fname", FirstName);
436 Player:SetNWString("rp_lname", LastName);
437
438 tmysql.query("UPDATE `cityrp_users` SET `rp_name_first`='" .. FirstName .. "',`rp_name_last`='" .. LastName .. "' WHERE `id`='" .. Player.SMFID .. "'");
439 end);
440end
441concommand.Add('cityrp_nc', GM.NewCharacterCreation);
442
443function GM.CustomizeChar ( Player, Cmd, Args )
444 if (!Player) then return; end
445 if !Args[1] or !Args[2] or !Args[3] then return; end
446 if (Player:Team() != TEAM_CITIZEN) then return; end
447 if (Player:GetCash() < GAMEMODE.ClothesPrice) then return end
448
449 local ClothesID = tonumber(Args[1]);
450 local FaceID = tonumber(Args[2])
451 local Sex = Player.PlayerSex
452 local ModelID = tonumber(Args[3])
453 local OldModelID = Player.ModelID
454
455 Player:SetSubMaterial(SEX_SUBCLOTHID[Sex][OldModelID],nil)
456 Player:SetSubMaterial(SEX_SUBFACEID[Sex][OldModelID],nil)
457
458 Player:TakeCash(GAMEMODE.ClothesPrice);
459
460 tmysql.query("UPDATE `cityrp_users` SET `model`='" .. Sex .. "_" .. ModelID .. "_" .. ClothesID .. "_" .. FaceID .. "' WHERE `id`='" .. Player.SMFID .. "'");
461
462 local NewCloth = Player:GetClothesPath(Sex, ClothesID)
463 local NewFace= Player:GetFacePath(Sex, FaceID, ModelID)
464
465 Player:SetModel(SEX_MODEL[Sex][ModelID]);
466 Player:SetSubMaterial(SEX_SUBCLOTHID[Sex][ModelID],NewCloth)
467 Player:SetSubMaterial(SEX_SUBFACEID[Sex][ModelID],NewFace)
468
469 Player.ModelID = ModelID
470 Player.PlayerClothes = ClothesID or 1
471 Player.PlayerFace = FaceID or 1;
472end
473concommand.Add("cityrp_cc", GM.CustomizeChar);
474
475--[[function GM.ChangeClothes ( Player, Cmd, Args )
476 if (!Player) then return; end
477 if (!Args[1]) then return; end
478 if (Player:Team() != TEAM_CITIZEN) then return; end
479 if Player:GetCash() < GAMEMODE.ClothesPrice then return end
480
481 local newClothes = tonumber(Args[1])
482 local modelInfo = Player:GetModelInfo()
483
484 if newClothes == modelInfo.clothes then return end
485 if newClothes >= SKINS_AVAILABLE[Player:GetSex()] or newClothes < 0 then return end
486
487 Player:TakeCash(GAMEMODE.ClothesPrice, true)
488 Player:SetSkin(newClothes)
489
490 // Save Data
491 local path = modelInfo.sex .. "_" .. modelInfo.face .. "_" .. newClothes
492 tmysql.query("UPDATE `cityrp_users` SET `model`='" .. path .. "' WHERE `id`='" .. Player.SMFID .. "'")
493 Player:SetPrivateInfoInt("clothes", newClothes)
494end
495concommand.Add("cityrp_cc", GM.ChangeClothes);]]
496
497function GM.ChangeSex ( Player, Cmd, Args )
498 if (!Player) then return; end
499 if (Player:Team() != TEAM_CITIZEN) then return; end
500 if (Player:GetCash() < GAMEMODE.SexChangePrice) then return end
501
502 local Sex = Player.PlayerSex
503 // Model Stuff
504 local newSex = "m";
505 if (Sex == SEX_MALE) then newSex = "f"; end
506
507 local modelInt = SEX_MALE;
508 if (newSex == "f") then modelInt = SEX_FEMALE; end
509
510 local ModelID = 1
511
512 Player:TakeCash(GAMEMODE.SexChangePrice);
513
514 tmysql.query("UPDATE `cityrp_users` SET `model`='" .. modelInt .. "_1_1_1' WHERE `id`='" .. Player.SMFID .. "'");
515
516 local OldModelID = Player.ModelID
517
518 Player:SetSubMaterial(SEX_SUBCLOTHID[Sex][OldModelID],nil)
519 Player:SetSubMaterial(SEX_SUBFACEID[Sex][OldModelID],nil)
520
521 local NewCloth = Player:GetClothesPath(modelInt, 1)
522 local NewFace= Player:GetFacePath(modelInt, 1, ModelID)
523
524 Player:SetModel(SEX_MODEL[modelInt][ModelID]);
525 Player:SetSubMaterial(SEX_SUBCLOTHID[modelInt][ModelID],NewCloth)
526 Player:SetSubMaterial(SEX_SUBFACEID[modelInt][ModelID],NewFace)
527
528 Player:SetNWInt("PlayerSex", modelInt)
529 Player.PlayerSex = modelInt;
530 Player.PlayerClothes = 1;
531 Player.PlayerFace = 1;
532 Player.ModelID = ModelID
533end
534concommand.Add("cityrp_cs", GM.ChangeSex);
535
536local PLAYER = FindMetaTable("Player")
537
538function PLAYER:LoadingDead ( deathTime )
539 if self.AlreadyLoaded then
540 timer.Destroy("DeadLoad");
541 self.RespawnTime = CurTime() + deathTime;
542 self:Notify("You must finish the remainder of your death time");
543 self:Freeze(false);
544 self:Kill();
545 end
546end
547
548function PLAYER:GetSpawnPosition ( )
549
550 tmysql.query("SELECT `vector`, `angle`, `deathtime` FROM `cityrp_spawn_locations` WHERE `steamid`='" .. self:SteamID() .. "'", function ( SpawnPos )
551
552 if (SpawnPos[1] and SpawnPos[1][1]) then
553 local vector = string.Explode(" ", SpawnPos[1][1]);
554 local angle = string.Explode(" ", SpawnPos[1][2]);
555 local deathTime = tonumber(SpawnPos[1][3]);
556
557 self:SetPos(Vector(vector[1], vector[2], vector[3]));
558 self:SetEyeAngles(Angle(angle[1], angle[2], angle[3]));
559
560 if deathTime > 0 then
561 self:Freeze(true);
562 timer.Create("DeadLoad", 2, 0, function () self:LoadingDead(deathTime); end);
563 end
564 end
565
566 end);
567
568end
569
570function PLAYER:SetSpawnPosition ( spawnVector, spawnAngle, deathTime, steamID )
571
572 local stringVector = string.Explode(" ", spawnVector)
573
574 for k, v in pairs(OwnableDoors) do
575 local nearDoor = math.Dist(v[1], v[2], stringVector[1], stringVector[2])
576
577 if nearDoor <= 1100 && self:IsInside() then
578 return;
579 end
580 end
581
582 if !deathTime then
583 deathTime = 0
584 end
585
586 tmysql.query("SELECT `steamid`, `vector`, `angle`, `deathtime` FROM `cityrp_spawn_locations` WHERE `steamid`='" .. self:SteamID() .. "'", function ( SpawnPos )
587
588 if (SpawnPos[1] and SpawnPos[1][1]) then
589 tmysql.query("UPDATE `cityrp_spawn_locations` SET `vector`='" .. spawnVector .. "',`angle`='" .. spawnAngle .. "',`deathtime`='" .. deathTime .. "' WHERE `steamid`='" .. steamID .. "'");
590 else
591 tmysql.query("INSERT INTO `cityrp_spawn_locations` (`steamid`, `vector`, `angle`, `deathtime`) VALUES ('" .. steamID .. "', '" .. spawnVector .. "', '" .. spawnAngle .. "', '" .. deathTime .. "')")
592 end
593
594 end);
595end
596
597function GM.SetSpawnPos ( Player, Cmd, Args )
598
599 local spawnPos = tostring(Player:GetPos());
600 local spawnAng = tostring(Player:GetAngles());
601
602 Player:SetSpawnPosition(spawnPos, spawnAng, 0, Player:SteamID())
603
604end
605concommand.Add("cityrp_save_pos", GM.SetSpawnPos);
606
607function GM.ChangeName ( Player, Cmd, Args )
608 if (Args[3] != Player:UniqueID()) then return; end
609 local FirstName = string.upper(string.sub(Args[1], 1, 1)) .. string.lower(string.sub(Args[1], 2));
610 local LastName = string.upper(string.sub(Args[2], 1, 1)) .. string.lower(string.sub(Args[2], 2));
611
612 if (!FirstName || !LastName) then return; end
613
614 if (!Player.CanRenameFree) then
615 if (Player:GetCash() < GAMEMODE.RenamePrice) then
616 return;
617 end
618
619 Player:TakeCash(GAMEMODE.RenamePrice, true);
620 end
621
622 if (!GAMEMODE.IsValidName(FirstName, LastName)) then
623 Player:ForceRename();
624 return;
625 end
626
627 tmysql.query("SELECT `id` FROM `cityrp_users` WHERE `rp_name_first`='" .. FirstName .. "' AND`rp_name_last`='" .. LastName .. "' LIMIT 1", function ( someoneElseHas )
628 if (!Player or !IsValid(Player) or !Player:IsValid()) then return; end
629
630 if (someoneElseHas && someoneElseHas[1] && someoneElseHas[1][1]) then
631 Player:Notify("That name is already taken.\n");
632 Player:ForceRename();
633 return;
634 end
635
636 Player.CanRenameFree = nil;
637
638 Player:SetNWString("rp_fname", FirstName);
639 Player:SetNWString("rp_lname", LastName);
640 tmysql.query("UPDATE `smf_members` SET `yim`='" .. FirstName .. "',`msn`='" .. LastName .. "' WHERE `aim`='" .. Player:SteamID() .. "'");
641 tmysql.query("UPDATE `cityrp_users` SET `rp_name_first`='" .. FirstName .. "',`rp_name_last`='" .. LastName .. "' WHERE `id`='" .. Player.SMFID .. "'");
642
643 tmysql.query("SELECT `id_member` FROM `smf_members` WHERE `aim`='" .. Player:SteamID() .. "'", function ( IDMEMBER )
644
645 tmysql.query("UPDATE `smf_themes` SET `value`='" .. FirstName .. "' ' ' '" .. LastName .. "' WHERE `id_member`='" .. IDMEMBER[1][1] .. "' AND `variable`='cust_rpname'");
646 tmysql.query("UPDATE `smf_themes` SET `value`='" .. Player:SteamID() .. "' WHERE `id_member`='" .. IDMEMBER[1][1] .. "' AND `variable`='cust_steami'");
647
648 end);
649 end);
650end
651concommand.Add("cityrp_MOFUCKA_cn", GM.ChangeName);
652
653function GM.ChangeFUN ( Player, Cmd, Args )
654 if (Args[2] != Player:UniqueID()) then return; end
655 local FUName = string.upper(string.sub(Args[1], 1, 1)) .. string.lower(string.sub(Args[1], 2));
656
657 if (!FUName) then return; end
658
659 tmysql.query("SELECT `id_member` FROM `smf_members` WHERE `member_name`='" .. FUName .. "' LIMIT 1", function ( someoneElseHasFun )
660 if (!Player or !IsValid(Player) or !Player:IsValid()) then return; end
661
662
663 Player:SetNWString("rp_funame", FUName);
664
665 tmysql.query("UPDATE `smf_members` SET `member_name`='" .. FUName .. "' WHERE `aim`='" .. Player:SteamID() .. "'");
666 end);
667end
668concommand.Add("cityrp_MOFUCKA_fun", GM.ChangeFUN)
669
670--[[
671function GM.ChangeFace ( Player, Cmd, Args )
672 if (!Player) then return; end
673 if (!Args[1]) then return; end
674 if (Player:Team() != TEAM_CITIZEN) then return; end
675
676 local Model = Args[1];
677
678 // Model Stuff
679 local modelInfo = GAMEMODE.ExplodeModelInfo(Model);
680 if (!modelInfo) then return; end
681
682 local newSex = SEX_MALE;
683 if (modelInfo.sex == 'f') then newSex = SEX_FEMALE; end
684 if (tonumber(modelInfo.sex) == 2) then newSex = SEX_FEMALE; end
685 if (Player:GetSex() != newSex) then return; end
686 if (Player:GetClothes() != modelInfo.clothes) then return; end
687
688 Player:TakeCash(GAMEMODE.FacialPrice, true);
689
690 local theirNewModel = Player:GetModelPath(modelInfo.sex or "m", tonumber(modelInfo.face) or 1, tonumber(modelInfo.clothes) or 1);
691
692 Player:SetModel(theirNewModel);
693 Player.PlayerModel = theirNewModel;
694 tmysql.query("UPDATE `cityrp_users` SET `model`='" .. modelInfo.sex .. "_" .. modelInfo.face .. "_" .. modelInfo.clothes .. "' WHERE `id`='" .. Player.SMFID .. "'");
695
696 Player:SetNWString("model", theirNewModel);
697 Player.PlayerSex = modelInfo.sex or "m";
698 Player.PlayerClothes = modelInfo.clothes;
699 Player.PlayerFace = tonumber(modelInfo.face) or 1;
700end
701concommand.Add("cityrp_cf", GM.ChangeFace);
702
703function GM.ChangeClothes ( Player, Cmd, Args )
704 if (!Player) then return; end
705 if (!Args[1]) then return; end
706 if (Player:Team() != TEAM_CITIZEN) then return; end
707
708 local Model = Args[1];
709
710 // Model Stuff
711 local modelInfo = GAMEMODE.ExplodeModelInfo(Model);
712 if (!modelInfo) then Msg("fail info\n"); return; end
713
714 local newSex = SEX_MALE;
715 if (modelInfo.sex == 'f') then newSex = SEX_FEMALE; end
716 if (tonumber(modelInfo.sex) == 2) then newSex = SEX_FEMALE; end
717 if (Player:GetSex() != newSex) then return; end
718 if (Player:GetFace() != modelInfo.face) then return; end
719
720 Player:TakeCash(GAMEMODE.ClothesPrice, true);
721
722 local theirNewModel = Player:GetModelPath(modelInfo.sex or "m", tonumber(modelInfo.face) or 1, tonumber(modelInfo.clothes) or 1);
723
724 Player:SetModel(theirNewModel);
725 Player.PlayerModel = theirNewModel;
726 tmysql.query("UPDATE `cityrp_users` SET `model`='" .. modelInfo.sex .. "_" .. modelInfo.face .. "_" .. modelInfo.clothes .. "' WHERE `id`='" .. Player.SMFID .. "'");
727
728 Player:SetNWString("model", theirNewModel);
729 Player.PlayerSex = modelInfo.sex or "m";
730 Player.PlayerClothes = modelInfo.clothes;
731 Player.PlayerFace = tonumber(modelInfo.face) or 1;
732end
733concommand.Add("cityrp_cc", GM.ChangeClothes);
734
735function GM.ChangeSex ( Player, Cmd, Args )
736 if (!Player) then return; end
737 if (Player:Team() != TEAM_CITIZEN) then return; end
738
739
740 // Model Stuff
741 local newSex = "m";
742 if (Player:GetSex() == SEX_MALE) then newSex = "f"; end
743
744 local modelInt = SEX_MALE;
745 if (newSex == "f") then modelInt = SEX_FEMALE; end
746
747 Player:TakeCash(GAMEMODE.SexChangePrice, true);
748
749 local theirNewModel = Player:GetModelPath(newSex, 1, 1);
750
751 Player:SetModel(theirNewModel);
752 Player.PlayerModel = theirNewModel;
753 tmysql.query("UPDATE `cityrp_users` SET `model`='" .. modelInt .. "_1_1' WHERE `id`='" .. Player.SMFID .. "'");
754
755 Player:SetNWString("model", theirNewModel);
756 Player.PlayerSex = modelInt;
757 Player.PlayerClothes = 1;
758 Player.PlayerFace = 1;
759end
760concommand.Add("cityrp_cs", GM.ChangeSex);
761]]
762function GM.JohnDoeBug ( Player, Cmd, Args )
763
764 tmysql.query("SELECT `rp_name_first`, `rp_name_last` FROM `cityrp_users` WHERE `steamid`='" .. Player:SteamID() .. "' LIMIT 1", function ( FixRPName )
765 if (!Player or !IsValid(Player) or !Player:IsValid()) then return; end
766 if (!FixRPName[1]) then return end
767
768 Player:SetNWString("rp_fname", FixRPName[1][1]);
769 Player:SetNWString("rp_lname", FixRPName[1][2]);
770
771 end)
772
773end
774concommand.Add("cityrp_no_john", GM.JohnDoeBug)
775
776function fixjohndoes ()
777 for k, v in pairs(player.GetAll()) do
778 GAMEMODE.JohnDoeBug(v)
779 end
780end
781timer.Create("fixjohns", 60, 0, fixjohndoes)
782
783function GM.Typing ( Player, Cmd, Args )
784 if (Args[1] && tostring(Args[1]) == "1") then
785 Player:SetNWInt("typing", 1);
786 Player.StartedTyping = CurTime();
787 else
788 Player.StartedTyping = nil;
789 Player:SetNWInt("typing", 0);
790 end
791end
792concommand.Add("pt", GM.Typing);
793
794function GM.AddBuddy ( Player, Cmd, Args )
795 if (!Args[1] || !Player.Buddies) then return; end
796 if (tostring(tonumber(Args[1])) != tostring(Args[1])) then return; end
797
798 table.insert(Player.Buddies, Args[1]);
799end
800concommand.Add("cityrp_ab", GM.AddBuddy);
801
802function GM.RemoveBuddy ( Player, Cmd, Args )
803 if (!Args[1] || !Player.Buddies) then return; end
804 if (tostring(tonumber(Args[1])) != tostring(Args[1])) then return; end
805
806 for k, v in pairs(Player.Buddies) do
807 if (v == Args[1]) then
808 Player.Buddies[k] = nil;
809 end
810 end
811end
812concommand.Add("cityrp_rb", GM.RemoveBuddy);
813
814function GM.BankDeposit ( Player, Cmd, Args )
815 if (!Args[1]) then return; end
816
817 local toTake = tonumber(Args[1]);
818
819 if (!toTake) then return; end
820 if (toTake <= 0) then return; end
821 if (Player:GetCash() < toTake) then return; end
822
823 Player:TakeCash(toTake, true);
824 Player:GiveBank(toTake, true);
825end
826concommand.Add("cityrp_b_d", GM.BankDeposit);
827
828function GM.BankWithdraw ( Player, Cmd, Args )
829 //if (!Player:NearNPC(2)) then return; end
830 if (!Args[1]) then return; end
831
832 local toTake = tonumber(Args[1]);
833
834 if (!toTake) then return; end
835 if (toTake <= 0) then return; end
836 if (Player:GetBank() < toTake) then return; end
837 if ((Player:GetCash() + toTake) > MAX_CASH) then return; end
838
839 Player:GiveCash(toTake, true);
840 Player:TakeBank(toTake, true);
841end
842concommand.Add("cityrp_b_w", GM.BankWithdraw);
843
844// Event Start Script
845function GM.StartEvent ( Player, Cmd, Args )
846 if not Player:IsOwner() then return false; end
847 local Event = Args[1];
848
849 if !file.Exists('cityrp/gamemode/events/' .. Event .. '.lua',"LUA") then
850 Player:PrintMessage(HUD_PRINTCONSOLE, "That event does not exist.");
851 return false;
852 end
853
854 include('cityrp/gamemode/events/' .. Event .. '.lua');
855end
856concommand.Add("cityrp2_encrypt3D_events", GM.StartEvent);
857
858--function Random_Fish ()
859 --local Fishmarket = function()
860 --Msg 'Starting Fish Market events\n';
861 --include('cityrp/gamemode/events/random/event_fishmarket.lua');
862 --Random_Fish()
863 --end
864 --timer.Simple( 1800, Fishmarket )
865--end
866--Random_Fish()
867
868function GM.ResetFirstName( Player, Cmd, Args )
869 Player:SetNWString("rp_fname", Player:GetNWString("rp_fname", "John"))
870end
871concommand.Add("cityrp_r_fn", GM.ResetFirstName)
872/*
873function GM.ResetLastCar( Player, Cmd, Args )
874 umsg.Start("cityrp_rs_lc")
875*/
876
877hook.Add("OnPlayerChangedTeam", "cityrp_onChangeTeamUpdate", function(pl, oT, nT)
878 pl:SetNWInt("cityrp_salary", (GAMEMODE.JobPaydayInfo[nT] && GAMEMODE.JobPaydayInfo[nT][2]) || 50);
879end)
880
881--[[net.Receive("ent_request_spawntime", function(len, Player)
882 local Ent = net.ReadEntity()
883
884 if IsValid(Ent) then
885 net.Start("ent_request_spawntime")
886 net.WriteFloat(Ent.SpawnTime)
887 net.WriteEntity(Ent)
888 net.Send(Player)
889 end
890end)]]