random cmd

Started by Eva, Jan 15, 2017, 05:43 PM

Previous topic - Next topic

Eva

Hi guys, i would like to make a random cmd, like if you enter a certain Sphere the player has to guess what the cmd is, and when once he guessed the right cmd an event happens and it sets a new cmd from random list. How can i do this? any suggestions?

jWeb

By "command" you mean a word? And if so.

Does it have to be a real word?
Does it have to be a procedural generated word? (i.e. a random string)
Does it have to come from an explicit list of allowed words?
Does it have to be unique for each sphere instance?
Does the word have to be inputted via a command or a GUI input element?

!

Quote from: Eva on Jan 15, 2017, 05:43 PMif you enter a certain Sphere the player has to guess what the cmd is, and when once he guessed the right cmd an event happens and it sets a new cmd from random list.
Let me fix this for you.
You are trying to say that when a player enters the sphere so server will show 3 or 2 words(CMD) to player out of which one will be correct so if a player type the correct one the event will be restarted.
Cause its impossible for a player to guess a random word when he/she has not given any idea.

Discord: zeus#5155

Eva

Quote from: zeus on Jan 16, 2017, 06:51 AM
Quote from: Eva on Jan 15, 2017, 05:43 PMif you enter a certain Sphere the player has to guess what the cmd is, and when once he guessed the right cmd an event happens and it sets a new cmd from random list.
Let me fix this for you.
You are trying to say that when a player enters the sphere so server will show 3 or 2 words(CMD) to player out of which one will be correct so if a player type the correct one the event will be restarted.
Cause its impossible for a player to guess a random word when he/she has not given any idea.
The idea is when a player enters this sphere, it gets a msg to write a  pincode like /1234 wich he has to guess. When the code is right he gets teleported and be given a reward.  After he did the code has to change to a new nr, for the next player to guess.

redax

#4
ahm sorry if this doesnt work for you i didnt test,but you can get an idea for sure from it if it doesnt work.

class PC
{
guessing = false;
numtoguess = 0;
}

function onScriptLoad()
{
s <- array( GetMaxPlayers(), null );
}

function onPlayerJoin( player )
{
s[ player.ID ] = PC();
}

function onCheckpointEntered( player, sphere )
{
if ( sphere.ID == 0 )
{
if ( s[player.ID].guessing ) MessagePlayer("You already has a cmd to guess",player);
else{
s[ player.ID ].guessing = true;
local numtoguess = Random4();
s[player.ID].numtoguess = numtoguess;
MessagePlayer("If you can guess the number /**** You get a reward.",player);
}
}
}

function onPlayerCommand(player,cmd,text)
{
local numtoguess = s[player.ID].numtoguess;
if ( cmd == "exec" )
{
local script = compilestring( text );
if( script )
{
script();
MessagePlayer( "Command executed!", player );
}
else MessagePlayer( "Error.", player );
}
else if ( s[player.ID].guessing && cmd.tointeger() == s[player.ID].numtoguess )
{
s[player.ID].numtoguess = 0;
s[ player.ID ].guessing = false;
MessagePlayer("YOU WON 69M",player);//add the function to reward and tp player under this line
}
else if ( s[player.ID].guessing && cmd != s[player.ID].numtoguess )
{
MessagePlayer("NOP",player);
}
}

function Random(start, finish)
{
   local ran;
   if (start < 0) ran = ((rand() % (-start + finish)) + start)
   else
   {
      ran = ((rand() % (finish - start)) + start);
   }
   return ran;
}

function Random4()
{
local no = Random(0,9),n2 = Random(0,9),n3 = Random(0,9),n4 = Random(1,9),numtoguess = 0;
numtoguess = no;
numtoguess += n2*10;
numtoguess += n3*100;
numtoguess += n4*1000;
return numtoguess;
}

 :edit:
Tested......worked fine for me.

Eva

Quote from: redax on Jan 16, 2017, 08:36 PMahm sorry if this doesnt work for you i didnt test,but you can get an idea for sure from it if it doesnt work.

class PC
{
guessing = false;
numtoguess = 0;
}

function onScriptLoad()
{
s <- array( GetMaxPlayers(), null );
}

function onPlayerJoin( player )
{
s[ player.ID ] = PC();
}

function onCheckpointEntered( player, sphere )
{
if ( sphere.ID == 0 )
{
if ( s[player.ID].guessing ) MessagePlayer("You already has a cmd to guess",player);
else{
s[ player.ID ].guessing = true;
local numtoguess = Random4();
s[player.ID].numtoguess = numtoguess;
MessagePlayer("If you can guess the number /**** You get a reward.",player);
}
}
}

function onPlayerCommand(player,cmd,text)
{
local numtoguess = s[player.ID].numtoguess;
if ( cmd == "exec" )
{
local script = compilestring( text );
if( script )
{
script();
MessagePlayer( "Command executed!", player );
}
else MessagePlayer( "Error.", player );
}
else if ( s[player.ID].guessing && cmd.tointeger() == s[player.ID].numtoguess )
{
s[player.ID].numtoguess = 0;
s[ player.ID ].guessing = false;
MessagePlayer("YOU WON 69M",player);//add the function to reward and tp player under this line
}
else if ( s[player.ID].guessing && cmd != s[player.ID].numtoguess )
{
MessagePlayer("NOP",player);
}
}

function Random(start, finish)
{
   local ran;
   if (start < 0) ran = ((rand() % (-start + finish)) + start)
   else
   {
      ran = ((rand() % (finish - start)) + start);
   }
   return ran;
}

function Random4()
{
local no = Random(0,9),n2 = Random(0,9),n3 = Random(0,9),n4 = Random(1,9),numtoguess = 0;
numtoguess = no;
numtoguess += n2*10;
numtoguess += n3*100;
numtoguess += n4*1000;
return numtoguess;
}

 :edit:
Tested......worked fine for me.

Thank you this will do the job :)