PDA

View Full Version : Simple global dcmd command wont work -.-


Jack_Leslie
30/08/2011, 04:25 AM
dcmd_g(playerid, params[])
{
new string[128];
if(GetPVarInt(playerid, "Logged") == 0) return SendClientMessage(playerid, COLOR_LIGHTRED, "You are not logged in!");
new message;
if(sscanf(params,"s",message)) return SendClientMessage(playerid, COLOR_ORANGE, "CMD: /g [message]");
format(string, sizeof(string), "[GLOBAL] %s(%d) says: %s", PlayerName(playerid), playerid, message);
SendClientMessageToAll(COLOR_WHITE, string);
return 1;
}


It just keeps sending "CMD: /g [message]"

It's been a while since I used dcmd style, but this should work -.-

=WoR=Varth
30/08/2011, 04:27 AM
dcmd_g(playerid, params[])
{
if(GetPVarInt(playerid, "Logged") == 0) return SendClientMessage(playerid, COLOR_LIGHTRED, "You are not logged in!");
if(sscanf(params,"s[128]",params)) return SendClientMessage(playerid, COLOR_ORANGE, "CMD: /g [message]");
format(params,128, "[GLOBAL] %s(%d) says: %s", PlayerName(playerid), playerid, params);
SendClientMessageToAll(COLOR_WHITE, params);
return 1;
}

Jack_Leslie
30/08/2011, 04:30 AM
dcmd_g(playerid, params[])
{
if(GetPVarInt(playerid, "Logged") == 0) return SendClientMessage(playerid, COLOR_LIGHTRED, "You are not logged in!");
if(sscanf(params,"s[128]",params)) return SendClientMessage(playerid, COLOR_ORANGE, "CMD: /g [message]");
format(params,128, "[GLOBAL] %s(%d) says: %s", PlayerName(playerid), playerid, params);
SendClientMessageToAll(COLOR_WHITE, params);
return 1;
}



Still sends "CMD: /g [message]" even with something after /g

=WoR=Varth
30/08/2011, 04:42 AM
Seems like nothing wrong there.
Check this code:

dcmd_asd(playerid, params[])
{
new int;
if(sscanf(params,"d",int)) return SendClientMessage(playerid, COLOR_ORANGE, "CMD: /g [message]");
format(params,128, "%d", int);
SendClientMessageToAll(COLOR_WHITE, params);
return 1;
}

Jack_Leslie
30/08/2011, 04:54 AM
It's not just that command, it's all my commands, it doesn't detect anything after the command.

=WoR=Varth
30/08/2011, 04:57 AM
Do you have the latest sscanf version?

Jack_Leslie
30/08/2011, 04:58 AM
Yep, I sure do. sscanf2 for r5

=WoR=Varth
30/08/2011, 05:01 AM
Have you tried the code I gave? (/asd)

Jack_Leslie
30/08/2011, 05:05 AM
Have you tried the code I gave? (/asd)

Yep and it replies with "CMD: /g [message]"

=WoR=Varth
30/08/2011, 05:12 AM
Wait a second, I just read my VM.
You have that code on your OnPlayerCommandText?
I think you should read this:
http://wiki.sa-mp.com/wiki/Fast_Commands#dcmd
http://forum.sa-mp.com/showthread.php?t=243191

Jack_Leslie
30/08/2011, 05:13 AM
No, I changed it, I took it off onplayercommandtext, and so now i just have full DCMD,

dcmd(stats, 5, cmdtext);
dcmd(g, 1, cmdtext);
dcmd(nopm, 4, cmdtext);
dcmd(buylevel, 8, cmdtext);

=WoR=Varth
30/08/2011, 05:26 AM
Then it's your sscanf. My code will send a message if you type a number (/asd 123).
Reinstall your plugin perhaps.

Jack_Leslie
30/08/2011, 05:31 AM
No, it's not my sscanf. My sscanf works perfectly on other game modes. Like I said, if I have strcmp styled commands on onplayercommandtext it does the same thing, it doesn't detect anything after /command.

