SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 29/04/2017, 10:30 AM   #4051
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,947
Reputation: 1510
Default Re: Little coding questions - For general minor queries 5

For permanent IDs, just generate a random sequence of characters - then you don't need to track state.
__________________
Tools:

Plugins:

Links:

[HLF]Southclaw is offline   Reply With Quote
Old 29/04/2017, 10:33 AM   #4052
Arthur Kane
Gangsta
 
Join Date: Sep 2012
Posts: 771
Reputation: 115
Default Re: Little coding questions - For general minor queries 5

Not permanent IDs. Just for reports. If their report is accepted or denied, their ID becomes available.

For example: Player A reports and his report is ID 1 because it's the first report.

Player B reports and his report is ID 2 because it's the second.

Player A's report gets handled.

Player C reports and his report is ID 1 because it's the first available.
Arthur Kane is offline   Reply With Quote
Old 29/04/2017, 10:57 AM   #4053
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,947
Reputation: 1510
Default Re: Little coding questions - For general minor queries 5

In that case use a y_iterate iterator, Iter_Free to grab the first free slot and Iter_Remove to remove it.
__________________
Tools:

Plugins:

Links:

[HLF]Southclaw is offline   Reply With Quote
Old 30/04/2017, 01:15 PM   #4054
rolex
Big Clucker
 
rolex's Avatar
 
Join Date: Nov 2008
Location: Brazil
Posts: 168
Reputation: 28
Default Re: Little coding questions - For general minor queries 5

What is the code for a user input in pawn? In C++ we save the user input in a variable with it:
cin >> variable.
In pawn when i want to do something like:

When player input a number "40" for example, that number be saved in variable "Number".

How can i do this? What is the code for it?
rolex is offline   Reply With Quote
Old 30/04/2017, 01:22 PM   #4055
Hansrutger
Gangsta
 
Hansrutger's Avatar
 
Join Date: May 2011
Location: Sweden
Posts: 928
Reputation: 158
Default Re: Little coding questions - For general minor queries 5

I assume you mean along with a command or without a command. For "with commands", find a suitable command plguin, for instance ZCMD. Along with that you combine it with sscanf which makes it a lot easier to read what strings contain. Example with ZCMD and sscanf:
Code:
CMD:something(playerid, params[])
{
        new target;
	if (sscanf(params, "u", target))
	{
		return SendClientMessage(playerid, 0xFF0000FF, "/something (target)");
	}
	if (!IsPlayerConnected(target) || !IsPlayerLoggedIn(target))
	{
		return SendClientMessage(playerid, 0xFF0000FF, "Target is not online or has not logged in yet.");
	}
        return 1;
}
Same principle follows in OnPlayerText, if you wanted to take care of raw input data.
Code:
public OnPlayerText(playerid, text[])
{
        new val = strval(text);
        if (val == 40)
        {
                SendClientMessage(playerid, 0xFFFFFFFF, "Hai.");
        }
        return 1;
}
__________________


Hansrutger is offline   Reply With Quote
Old 30/04/2017, 02:16 PM   #4056
Dayrion
High-roller
 
Dayrion's Avatar
 
Join Date: Jan 2016
Location: France
Posts: 1,915
Reputation: 256
Default Re: Little coding questions - For general minor queries 5

