Convert dcmd to zcmd+sscanf
#1

Hello, i am trying to set this command:

Code:
dcmd_setlevel(playerid,params[])
{
	new level,id,file[256],n[MAX_PLAYER_NAME];//creating the new variabls
	new tmp[256], tmp2[256], Index,str[50];// creating the new variables
	tmp = strtok(params,Index), tmp2 = strtok(params,Index),id = strval(tmp),level = strval(tmp2);// setting them to strtok so we can use them as parameters of our command
	GetPlayerName(id,n,MAX_PLAYER_NAME);//getting the players name
	format(file,sizeof(file),"gAdmin/Users/%s.txt",n);//formatting the file
	if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,GREY,"You are not an RCON admin!");//if the player is not rcon admin
	if(!strlen(params)) return SendClientMessage(playerid,GREY,"USAGE: /setlevel <ID> <Level>");// if the string is empty
	if(!IsPlayerConnected(id))return SendClientMessage(playerid,GREY,"You have entered an incorrect ID"); //if the id is not connected
	PInfo[id][Level] = level;//sets the level of the player
		dini_IntSet(file,"Level",level);//saves the new level to the file
		format(str,sizeof(str),"You have set %s's level to %d",n,level);//creates the string
		SendClientMessage(playerid,LIGHTBLUE,str);
		return 1;
	}
To ZCMD, but the problem is when i use it it says that strtok is not defined, i know i have to use Sscanf for it but i have no idea how to implement sscanf in there...

Can anybody help me?

Thanks in advance!
Reply
#2

pawn Code:
CMD:setlevel(playerid, params[])
{
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, GREY, "You are not an RCON admin!");
   
    new
        pLevel,
        pID
    ;
   
    if(sscanf(params, "dd", pID, pLevel)) return SendClientMessage(playerid, GREY, "USAGE: /setlevel <ID> <Level>");
    if(!IsPlayerConnected(pID)) return SendClientMessage(playerid, GREY, "You have entered an incorrect ID");
   
    new
        pName[MAX_PLAYER_NAME],
        file[56]
    ;
       
    GetPlayerName(pID, pName, sizeof(pName));
   
    format(file, sizeof(file), "gAdmin/Users/%s.txt", pName);
   
    PInfo[pID][Level] = pLevel;
    dini_IntSet(file, "Level", pLevel);

    format(file, sizeof(file), "You have set %s's level to %d", pName, pLevel);
    SendClientMessage(playerid, LIGHTBLUE, file);
    return 1;
}
Reply
#3

Ooh and u even did it with enters so i can learn from it, really nice, a big help Rafaellos, let me test it
Reply
#4

If you give me the variable for your admin system (pAdmin maybe?) and tell me which level, I'll configure one for you.
Reply
#5

THis is my enum;

Code:
enum gPInfo
{
	Logged,
	Regged,
	Level,
	Team
};

new PInfo[MAX_PLAYERS][gPInfo];
Level is the admin level
going with PInfo[id][Level]
or PInfo[playerid][Level]

The code from Rafaellos gave me a error:

Admin.pwn(202) : error 017: undefined symbol "level"

When i defined it, the script loaded successfull but ingame it said SERVER: Unknown command,
which it did with all my ZCMD commands today...
Reply
#6

I edited my code, forgot to change something in sscanf. "level" is not a part of the code I provided. Show me which line.
Reply
#7

Well the code u updated fixed the error too,

The only problem is, the filterscript says loading.., BUT it does not run, it doesnt show the OnFilterScriptInit texts, this is my fs:

Code:
// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT

#include <a_samp>
#include <dini>
#include <sscanf2>
#include <zcmd>

#define GREY 0xAFAFAFAA
#define GREEN 0x33AA33AA
#define YELLOW 0xFFFF00AA
#define WHITE 0xFFFFFFAA
#define LIGHTBLUE 0x33CCFFAA
#define ORANGE 0xFF9900AA

enum gPInfo
{
	Logged,
	Regged,
	Level,
	Team
};

new PInfo[MAX_PLAYERS][gPInfo];


public OnFilterScriptInit()
{

	GameTextForAll("gAdmin loaded!", 2000, 5);
	SendClientMessageToAll(ORANGE, "gAdmin loaded!");
	print("gAdmin loaded!");
	print("\n--------------------------------------");
	print(" GingeDevil Admin Script Loaded!		   ");
	print("--------------------------------------\n");
	return 1;
}

public OnFilterScriptExit()
{
	return 1;
}
public OnPlayerRequestClass(playerid, classid)
{
	SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
	SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
	SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
	return 1;
}

public OnPlayerConnect(playerid)
{
	GameTextForPlayer(playerid, "Welcome to GingeDevil RP!", 2000, 5);
	PInfo[playerid][Logged] = 0;
	PInfo[playerid][Regged] = 0;
	PInfo[playerid][Level] = 0;
	PInfo[playerid][Team] = 0;
	new n[MAX_PLAYER_NAME], file[256];
	GetPlayerName(playerid,n,sizeof(n));
	format(file,sizeof(file),"gAdmin/Users/%s.txt",n);
	if(dini_Exists(file))
	{
 		print("Code pos #1");
		SendClientMessage(playerid,LIGHTBLUE,"You are registered, Please /login!");
		PInfo[playerid][Regged] = 1;
		PInfo[playerid][Logged] = 0;
		return 1;
	}
	if(!dini_Exists(file))
	{
 		print("Code pos #2");
 		SendClientMessage(playerid,LIGHTBLUE,"You are not registered, Please /register!");
		PInfo[playerid][Regged] = 0;
		PInfo[playerid][Logged] = 0;
		return 1;
	}

	if(PInfo[playerid][Team] == 1)
	{
		SetPlayerColor(playerid, GREEN);
		return 1;
	}
	return 1;
}

