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

Messages - Rhytz

#1
If by that you mean indent it properly... For some reason the [ code ] tag gets rid of my indentation. It still looks right in the preview though
#2
Quote from: KAKAN on Apr 15, 2017, 11:24 AMum, you forgot this?

I refactored the code so I wouldn't have to rely on FindPlayer and the player ID to get the player instance. Now when a player scores his first point, his player instance is added to the playerScores array. Now it all works fine, without the ugly timer, and without FindPlayer :)

Here's the final code:
function payoutPlayers(){
local topArray = [];
foreach(scoreinfo in playerScores){
if(scoreinfo){
topArray.push({player = scoreinfo.player, score = scoreinfo.score});
}
}

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

Here's a little preview of the script in action:
http://www.youtube.com/watch?v=6N9BtZgMCS0#
#3
Quote from: EK.IceFlake on Apr 15, 2017, 04:05 AMA much more solid workaround would be to keep an array of every online player with their instance

Good stuff, woke up today with my mind all cleared up and a similar idea... Why am I not simply storing the player instance in the array, so I don't need FindPlayer(). Gonna try that, thanks!

Quote from: kennedyarz on Apr 15, 2017, 12:26 AMHi, I do not know anything about LU, but you could not deal with those capital letters?

typeof(_player) returns "Player"

Quote from: KAKAN on Apr 15, 2017, 09:17 AMLU works with that. See the first code. That's the thing.

Yeah i prefixed the variables with an underscore just in case something else in the script was interfering with those variables (i use player and payout variables elsewhere)

Anyway thanks for the help guys, gonna poke around with it and see if I can create a better solution. Will report back in!
#4
Unfortunately the problem persisted using that code, and whatever i tried. So I'm now resorting to a somewhat gross workaround, but it does the job.

NewTimer("delayedCash", realpos * 100, 1, _player, _payout);

function delayedCash(player, cash){
player.Cash += cash;
}

So here's the finished product:
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(typeof(_player) != "Player") _player = FindPlayer( scoreinfo.id );

if(_player && typeof(_player) == "Player"){ 
local realpos = pos + 1;
//_player.Cash += _payout; //Why does this not work!!!!??!?!?
//Delay the payout, this does seem to work
NewTimer("delayedCash", realpos * 100, 1, _player, _payout);
BigMessage(_player, "You came " + realpos + " in the " + currentMinigame.name, 5000, 3);
_payout = abs(_payout * 0.8);
}else{
print("Error retrieving player for payout");
}
}
}

function delayedCash(player, cash){
player.Cash += cash;
}

If anyone has a more solid solution than what I did, I'm all ears  :)
#5
I added _player = null; in an attempt to fix the issue, but it didn't help unfortunately. I think FindPlayer must be returning that 1, after _player.Cash is called in the previous iteration.

I have no clue where else that 1 could come from?

Again, the code works fine without the _player.Cash += _payout; line... Then the _player variable contains a valid Player instance in every iteration, and every player sees the BigMessage. With that line, only the first player gets to see the BigMessage, AND gets the money, but the loop errors and halts on the second iteration.

Edit: didnt see your pastebin fix, gonna test, ty!
#6
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
#7
Did you ever figure this out Motley?
#8
I think you're gonna have a hard time getting it to work like this either way... Most, if not all SMTP servers require authentication, and communicate using SSL/TLS nowadays, and thats tricky/impossible to work with using just the socket functions available in LU/VCMP.
#9
You need to atleast get rid of g_MailSocket.SetLostConnFunc( "CloseConnection" ); because SetNewConnFunc and SetLostConnFunc don't work together in LU.

You should also create a function to check the response from the server.
#10
I'd use a service like Mailgun if I wanted to send mail from my server
#11
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.