Little coding questions - For general minor queries 5

Hy,

How do you get data from 3-D array ?

Something like this doesn't work
Код:
new someArray[3][2][] = 
{
    {"One" ,1},
    {"Two" ,2},
    {"Four" ,3},
};

...

new someVar = someArray[0][1];
but this works
Код:
printf("%s %i" ,someArray[1][0] ,someArray[1][1]);
Reply

Quote:
Originally Posted by several
Посмотреть сообщение
How do you get data from 3-D array ?
You array has 3 rows, 2 columns and each field is an array, although 1, 2, 3 don't look like one
Lets add the brackets to make it clear, it should look like that
PHP код:
new someArray[3][2][] = 
{
    {
"One" , {1}},
    {
"Two", {2}},
    {
"Four", {3}}
};
// or like that if you represent the string as array
new someArray2[3][2][] = 
{
    {
        {
'O''n''e'EOS},
        {
1}
    }, {
        {
'T''w''o'EOS},
        {
2}
    }, {
        {
'F''o''u''r'EOS},
        {
3}
    }
}; 
With that it should be clear that you need to do
PHP код:
new someVar someArray[0][1][0]; 
printf does work because it only gets the address, you could even print someArray or someArray[0] if you want
Reply

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
You array has 3 rows, 2 columns and each field is an array, although 1, 2, 3 don't look like one
Lets add the brackets to make it clear, it should look like that
PHP код:
new someArray[3][2][] = 
{
    {
"One" , {1}},
    {
"Two", {2}},
    {
"Four", {3}}
};
// or like that if you represent the string as array
new someArray2[3][2][] = 
{
    {
        {
'O''n''e'EOS},
        {
1}
    }, {
        {
'T''w''o'EOS},
        {
2}
    }, {
        {
'F''o''u''r'EOS},
        {
3}
    }
}; 
With that it should be clear that you need to do
PHP код:
new someVar someArray[0][1][0]; 
printf does work because it only gets the address, you could even print someArray or someArray[0] if you want
Ehhh ,I'm an idiot ,thanks.
Reply

Sorry for reposting but i was wondering if something like this was possible in pawn:

Код:
enum CORD
{
	Float:X,
	Float:Y,
	Float:Z,
	INT,
	VW
}

stock pPos(id ,& CORD:cord)
{
	cord[INT] = GetPlayerVirtualWorld(id);
	cord[VW] = GetPlayerInterior(id);
	GetPlayerPos(id ,cord[X] ,cord[Y] ,cord[Z]);	
}

... 
new pos[CORD];
pPos(playerid ,pos);
instead of
Код:
stock pPos(id ,& Float:x ,& Float:y  ,...)

... 
new pos[CORD];
pPos(playerid ,pos[X] ,pos[Y] ,...);
Reply

Quote:
Originally Posted by several
Посмотреть сообщение
<>
Sure, but the enum is just an enumerator, you can't pass it directly as a parameter like that, you need an array with the first dimension set as that enum so you have where to store the new values:
PHP код:
enum gePosInfo
{
    
Float:X,
    
Float:Y,
    
Float:Z,
    
INT,
    
VW
}
stock GetPlayerPosInfoplayeridposInfogePosInfo ] ) // you don't need & because arrays are automatically passed by reference
{
    
posInfoINT ] = GetPlayerVirtualWorldplayerid );
    
posInfoVW ] = GetPlayerInteriorplayerid );
    
GetPlayerPosplayeridposInfo], posInfo], posInfo] );
}
public 
OnPlayerUpdateplayerid )
{
    new 
lPosInfogePosInfo ] = { -1.0, -1.0, -1.0, -1, -};
    
printf"Before: %f %f %f %d %d"lPosInfo], lPosInfo], lPosInfo], lPosInfoINT ], lPosInfoVW ] ); // prints -1.0, -1.0, -1.0, -1, -1
    
GetPlayerPosInfoplayeridlPosInfo );
    
printf"After: %f %f %f %d %d"lPosInfo], lPosInfo], lPosInfo], lPosInfoINT ], lPosInfoVW ] ); // prints correct values
    
return 1;

Also, about your 3D array problem: it is way better to use enums in that case:
PHP код:
enum someEnum
{
    
someString], // max string size is 8
    
someVar
};
new 
someArray][ someEnum ] =  

    { 
"One"}, 
    { 
"Two"}, 
    { 
"Four"
};
// get elements:
for( new 0sizeofsomeArray ); ++ )
{
    
printf"someArray[ %d ] = { '%s', %d }"isomeArray][ someString ], someArray][ someVar ] );

With this method only what you need will be an actual sub-array: the string in this case (in Pawn, a string is an array of characters [represented by ASCII values]), without setting the integer as an array too, which made no sense and is bad. Using enum in that case also offers more protection at compile time and you can easily access them by using the name of the element.
Reply

Is it possible to put the server maps out of gamemode? without filterscript?
What code do I have to do to do this?

like:
PHP код:
"#include         "..modules\maps\house.pwn
But if I do, what, what code should I put in house.pwn to put the map in?
Reply

