/messageon and /messageoff
#1

hi,
i made some teleport commands and whit every teleport all the other players get a message. Now i like to turn on and off the message for every player. I tried it but i failed:

Код:
if(strcmp("/messageoff",cmdtext,true) == 0)
	{
 	if(GetPVarInt(playerid,"SendJumpMessage") == 0)
	{
	SendClientMessage(playerid,COLOR_YELLOW,"Jumpmessages are now OFF!");
	SetPVarInt(playerid,"SendJumpMessage",1);
	}
	else
	{
	SendClientMessage(playerid,COLOR_YELLOW,"Jumpmessages are already off!");
	}
	return 1;
}


	if(strcmp("/messageon",cmdtext,true) == 0)
	{
	if(GetPVarInt(playerid,"SendJumpMessage") == 1)
	{
	SendClientMessage(playerid,COLOR_YELLOW,"Jumpmessages are now ON!");
	SetPVarInt(playerid,"SendJumpMessage",0);
	}
	else
	{
	SendClientMessage(playerid,COLOR_YELLOW,"Jumpmessages are already on!");
	}
	return 1;
}
And here are the teleport:
Код:
    if(!strcmp(strget(cmdtext,0),"/cave"))
	{
	if(GetPVarInt(playerid,"jump") == 0)
	{
	if(!strlen(strget(cmdtext,1)))
	return
	SendClientMessage(playerid,COLOR_GREY,"Use: /cave 1 - 25");
	new cave = strval(strget(cmdtext,1));
	new name[MAX_PLAYER_NAME];
	new string[128];
	GetPlayerName(playerid,name,sizeof(name));
	SetPVarInt(playerid, "jump", 1);
	SetTimerEx("JumpTimer",7800,false,"i",playerid);
	SetTimerEx("caveloading",1500,false,"i",playerid);
	GivePlayerWeapon(playerid,46,1);
	for(new i; i < MAX_PLAYERS; i++)
	TogglePlayerControllable(playerid,0);
	{
	if(cave==1)
	{
	SetPlayerPos(playerid,2000.8845,-161.3129,240.9698);
	format(string,sizeof(string),"* [ID: %d] %s has teleported to /cave 1",playerid,name);
	if(GetPVarInt(i,"SendJumpMessage") == 0)
	{
	SendClientMessageToALL(COLOR_WHITE,string);
	}}
	if(cave==2)
	{
	SetPlayerPos(playerid,-3179.7832,-998.5700,770.7665);
	format(string,sizeof(string),"* [ID: %d] %s has teleported to /cave 2",playerid,name);
	if(GetPVarInt(i,"SendJumpMessage") == 0)
	{
	SendClientMessageToALL(COLOR_WHITE,string);
	}}
I hope you know what i mean and you can help me
Reply
#2

Simple, you need FOREACH include, just search in ******, don't be lazy okay?

pawn Код:
// A simple replace for your command ( messageon and messageoff )
if ( !strcmp( cmdtext, "/messages", true ) )
{
    SetPVarInt( playerid, "SendJumpMessage", ( GetPVarInt( playerid, "SendJumpMessage" ) == 1 ) ? 0 : 1 );

    switch ( GetPVarInt( playerid, "SendJumpMessage" ) )
    {
        case 0 : SendClientMessage( playerid, COLOR_YELLOW, "Jump messages are now on." );
        case 1 : SendClientMessage( playerid, COLOR_YELLOW, "Jump messages are now off." );
    }

    return 1;
}

// Example teleport cmd

if ( !strcmp( cmdtext, "/middleOfSA", true ) )
{
    SetPlayerPos( playerid, 0.0, 0.0, 0.0 + 3.0 );

    foreach (Player, i)
    {
        if ( GetPVarInt( i, "SendJumpMessage" ) == 0 )
        {
            new
                string[ 128 ], name[ 24 ]
            ;

            GetPlayerName( playerid, name, sizeof ( name ) );
   
            format( string, sizeof ( string ), "* [ID: %d] %s has teleported to /middleOfSA", playerid, name );

            SendClientMessage( i, COLOR_WHITE, string );
        }
    }

    return 1;
}

// Sorry for crappy indentation
Reply
#3

what does the foreach do?
Reply
#4

A loop, faster than for ( new i; i < MAX_PLAYERS; i ++ )

This forum requires that you wait 120 seconds between posts. Please try again in 39 seconds. ( Why!? I was trying to help someone :\ )
Reply
#5

Why using 2 commands? Why not use 1 command that toggle's it on or off by using a variable. In my opinion it would be more effective.


Here an example:
pawn Код:
//Somewhere at the beginning of the script
new ShowMessages[MAX_PLAYERS];


//under OnPlayerConnect
ShowMessages[playerid] = 1;


//under OnPlayerCommand
if(strcmp(cmd, "/togglemessage", true) == 0)
{
    if(IsPlayerConnected(playerid))
    {
        if(ShowMessages[playerid] == 1)
        {
            ShowMessages[playerid] = 0;
            SendClientMessage(playerid, COLOR_WHITE, "You have {00FFFF}Disabled {FFFFFF}the messages, Type /togglemessage again to toggle it."); //Not sure if both colours are correct :P just a guess.
            return 1;
        }
        if(ShowMessages[playerid] == 0)
        {
            ShowMessages[playerid] = 1;
            SendClientMessage(playerid, COLOR_WHITE, "You have {FFFF00}Enabled{FFFFFF} the messages, Type /togglemessage again to toggle it."); //Not sure if both colours are correct :P just a guess.
            return 1;
        }
    }
    return 1;
}


And in every of your teleport commands, add the codes that is shown below.
pawn Код:
if(ShowMessages[playerid] == 1)
{
SendClientMessage(playerid, 0x........, "You have been teleported to ...");
}
There is no need to add (view codes below), because it there isnt any codes needed when ShowMessages is false (ShowMessages == 0).
pawn Код:
if(ShowMessages[playerid] == 0)
{
    //Add Pawno Codes
}

This seems very complecated but once you get it its very simple, but I hope this helps.

Regards,
Rolyy
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)