PDA

View Full Version : Not performing correctly (Commands)


Sime30
06/07/2015, 03:25 PM
Edit: Thanks SickAttack, Kaliber and Jefff for solving this problem. I have chosen the best solution to my problem. Use it if you need it.

Problem was in <= MAX_PLAYER_NAME should be < MAX_PLAYER_NAME but here you go better
InGameChatRemoveUnderscore(playerid)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
for(new i = strlen(name)-1; i > -1; i--)
if(name[i] == '_')
name[i] = ' ';

return name;
}




Hi guys!

Haven't use samp servers for a while now and wanted to update my gamemode a bit.
The thing is, my commands stopped working(not all of them).

Things I remember I have done:
- Updated ZCMD to I-ZCMD
- Updated to PlayerPoolSize and VehiclePoolSize , new functions in 0.3.7


I reverted to ZCMD and some of the for(new... loops back to basic ones.


When I type this command, it returns me -Command not recognized-


CMD:b(playerid, params[])
{
new string[128];
if(isnull(params)) return SCM(playerid,LIGHTBLUE,"Use: {FFFFFF}/b [text]");
format(string, sizeof(string), "%s: (( %s ))",InGameChatRemoveUnderscore(playerid),params);
ProxDetector(25.0, playerid, string, COLOR_WHITE);
return 1;
}

public OnPlayerCommandPerformed(playerid, cmdtext[], success)
{
if(!success) return SendClientMessage(playerid, LIGHTBLUE, "Las Vegas: Origins -{FFFFFF} Command not recognized, use {33CCFF}/help" );
return 1;
}


forward ProxDetector(Float:radi, playerid, string[],color);
public ProxDetector(Float:radi, playerid, string[],color)
{
if(PlayerInfo[playerid][Logged] == false) return 1;
new Float:x,Float:y,Float:z;
GetPlayerPos(playerid,x,y,z);
foreach(Player,i)
{
if(IsPlayerInRangeOfPoint(i,radi,x,y,z) && GetPlayerVirtualWorld(playerid) == GetPlayerVirtualWorld(i) && PlayerInfo[i][Logged] == true)
{
SendClientMessage(i,color,string);
}
}
return 1;
}


For example, my command /makebiz works perfectly, while /givemoney will give me money, but will send me a message "Command not recognized".

Yeah, I really don't know what I have done hahaha. Maybe ZCMD, SSCANF2?


CMD:givemoney(playerid, params[])
{
if(PlayerInfo[playerid][AdminLevel] < HEAD_ADMIN) return SendClientMessage(playerid, COLOR_NICERED, "Denied!");
new id,money;
if(sscanf(params, "ui",id,money)) return SendClientMessage(playerid, LIGHTBLUE, "Use:{FFFFFF} /givemoney [ID Player] [Money]");
if(PlayerInfo[id][Logged] == false) return SCM(playerid, COLOR_ERROR,"That player is Offline!");
if(id == INVALID_PLAYER_ID)return SCM(playerid,COLOR_ERROR,"Wrong ID!");
GiveHimMoney(id, money);
new str[100];
format(str,sizeof(str),"You gave{FFFFFF} %s {00C0FF}$%d",InGameChatRemoveUnderscore(id), money);
SendClientMessage(playerid,LIGHTBLUE,str);
format(str,sizeof(str),"Admin {FFFFFF} %s gave you {00C0FF}$%d ",InGameChatRemoveUnderscore(playerid),money);
SendClientMessage(id,LIGHTBLUE,str);
return 1;
}

SickAttack
06/07/2015, 03:39 PM
I assume the function/macro "SCM" is returning 0; therefore, that message shows up. Or it could be a flaw in one of the functions being called.

JaydenJason
06/07/2015, 03:42 PM
I assume the function/macro "SCM" is returning 0; therefore, that message shows up.

I doubt that, I think SCM is just a redefinition of SendClientMessage
#define SCM SendClientMessage

Howeeeeever, I think that it would have to do something with the new zcmd include you have, have you tried to use the previous zcmd include and see if the commands still return the unknown command thing?

Sime30
06/07/2015, 03:44 PM
I doubt that, I think SCM is just a redefinition of SendClientMessage
#define SCM SendClientMessage

Howeeeeever, I think that it would have to do something with the new zcmd include you have, have you tried to use the previous zcmd include and see if the commands still return the unknown command thing?

Yes, it's just a redefinition. Yes, I reverted it to the original Zeex's ZCMD and the problem persists.

SickAttack
06/07/2015, 03:45 PM
I doubt that, I think SCM is just a redefinition of SendClientMessage
#define SCM SendClientMessage

Howeeeeever, I think that it would have to do something with the new zcmd include you have, have you tried to use the previous zcmd include and see if the commands still return the unknown command thing?

Check the functions used in the command and post them here as well. Also you could remove that definition since you are already using SendClientMessage.

Sime30
06/07/2015, 03:57 PM
CMD:b(playerid, params[])
{
new string[128];
if(isnull(params)) return SCM(playerid,LIGHTBLUE,"Use: {FFFFFF}/b [text]");
format(string, sizeof(string), "%s: (( %s ))",InGameChatRemoveUnderscore(playerid),params);
ProxDetector(25.0, playerid, string, COLOR_WHITE);
return 1;
}


ProxDetector is above, and here is InGameChat...

InGameChatRemoveUnderscore(playerid)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
for(new i; i <= MAX_PLAYER_NAME; i++)
{
if(name[i] == '_') name[i] = ' ';
}
return name;
}


