PDA

View Full Version : A few questions about Pawno


Mike97300
13/06/2012, 07:49 PM
Well, my first question is, how do I make it check if I have a cretin number variable for example

Crack[playerid] = 0;

Okay, I'm not sure if that's right or not, but is there a way to check if you have a certain amount? For example.

COMMAND:usecrack(playerid, params[])
{
if/*the number not being equal to one*/ SendClientMessage(playerid,COLOR_WHITE, "You don't have any crack!");
else
{
SetPlayerHealth(playerid,100);
return 1;
}

That's something that I just made real quick, if someone could help me or correct me, that would be appreciated.

ReneG
13/06/2012, 07:54 PM
http://wiki.sa-mp.com/wiki/Control_Structures

@if statements.
Btw pawno is the editor. Pawn is the scripting language

Mike97300
13/06/2012, 07:56 PM
Okay, lets say when you buy crack you want to add one to the number, how would you do that?
And tell me if this is wrong.

crack = 0;
COMMAND:usecrack(playerid, params[])
{
if(!crack = 1) SendClientMessage(playerid,COLOR_WHITE, "You don't have any crack!");
else
{
SetPlayerHealth(playerid,100);
return 1;
}

iRage
13/06/2012, 07:57 PM
COMMAND:usecrack(playerid, params[])
{
if(Crack[playerid] != 1) SendClientMessage(playerid,COLOR_WHITE, "You don't have any crack!");
else
{
SetPlayerHealth(playerid,100);
return 1;
}



Your code wouldn't work though due to missing some }'s, use the following, it even looks neater


COMMAND:usecrack(playerid, params[])
{
if(Crack[playerid] != 1)
{
SendClientMessage(playerid,COLOR_WHITE, "You don't have any crack!");
}
else
{
SetPlayerHealth(playerid,100);
}
return 1;
}

Mike97300
13/06/2012, 08:02 PM
I see, thanks! And should I put the

crack = 0;

On top of the script?

Also, how do you add one number for example, if you buy crack, it would increase the number by one so you could use it.

And my last two questions, how do you save the players number after they log off so they don't get reset to 0 when they log back in? Thanks.

Elysian`
13/06/2012, 08:15 PM
Ahh you need a saving/loading system, go look in the tutorials there is one made my Kush..

also you use (to add a number):
Crack[playerid] = 1;

NOTE: We don't use 2 " = " because we are not checking if they have that number.

Mike97300
13/06/2012, 08:19 PM
Now, would this work?

COMMAND:usecrack(playerid, params[])
{
if (crack != 1)
{
SendClientMessage(playerid,COLOR_WHITE, "You don't have any crack!");
}
else
{
SetPlayerHealth(playerid,100);
(crack -=1);
}
return 1;
}

COMMAND:buycrack(playerid, params[])
{
(crack +=1);
return 1;
}

I just made it, and I'm guessing the way that works is it does it for everyone, how do I make it for a specific player?

And when I use this

Crack[playerid] = 1;

I get errors saying that it is not defined etc.

Elysian`
13/06/2012, 08:23 PM
EDIT: I saw your edit above, Good job. ^^

MP2
13/06/2012, 08:27 PM
To check if they have crack:


if(!somevar[playerid]) return SendClientMessage(playerid, COLOR_RED, "You do not have any crack.");
SetPlayerHealth(...);
somevar[playerid]--, // remove 1


To add crack replace -- with ++

Mike97300
13/06/2012, 08:30 PM
EDIT: Never mind, the crack thing was an experiment for my project which is this so far.

new
FactionLeader = 1;

My command

COMMAND:makeleader(playerid, params[])
{
new giveplayerid, reason[24], string[125], name[24], name2[24];
if(PlayerInfo[playerid][Adminlevel] < 1) return SendClientMessage(playerid,COLOR_ERROR,"[ERROR]: You are not authorized to use this command ");
new targetid;
if(sscanf(params, "is[24]", targetid)) return SendClientMessage(playerid, COLOR_SYNTAX, "[SYNTAX]: /makeleader [PlayerID/PartOfName]");
else if(giveplayerid == INVALID_PLAYER_ID) return SendClientMessage(playerid,WHITE,"[ERROR] Player Is Not Connected");
else
{
GetPlayerName(giveplayerid, name, sizeof(name));
GetPlayerName(playerid, name2, sizeof(name2));
format(string, sizeof(string), "%s has given %s faction leadership!", name2, name, giveplayerid);
SendClientMessage(targetid,COLOR_GREEN, string);
(FactionLeader,targetid, += 1);

}
return 1;
}

I get the following errors

C:\Users\GTW\BaseNorton V2\gamemodes\Gamemode.pwn(1031) : error 029: invalid expression, assumed zero
C:\Users\GTW\BaseNorton V2\gamemodes\Gamemode.pwn(1031) : error 029: invalid expression, assumed zero
C:\Users\GTW\BaseNorton V2\gamemodes\Gamemode.pwn(1031) : warning 215: expression has no effect
C:\Users\GTW\BaseNorton V2\gamemodes\Gamemode.pwn(2296) : warning 203: symbol is never used: "FactionLeader"

I have no idea whats wrong with it, I overlooked it and fixed a few errors, also, how do I make it so the person that ID I put get's it increased and not you?

Yuryfury
13/06/2012, 11:04 PM
if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, COLOR_SYNTAX, "[SYNTAX]: /makeleader [PlayerID/PartOfName]");


*sscanf specifiers*

Specifier(s) Name Example values
i, d Integer 1, 42, -10
c Character a, o, *
l Logical true, false
b Binary 01001, 0b1100
h, x Hex 1A, 0x23
o Octal 045 12
n Number 42, 0b010, 0xAC, 045
f Float 0.7, -99.5
g IEEE Float 0.7, -99.5, INFINITY, -INFINITY, NAN, NAN_E
u User name/id (bots and players) ******, 0
q Bot name/id ShopBot, 27
r Player name/id ******, 42
Source: http://forum.sa-mp.com/showthread.php?t=120356

Also,

format(string, sizeof(string), "%s has given %s faction leadership!", name2, name); //removed giveplayerid


What is this?

(FactionLeader,targetid, += 1);
Function values are within parenthesis. You have no function here though... You probably want to do something like:

FactionLeader[targetid]=1;