=WoR=Varth
30/08/2011, 05:42 AM
Just get rid the sscanf:

dcmd_g(playerid, params[])
{
if(GetPVarInt(playerid, "Logged") == 0) return SendClientMessage(playerid, COLOR_LIGHTRED, "You are not logged in!");//I suggest to to not using per player variable.
if(!strlen(params)) return SendClientMessage(playerid, COLOR_ORANGE, "CMD: /g [message]");
format(params,128, "[GLOBAL] %s(%d) says: %s", PlayerName(playerid), playerid, params);
SendClientMessageToAll(COLOR_WHITE, params);
return 1;
}

Jack_Leslie
30/08/2011, 08:31 AM
Just get rid the sscanf:

dcmd_g(playerid, params[])
{
if(GetPVarInt(playerid, "Logged") == 0) return SendClientMessage(playerid, COLOR_LIGHTRED, "You are not logged in!");//I suggest to to not using per player variable.
if(!strlen(params)) return SendClientMessage(playerid, COLOR_ORANGE, "CMD: /g [message]");
format(params,128, "[GLOBAL] %s(%d) says: %s", PlayerName(playerid), playerid, params);
SendClientMessageToAll(COLOR_WHITE, params);
return 1;
}


I appericiate your help but if your not going to listen to what the problem actually is, DON'T BOTHER.

The problem IS NOT the sscanf, ANTYHING in ANY commands wether it be DCMD or strcmp, it does not detect anything after the "/command"!

=WoR=Varth
30/08/2011, 08:38 AM
You mean they doesn't have params? I dont get what you said before.
Debug the params for sure.

print(params);//Inside your command before sscanf

