Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: Debian on Sep 12, 2015, 03:22 PM

Title: How to get a name from a array?
Post by: Debian on Sep 12, 2015, 03:22 PM
Nogoto + on works perfect, but there in nogoto off i get a problem at  nogoto.remove( player.Name ); because it is not a integer. I dont want to use player.ID because  i will save that array while unloading. So this can prevent additional database from making and reduce usage of a lot of databases because i will be using for other scripts too.

else if ( cmd == "nogoto" ) {
if (params[0] == "on") {
if(nogoto.find( player.Name ) == null){
nogoto.push( player.Name );
MessagePlayer( "Players cannot teleport to you.", player );
}
else MessagePlayer( "You have already enabled nogoto.", player );
}
else if (params[0] == "off") {
if(nogoto.find( player.Name ) != null){
nogoto.remove( player.Name );
MessagePlayer( "Players can teleport to you.", player );
}
else MessagePlayer( "You have already disabled nogoto.", player );
}
else  MessagePlayer( "Correct Syntax : /" + cmd + " on/off ", player );
}
Title: Re: How to get a name from a array?
Post by: Thijn on Sep 12, 2015, 03:35 PM
Use tables.

local nogoto = {};
nogoto.rawset(player.Name, true);
nogoto.rawget(player.Name);
nogoto.delete(player.Name);
Title: Re: How to get a name from a array?
Post by: DizzasTeR on Sep 12, 2015, 03:38 PM
According to what I get from your fair enough English, try this.

nogoto.remove( nogoto.find( player.Name ) != null ) );
Title: Re: How to get a name from a array?
Post by: Thijn on Sep 12, 2015, 04:10 PM
Quote from: Doom_Killer on Sep 12, 2015, 03:38 PMAccording to what I get from your fair enough English, try this.

nogoto.remove( nogoto.find( player.Name ) != null ) );
Did you test that? :P
(Hint: The answer is probably no)
Title: Re: How to get a name from a array?
Post by: . on Sep 12, 2015, 04:17 PM
Quote from: Doom_Killer on Sep 12, 2015, 03:38 PMnogoto.remove( nogoto.find( player.Name ) != null ) );

What @Thijn meant:

... ) );
Leftover bracket!

... nogoto.find( player.Name ) != null ...
Wrong use of an expression. The result is always one of two possibilities. Either remove whatever exists at the index "true" if player exists or the index "false" if it doesn't.

But this is an array (if I understand correctly) and thus the boolean result from the expression might be casted to an integer to satisfy the argument requirements and you're again left two possible results. Remove what's at index 0 if the expression is "false" or remove what's at index 1 if the expression is "true".

Final answer: DON'T!
Title: Re: How to get a name from a array?
Post by: DizzasTeR on Sep 12, 2015, 04:23 PM
Don't expect me to be dashing for everyone, just open your eyes and you will find some useful words, IF and only IF you get the point. ( hint: idea ) :p
Title: Re: How to get a name from a array?
Post by: FinchDon on Sep 12, 2015, 04:41 PM
Why you want in array use simple one :\
Title: Re: How to get a name from a array?
Post by: KAKAN on Sep 12, 2015, 04:43 PM
Why ya use like that?
NOTE:- This is just a suggestion.
This one is way far easier than the one u made:-
function onScriptLoad()
{
nogoto <- array(GetMaxPlayers(), false);
}

Here is the cmd:-
else if ( cmd == "nogoto" )
{
if(!text)PrivMessage(player,"Use "+cmd+" <on/off>.");
else
{
switch(text.tolower())
{
case "on":
if ( nogoto[ player.ID ] ) MessagePlayer(">> Your nogoto is already on.",player);
else
{
nogoto[ player.ID ] = true;
PrivMessage(player,"Your nogoto is now on.");
}
break;

case "off":
if ( !nogoto[ player.ID ] ) MessagePlayer(">> Your nogoto is already off.",player);
else
{
nogoto[ player.ID ] = false;
PrivMessage(player,"Your nogoto is now off.");
}
break;

default: PrivMessage(player,"Syntax Error: Use /" + cmd + " <on/off>."); break;
}
}
}

Now you know what is needed to add on your goto cmd tho, Good Luck!
Title: Re: How to get a name from a array?
Post by: Debian on Sep 12, 2015, 05:14 PM
Kakan and finch, this one is for strong in database/... when server unloads.

Finally made it, does  rawset will create a new value each time it is called?

nogoto <- {};   

Onplayerjoin :
   nogoto.rawset(player.Name, true);

else if ( cmd == "nogoto" ) {
if (params[0] == "on") {
if( nogoto.rawget( player.Name ) == false){
nogoto.rawset(player.Name, true);
MessagePlayer( "Players cannot teleport to you.", player );
}
else MessagePlayer( "You have already enabled nogoto.", player );
}
else if (params[0] == "off") {
if( nogoto.rawget( player.Name ) == true){
nogoto.rawset(player.Name, false);
MessagePlayer( "Players can teleport to you.", player );
}
else MessagePlayer( "You have already disabled nogoto.", player );
}
else  MessagePlayer( "Correct Syntax : /" + cmd + " on/off ", player );
}

Title: Re: How to get a name from a array?
Post by: Thijn on Sep 12, 2015, 06:45 PM
Quote from: Debian on Sep 12, 2015, 05:14 PMFinally made it, does  rawset will create a new value each time it is called?
It will not if you use the same key.
Title: Re: How to get a name from a array?
Post by: Debian on Sep 13, 2015, 04:01 AM
This line    nogoto.rawset(player.Name, false); in onplayerjoin is making it false each time a player joins and if i dont use it always gives errors as index of player.Name doesn't exist. for rawget(player.Name).  I tried    nogoto.rawin(player.Name); in onplayerspawn and if( nogoto.rawget( player.Name ) == null ) in command to test whether it works but it is still not working.
Title: Re: How to get a name from a array?
Post by: Thijn on Sep 13, 2015, 09:38 AM
Post your code and a screenshot of the error message.