if(strcmp(cmd,"/setworld",true) == 0) { new world; tmp=strtok(cmdtext,idx); if(!strlen(tmp)) return SendClientMessage(playerid,-1,"Use /setworld [WORLD]"); world=strval(tmp); if(world <= 1 || world >= 255) SetPlayerVirtualWorld(playerid,world); return 1; } |
PS: Nгo me julguem,ainda estou aprendendo.
O que hб de errado com meu comando? Vi um tutorial de strtok e usei um comando como exemplo,mas ele nгo muda a world. |
Aparentemente seu cуdigo esta correto !
@edit Vocк quer setar a world do jogador que usar o comando certo ? @off Aconselharia a usar sscanf ! |
if(world <= 1 || world >= 255) |
#include <a_samp> public OnPlayerCommandText(playerid, cmdtext[]) { new cmd[100], idx; cmd = strtok(cmdtext, idx); if (strcmp("/setworld", cmd, true) == 0) { if (IsPlayerAdmin(playerid)) { new tmp1[128], tmp2[128]; tmp1 = strtok(cmdtext, idx); tmp2 = strtok(cmdtext, idx); if (!strlen(tmp1) || !strlen(tmp2)) return SendClientMessage(playerid, -1, "{FFFFFF}Use: /setworld [player] [world]"); if (IsPlayerConnected(strval(tmp1))) return SendClientMessage(playerid, -1, "{FFFFFF}Player nгo conectado."); SetPlayerVirtualWorld(strval(tmp1),strval(tmp2)); } return 1; } return 0; } strtok(const string[], &index) { new length = strlen(string); while ((index < length) && (string[index] <= ' ')) { index++; } new offset = index; new result[20]; while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1))) { result[index - offset] = string[index]; index++; } result[index - offset] = EOS; return result; }
Pode usar isso como Filterscript que vai funcionar
Код:
#include <a_samp> public OnPlayerCommandText(playerid, cmdtext[]) { new cmd[100], idx; cmd = strtok(cmdtext, idx); if (strcmp("/setworld", cmd, true) == 0) { if (IsPlayerAdmin(playerid)) { new tmp1[128], tmp2[128]; tmp1 = strtok(cmdtext, idx); tmp2 = strtok(cmdtext, idx); if (!strlen(tmp1) || !strlen(tmp2)) return SendClientMessage(playerid, -1, "{FFFFFF}Use: /setworld [player] [world]"); if (IsPlayerConnected(strval(tmp1))) return SendClientMessage(playerid, -1, "{FFFFFF}Player nгo conectado."); SetPlayerVirtualWorld(strval(tmp1),strval(tmp2)); } return 1; } return 0; } strtok(const string[], &index) { new length = strlen(string); while ((index < length) && (string[index] <= ' ')) { index++; } new offset = index; new result[20]; while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1))) { result[index - offset] = string[index]; index++; } result[index - offset] = EOS; return result; } |
new cmd[256], idx; cmd = strtok(cmdtext, idx); if(strcmp(cmd, "/SetVirtualWorld", true) == 0) { cmd = strtok(cmdtext, idx); if(!strlen(cmd)) { SendClientMessage(playerid, Vermelho, "[>]"BRANCO" Use /Set VirtualWorld [Player] [Virtual World]"); return 1; } new id = strval(cmd); if(!IsPlayerConnected(id)) { SendClientMessage(playerid, Vermelho, "[>]"BRANCO" Player offline"); return 1; } cmd = strtok(cmdtext, idx); if(!strlen(cmd)) { SendClientMessage(playerid, Vermelho, "[>]"BRANCO" Use /Set VirtualWorld [Player] [Virtual World]"); return 1; } new vw = strval(cmd); if(vw < 0) { SendClientMessage(playerid, Vermelho, "[>]"BRANCO" O Virtual World deve ser maior ou igual a 0"); return 1; } SetPlayerVirtualWorld(id, vw); format(String, sizeof(String), " O administrador %s setou seu virtual world para %d", pName(playerid), vw); SendClientMessage(id, Amarelo, String); format(String, sizeof(String), "Vocк setou o virtual world do player %s para %d", pName(id), vw); SendClientMessage(playerid, Amarelo, String);
E ai safchdion, tudo bem?
Sу queria deixar um code aqui, rs... Код:
new cmd[256], idx; cmd = strtok(cmdtext, idx); if(strcmp(cmd, "/SetVirtualWorld", true) == 0) { cmd = strtok(cmdtext, idx); if(!strlen(cmd)) { SendClientMessage(playerid, Vermelho, "[>]"BRANCO" Use /Set VirtualWorld [Player] [Virtual World]"); return 1; } new id = strval(cmd); if(!IsPlayerConnected(id)) { SendClientMessage(playerid, Vermelho, "[>]"BRANCO" Player offline"); return 1; } cmd = strtok(cmdtext, idx); if(!strlen(cmd)) { SendClientMessage(playerid, Vermelho, "[>]"BRANCO" Use /Set VirtualWorld [Player] [Virtual World]"); return 1; } new vw = strval(cmd); if(vw < 0) { SendClientMessage(playerid, Vermelho, "[>]"BRANCO" O Virtual World deve ser maior ou igual a 0"); return 1; } SetPlayerVirtualWorld(id, vw); format(String, sizeof(String), " O administrador %s setou seu virtual world para %d", pName(playerid), vw); SendClientMessage(id, Amarelo, String); format(String, sizeof(String), "Vocк setou o virtual world do player %s para %d", pName(id), vw); SendClientMessage(playerid, Amarelo, String); |