Jack_Leslie
30/08/2011, 08:41 AM
Example: (I'm uising strcmp because I'm not gonna convert every command to DCMD until i fix this problem:

One command:

if(strcmp(cmd, "/g", true) == 0 || strcmp(cmd, "/global", true) == 0)
{
if(GetPVarInt(playerid, "Logged") == 0)
{
SendClientMessage(playerid, COLOR_LIGHTRED, "You are not logged in!");
return 1;
}
new length = strlen(cmdtext);
while ((idx < length) && (cmdtext[idx] <= ' '))
{
idx++;
}
new offset = idx;
new result[64];
while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
{
result[idx - offset] = cmdtext[idx];
idx++;
}
result[idx - offset] = EOS;
if(!strlen(result))
{
SendClientMessage(playerid, COLOR_ORANGE, "CMD: /g(lobal) [message]");
return 1;
}
GetPlayerName(playerid, sendername, sizeof(sendername));
format(string, sizeof(string), "[GLOBAL] %s(%d) says: %s", sendername, playerid, result);
SendClientMessageToAll(COLOR_WHITE, string);
return 1;
}


It's meant to check for a result (text typed afte "/g")
If I type no text after "/g", it sends me "CMD: /g(lobal) [message]"
But, if I type text after "/g", it still sends me "CMD: /g(lobal) [message]" instead of the string with the result. Because it thinks there is no result, just like for every other command I have.

=WoR=Varth
30/08/2011, 08:55 AM
Debug your OnPlayerCOmmandText:

print(cmdtext);//Before any of your command/code

Jack_Leslie
30/08/2011, 10:46 AM
Debug your OnPlayerCOmmandText:

print(cmdtext);//Before any of your command/code


My script isn't reading the cmdtext, it prints nothing -.-

Jack_Wilson
30/08/2011, 10:52 AM
What have you got on your OnPlayerCommandText?

Jack_Leslie
30/08/2011, 10:53 AM
public OnPlayerCommandText(playerid, cmdtext[])
{
print(cmdtext);
new string[258];
new tmp[128];
new cmd[128];
new sendername[MAX_PLAYER_NAME];
new giveplayer[MAX_PLAYER_NAME];
new giveplayerid, idx;
cmd = strtok(cmdtext, idx);
if(strcmp(cmd, "/stats", true) == 0)
{
if(GetPVarInt(playerid, "Logged") == 0)
{
SendClientMessage(playerid, COLOR_LIGHTRED, "You are not logged in!");
return 1;
}
new line2[128], line3[128], line4[128], team[128];
format( line2, sizeof(line2), ">> Los Santos Gang Wars Statitics <<");
format( line3, sizeof(line3), "__________________________________________");
new level = PlayerInfo[playerid][pScore];
new admlevel = PlayerInfo[playerid][pAdmin];
new kills = PlayerInfo[playerid][pKills];
new deaths = PlayerInfo[playerid][pDeaths];
new cash = PlayerInfo[playerid][pMoney];
new vip = PlayerInfo[playerid][pVIP];
SendClientMessage(playerid, COLOR_ORANGE, line2);
SendClientMessage(playerid, COLOR_LIGHTBLUE, line3);
format(string, sizeof(string), "Name: %s(%d)", PlayerName(playerid), playerid);
SendClientMessage(playerid, COLOR_WHITE, string);
format(string, sizeof(string), "Level: %d", level);
SendClientMessage(playerid, COLOR_WHITE, string);
format(string, sizeof(string), "Admin Level: %d", admlevel);
SendClientMessage(playerid, COLOR_WHITE, string);
format(string, sizeof(string), "Kills: %d - Deaths: %d", kills, deaths);
SendClientMessage(playerid, COLOR_WHITE, string);
format(string, sizeof(string), "Cash: %d", cash);
SendClientMessage(playerid, COLOR_WHITE, string);
format(string, sizeof(string), "VIP: %d", vip);
SendClientMessage(playerid, COLOR_WHITE, string);
if(gTeam[playerid] == TEAM_GROVE) { team = "Grove St. Gangstas (1)"; }
if(gTeam[playerid] == TEAM_BALLAS) { team = "Temple Drive Ballas (2)"; }
if(gTeam[playerid] == TEAM_AZTECAS) { team = "Los Aztecas (3)"; }
if(gTeam[playerid] == TEAM_VAGOS) { team = "Los Santos Vagos (4)"; }
format(string, sizeof(string), "Team: %s", team);
SendClientMessage(playerid, COLOR_WHITE, string);
format( line4, sizeof(line4), "__________________________________________");
SendClientMessage(playerid, COLOR_LIGHTRED, line4);
return 1;
}
if(strcmp(cmd, "/g", true) == 0 || strcmp(cmd, "/global", true) == 0)
{
if(GetPVarInt(playerid, "Logged") == 0)
{
SendClientMessage(playerid, COLOR_LIGHTRED, "You are not logged in!");
return 1;
}
new length = strlen(cmdtext);
while ((idx < length) && (cmdtext[idx] <= ' '))
{
idx++;
}
new offset = idx;
new result[64];
while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
{
result[idx - offset] = cmdtext[idx];
idx++;
}
result[idx - offset] = EOS;
if(!strlen(result))
{
SendClientMessage(playerid, COLOR_ORANGE, "CMD: /g(lobal) [message]");
return 1;
}
print(cmdtext);
GetPlayerName(playerid, sendername, sizeof(sendername));
format(string, sizeof(string), "[GLOBAL] %s(%d) says: %s", sendername, playerid, result);
SendClientMessageToAll(COLOR_WHITE, string);
return 1;
}
if(strcmp(cmd, "/pm", true) == 0)
{
if(GetPVarInt(playerid, "Logged") == 0)
{
SendClientMessage(playerid, COLOR_LIGHTRED, "You are not logged in!");
return 1;
}
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_ORANGE, "CMD: /pm [playerid/name] [message]");
return 1;
}
giveplayerid = ReturnUser(tmp);
if(GetPVarInt(giveplayerid, "Logged") == 0)
{
SendClientMessage(playerid, COLOR_LIGHTRED, "That player has not logged in!");
return 1;
}
if(playerid == giveplayerid)
{
SendClientMessage(playerid, COLOR_LIGHTRED, "You cannot PM yourself, silly!");
return 1;
}
if(BlockingPM[giveplayerid] == 1)
{
SendClientMessage(playerid, COLOR_LIGHTRED, "That player is blocking PMs!");
return 1;
}
GetPlayerName(playerid, sendername, sizeof(sendername));
GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
new length = strlen(cmdtext);
while ((idx < length) && (cmdtext[idx] <= ' '))
{
idx++;
}
new offset = idx;
new result[96];
while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
{
result[idx - offset] = cmdtext[idx];
idx++;
}
result[idx - offset] = EOS;
if(!strlen(result))
{
SendClientMessage(playerid, COLOR_ORANGE, "CMD: /pm [playerid/name] [message]");
return 1;
}
format(string, sizeof(string), "PM: You have sent a PM to %s.", giveplayer);
SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
format(string, sizeof(string), "PM From %s(%d): %s", sendername, playerid, (result));
SendClientMessage(giveplayerid, COLOR_LIGHTBLUE, string);
return 1;
}
if(strcmp(cmd, "/ban", true) == 0)
{
if(GetPVarInt(playerid, "Logged") == 0)
{
SendClientMessage(playerid, COLOR_LIGHTRED, "You are not logged in!");
return 1;
}
if(PlayerInfo[playerid][pAdmin] < 1)
{
SendClientMessage(playerid, COLOR_LIGHTRED, "ADM: You're not authorized to use this command!");
return 1;
}
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_ORANGE, "ADM: /ban [playerid/name] [ban reason]");
return 1;
}
giveplayerid = ReturnUser(tmp);
if(giveplayerid == INVALID_PLAYER_ID)
{
SendClientMessage(playerid, COLOR_LIGHTRED, "Invalid playerid/name!");
return 1;
}
if(GetPVarInt(giveplayerid, "Logged") == 0)
{
SendClientMessage(playerid, COLOR_LIGHTRED, "That player has not logged in!");
return 1;
}
if(playerid == giveplayerid)
{
SendClientMessage(playerid, COLOR_LIGHTRED, "You cannot ban yourself, silly!");
return 1;
}
GetPlayerName(playerid, sendername, sizeof(sendername));
GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
new length = strlen(cmdtext);
while ((idx < length) && (cmdtext[idx] <= ' '))
{
idx++;
}
new offset = idx;
new result[96];
while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
{
result[idx - offset] = cmdtext[idx];
idx++;
}
result[idx - offset] = EOS;
if(!strlen(result))
{
SendClientMessage(playerid, COLOR_ORANGE, "ADM: /ban [playerid/name] [ban reason]");
return 1;
}
format(string, sizeof(string), "ADM: %s has been banned by an Admin, reason: %s", giveplayer, (result));
SendClientMessageToAll(COLOR_LIGHTRED, string);
format(string, sizeof(string), "ADM: You've been banned by an Admin, reason: %s", (result));
SendClientMessage(giveplayerid, COLOR_LIGHTRED, string);
format(string, sizeof(string), "ADMWARN: %s has banned %s for %s", sendername, giveplayer, (result));
foreach (Player, i)
{
if(PlayerInfo[i][pAdmin] >= 1)
{
SendClientMessage(i, COLOR_LIGHTRED, string);
return 1;
}
}
PlayerInfo[giveplayerid][pBanned] = 1;
format(string, sizeof(string), "Ban Reason: %s", (result));
strmid(PlayerInfo[giveplayerid][pBanReason], string, 0, strlen(string), 255);
Kick(giveplayerid);
return 1;
}
if(strcmp(cmd, "/blockpm", true) == 0)
{
if(GetPVarInt(playerid, "Logged") == 0)
{
SendClientMessage(playerid, COLOR_LIGHTRED, "You are not logged in!");
return 1;
}
if(BlockingPM[playerid] == 0)
{
BlockingPM[playerid] = 1;
SendClientMessage(playerid, COLOR_ORANGE, "CMD: You are now blocking PMs!");
return 1;
}
if(BlockingPM[playerid] == 1)
{
BlockingPM[playerid] = 0;
SendClientMessage(playerid, COLOR_ORANGE, "CMD: You have unblocked PMs!");
return 1;
}
return 1;
}
if(strcmp(cmd, "/buylevel", true) == 0)
{
if(GetPVarInt(playerid, "Logged") == 0)
{
SendClientMessage(playerid, COLOR_LIGHTRED, "You are not logged in!");
return 1;
}
new levelcost = 10000;
new nxtlevel = PlayerInfo[playerid][pScore]+1;
new costlevel = nxtlevel*levelcost;
if(PlayerInfo[playerid][pMoney] < costlevel)
{
format(string, sizeof(string), "You can't afford that! (%d)", costlevel);
SendClientMessage(playerid, COLOR_LIGHTRED, string);
return 1;
}
else
{
GivePlayerMoney(playerid, -costlevel);
PlayerInfo[playerid][pMoney] = PlayerInfo[playerid][pMoney] - costlevel;
PlayerInfo[playerid][pScore]++;
format(string, sizeof(string), "You've bought Level %d for %d!", nxtlevel, costlevel);
SendClientMessage(playerid, COLOR_VAGOS, string);
SetPlayerScore(playerid, nxtlevel);
return 1;
}
return 1;
}
if (strcmp(cmd, "/savepos", true)==0)
{
new Float:X, Float:Z, Float:Y, Float:A;
GetPlayerPos(playerid, X, Y, Z);
GetPlayerFacingAngle(playerid, A);
new File:pos=fopen("OnFootPos.txt", io_append);
format(string, sizeof(string), "(%f, %f, %f, %f);\r\n", X, Y, Z, A);
SendClientMessage(playerid,COLOR_GREY,"OnFootPosition saved to OnFootPos.txt !");
fwrite(pos, string);
fclose(pos);
return 1;
}
if (strcmp(cmd, "/savecampos", true)==0)
{
new Float:X, Float:Z, Float:Y;
GetPlayerCameraPos(playerid, X, Y, Z);
new File:pos=fopen("CameraPos.txt", io_append);
format(string, sizeof(string), "(%f, %f, %f);\r\n", X, Y, Z);
SendClientMessage(playerid,COLOR_GREY,"CameraPos saved to CameraPos.txt !");
fwrite(pos, string);
fclose(pos);
return 1;
}
if(strcmp(cmd, "/kill", true) == 0)
{
SetPlayerHealth(playerid, 0);
format(string, sizeof(string), "%s(%d) has just committed suicide!", PlayerName(playerid), playerid);
SendClientMessageToAll(COLOR_LIGHTRED, string);
return 1;
}
if(strcmp(cmd, "/class", true) == 0)
{
SetPlayerHealth(playerid, 0);
ForceClassSelection(playerid);
format(string, sizeof(string), "%s(%d) has killed himself.", PlayerName(playerid), playerid);
SendClientMessageToAll(COLOR_LIGHTRED, string);
ForceClassSelection(playerid);
return 1;
}
return 0;
}

=WoR=Varth
30/08/2011, 10:59 AM
Do you returning 0 in every end of your OnPlayerCommandText?

Jack_Leslie
30/08/2011, 11:01 AM
Nope, return 1; in every command.

=WoR=Varth
30/08/2011, 11:08 AM
I mean at the end of OnPlayerCommandText

public OnPlayerCommandText(forgot the argument)
{
if(strcmp...............
{
.............
return 1;
}
return 0;
}
In your FS(If you have any)

Jack_Leslie
30/08/2011, 11:09 AM
Look at the code I posted.. it's my whole OnPlayerCommandText, and at the bottom, it's return 0;

=WoR=Varth
30/08/2011, 11:15 AM
Look at the code I posted.. it's my whole OnPlayerCommandText, and at the bottom, it's return 0;

I don't know if you don't have any FS.

Jack_Leslie
30/08/2011, 11:18 AM
No I don't, I would of said if I did