SA-MP Forums Archive
Variable Not Increasing - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Variable Not Increasing (/showthread.php?tid=350803)



Variable Not Increasing - Mike97300 - 13.06.2012

Well, I have a command setup to where the variable will increase but it doesn't here's the script, no errors, just doesn't work.


First command to increase it.
Код:
//------[Makeleader]-------
COMMAND:makeleader(playerid, params[])
{
   	if(PlayerInfo[playerid][Adminlevel] < 1) return SendClientMessage(playerid,COLOR_ERROR,"[ERROR]: You are not authorized to use this command ");
   	new targetid;
   	new giveplayerid;
 	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
 	{
		SendClientMessage(targetid,COLOR_GREEN, "You have been made a faction leader!");
		FactionLeader[targetid] += 1;
   	}
    return 1;
}
Second command to test your leader
Код:
COMMAND:Invite(playerid, params[])
{
    if(FactionLeader[playerid] <= 1) return 0;
   	new targetid;
   	new giveplayerid;
 	if(sscanf(params, "is[24]", targetid)) return SendClientMessage(playerid, COLOR_SYNTAX, "[SYNTAX]: /invite [PlayerID/PartOfName]");
 	else if(giveplayerid == INVALID_PLAYER_ID) return SendClientMessage(playerid,WHITE,"[ERROR] Player Is Not Connected");
 	else
 	{
 	    SendClientMessage(targetid,COLOR_GREEN, "Your faction has been set to LSPD!");
 	    LSPDMember[targetid] += 1;
	}
    return 1;
}
Where I kept my define

Код:
public OnPlayerConnect(playerid)
{
    FactionLeader[playerid] = 0;



Re: Variable Not Increasing - Kindred - 13.06.2012

Try to change += to ++.

So, for example,
pawn Код:
FactionLeader[targetid] += 1;
would change to
pawn Код:
FactionLeader[targetid] ++;
All looks fine, but you can always try this.

EDIT: on second thought, why do you check if the players faction is less then or equal to 1? Shouldn't it be 0?

Also, why do you add onto the variable. Why not set it to a number, like 1 or something.


Re: Variable Not Increasing - Chris1337 - 13.06.2012

try instead this :

HE SAID IT FIRST


Re: Variable Not Increasing - Mike97300 - 13.06.2012

I changed it all to this

Код:
//------[Makeleader]-------
COMMAND:makeleader(playerid, params[])
{
   	if(PlayerInfo[playerid][Adminlevel] < 1) return SendClientMessage(playerid,COLOR_ERROR,"[ERROR]: You are not authorized to use this command ");
   	new targetid;
   	new giveplayerid;
 	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
 	{
		SendClientMessage(targetid,COLOR_GREEN, "You have been made a faction leader!");
		FactionLeader[targetid] ++;
   	}
    return 1;
}
Код:
//---[invite]----
COMMAND:Invite(playerid, params[])
{
    if(FactionLeader[playerid] < 1) return 0;
   	new targetid;
   	new giveplayerid;
 	if(sscanf(params, "is[24]", targetid)) return SendClientMessage(playerid, COLOR_SYNTAX, "[SYNTAX]: /invite [PlayerID/PartOfName]");
 	else if(giveplayerid == INVALID_PLAYER_ID) return SendClientMessage(playerid,WHITE,"[ERROR] Player Is Not Connected");
 	else
 	{
 	    SendClientMessage(targetid,COLOR_GREEN, "Your faction has been set to LSPD!");
 	    LSPDMember[targetid] ++;
	}
    return 1;
}



Re: Variable Not Increasing - PrawkC - 13.06.2012

Are you typing part of the name or their id? because if you're typing their name, the way you did sscanf is wrong, instead of "i" you want to use "u" .. i means integer, where as u means user.