Quote:
Originally Posted by axellech
Посмотреть сообщение
Is it possible to put the server maps out of gamemode? without filterscript?
What code do I have to do to do this?

like:
PHP код:
"#include         "..modules\maps\house.pwn
But if I do, what, what code should I put in house.pwn to put the map in?
Yes, it should be as followed.
PHP код:
//house.pwn
CreateHouses()
{
        
CretaeDynamicObject(.....);
        
CretaeDynamicObject(.....);
        
CretaeDynamicObject(.....);
        
//.....
        
CretaeDynamicObject(.....);
        
CretaeDynamicObject(.....);

PHP код:
//your gaemode file
OnGamemodeInIt()
{
        
CreateHouses();
        return 
1;

Reply

Quote:
Originally Posted by Eoussama
Посмотреть сообщение
Yes, it should be as followed.
PHP код:
//house.pwn
CreateHouses()
{
        
CretaeDynamicObject(.....);
        
CretaeDynamicObject(.....);
        
CretaeDynamicObject(.....);
        
//.....
        
CretaeDynamicObject(.....);
        
CretaeDynamicObject(.....);

PHP код:
//your gaemode file
OnGamemodeInIt()
{
        
CreateHouses();
        return 
1;

Thank you <3
Reply

How to put a custom texture on "room decorating images" objects?
"custom images into object, how to do this?"
Reply

i need some help here
PHP код:
error 001expected token"-string end-"but found "-identifier-"
warning 215expression has no effect
error 001
expected token";"but found ")"
error 029invalid expressionassumed zero
fatal error 107
too many error messages on one line 
non-formatted messages work fine, using format causes the above mentioned problems.

all these errors coming from
PHP код:
new str[70];
format(strsizeof str"You can't chat while you're muted, you must wait %d seconds."PlayerStat[playerid][MuteTime]);
SendErrorMessage(playeridstr); // this line 
definition of SendErrorMessage
PHP код:
#define SendErrorMessage(%1,%2) \
    
SendClientMessage(%1COLOR_PINK"[ERROR] {FFFFFF} " %2
Reply

Quote:
Originally Posted by GaByM
Посмотреть сообщение
PHP код:
#include <a_samp>
main()
{
    new 
k;
    if(
k)
        return 
1;
    else
    {
    }
    return 
1;

PHP код:
D:\SERVER\gamemodes\a.pwn(10) : warning 225unreachable code 
Why?
PHP код:
#include <a_samp> 
main() 

    new 
k
    if(
k
        return 
1
    else if (!
k
    { 
    } 
    return 
1

try this.
Reply

Hi, this error "Array index out of bounds" show when you acces an element past over you defined variable like new variable[20] and you acces 20 or 21 etc.
So I have this error

Код:
[20:58:23] [debug] AMX backtrace:
[20:58:23] [debug] #0 00068d9c in ?? (1) from rpggm.amx
[20:58:23] [debug] #1 001c3860 in public TimerSeconds () from rpggm.amx
[20:58:24] [debug] Run time error 4: "Array index out of bounds"
[20:58:24] [debug]  Accessing element at index 27 past array upper bound 25
so this error show me I have a variable [26] and I acces upper element, but I can sure you I have no variable with value [24] [25] or [26]
So I ask you what else can produce this error?
Reply

Solved thx anyway
Reply

When using mysql_tquery, should I use cache_delete(x) if I don't use cache_save()? AFAIK the result isn't stored by default, but I want to be sure, so I won't get memory leaks.
Reply

I'm not really good at mapping. Is it possible for the text of the object below to be changed?

Reply

Quote:
Originally Posted by [HLF]Southclaw
Посмотреть сообщение
Yeah you can change that, either via SetObjectMaterialText or (when 0.3.8 comes out) via changing the texture and providing the new object+texture as a downloadable asset.
Used SetObjectMaterialText but had a little problem

Код:
new obj0 = CreateObject(3715, 1362.1599, -1036.0848, 31.3095, 0.0000, 0.0000, 84.1780);
SetObjectMaterialText(obj0, "SAMPTESTSAMPTEST SAMPTEST", 2, 120, "Castellar", 60, 0, 0xFFFFFFFF, 0xFF000000, 2);
RESULT:
Reply

Quote:
Originally Posted by [HLF]Southclaw
Посмотреть сообщение
You'll have to just pad it with spaces, there's sadly no way to alter UV coordinates with material functions.
It still doesn't work, the same result.
Reply

Which one is preferable to update the car's health?
- Using OnPlayerUpdate and checking if the player is inside a vehicle
- A timer though every vehicle running every second/500 ms
- A timer though every player running every second/500ms
Reply

Quote:
Originally Posted by [HLF]Southclaw
Посмотреть сообщение
The answer would depend on your average player count, amount of vehicles and future scale plans.
Yep, obivously. My bad.
Average 60-80 players & +1000 vehicles.

I'm asking myself between a timer and OnPlayerUpdate. I find the timer will be not accurate for the vehicle's health and OnPlayerUpdate is called too much time for this use.
Reply

Use a timer. As you said OnPlayerUpdate gets called 30+ times in a second, so isn't very efficient when there are a lot of players driving
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)