[Support] VIP Dvar system
-
init() { level.vipXuids = []; // You can predefine XUIDs in your script like this level.vipXuids[0] = "predefined_xuid_here"; level.vipXuids[1] = "another_one"; level.vipXuids[2] = "etc, etc."; level thread onPlayerConnect(); } onPlayerConnect() { for(;;) { level waittill("connected", player); if(isInArray(level.vipXuids, player getXUID())) { // If the player XUID is in the predefined array, give them VIP status and set their VIP dvar player.status = "VIP++"; // Give them VIP status for the script self setPlayerVipDvar(true); // Set their VIP status DVAR } else if(player getPlayerDvar()) { // If the player does not have their XUID in the predefined array but has their VIP dvar set player.status = "VIP++"; // Give them VIP status for the script self setPlayerVipDvar(true); // Set their VIP status DVAR } /* You could combine the two conditions using an || operator, but this should be a little easier to understand for beginners. */ player thread onPlayerSpawned(); } } onPlayerSpawned() { self endon("disconnect"); level endon("game_ended"); for(;;) { self waittill("spawned_player"); if(self.status == "VIP++") { // If player has VIP status // Do VIP things } } } setPlayerVipDvar(value) { setPlayerDvar(self, "vip_status", value); } getPlayerVipDvar() { return getPlayerDvar(self, "vip_status"); } setPlayerDvar(player, dvar, value) { dvar = player getXUID() + "_" + dvar; setDvar(dvar, value); } getPlayerDvar(player, dvar) { dvar = player getXUID() + "_" + dvar; return getDvar(dvar); }
tried doing this on my server and it somewhat works but for some reason, on spawn, it gives everyone VIP, even if they arent in the defined array of XUIDs. can anyone help?
-
mikzy I too require support in this subject matter
-
didn't see this thread until now. Gonna repost my answer again
Cahz said in [Support] Can you set DVAR so players have VIP when map changes?:
mikzy I don't think the post above was as clear as it could be, so im gonna show you how i got this to work on my server.
First we need some utilities in order for this to work. Import this code anywhere into yours.
setPlayerDvar(player, dvar, value) { thedvar = player getXUID() + "_" + dvar; setDvar(thedvar, value); } getPlayerDvar(player, dvar) { thedvar = player getXUID() + "_" + dvar; return getDvar(thedvar); }
Once that is done, you can add dvars to functions like so.
func_givevip(player) { if(player != self && player.status != "VIP") { player.status = "VIP"; setPlayerDvar(player, "VIP", true); //sticky dvar function!! } }
Then all you'd need to do is add an if check in your onPlayerConnect to give players with the dvar enabled vip.
onPlayerConnect() { for(;;) { level waittill("connecting", player); player thread onPlayerSpawned(); if(getPlayerDvar(player, "VIP") == "") {} else if(getPlayerDvar(player, "VIP") == true) player.status = "VIP"; } }
I found that it had to be done this way because getPlayerDvar does not reliably get the variable when checking for numbers, or true/false.
So using "" as false, and "true" as true it is able to work properly -
-solved