SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 06/08/2012, 06:00 PM   #1731
Nero_3D
High-roller
 
Nero_3D's Avatar
 
Join Date: Jun 2007
Location: Germany
Posts: 3,353
Reputation: 354
Default AW: Little coding questions - For general minor queries 5

That wont work because its an enum, an enum doesnt create a real array inside

Lets check how the compiler sees your code
pawn Code:
// by default it is always ( += 1 )
enum wData // 33 + (MAX_WEAPONS * 1)
{
    wSetID, // no value given = 0
    wSetName[32], // 0 + (1) = 1
    wWeapons[MAX_WEAPONS] //  1 + (32 * 1) = 33
};
pawn Code:
new WeaponSet[][wData] = // WeaponSet[][33 + MAX_WEAPONS]
{
    {1, "Test Kit #1", {WEAPON_MINIGUN, WEAPON_GRENADE}}
// etc...
};
Thats just a 2d array, to your error line
pawn Code:
// wont work, there is no array behind that
for(new tI, tS = sizeof(WeaponSet[i][wData: 33]); tI < tS; tI++)
// also, sizeof(WeaponSet[]) would be (33 + MAX_WEAPONS)

I think the best way would be to loop through the array till it finds a 0 (for no weapon)
pawn Code:
for(new i; WeaponSet[0][i] != 0; i++)
Also if this should be constant data, dont use enums because they waste many cells / memory
__________________


Nero_3D is online now   Reply With Quote
Old 06/08/2012, 07:43 PM   #1732
Garsino
Huge Clucker
 
Garsino's Avatar
 
Join Date: Mar 2012
Location: Norway
Posts: 232
Reputation: 116
Default Re: AW: Little coding questions - For general minor queries 5

Quote:
Originally Posted by Nero_3D View Post
That wont work because its an enum, an enum doesnt create a real array inside

Lets check how the compiler sees your code
pawn Code:
// by default it is always ( += 1 )
enum wData // 33 + (MAX_WEAPONS * 1)
{
    wSetID, // no value given = 0
    wSetName[32], // 0 + (1) = 1
    wWeapons[MAX_WEAPONS] //  1 + (32 * 1) = 33
};
pawn Code:
new WeaponSet[][wData] = // WeaponSet[][33 + MAX_WEAPONS]
{
    {1, "Test Kit #1", {WEAPON_MINIGUN, WEAPON_GRENADE}}
// etc...
};
Thats just a 2d array, to your error line
pawn Code:
// wont work, there is no array behind that
for(new tI, tS = sizeof(WeaponSet[i][wData: 33]); tI < tS; tI++)
// also, sizeof(WeaponSet[]) would be (33 + MAX_WEAPONS)

I think the best way would be to loop through the array till it finds a 0 (for no weapon)
pawn Code:
for(new i; WeaponSet[0][i] != 0; i++)
Also if this should be constant data, dont use enums because they waste many cells / memory
Well I think I'll make it work with strings instead. Then use sscanf to split up the data. Thanks for the help both of you!
__________________
Garsino is offline   Reply With Quote
Old 08/08/2012, 11:17 PM   #1733
Kwashiorkor
Big Clucker
 
Join Date: Mar 2012
Location: Western Germany
Posts: 98
Reputation: 9
Default AW: Little coding questions - For general minor queries 5

its quite late and im having a problem im not able to solve :/
Code:
enum d
{
	b,
	Float:c[3]
}
new a[2][d] = {
	{1,	{1.0,...}  		}, <--- errorline (13)
	{1, {1.0,1.0,1.0}	}
};<--- errorline (15)

(13) : error 029: invalid expression, assumed zero
(15) : error 010: invalid function or declaration
(16) : warning 203: symbol is never used: ""
(16) : warning 203: symbol is never used: "a"
instead of filling in a value for every single field i wanted to use {1.0,...} so the following fields are getting the same value (1.0). i know that "a" isnt used and that code doesnt look useful but its just to show you my problem
Kwashiorkor is offline   Reply With Quote
Old 09/08/2012, 08:25 AM   #1734
leonardo1434
High-roller
 
leonardo1434's Avatar
 
Join Date: Mar 2012
Posts: 1,688
Reputation: 179
Default Re: Little coding questions - For general minor queries 5

Try that..

pawn Code:
enum d
{
    b,
    Float:c[3]
}
new a[2][d] =
{
   {1,...},
   {2.0,...}
};
__________________
c++
leonardo1434 is offline   Reply With Quote
Old 09/08/2012, 01:17 PM   #1735
Kwashiorkor
Big Clucker
 