public OnPlayerDisconnect(playerid, reason)
{

	new n[MAX_PLAYER_NAME], file[256];
	GetPlayerName(playerid,n,sizeof(n));
	format(file,sizeof(file),"gAdmin/Users/%s.txt",n);
	PInfo[playerid][Logged] = 0;
 	if(dini_Exists(file))
  		{
    	print("Code pos #3");
  		dini_IntSet(file,"Logged",0);
   		return 1;
    	}
	return 1;
}
CMD:me(playerid, params[])
	{
		new string[128],msg[128],pname[MAX_PLAYER_NAME];
		GetPlayerName(playerid,pname,sizeof(pname));
		if(sscanf(params,"sz",msg)) return SendClientMessage(playerid,ORANGE, "USAGE: /me <text>");
		format(string,sizeof(string),"*%s %s",pname,msg);
		SendClientMessageToAll(GREY,string);
		return 1;
	}
	
CMD:kick(playerid, params[])
	{
	new string[128], id, reason, name[MAX_PLAYER_NAME];
 	if(sscanf(params, "us[100]",id, reason)) return SendClientMessage(playerid, ORANGE, "USAGE: /kick <playerid/partofname> <reason>");
 	if(PInfo[playerid][Level] >= 3) return SendClientMessage(playerid, ORANGE, "You're not an admin.");
	Kick(id);
	GetPlayerName(id, name, sizeof(name));
	format(string, sizeof(string), "%s has been kicked of the server. Reason: %s", name, reason);
	SendClientMessageToAll(ORANGE, string);
	return 1;
}

CMD:promote(playerid, params[])
{
	new level,id,file[256],n[MAX_PLAYER_NAME];//creating the new variabls
	new tmp[256], tmp2[256], Index,str[50];// creating the new variables
	tmp = strtok(params,Index), tmp2 = strtok(params,Index),id = strval(tmp),level = strval(tmp2);// setting them to strtok so we can use them as parameters of our command
	GetPlayerName(id,n,MAX_PLAYER_NAME);//getting the players name
	format(file,sizeof(file),"gAdmin/Users/%s.txt",n);//formatting the file
	if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,GREY,"You are not an RCON admin!");//if the player is not rcon admin
	if(!strlen(params)) return SendClientMessage(playerid,GREY,"USAGE: /setlevel <ID> <Level>");// if the string is empty
	if(!IsPlayerConnected(id))return SendClientMessage(playerid,GREY,"You have entered an incorrect ID"); //if the id is not connected
	PInfo[id][Level] = level;//sets the level of the player
		dini_IntSet(file,"Level",level);//saves the new level to the file
		format(str,sizeof(str),"You have set %s's level to %d",n,level);//creates the string
		SendClientMessage(playerid,LIGHTBLUE,str);
		return 1;
}*/
/*
CMD:test( playerid, params[ ])
{
	print("Working");
    new id;
    id = strval( params );
    return SendClientMessage( id, 0xAAAAAA, "Test" );
}*/

CMD:setlevel(playerid, params[])
{
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, GREY, "You are not an RCON admin!");

    new
        pLevel,
        pID
    ;

    if(sscanf(params, "dd", pID, pLevel)) return SendClientMessage(playerid, GREY, "USAGE: /setlevel <ID> <Level>");
    if(!IsPlayerConnected(pID)) return SendClientMessage(playerid, GREY, "You have entered an incorrect ID");

    new
        pName[MAX_PLAYER_NAME],
        file[56]
    ;

    GetPlayerName(pID, pName, sizeof(pName));

    format(file, sizeof(file), "gAdmin/Users/%s.txt", pName);

    PInfo[pID][Level] = pLevel;
    dini_IntSet(file, "Level", pLevel);

    format(file, sizeof(file), "You have set %s's level to %d", pName, pLevel);
    SendClientMessage(playerid, LIGHTBLUE, file);
    return 1;
}
Reply
#8

Go ingame, type /rcon login [password], then /rcon unloadfs [FSNAME] and again /rcon loadfs [FSNAME]. If doesn't work, repeat the process and the restart the server. Or maybe you have the same cmds in your main script.
Reply
#9

I found the problem, it was my stupid fault of not loading the sscanf plugin in the server config -.-

Well doing that, i made a /giveweapon command, the only thing is, it keeps saying: You have to be level 3 to use that command!

This is the giveweapon code
Code:
	CMD:giveweapon(playerid, params[])
	{
	    if(PInfo[playerid][Level] > 3)
		{
		    new PID;
		    new gun;
		    new ammo;
		    new str[128];
		    new Playername[MAX_PLAYER_NAME], Adminname[MAX_PLAYER_NAME];
		    GetPlayerName(playerid, Adminname, sizeof(Adminname));
		    GetPlayerName(PID, Playername, sizeof(Playername));
		    if(sscanf(params, "us[64]", PID, gun, ammo)) return SendClientMessage(playerid, ORANGE, "USAGE: /giveweapon [playerid][weaponid][ammo]");
				if(!IsPlayerConnected(PID)) return SendClientMessage(playerid, ORANGE, "Player is not connected!");
				format(str, sizeof(str), "'%s' gave weapons to '%s'.", Adminname, Playername);
				SendClientMessageToAll(GREEN, str);
				GivePlayerWeapon(PID, gun, ammo);
			}
 			else
	 		{
				SendClientMessage(playerid, ORANGE, "You have to be level 3 to use that command!");
	 		}
	    return 1;
	}
Reply
#10

Show defines and vars (new's).
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)