The thing is, if I type /b, it shows the usage, but anything after that like /b test will show command not recognized.

Sime30
06/07/2015, 08:16 PM
Any thoughts about this?

SickAttack
06/07/2015, 10:14 PM
The issue is caused by a flaw in "InGameChatRemoveUnderscore(playerid)".

// [ DEVELOPMENT GAMEMODE ]

// INCLUDES:

#include <a_samp>
#include <zcmd>

// DEFINES:

#define isnull(%1) ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))

// MAIN:

main()
{
print("Development Mode: rp_name.amx");
}

// CALLBACKS:

public OnGameModeInit()
{
return 1;
}

public OnGameModeExit()
{
return 1;
}

// COMMANDS:

CMD:b(playerid, params[])
{
new string[144];
if(isnull(params)) return SendClientMessage(playerid, -1, "Usage: /b (message).");

format(string, sizeof(string), "%s: (( %s ))", ReplaceString("_", " ", PlayerName(playerid)), params);
SendClientMessageToAll(-1, string);
return 1;
}

// FUNCTIONS:

stock PlayerName(playerid)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, MAX_PLAYER_NAME);
return name;
}

stock ReplaceString(search[], replace[], source[])
{
new string[256], length;
for(new i = 0; i < strlen(source); i ++)
{
if(strlen(search) > 1 && i != (strlen(source) - 1))
{
new bool:match = false, start = i;
for(new j = 0; j < strlen(search) && !match; j ++)
{
if(source[i] != search[j] && j == 0)
{
string[length] = source[i];
match = true;
}
else
{
if(source[i] == search[j]) i ++;
else match = true;
}
}

if(match == true)
{
while(start <= i)
{
string[length] = source[start];
length ++;
start ++;
}
}
else
{
for(new j; j < strlen(replace); j ++)
{
string[length] = replace[j];
length ++;
}

i = (start + (strlen(search) - 1));
}
}
else
{
if(strlen(search) == 1 && source[i] == search[0])
{
for(new j; j < strlen(replace); j ++)
{
string[length] = replace[j];
length ++;
}
}
else
{
string[length] = source[i];
length ++;
}
}
}

string[length] = EOS;
return string;
}

Sime30
06/07/2015, 10:30 PM
@SickAttack

That done the trick. Just tested and it works as intended.
I don't know where did I get my code from, maybe some snippet from this forum. Anyway, I will change all my codes now to this and test. I will reply here for further information.


Thanks man :)

Kaliber
06/07/2015, 10:44 PM
@SickAttack:

Your function ReplaceString is horrible :mad:

Just easy do this:

stock ReplaceString(const search[],const replace[], source[], size=sizeof source) //(c) by Kaliber
{
new i=strfind(source,search),tmp=strlen(search);
if(i==-1) return 0;
for( ; i!=-1; i=strfind(source,search,false,i+1))
{
strdel(source,i,i+tmp),strins(source,replace,i,siz e);
}
return 1;
}

Greekz :cool:

Sime30
06/07/2015, 11:42 PM
@Kaliber

Thanks for your code, but I am having a little problem. First letter of the name won't be shown.

Name_Surname - Default

ame_Surname - Your code

Oh and SickAttack, your code works perfectly. Don't know if I should stick with your code or just fix an issuee in Kaliber's code...

Jefff
07/07/2015, 12:04 AM
Problem was in <= MAX_PLAYER_NAME should be < MAX_PLAYER_NAME but here you go better
InGameChatRemoveUnderscore(playerid)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
for(new i = strlen(name)-1; i > -1; i--)
if(name[i] == '_')
name[i] = ' ';

return name;
}

Sime30
07/07/2015, 12:37 AM
Problem was in <= MAX_PLAYER_NAME should be < MAX_PLAYER_NAME but here you go better
InGameChatRemoveUnderscore(playerid)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
for(new i = strlen(name)-1; i > -1; i--)
if(name[i] == '_')
name[i] = ' ';

return name;
}

YES, I remember changing to <= because I was editing loops. Stupid me.
Your code works great as did SickAttack's. Should I stick with this code then?

Jefff
07/07/2015, 12:42 AM
Yes its ok, simply and short

Sime30
07/07/2015, 12:46 AM
Ok. Thank you very much!!!

I will make an edit to the first post of this thread, "solution" to this problem :)