Join Date: Mar 2012
Location: Western Germany
Posts: 98
Reputation: 9
Default AW: Little coding questions - For general minor queries 5

no thats not what i am looking for
Kwashiorkor is offline   Reply With Quote
Old 15/08/2012, 05:50 AM   #1736
Willy
Little Clucker
 
Willy's Avatar
 
Join Date: Jul 2010
Posts: 6
Reputation: 0
Default Re: Little coding questions - For general minor queries 5

I can't break the animation on SPECIAL_ACTION_CUFFED
Code:
	if(strcmp(cmd, "/cuff", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
			if(IsACop(playerid) || IsAAgent(playerid) || IsANG(playerid))
			{
			    tmp = strtok(cmdtext, idx);
				if(!strlen(tmp))
				{
					SendClientMessage(playerid, COLOR_WHITE, "USAGE: /cuff [Playerid/PartOfName]");
					return 1;
				}
				if(IsPlayerInAnyVehicle(playerid))
				{
					SendClientMessage(playerid, COLOR_GREY, "   Cannot use this while in a Car !");
					return 1;
				}
				giveplayerid = ReturnUser(tmp);
			    if(IsPlayerConnected(giveplayerid))
				{
					if(IsACop(giveplayerid))
					{
						SendClientMessage(playerid, COLOR_GREY, "   You can't Cuff Cops !");
						return 1;
					}
					if(IsANG(giveplayerid))
					{
						SendClientMessage(playerid, COLOR_GREY, "   You can't Cuff National Guards !");
						return 1;
					}
					if(PlayerTied[giveplayerid] > 0)
					{
						SendClientMessage(playerid, COLOR_GREY, "   That player is Tied up !");
						return 1;
					}
					if(PlayerCuffed[giveplayerid] > 1)
					{
						SendClientMessage(playerid, COLOR_GREY, "   That player is already Cuffed !");
						return 1;
					}
					if(IsPlayerInAnyVehicle(giveplayerid))
					{
						SendClientMessage(playerid, COLOR_GREY, "   Suspect is in a car, get him out first !");
						return 1;
					}
					if(PlayerCuffed[giveplayerid] == 1 || GetPlayerSpecialAction(giveplayerid) == SPECIAL_ACTION_HANDSUP)
					{
							if(ProxDetectorS(8.0, playerid, giveplayerid))
							{
							    if(giveplayerid == playerid) { SendClientMessage(playerid, COLOR_GREY, "   You can't Cuff yourself !"); return 1; }
						    	GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
						    	GetPlayerName(playerid, sendername, sizeof(sendername));
						    	format(string, sizeof(string), "* You were Cuffed by Officer %s.", sendername);
						    	SendClientMessage(giveplayerid, COLOR_LIGHTBLUE, string);
								if(PlayerInfo[giveplayerid][pMask] == 1)
						    	{
								    format(string, sizeof(string), "* You Cuffed A Stranger.");
							    	SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
							    	format(string, sizeof(string), "* %s Hand Cuffs A Stranger, so he wont go anywhere.", PlayerName(playerid));
							    	ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
								}
								else
								{
								    format(string, sizeof(string), "* You Cuffed %s.", giveplayer);
									SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
									format(string, sizeof(string), "* %s Hand Cuffs %s, so he wont go anywhere.", sendername ,giveplayer);
									ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
								}
								GameTextForPlayer(giveplayerid, "~r~Cuffed", 2500, 3);
								TogglePlayerControllable(giveplayerid, 1);
								ClearAnimations(giveplayerid);
								SetPlayerSpecialAction(giveplayerid,SPECIAL_ACTION_CUFFED);
								SetPlayerSpecialAction(giveplayerid,SPECIAL_ACTION_CUFFED);
								PlayerCuffed[giveplayerid] = 2;
								PlayerCuffedTime[giveplayerid] = 86400;
							}
							else
							{
						    	SendClientMessage(playerid, COLOR_GREY, "   That player is not near you !");
						    	return 1;
							}
					}
					else
					{
						SendClientMessage(playerid, COLOR_GREY, "   That player needs to be restrained first !");
						return 1;
					}
				}
				else
				{
				   SendClientMessage(playerid, COLOR_GREY, "   That player is Offline !");
				   return 1;
				}
			}
			else
			{
				SendClientMessage(playerid, COLOR_GREY, "   You are not a Cop / FBI / SAST !");
			}
		}
		return 1;
	}
	if(strcmp(cmd, "/uncuff", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
			if(IsACop(playerid) || IsAAgent(playerid) || IsANG(playerid))
			{
			    tmp = strtok(cmdtext, idx);
				if(!strlen(tmp))
				{
					SendClientMessage(playerid, COLOR_WHITE, "USAGE: /uncuff [Playerid/PartOfName]");
					return 1;
				}
				giveplayerid = ReturnUser(tmp);
				if(IsPlayerConnected(giveplayerid))
				{
					if(giveplayerid != INVALID_PLAYER_ID)
					{
					    if(ProxDetectorS(8.0, playerid, giveplayerid))
						{
						    if(giveplayerid == playerid) { SendClientMessage(playerid, COLOR_GREY, "   You can't Uncuff yourself !"); return 1; }
							if(PlayerCuffed[giveplayerid])
							{
							    GetPlayerName(playerid, sendername, sizeof(sendername));
							    GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
							    format(string, sizeof(string), "* You were Uncuffed by %s.", sendername);
								SendClientMessage(giveplayerid, COLOR_LIGHTBLUE, string);
								if(PlayerInfo[giveplayerid][pMask] == 1)
						    	{
								    format(string, sizeof(string), "* You uncuffed A Stranger.");
							    	SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
							    	format(string, sizeof(string), "* %s has uncuffed A Stranger.", PlayerName(playerid));
							    	ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
								}
								else
								{
								    format(string, sizeof(string), "* You uncuffed %s.", giveplayer);
									SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
									format(string, sizeof(string), "* %s has uncuffed %s.", sendername ,giveplayer);
									ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
								}
								GameTextForPlayer(giveplayerid, "~g~Uncuffed", 2500, 3);
								TogglePlayerControllable(giveplayerid, 1);
								ClearAnimations(giveplayerid);
								PlayerCuffed[giveplayerid] = 0;
								PlayerCuffedTime[giveplayerid] = 0;
							}
							else
							{
							    SendClientMessage(playerid, COLOR_GREY, "   That player isn't Cuffed !");
							    return 1;
							}
						}
						else
						{
						    SendClientMessage(playerid, COLOR_GREY, "   That player is not near you !");
						    return 1;
						}
					}
				}
				else
				{
				    SendClientMessage(playerid, COLOR_GREY, "   That player is Offline !");
				    return 1;
				}
			}
			else
			{
				SendClientMessage(playerid, COLOR_GREY, "   You are not a Cop / FBI / SAST !");
			}
		}
		return 1;
Willy is offline   Reply With Quote
Old 15/08/2012, 09:49 AM   #1737
Garsino
Huge Clucker
 
Garsino's Avatar
 
Join Date: Mar 2012
Location: Norway
Posts: 232
Reputation: 116
Default Re: Little coding questions - For general minor queries 5

That's because SPECIAL_ACTION_CUFFED isn't an animation in terms of the other anims. It's a special action that can only be cleared by other special actions, and in some cases, pressing ENTER/etc..

If you want to clear it script wise use:
pawn Code:
SetPlayerSpecialAction(giveplayerid, SPECIAL_ACTION_NONE);
__________________
Garsino is offline   Reply With Quote
Old 16/08/2012, 01:43 AM   #1738
IceMeteor
Big Clucker
 
Join Date: Nov 2011
Location: Indonesia
Posts: 141
Reputation: 20
Default Re: Little coding questions - For general minor queries 5

Hello, I still cofused about the usage of MoveObject, the default rot is -1000 right, so if i want to rotate it 90 deg, what number i have to put?
And, if I set PVarInt in the filterscript, can it be read at the GM?
IceMeteor is offline   Reply With Quote
Old 16/08/2012, 08:46 AM   #1739
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,493
Reputation: 1028
Default Re: Little coding questions - For general minor queries 5

Quote:
Originally Posted by IceMeteor View Post
Hello, I still cofused about the usage of MoveObject, the default rot is -1000 right, so if i want to rotate it 90 deg, what number i have to put?
And, if I set PVarInt in the filterscript, can it be read at the GM?
I think -1000 is just some arbitrary number, the function probably checks if the value is -1000 and if it is, don't rotate.
The input is in degrees so just put 90.

As for PVars, yes, they can be read (and written I think) across scripts
[HLF]Southclaw is offline   Reply With Quote
Old 16/08/2012, 12:22 PM   #1740
detter
Big Clucker
 
Join Date: Dec 2010
Posts: 153
Reputation: 10
Default Re: Little coding questions - For general minor queries 5

Should I forward every single of my functions?
I'm not really sure what it does.
detter 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 03: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 04:07 PM.


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