[Script Help] How to use Variables outside zcmd:
#1

I have a script as follows:
Code:
CMD:th(playerid, params[])
{
	for(new vid; vid<MAX_VEHICLES; vid++) 
	{
		new Float:vx, Float:vy, Float:vz;
		GetVehiclePos(vid,vx,vy,vz);  
		GetXYBehindCar(vid,vx,vy,3.5);
		if(IsPlayerInRangeOfPoint(playerid,2.5,vx,vy,vz))
		{
			CarPack = GetPlayerVehicleID(playerid)
			if(IsThueXeVehicle(vid))
			{
				if(PackCar[vid] == 5) return SendClientMessage(playerid, COLOR_LIGHTRED, "SERVER: Xe nay da bo du so hang.");
				SetPlayerSpecialAction(playerid,0); 
				ClearAnimations(playerid);
				ApplyAnimation(playerid, "CARRY", "crry_prtial", 4.0, 0, 0, 0, 0, 1);
				RemovePlayerAttachedObject(playerid,0);
				PackCar[CarPack]++;
				LayPack = PackCar[vid];
				PlayerInfo[playerid][pPackTruonghop] = 0; 
				if(PackCar[vid] == 1)
				{
					Vehicle[playerid][0] = CreateObject(1220,0,0,-1000,0,0,0,100);
					AttachObjectToVehicle(Vehicle[playerid][0], vid, 0.450000,-1.049999,0.300000,0.000000,0.000000,0.000000);
					return 1; 
				}
				if(PackCar[vid] == 2)
				{ 
				 	Vehicle[playerid][1] = CreateObject(1220,0,0,-1000,0,0,0,1);
					AttachObjectToVehicle(Vehicle[playerid][1], vid, -0.449999,-1.049999,0.300000,0.000000,0.000000,89.099983);
					return 1;
			    }
				if(PackCar[vid] == 3)
			    {
					Vehicle[playerid][2] = CreateObject(1220,0,0,-1000,0,0,0,100);
					AttachObjectToVehicle(Vehicle[playerid][2], vid, -0.449999,-1.950000,0.300000,0.000000,0.000000,-67.500007);
					return 1;
			    }
				if(PackCar[vid] == 4)
			    {
			    	Vehicle[playerid][3] = CreateObject(1220,0,0,-1000,0,0,0,100);
					AttachObjectToVehicle(Vehicle[playerid][3], vid, 0.450000,-1.950000,0.300000,0.000000,0.000000,97.199974);
					return 1;
			    }
				if(PackCar[vid] == 5)
				{
					Vehicle[playerid][4] = CreateObject(1220,0,0,-1000,0,0,0,100);
					AttachObjectToVehicle(Vehicle[playerid][4], vid, -0.0
					
					
					
(......)
And I need to use variable Packcar[vid] outsize a CMD:th{}. But it don't work. I am a Pawno Beginner. Plz help me solve this problem. Thanks.
Reply
#2

Quote:
Originally Posted by Y_Less
View Post
What do you mean "outside " it? They look like globals since they aren't declared there so you already can use them in other callbacks.
I want to use it in OnPlayerChangeState. But I get the error: error 017: undefined symbol "vid"
... sr for my bad english.
Reply
#3

Quote:
Originally Posted by Y_Less
View Post
Then you need to declare "vid" in that callback too. I think you need to go read some basic tutorials on programming if you don't even know how variables work - don't worry about ZCMD commands and vehicles for now, just learn the basics.
Thanks, I will learn the basics later. But you don't understand me. I want to use vid's value of CMD:th{} in OnPlayerChangeState. If I declare "vid" in that callback too, vid's value in OnPlayerChangeState will different from vid's value in CMD:th{}. Sorry, Can you guide me? I really need it right now.
Reply
#4

Quote:
Originally Posted by Y_Less
View Post
Yes, that sort of thing is covered by the basics you will "learn later". If you need it now, then learn it now!
Sorry if I disturb you. I will learn right now, but what I should learn first(in Basic Script)?
Reply
#5

variable that you declared is local variable, which is only usable in your command. If you want to use variables in commands and other callbacks, you will need to use global variables, which you will have to declare on the top of the script because you want it to be "known" in all script
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)