An error and a question
#1
First the error:
with this code, when I execute a command, it says Unknow command and Player not found, but the code is executed, for my case it gives me the error I said, but mobs spawned.
Code:
function HandleApocalypseCommand( Split, Player )
       local HasSpawned = false;
       local KillPlayer = function(OtherPlayer)
           if (OtherPlayer:GetName() == Split[2]) then
               OtherPlayer:GetWorld():SpawnMob( OtherPlayer:GetPosX(), OtherPlayer:GetPosY(), OtherPlayer:GetPosZ(), 50 );
               OtherPlayer:GetWorld():SpawnMob( OtherPlayer:GetPosX(), OtherPlayer:GetPosY(), OtherPlayer:GetPosZ(), 50 );
               OtherPlayer:GetWorld():SpawnMob( OtherPlayer:GetPosX(), OtherPlayer:GetPosY(), OtherPlayer:GetPosZ(), 95 );
               OtherPlayer:GetWorld():SpawnMob( OtherPlayer:GetPosX(), OtherPlayer:GetPosY(), OtherPlayer:GetPosZ(), 95 );
               OtherPlayer:GetWorld():SpawnMob( OtherPlayer:GetPosX(), OtherPlayer:GetPosY(), OtherPlayer:GetPosZ(), 52 );
               OtherPlayer:GetWorld():SpawnMob( OtherPlayer:GetPosX(), OtherPlayer:GetPosY(), OtherPlayer:GetPosZ(), 52 );
               OtherPlayer:GetWorld():SpawnMob( OtherPlayer:GetPosX(), OtherPlayer:GetPosY(), OtherPlayer:GetPosZ(), 57 );
               OtherPlayer:GetWorld():SpawnMob( OtherPlayer:GetPosX(), OtherPlayer:GetPosY(), OtherPlayer:GetPosZ(), 51 );
               OtherPlayer:GetWorld():SpawnMob( OtherPlayer:GetPosX(), OtherPlayer:GetPosY(), OtherPlayer:GetPosZ(), 54 );
               HasSpawned = true;
           end
       end

       local dowithplayer = function(OtherPlayer)
          
       end
      
       cRoot:Get():FindAndDoWithPlayer(Split[2], KillPlayer);
       if (HasKilled) then
           Player:SendMessage( "You're causing the die of ..Split[2]..!");
       else
           Player:SendMessage( "Player not found" );
       end        
       if Split[2] == nil then
           Player:SendMessage( cChatColor.Green .. "Usage: /creeper [Player]" )
           return true
       end
end

