PDA

View Full Version : Promote command.


xX4m4zingXx
18/01/2015, 10:36 AM
I want to create a promote command.
I was looking at a kick command and tried to create a promote command from it.
this is my code:
#include <a_samp>
#include <zcmd>

public OnPlayerCommandText(playerid, cmdtext[])
{
CMD:giverights(playerid, pRights)
{
if(PlayerInfo[playerid][pRights] == 3)
{
new target;
new rights[64];
new str[128];
new Playername[MAX_PLAYER_NAME], Adminname[MAX_PLAYER_NAME];
GetPlayerName(playerid, Adminname, sizeof(Adminname));
GetPlayerName(target, Playername, sizeof(Playername));
if(sscanf(params, "us[64]", target,rights)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /kick [playerid] [reason]");
if(!IsPlayerConnected(target))
return SendClientMessage(playerid, COLOR_GREY, "Player is not connected!");
PlayerInfo[target][pRights] = rights;
}
}
}
Error:
C:\Users\Ruud\Documents\Samp\filterscripts\admin.p wn(6) : error 029: invalid expression, assumed zero
C:\Users\Ruud\Documents\Samp\filterscripts\admin.p wn(6) : error 017: undefined symbol "cmd_giverights"
C:\Users\Ruud\Documents\Samp\filterscripts\admin.p wn(6) : error 029: invalid expression, assumed zero
C:\Users\Ruud\Documents\Samp\filterscripts\admin.p wn(6) : fatal error 107: too many error messages on one line

CalvinC
18/01/2015, 10:45 AM
#include <a_samp>
#include <zcmd>


CMD:giverights(playerid, params[])
{
if(PlayerInfo[playerid][pRights] < 3) return 0;
new target, rights[64], str[128], Playername[MAX_PLAYER_NAME], Adminname[MAX_PLAYER_NAME];
GetPlayerName(playerid, Adminname, sizeof(Adminname));
GetPlayerName(target, Playername, sizeof(Playername));
if(sscanf(params, "us[64]", target,rights)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /kick [playerid] [reason]");
if(!IsPlayerConnected(target)) return SendClientMessage(playerid, COLOR_GREY, "Player is not connected!");
PlayerInfo[target][pRights] = rights;
return 1;
}
ZCMD commands shouldn't be placed under OnPlayerCommandText.
Also fixed some other errors for you as you can examine.

xX4m4zingXx
18/01/2015, 11:31 AM
It says that PlayerInfo isn't defined.
can I take things from other filterscripts?
I got a login script where I want to take PlayerInfo from.
Or do I have to recreate that small part?
This is the login script:
#include <a_samp>
#include <YSI\y_ini>

//Dialogs
#define DIALOG_REGISTER 1
#define DIALOG_LOGIN 2
#define DIALOG_SUCCESS_1 3
#define DIALOG_SUCCESS_2 4
//Users path
#define PATH "/users/%s.ini"
//Colors
#define COL_WHITE "{FFFFFF}"
#define COL_RED "{F81414}"
#define COL_GREEN "{00FF22}"
#define COL_LIGHTBLUE "{485CFF}"
#define COL_YELLOW "{F7C600}"

enum pInfo
{
pPass,
pCash,
pRights,
pKills,
pDeaths
}
new PlayerInfo[MAX_PLAYERS][pInfo];

stock strreplace(string[], find, replace)
{
for(new i=0; string[i]; i++)
{
if(string[i] == find)
{
string[i] = replace;
}
}
}

stock GetName(playerid)
{
new
name[24];
GetPlayerName(playerid, name, sizeof(name));
strreplace(name, '_', ' ');
return name;
}

main()
{
print("Login by Ruud");
}

public OnFilterScriptInit()
{
SetGameModeText("Login script");
return 1;
}

forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
INI_Int("Password",PlayerInfo[playerid][pPass]);
INI_Int("Cash",PlayerInfo[playerid][pCash]);
INI_Int("Rights",PlayerInfo[playerid][pRights]);
INI_Int("Kills",PlayerInfo[playerid][pKills]);
INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
return 1;
}

stock UserPath(playerid)
{
new string[128],playername[MAX_PLAYER_NAME];
GetPlayerName(playerid,playername,sizeof(playernam e));
format(string,sizeof(string),PATH,playername);
return string;
}

stock udb_hash(buf[]) {
new length=strlen(buf);
new s1 = 1;
new s2 = 0;
new n;
for (n=0; n<length; n++)
{
s1 = (s1 + buf[n]) % 65521;
s2 = (s2 + s1) % 65521;
}
return (s2 << 16) + s1;
}

public OnPlayerConnect(playerid)
{
if(fexist(UserPath(playerid)))
{
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
new string[128], playerName[24];
GetPlayerName(playerid, playerName, sizeof(playerName));
format(string, 128, COL_YELLOW"Welcome back "COL_LIGHTBLUE"%s "COL_WHITE"\nplease type your password below to log in.", GetName(playerid));
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, ""COL_WHITE"Login", string, "Login", "Quit");
}
else
{
new string[128], playerName[24];
GetPlayerName(playerid, playerName, sizeof(playerName));
format(string, 128, COL_YELLOW"Welcome "COL_LIGHTBLUE"%s "COL_WHITE"\n Type your password below to register a new account.", GetName(playerid));
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, COL_WHITE"Registering...", string, "Register", "Quit");
}
return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch( dialogid )
{
case DIALOG_REGISTER:
{
if (!response) return Kick(playerid);
if(response)
{
if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, ""COL_WHITE"Registering...",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Password",udb_hash(inputtext));
INI_WriteInt(File,"Cash",0);
INI_WriteInt(File,"Rights",0);
INI_WriteInt(File,"Kills",0);
INI_WriteInt(File,"Deaths",0);
INI_Close(File);

SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
}
}

case DIALOG_LOGIN:
{
if ( !response ) return Kick ( playerid );
if( response )
{
if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
{
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
}
else
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,""COL_WHITE"Login",""COL_RED"You have entered an incorrect password.\n"COL_WHITE"Type your password below to login.","Login","Quit");
}
return 1;
}
}
}
return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
INI_WriteInt(File,"Rights",PlayerInfo[playerid][pRights]);
INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
INI_Close(File);
return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
PlayerInfo[killerid][pKills]++;
PlayerInfo[playerid][pDeaths]++;
return 1;
}

