What is wrong with this?
#1

I've been experimenting with this for a while now, but i can't figure out why this isnt working!

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
	new vehicle = GetPlayerVehicleID(playerid); //The vehicle ID the player is in
	new plrHP = GetPlayerHealth(playerid); //The players health

	if (strcmp("/godon", cmdtext, true, 10) == 0) //God mode for both vehicle and player, admin cmd || ON
	{
		if(IsPlayerInAnyVehicle(playerid))
		{
 			SetPlayerHealth(playerid, 100000);
 			SetVehicleHealth(vehicle, 1000000);
		}
		else
		{
 			SetPlayerHealth(playerid, 100000);
		}
 		SendClientMessage(playerid, 0xFF0000FF, "ACCESS: God mode ON");
 		return 1;
	}
	if (strcmp("/godoff", cmdtext, true, 10) == 0) //God mode for both vehicle and player, admin cmd || OFF
	{
 		if(IsPlayerInAnyVehicle(playerid))
	 	{
	  	SetPlayerHealth(playerid, 100);
	  	SetVehicleHealth(vehicle, 1000);
		}
		else
		{
		  SetPlayerHealth(playerid, 100);
		}
		SendClientMessage(playerid, 0xFF0000FF, "ACCESS: God mode OFF");
		return 1;
	}
	return SendClientMessage(playerid, 0xFF0000FF, "ERROR: Unknown command");
}
(color codes are temporary)
Reply
#2

Try that.
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (!strcmp("/godon", cmdtext)) //God mode for both vehicle and player, admin cmd || ON
    {
        if(IsPlayerInAnyVehicle(playerid))
        {
            SetPlayerHealth(playerid, 100000);
            SetVehicleHealth(GetPlayerVehicleID(playerid), 1000000);
        }
        else
        {
            SetPlayerHealth(playerid, 100000);
        }
        SendClientMessage(playerid, 0xFF0000FF, "ACCESS: God mode ON");
        return 1;
    }
    if (!strcmp("/godoff", cmdtext)) //God mode for both vehicle and player, admin cmd || OFF
    {
        if(IsPlayerInAnyVehicle(playerid))
        {
          SetPlayerHealth(playerid, 100);
          SetVehicleHealth(GetPlayerVehicleID(playerid), 1000);
        }
        else
        {
          SetPlayerHealth(playerid, 100);
        }
        SendClientMessage(playerid, 0xFF0000FF, "ACCESS: God mode OFF");
        return 1;
    }
    return SendClientMessage(playerid, 0xFF0000FF, "ERROR: Unknown command");
}
Reply
#3

It works now, thanks

What did you do?
Reply
#4

Quote:
Originally Posted by Coolman12
It works now, thanks

What did you do?
He removed these.
pawn Код:
new vehicle = GetPlayerVehicleID(playerid); //The vehicle ID the player is in
new plrHP = GetPlayerHealth(playerid); //The players health
and neatened up your code.
Reply
#5

Oh

I didn't know they could cause these things
Reply
#6

Well they didn't, they were just unnecessary. I think your problem was this.

if (strcmp("/godon", cmdtext, true, 10) == 0)

You really don't need anything past cmdtext.
Reply
#7

@Coolman12: You should consider using zcmd, it's easier and faster than normal strcmp.
Reply
#8

Ok

Ty for the info.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)