Return CMD -
Peveral - 14.09.2017
Hello,So i have this code:
PHP код:
if(strcmp(cmd, "/enter", true) == 0)
{
Bla bla bla
}
I wanna return this cmd "/enter" somewhere else.
Any idea how to return it?
I cant use "return cmd_enter(playerid, params);" cuz im not using zcmd.
If there is anyways to return it or any other ways,I would like to learn.
Re: Return CMD -
Vince - 14.09.2017
You put all the contents of that command in a separate function and then you call that function from wherever you want. Return cmd_ is, IMO, a poor design choice.
Re: Return CMD -
Zeth - 14.09.2017
you can make a function then run that program on that cmd and as on other function like what Vince said. Here is a example:
PHP код:
forward returncommand(playerid);
public returncommand(playerid)
{
Bla bla bla //content
return 1; //return the function
}
then you can use it wherever you want.
PHP код:
if(strcmp(cmd, "/enter", true) == 0)
{
returncommand(playerid);
}
Re: Return CMD -
Peveral - 14.09.2017
hmm Thanks,Where should i make functions?Can i just make them anywhere or there is any place for them?
Re: Return CMD -
Zeth - 14.09.2017
Quote:
Originally Posted by Peveral
hmm Thanks,Where should i make functions?Can i just make them anywhere or there is any place for them?
|
Yeah you can place them anywhere, there is no problem.
Re: Return CMD -
Peveral - 14.09.2017
Well there are errors,
undefined symbol "returncommand"
I defined it already but idk why
Re: Return CMD -
Zeth - 14.09.2017
did u made forward and public of returncommand?
Re: Return CMD -
Peveral - 14.09.2017
Yes,Just like you said
Re: Return CMD -
Peveral - 14.09.2017
I have this now
PHP код:
forward returnenter(playerid);
public returnenter(playerid)
{
My Codes
}
if(strcmp(cmd, "/enter", true) == 0)
{
returnenter(playerid);
}
But it will say undefined symbol returnenter
Re: Return CMD -
Peveral - 14.09.2017
so guys any idea
Respuesta: Return CMD -
Cothect - 14.09.2017
You defined 'returnenter(playerid) ' within OnPlayerCommandText? you not can define a new callback inside of other callback.
Re: Return CMD -
Peveral - 15.09.2017
Hmm,So where should i make function
Respuesta: Re: Return CMD -
Cothect - 15.09.2017
Quote:
Originally Posted by Peveral
Hmm,So where should i make function
|
The callbacks are the 'public', within them you can not define stocks, nor other callbacks, example of the erroneous:
Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
forward hello();
public hello()
{
// code
}
//or
stock hello2()
{
// code
}
//or
hello3()
{
// code
}
return 0;
}
Right:
Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
if(strcmp(cmd, "/enter", true) == 0)
{
hello();
hello2();
hello3();
}
return 0;
}
forward hello()
public hello()
{
// code
}
stock hello2()
{
// code
}
hello3()
{
// code
}
Re: Return CMD -
Peveral - 15.09.2017
Thanks alot
Re: Return CMD -
iSpark - 15.09.2017
Well if you're using the callback OnPlayerCommamdText() to give in the functionality to the commands then why not call OnPlayerCommamdText() from some where else (function) with the parameter defined by you, in this case /enter.
i.e.
Код:
OnPlayerCommandText(playerid, cmdtext[])
{
if(!strcmp(cmdtext, "/enter"))
// code
return 1;
}
Then later somewhere else.
Код:
MyFunc(playerid)
{
OnPlayerCommandText(playerid, "/enter");
}
P.S. Don't mind the indentation or some minor error, posted this via my phone.
Re: Return CMD -
Paulice - 15.09.2017
Above.
Call OnPlayerCommandText with the command in cmdtext parameter.