Return CMD
#1

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.
Reply
#2

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.
Reply
#3

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); 

Reply
#4

hmm Thanks,Where should i make functions?Can i just make them anywhere or there is any place for them?
Reply
#5

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.
Reply
#6

Well there are errors,
undefined symbol "returncommand"
I defined it already but idk why
Reply
#7

did u made forward and public of returncommand?
Reply
#8

Yes,Just like you said
Reply
#9

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
Reply
#10

so guys any idea
Reply
#11

You defined 'returnenter(playerid) ' within OnPlayerCommandText? you not can define a new callback inside of other callback.
Reply
#12

Hmm,So where should i make function
Reply
#13

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
}
Reply
#14

Thanks alot
Reply
#15

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.
Reply
#16

Above.

Call OnPlayerCommandText with the command in cmdtext parameter.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)