Now the question:
Is there any way of set a player on fire?
I searched in API.txt and I con't find anything to to that.
Reply
Thanks given by:
#2
the only way i can think of is by settings the block where the player is on fire.
Reply
Thanks given by:
#3
(05-01-2013, 04:42 AM)STR_Warrior Wrote: the only way i can think of is by settings the block where the player is on fire.
Ok, I'll search in the API
Reply
Thanks given by:
#4
(05-01-2013, 04:29 AM)tonibm19 Wrote: First the error:
with this code, when I execute a command, it says Unknow command and Player not found, but the code is executed, for my case it gives me the error I said, but mobs spawned.
Code:
function HandleApocalypseCommand( Split, Player )
       local HasSpawned = false;
       local KillPlayer = function(OtherPlayer)
           if (OtherPlayer:GetName() == Split[2]) then
               OtherPlayer:GetWorld():SpawnMob( OtherPlayer:GetPosX(), OtherPlayer:GetPosY(), OtherPlayer:GetPosZ(), 50 );
               OtherPlayer:GetWorld():SpawnMob( OtherPlayer:GetPosX(), OtherPlayer:GetPosY(), OtherPlayer:GetPosZ(), 50 );
               OtherPlayer:GetWorld():SpawnMob( OtherPlayer:GetPosX(), OtherPlayer:GetPosY(), OtherPlayer:GetPosZ(), 95 );
               OtherPlayer:GetWorld():SpawnMob( OtherPlayer:GetPosX(), OtherPlayer:GetPosY(), OtherPlayer:GetPosZ(), 95 );
               OtherPlayer:GetWorld():SpawnMob( OtherPlayer:GetPosX(), OtherPlayer:GetPosY(), OtherPlayer:GetPosZ(), 52 );
               OtherPlayer:GetWorld():SpawnMob( OtherPlayer:GetPosX(), OtherPlayer:GetPosY(), OtherPlayer:GetPosZ(), 52 );
               OtherPlayer:GetWorld():SpawnMob( OtherPlayer:GetPosX(), OtherPlayer:GetPosY(), OtherPlayer:GetPosZ(), 57 );
               OtherPlayer:GetWorld():SpawnMob( OtherPlayer:GetPosX(), OtherPlayer:GetPosY(), OtherPlayer:GetPosZ(), 51 );
               OtherPlayer:GetWorld():SpawnMob( OtherPlayer:GetPosX(), OtherPlayer:GetPosY(), OtherPlayer:GetPosZ(), 54 );
               HasSpawned = true;
           end
       end

       local dowithplayer = function(OtherPlayer)
          
       end
      
       cRoot:Get():FindAndDoWithPlayer(Split[2], KillPlayer);
       if (HasKilled) then
           Player:SendMessage( "You're causing the die of ..Split[2]..!");
       else
           Player:SendMessage( "Player not found" );
       end        
       if Split[2] == nil then
           Player:SendMessage( cChatColor.Green .. "Usage: /creeper [Player]" )
           return true
       end
end
for the unknown command, its easy. put return true before the last end.

i think you should change " if (HasKilled) then" to "if HasKilled == true then"
Reply
Thanks given by:
#5
(05-01-2013, 04:54 AM)STR_Warrior Wrote: i think you should change " if (HasKilled) then" to "if HasKilled == true then"

Definitely NOT. Do NOT compare boolean values, that's bad practice in C++ and makes the code less readable.

I think the problem is that you're using two variable names: You have HasSpawned and set HasSpawned to true, but then test HasKilled, which, in this piece of code, is undeclared.
Reply
Thanks given by:
#6
(05-01-2013, 06:02 AM)xoft Wrote: Definitely NOT. Do NOT compare boolean values, that's bad practice in C++ and makes the code less readable.

oooowwwww... oops Wink
Reply
Thanks given by:
#7
Setting the player on fire is not yet possible through the API (and even MCServer does a really poor job, especially of un-setting the fire). We haven't yet reached a consensus on where exactly to put the fire handling, whether into cEntity or cPawn.

(05-01-2013, 06:02 AM)xoft Wrote: Definitely NOT. Do NOT compare boolean values, that's bad practice in C++ and makes the code less readable.

To elaborate on that a bit, although I'm gonna be talking C/C++ here, it might be different in Lua: Imagine you have two bool values and want to compare them. An unsuspecting victim might try a simple code like
if (BoolVal1 == BoolVal2)
However, this won't work. The compiler is free to use zero for false and nonzero for true, which means two values that are logically true needn't be actually equal. "5" is true, "7" is true, but 5 != 7.
Doing a comparison like
if (BoolVal == true)
you're comparing BoolVal's value (which could be a number, really) with "1" or "-1" or even "255", depending on the compiler.

From another point of view, using code like this is somewhat misleading:
if (ShouldDoIt == false)

So the best practice is to use bool values directly:
if (ShouldDoIt)
{
  DoIt();
}
if (!ShouldExit)
{
  DoIt();
}
Reply
Thanks given by:
#8
(05-01-2013, 06:02 AM)xoft Wrote: I think the problem is that you're using two variable names: You have HasSpawned and set HasSpawned to true, but then test HasKilled, which, in this piece of code, is undeclared.
No, it isn't, i did this error only with this command. With other commands like /creeper it works.
As STR_Warrior said, I thing that the problem is that I didn't put return true in the final. I'll fix it.
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)