Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Topics - Rhytz

#1
I'm actually having this issue on LU, but I was advised to ask here since we couldn't figure it out.

So I'm creating this minigame script, and at the end of each minigame, every participating player gets paid a certain amount of money depending on how well they played (0.8x of what the previous player got).

Edit, pastebin'd for better readabilty: https://pastebin.com/y0Rn3Fnm
function payoutPlayers(){
local topArray = [];
foreach(id, score in playerScores){
if(score > 0){
topArray.push({id = id, score = score});
}
}

topArray.sort(sortScores);
local _payout = currentMinigame.payout;
foreach(pos, scoreinfo in topArray){
local _player = FindPlayer(scoreinfo.id);
if(_player){
local realpos = pos + 1;
//_player.Cash += _payout;
BigMessage(_player, "You came " + realpos + " in the " + currentMinigame.name, 5000, 3);
_payout = abs(_payout * 0.8);
}
_player = null;
}
}

So this code works, until you uncomment the _player.Cash += _payout; line. Then only the first iteration will succeed, and it will error on the second one. For some reason when that line is uncommented, _player is set to the player ID(int), instead of a Player reference.

Here's testing with that line commented out, and some debug prints. All works fine:
SCRIPT: before if(_player): Theremin
SCRIPT: before _player.Cash: Theremin
SCRIPT: Cash: 18005 _player: Theremin(Player)pos: 1 payout: 15000(integer)
SCRIPT: before BigMessage: Theremin
SCRIPT: Cash: 18005 _player: Theremin(Player)pos: 1 payout: 15000(integer)
SCRIPT: before if(_player): Rhytz
SCRIPT: before _player.Cash: Rhytz
SCRIPT: Cash: 4054 _player: Rhytz(Player)pos: 2 payout: 12000(integer)
SCRIPT: before BigMessage: Rhytz
SCRIPT: Cash: 4054 _player: Rhytz(Player)pos: 2 payout: 12000(integer)
SCRIPT: [lu-minigames] Minigame ended

However, when I uncomment the _player.Cash += _payout; line, this is what I get:
SCRIPT: before if(_player): Theremin
SCRIPT: before _player.Cash: Theremin
SCRIPT: Cash: 18005 _player: Theremin(Player)pos: 1 payout: 15000(integer)
SCRIPT: before BigMessage: Theremin
SCRIPT: Cash: 33005 _player: Theremin(Player)pos: 1 payout: 15000(integer)
SCRIPT: before if(_player): 1
SCRIPT: before _player.Cash: 1

AN ERROR HAS OCCURED [the index 'Cash' does not exist]

CALLSTACK
*FUNCTION [payoutPlayers()] Scripts/lu-minigames/main_s.nut line [164]
*FUNCTION [stopMinigame()] Scripts/lu-minigames/main_s.nut line [141]

LOCALS
[playerScores] ARRAY
[currentMinigame] TABLE
[realpos] 2
[_player] 1
[@ITERATOR@] 2
[scoreinfo] TABLE
[pos] 1
[_payout] 12000
[topArray] ARRAY
[this] TABLE
[minigameState] "ended"
[eligiblePlayers] TABLE
[currentMinigame] TABLE
[this] TABLE

So can anyone tell if there is something wrong with my code? Or have a run into an unfortunate LU bug?

Hoping someone can help
#2
Snippet Showroom / Lu Php/websdk
Nov 20, 2016, 09:09 PM
Hi there,

VCMP may already have a similar solution for this, but I have created a SDK for Liberty Unleashed that allows your server and website to easily communicate with each other. I'm sure it can be easily ported to work with VCMP as well, since both mods are so similar.  Or it might at least contain some useful code snippets and concepts, so I thought I might as well post it here.

Check out the project on GitHub

Feel free to contribute/fork.