PDA

View Full Version : OnPlayerCommandPerformed - PROBLEM


SuperChock
27/12/2011, 11:10 PM
Hello, I'm using this code, but don't work correctly:


public OnPlayerCommandPerformed(playerid, cmdtext[], success)
{
if(pLs[playerid][pBlock] > GetTickCount())
return SendClientMessage(playerid, 0xFF0000FF, "Forbidden commands flood.");
pLs[playerid][pBlock] = GetTickCount() + 3000;
if(!success)
return SendClientMessage(playerid, 0xFF0000FF, "Ops! Unknown Command!");
return 1;
}


When the flood happens, the message is displayed but the command is executed along :(

Mikkel_Pedersen
27/12/2011, 11:19 PM
Go from:

return SendClientMessage(playerid, 0xFF0000FF, "Forbidden commands flood.");

to

return SendClientMessage(playerid, 0xFF0000FF, "Forbidden commands flood."), 0;

SuperChock
27/12/2011, 11:52 PM
But I've tried returning 0 and didn't work O.o

EDIT: Besides not working with return 0, the message "SERVER: Unknown Command." is displayed ???

BrandyPenguin
27/12/2011, 11:57 PM
I think that you have add check for all the commands because that callback will called when command action is done. I may misunderstand that public also.

SuperChock
28/12/2011, 12:02 AM
All commands? I'm still not crazy... HAHAHAHAHAHA.

If I really need to put in all the commands, I have taken this system. :(

Mikkel_Pedersen
28/12/2011, 12:03 AM
Oh my fault. I should have told you to use "OnPlayerCommandReceived(playerid, cmdtext[])" instead. In this callback, if you return 0, the command won't be performed.

And forget what I said about returning 0 in "OnPlayerCommandPerformed(playerid, cmdtext[], success)" As that will actually return the default "Server: Unknown command." text.

SuperChock
28/12/2011, 12:06 AM
public OnPlayerCommandReceived(playerid, cmdtext[])
{
if(pLs[playerid][pBlock] > GetTickCount())
return SendClientMessage(playerid, 0xFF0000FF, "Forbidden commands flood."), 0;
pLs[playerid][pBlock] = GetTickCount() + 3000;
return 1;
}


This?

Mikkel_Pedersen
28/12/2011, 12:08 AM
I think that should work. Can't gurantee, but try it out. The odds are better while using the actual callback that was made for denying a command to be performed.

SuperChock
28/12/2011, 12:12 AM
Yeah, very good. It worked perfectly.

Thank you very much :D