What means this kind of stuff?
PHP Code:
enum Lalal (<<=1)
{... 
__________________
actor_plus - v5.0.2
« I'm a goner, somebody catch my breath,
I'm a goner, somebody catch my breath »
Dayrion is offline   Reply With Quote
Old 30/04/2017, 04:12 PM   #4057
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,947
Reputation: 1510
Default Re: Little coding questions - For general minor queries 5

Quote:
Originally Posted by Dayrion View Post
What means this kind of stuff?
PHP Code:
enum Lalal (<<=1)
{... 
Brackets after an enumerator definition determine what transformation happens to each successive element. The default is (+=1) where each variable is the value of the previous plus 1. <<=1 means bit shift left by 1 meaning if the first element is 1, the next will be 2, 4, 8, 16, etc... this is generally used for bit fields/bit masking.
__________________
Tools:

Plugins:

Links:

[HLF]Southclaw is offline   Reply With Quote
Old 30/04/2017, 04:40 PM   #4058
rolex
Big Clucker
 
rolex's Avatar
 
Join Date: Nov 2008
Location: Brazil
Posts: 168
Reputation: 28
Default Re: Little coding questions - For general minor queries 5

I'm trying to create a Login/Register/Save Account system using DINI (I'm don't know MYSql yet...)

So.. i want to Create a file with NAME AND PASSWORD.

1- When player connect, and he don't have account, system create a DINI File with her name and password without dialog.

2- If Player who login have an account, just ask the password from him.

3- When player disconnect from the server, have file updated.

but that code isn't working correctly, why?

OnPlayerConnect
Code:
public OnPlayerConnect(playerid)
{
 	SpawnPlayer(playerid);
	GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
	if(!strcmp(dini_Get("Players/%s.ini", "Nome"), PlayerName[playerid])) return SendClientMessage(playerid, red, "Esse nickname já existe! registre outro usando o /registrar!");
	TogglePlayerControllable(playerid, 0);
	return 1;
}
OnPlayerDisconnect
Code:
public OnPlayerDisconnect(playerid, reason)
{
	new string[128]; //Define string
	GetPlayerName(playerid, PlayerName, sizeof(PlayerName)); // Salva o nome do player no "PlayerName"
	format(string, sizeof(string), "Players/%s.ini", PlayerName); // Cria o .INI do player caso não exista.
	if(fexist(string))  // Se existir, então:
	dini_Create(string); // Creates a string " "
	dini_IntSet(string, "Admin Level", AdminLevel[playerid]); // Salva o level de admin do player*/
	return 1;
}
CMD Field.
Code:
CMD:registrar(playerid, params[])
{
	new string[128], Senha;
	if(sscanf(params, "i", Senha))
	GetPlayerName(playerid, PlayerName, sizeof(PlayerName)); // Salva o nome do player no "PlayerName"
	format(string, sizeof(string), "Players/%s.ini", PlayerName); // Salva um .ini com o nome que está na variavel "PlayerName"
    if(fexist(string))
	dini_Int(string, "Senha");
	dini_Int(string, "Nome");
	dini_Create(string); // cria o arquivo.
	dini_IntSet(string, "Senha", Senha);
	dini_Set(string, "Nome", PlayerName[playerid]);
	SendClientMessage(playerid, green, "Você se cadastrou!");
	return 1;
}

CMD:login(playerid, params[])
{
	new file[64], password[256], password2[256];
	format(file, sizeof(file), "Players/%s.ini", PlayerName);
	format(password, sizeof(password), "%s", dini_Get(file, "Senha"));
	if(strcmp((password,true) && (password2, true))) return SendClientMessage(playerid, red, "Senha errada!");
	else
	SendClientMessage(playerid, green, "Você logou!");
	TogglePlayerControllable(playerid, 1);
	SpawnPlayer(playerid);
	return 1;
}

What is wrong in that code?
rolex is offline   Reply With Quote
Old 30/04/2017, 06:06 PM   #4059
GaByM
Big Clucker
 
GaByM's Avatar
 
Join Date: Jan 2014
Location: Romania
Posts: 112
Reputation: 10
Default Re: Little coding questions - For general minor queries 5

This:
PHP Code:
Create3DTextLabel("I'm at the coordinates:\n30.0, 40.0, 50.0"0x008080FF3.04.04.040.000); 
and this
PHP Code:
CMD:yes(playerid,params[])
{
    new 
str[80] = "I'm at the coordinates:\n30.0, 40.0, 50.0";
    
Create3DTextLabel(str,-1,0,0,3,40.0,0,0);
    return 
1;

shows:
I'm at the coordinates:
30.0, 40.0, 50.0"

But this
PHP Code:
CMD:yes(playerid,params[]) //params = "I'm at the coordinates:\n30.0, 40.0, 50.0"
{
    new 
str[144];
    
format(str,144,"%s",params);
    
Create3DTextLabel(str,-1,0,0,3,40.0,0,0);
    return 
1;

or creating a 3dtextlabel with a text from database shows I'm at the coordinates:\n30.0, 40.0, 50.0

Instead of splitting the text '\n' just shows like a normal character. Why?
GaByM is offline   Reply With Quote
Old 30/04/2017, 06:44 PM   #4060
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,947
Reputation: 1510
Default Re: Little coding questions - For general minor queries 5

\n is a representation of a single character code. If you store a literal backslash followed by a lowercase n, it will render a backslash and a lowercase n. \n only works in the source code, if it comes from any other source it will just be literal \ and n characters.

If you want to allow users to enter newlines, you'll have to scan their input and replace instances of "\n" with an actual newline '\n' (notice the explicit use of " and ' here - the first is a string and the second is a character)
__________________
Tools:

Plugins:

Links:

[HLF]Southclaw is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to make a soldier aotumaticly be general when the general dies ? AlbanianGuy Scripting Help 35 13/05/2012 03:35 PM
Minor problem Desert Help Archive 4 17/03/2010 06:24 PM
Counting with mysql queries actiwe Help Archive 2 26/02/2010 02:36 PM
SQL queries using GROUP BY Dabombber Help Archive 2 05/10/2009 07:47 PM


All times are GMT. The time now is 06:50 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.