Variable?
#1

Heey all,
Anyone know how i can make this variable?
This dont work:S
Код:
if(kidnap==0)
{
kidnap=1;
}
if(kidnap==1)
{
kidnap=0;
}
I need for ransom command:
Код:
dcmd_ransom(playerid,params[])
{
	new string[128];
	new ID;
	new kidnapid = GetPVarInt(playerid, "kidnap1");
	new vehicleid;
	vehicleid = GetPlayerVehicleID(ID);
	if(sscanf(params, "i", ID))
	{
	    SendClientMessage(playerid,COLOR_ERROR,"USAGE: /ransom (id)");
	    return 1;
	}
	if(!IsPlayerConnected(ID))
	{
	    format(string,sizeof(string),"The player ID (%d) is not connected to the server. You cannot ransom them",ID);
	    SendClientMessage(playerid,COLOR_RED,string);
	    return 1;
	}
	if(GetPlayerMoney(playerid) < KidnapPrice[kidnapid][1])
	{
 		SendClientMessage(playerid,COLOR_RED,"You cannot afford to pay the ransom of this player.");
		return 1;
	}
	if(GetPlayerMoney(playerid) > KidnapPrice[kidnapid][1])
	{
		if(IsPlayerInVehicle(ID,vehicleid) && IsKidnapped[ID] !=0)
		{
			new string2[128];
		 	DeletePVar(playerid, "kidnap1");
			RemovePlayerFromVehicle(ID);
			TogglePlayerControllable(ID,1);
	  		GivePlayerMoney(playerid,-KidnapPrice[kidnapid][1]);
	  		GivePlayerMoney(playerid,KidnapPrice[kidnapid][1]);
			format(string2,sizeof(string2),"%s(%d) has paid your ransom so now you are free to go!",PlayerName(playerid),playerid);
                        IsKidnapped[ID] =0l
			SendClientMessage(ID,COLOR_LIGHTBLUE,string2);
			}
		if(IsPlayerInVehicle(ID,vehicleid) && IsKidnapped[ID] ==0)
		{
			SendClientMessage(playerid, COLOR_RED, "This player is not kidnapped!");
		}
	}
	return 1;
}
My problem is when i use command on someone who is kidnapped its says the player is not kidnapped because the variable loads to fast i think.
How i can fix this?

Thanks Admigo
Reply
#2

Quote:
Originally Posted by admigo
Посмотреть сообщение
Heey all,

Код:
if(kidnap==0)
{
kidnap=1;
}
if(kidnap==1)
{
kidnap=0;
}
What is this >>>??
Reply
#3

let me gues: kidnap got set to 0 each time?
if it was 0, then it was set to 1, then to 0 again (double "if"), and if it was 1, then the first "if" got ignored, then set to 0.. this will work:
Код:
if(kidnap==0)
{
kidnap=1;
}
else if(kidnap==1) //you forgot the "else" :)
{
kidnap=0;
}
anyways, if its 0 or 1 only, then why not use this:
Код:
kidnap=1-kidnap;
..it will switch between 0-1-0-1 each time ^^

edit: explanation added as introducion. oh btw, a switch-case check does that job aswell:
Код:
switch(kidnap)
{
	case 0:
	{
		kidnap=1;
	}
	case 1:
	{
		kidnap=0;
	}
}
Reply
#4

OMG thanks can u give explain?
Reply
#5

Pls explain with my ransom command
Reply
#6

pawn Код:
new kidnap;
pawn Код:
if(kidnap==0)
{
    kidnap=1;
}
else if(kidnap==1)
{
    kidnap=0;
}
Reply
#7

It checks for the Kidnap variable if it is 1 then it turns it to 0 and vice versa.
pawn Код:
if(kidnap==0)
{
kidnap=1;
}
if(kidnap==1)
{
kidnap=0;
}
Here kidnap is turned into 1. Then you made it recheck the kidnap variable and then turned it back into 0. So you basically just did nothing.

pawn Код:
if(kidnap==0)
{
    kidnap=1;
}
else if(kidnap==1)
{
    kidnap=0;
}
Here you give the command to the script to check if Kidnap=0 then do Kidnap=1. And then "else if" makes it check if it isn't 0 and then turn it to 1. Here the script will check if Kidnap=0 then it will turn it to 1 and if it isn't 0, it's 1 then it will turn it into 0.
Reply
#8

Thanks all,Fixed:P
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)