CalvinC
18/01/2015, 02:10 PM
You cannot use information from filterscripts/gamemodes in other filterscripts/gamemodes.

xX4m4zingXx
18/01/2015, 03:35 PM
Okay, thank you.

xX4m4zingXx
18/01/2015, 08:39 PM
I got this script now:
#include <a_samp>
#include <zcmd>
#include <YSI\y_ini>
#include <sscanf2>

#define PATH "/users/%s.ini"

enum pInfo
{
pRights
}

new PlayerInfo[MAX_PLAYERS][pInfo];

forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
INI_Int("Rights",PlayerInfo[playerid][pRights]);
return 1;
}

CMD:giverights(playerid, rights)
{
if(PlayerInfo[playerid][pRights] < 3) return 0;
new target, rights[64], Playername[MAX_PLAYER_NAME], Adminname[MAX_PLAYER_NAME];
GetPlayerName(playerid, Adminname, sizeof(Adminname));
GetPlayerName(target, Playername, sizeof(Playername));
if(sscanf(pRights, "us[64]", target,rights)) return SendClientMessage(playerid, 0xFFFFFFAA, "USAGE: /kick [playerid] [reason]");
if(!IsPlayerConnected(target)) return SendClientMessage(playerid, 0xFFFFFFAA, "Player is not connected!");
PlayerInfo[target][pRights] = rights;
return 1;
}

I got this error:
C:\Users\Ruud\Documents\Samp\filterscripts\admin.p wn(25) : warning 217: loose indentation
C:\Users\Ruud\Documents\Samp\filterscripts\admin.p wn(25) : warning 219: local variable "rights" shadows a variable at a preceding level
C:\Users\Ruud\Documents\Samp\filterscripts\admin.p wn(28) : error 035: argument type mismatch (argument 1)
C:\Users\Ruud\Documents\Samp\filterscripts\admin.p wn(30) : error 006: must be assigned to an array

