Liberty Unleashed
Scripting => Script Help => Topic started by: MarcinBBlack on June 29, 2017, 01:08:08 am
-
Hi,
for last few days I've been struggling with calling my function through NewTimer. In the result server throws the following error message : "An error has occured [wrong number of parameters]
CALLSTACK
LOCALS".
Looks like my passed argument 'playerTeam' is treated as null (its instance of DominationTeam class), however printing 'playerTeam.Score' outside of timer shows that there is value indeed.
I tried also to pass just simply number and increase it. In that case there is no error like that, but I guess the variable is passed by value so only copy of it is taken to the function (it prints 1 at every timer tick).
Another way I tried is to create score variable with bigger scope than just function. In this solution no error is thrown, but Message(score) called after incrementing the score value showed nothing.
I really don't have idea what Im doing wrong, so an help will be greatly appreciated ;).
Below I put the code, onPlayerEnterCheckpoint method is the place where issue happens.
local RED = Colour(255,0,0);
local BLUE = Colour(0,0,255);
local WHITE = Colour(255,255,255);
//
class DominationTeam
{
Name = null;
TeamColour = WHITE;
Score = 0;
constructor(colorOfTheTeam)
{
Score = 0;
if(colorOfTheTeam == RED || colorOfTheTeam == BLUE)
TeamColour = colorOfTheTeam ;
Name = colorOfTheTeam == RED ? "Red" : "Blue";
}
}
//
local redTeam = DominationTeam(RED);
local blueTeam = DominationTeam(BLUE);
local domPointBlip = null;
local scoreTimer = null;
//
function onPlayerSpawn(player,spawn)
{
local playerCount = GetPlayerCount();
player.Team = playerCount % 2 == 0 ? 1 : 0 ;
}
function onPlayerCommand(player,cmd,text)
{
if (cmd == "domination")
{
local playerPos = player.Pos;
local checkpointPos = Vector(playerPos.x + 5, playerPos.y + 5, playerPos.z);
CreateCheckpoint(checkpointPos,2.0, WHITE);
domPointBlip = CreateBlip(BLIP_NONE, checkpointPos);
domPointBlip.Colour = WHITE;
Message("Domination begins!");
}
}
function SetTeamScore(team)
{
team.Score+=1;
::print(team.Score);
}
function onPlayerEnterCheckpoint(player, cp)
{
local playerTeamId = player.Team;
cp.Colour = playerTeamId == 0 ? RED : BLUE ;
domPointBlip.Colour = playerTeamId == 0 ? 0 : 1;
local playerTeam = playerTeamId == 0 ? redTeam : blueTeam;
Message(playerTeam.Name + " " + playerTeam.Score);
NewTimer("SetTeamScore", 3000, 5, playerTeam);
}
-
megamind, are you retarded? no such event exist.
Stop trying to help if you havent got any idea about what functions exist. Youre making a retarded faggot of yourself. I really dont know from where idiots like you come from. Maybe from pakishitstan. Stick to playing.
For the topic starter:
create an array for player team
playerteam <- array(128,null)
then, in onplayerspawn
function onPlayerSpawn(player,spawn)
{
local playerCount = GetPlayerCount();
playerteam[player.ID] = playerCount % 2 == 0 ? 1 : 0 ;
}
replace the other playerTeam things with playerteam[player.ID]
What a shut u r this code doesn't work maybe you should leave coding
Fuk off
-
This code actually works much more than your brain ;)
doesnt work's loser! dweeb
-
I already know that your losing brain doesnt work, child ;)
so why u arguing ???? ;)
-
Ok so the problem was with passing class instance member to function invoked in timer. I resolved it by passing teamId and increasing red or blue team score based on that.
Doppelherz and mega mind : no really need for offensive behavior like that. Stay cool ;).