nezo2001
18/01/2015, 08:42 PM
if(sscanf(params, "us[64]", target,rights)) return SendClientMessage(playerid, 0xFFFFFFAA, "USAGE: /kick [playerid] [reason]");

xX4m4zingXx
18/01/2015, 08:48 PM
Now I get this error:
C:\Users\Ruud\Documents\Samp\filterscripts\admin.p wn(33) : warning 217: loose indentation
C:\Users\Ruud\Documents\Samp\filterscripts\admin.p wn(33) : warning 219: local variable "rights" shadows a variable at a preceding level
C:\Users\Ruud\Documents\Samp\filterscripts\admin.p wn(36) : error 017: undefined symbol "params"
C:\Users\Ruud\Documents\Samp\filterscripts\admin.p wn(38) : error 006: must be assigned to an array

nezo2001
18/01/2015, 09:05 PM
CMD:giverights(playerid, params[])

xX4m4zingXx
23/01/2015, 06:03 PM
Okay, I have this code now:
CMD:giverights(playerid, params[])
{
if(PlayerInfo[playerid][pRights] < 3) return 0;
new target, rights[64], Playername[MAX_PLAYER_NAME], Adminname[MAX_PLAYER_NAME];
GetPlayerName(playerid, Adminname, sizeof(Adminname));
GetPlayerName(target, Playername, sizeof(Playername));
if(sscanf(params, "us[64]", target,rights)) return SendClientMessage(playerid, 0xFFFFFFAA, "USAGE: /kick [playerid] [reason]");
if(!IsPlayerConnected(target)) return SendClientMessage(playerid, COL_GREY, "Player is not connected!");
PlayerInfo[target][pRights] = rights;
return 1;
}
And I have this error:
C:\Users\Ruud\Documents\Samp\RP alles in 1\gamemodes\RP.pwn(582) : error 006: must be assigned to an array

DavidSparks
23/01/2015, 06:35 PM
What line is 582?

xX4m4zingXx
23/01/2015, 06:37 PM
What line is 582?
I added my previous post.
The line is red by now.

xX4m4zingXx
24/01/2015, 06:11 PM
Okay, I have this code now:
CMD:giverights(playerid, params[])
{
if(PlayerInfo[playerid][pRights] < 3) return 0;
new target, rights[64], Playername[MAX_PLAYER_NAME], Adminname[MAX_PLAYER_NAME];
GetPlayerName(playerid, Adminname, sizeof(Adminname));
GetPlayerName(target, Playername, sizeof(Playername));
if(sscanf(params, "us[64]", target,rights)) return SendClientMessage(playerid, 0xFFFFFFAA, "USAGE: /kick [playerid] [reason]");
if(!IsPlayerConnected(target)) return SendClientMessage(playerid, COL_GREY, "Player is not connected!");
PlayerInfo[target][pRights] = rights;
return 1;
}
And I have this error:
C:\Users\Ruud\Documents\Samp\RP alles in 1\gamemodes\RP.pwn(582) : error 006: must be assigned to an array

Ironboy
24/01/2015, 06:17 PM
pRights must be considered as a string variable, so check your enum.

xX4m4zingXx
25/01/2015, 10:09 AM
pRights must be considered as a string variable, so check your enum.

I don't get it?
My pRights should be an integer.

xX4m4zingXx
25/01/2015, 01:57 PM
Bump

xX4m4zingXx
25/01/2015, 03:31 PM
Bump

Ironboy
25/01/2015, 03:34 PM
Bump

It shouldn't be integer when you try to make it hold characters.

Schneider
25/01/2015, 03:41 PM
CMD:giverights(playerid, params[])
{
if(PlayerInfo[playerid][pRights] < 3) return 0;
new target, rights, Playername[MAX_PLAYER_NAME], Adminname[MAX_PLAYER_NAME];
if(sscanf(params, "ud", target,rights)) return SendClientMessage(playerid, 0xFFFFFFAA, "USAGE: /giverights [playerid] [level]");
if(!IsPlayerConnected(target)) return SendClientMessage(playerid, COL_GREY, "Player is not connected!");
GetPlayerName(playerid, Adminname, sizeof(Adminname));
GetPlayerName(target, Playername, sizeof(Playername));
PlayerInfo[target][pRights] = rights;
return 1;
}