SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 08/11/2017, 08:07 PM   #4441
Dayrion
High-roller
 
Dayrion's Avatar
 
Join Date: Jan 2016
Location: France
Posts: 1,556
Reputation: 160
Default Re: Little coding questions - For general minor queries 5

Hey. I should misunderstood something about Dynamic 3D Text Label.
I've this code
PHP Code:
CMD:test_label(playeridparams[])
{
    
extract params -> new player:targetid; else return 0;

    new 
Float:x,
        
Float:y,
        
Float:z;

    
GetPlayerPos(targetidxyz);

    
CreateDynamic3DTextLabel("TEST LABEL123456"0xFF0000FFxy5.030.0targetid_, .testlos 1, .playerid playerid);
    return 
1;

The label is correctly created (even if the pose is the same despite of the z) but I can't see him though objects like testlos should. If anyone have ideas, tips, or something I'll take it.
__________________
Sometimes you might be lucky enough to bump into the one person
you wanna spend the rest of your life with, and that is love.
Oscar
Dayrion is offline   Reply With Quote
Old 08/11/2017, 08:08 PM   #4442
n00blek
Huge Clucker
 
Join Date: Aug 2017
Location: England is my city
Posts: 262
Reputation: 18
Default Re: Little coding questions - For general minor queries 5

Can i divide vehicle velocity by 1/2?
Im gonna explain
On a lot of servers velocity is neutral. Im riding a bike and it says im going 130 KH/h. Nonsense.
Is there a way to divide velocity for example if im going 100 km/h it says 50. Only 2 exceptions if im going 1 it doesnt say 0.5 but 1 km/h BUT if im going 1.5kmh it says 1kmh and so on. Is it possible?
__________________
RMTeam Roleplay! Under construction.

192.168.64.100:7777

PM me for donations(not money, script commands)
n00blek is offline   Reply With Quote
Old 08/11/2017, 08:12 PM   #4443
IstuntmanI
High-roller
 
IstuntmanI's Avatar
 
Join Date: Mar 2009
Location: Romania
Posts: 1,885
Reputation: 370
Default Re: Little coding questions - For general minor queries 5

Quote:
Originally Posted by Dayrion View Post
Hey. I should misunderstood something about Dynamic 3D Text Label.
I've this code
PHP Code:
CMD:test_label(playeridparams[])
{
    
extract params -> new player:targetid; else return 0;

    new 
Float:x,
        
Float:y,
        
Float:z;

    
GetPlayerPos(targetidxyz);

    
CreateDynamic3DTextLabel("TEST LABEL123456"0xFF0000FFxy5.030.0targetid_, .testlos 1, .playerid playerid);
    return 
1;

The label is correctly created (even if the pose is the same despite of the z) but I can't see him though objects like testlos should. If anyone have ideas, tips, or something I'll take it.
You have to set the testlos to 0. Testlos = test Line of Sight, so you don't want it to test the line of sight. With 1, if there's an object on the line to the label, the label won't appear.
__________________


IstuntmanI is offline   Reply With Quote
Old 08/11/2017, 08:19 PM   #4444
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,769
Reputation: 1297
Default Re: Little coding questions - For general minor queries 5

Quote:
Originally Posted by n00blek View Post
Can i divide vehicle velocity by 1/2?
Im gonna explain
On a lot of servers velocity is neutral. Im riding a bike and it says im going 130 KH/h. Nonsense.
Is there a way to divide velocity for example if im going 100 km/h it says 50. Only 2 exceptions if im going 1 it doesnt say 0.5 but 1 km/h BUT if im going 1.5kmh it says 1kmh and so on. Is it possible?
Read this, enjoy: http://forum.sa-mp.com/showthread.php?t=364124
__________________



[HLF]Southclaw is offline   Reply With Quote
Old 09/11/2017, 11:48 AM   #4445
Derzhavin
Little Clucker
 
Derzhavin's Avatar
 
Join Date: Jul 2015
Location: Siberia
Posts: 24
Reputation: 0
Default Re: Little coding questions - For general minor queries 5

Quote:
Originally Posted by Derzhavin View Post
can u help me? when i get checkpoint nothing happens

Code:
				if(PlayerInfo[i][pJob] == 2 && PlayerInfo[i][TaxiS] == 02)
				{
					if(IsTaxi(i) && GetPlayerState(i) == 2 && GetPlayerVehicleID(i) == GetPlayerVehicleID(playerid))
					{
						if(PlayerInfo[playerid][pLevel] == 1)
						{
						new stringl[256];
						format(stringl,sizeof(stringl),"%s in your taxi.",PlayerInfo[playerid][pName]);
						SendClientMessage(i,0x0099FFAA, stringl);
						format(stringl,sizeof(stringl),"you in %s 's taxi.",PlayerInfo[i][pName]);
						SendClientMessage(playerid,0x0099FFAA, stringl);
						SetPlayerCheckpoint(i, 781.5677,841.8466,5.8482,5.0);
      					cKar[i] = 1;
						}
	  					else
	  					{
	  					    SCM(playerid, COLOR_RED, "Social taxi only for newbie");
	  					    RemovePlayerFromVehicle(playerid);
				    	}
					}
				}
public OnPlayerEnterCheckpoint(playerid)

Code:
		if(IsPlayerInRangeOfPoint(i,2.0,781.5677,841.8466,5.8482))
		{
	  		PlayerInfo[i][pCash] += 500;
	        DisablePlayerCheckpoint(i);
	        SCM(i, COLOR_GREEN, "u get 500$");
		}
		return true;
		}
still have problems
__________________
ruskivodkaputin.

sorry for bad eng. thx.
Derzhavin is offline   Reply With Quote
Old 09/11/2017, 05:09 PM   #4446
several
Little Clucker
 
Join Date: Nov 2017
Posts: 3
Reputation: 0
Default Re: Little coding questions - For general minor queries 5

Hy,

How do you get data from 3-D array ?

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

...

new someVar = someArray[0][1];
but this works
Code:
printf("%s %i" ,someArray[1][0] ,someArray[1][1]);
several is offline   Reply With Quote
Old 09/11/2017, 07:57 PM   #4447
Nero_3D
High-roller
 
Nero_3D's Avatar
 
Join Date: Jun 2007
Location: Germany
Posts: 3,753
Reputation: 630
Default Re: Little coding questions - For general minor queries 5

Quote:
Originally Posted by several View Post
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 Code:
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 Code:
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
__________________
Nero_3D is offline   Reply With Quote
Old 09/11/2017, 08:25 PM   #4448
several
Little Clucker
 
Join Date: Nov 2017
Posts: 3
Reputation: 0
Default Re: Little coding questions - For general minor queries 5

Quote:
Originally Posted by Nero_3D View Post
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 Code:
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 Code:
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.
several is offline   Reply With Quote
Old 10/11/2017, 05:17 PM   #4449
several
Little Clucker
 
Join Date: Nov 2017
Posts: 3
Reputation: 0
Default Re: Little coding questions - For general minor queries 5

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

Code:
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
Code:
stock pPos(id ,& Float:x ,& Float:y  ,...)

... 
new pos[CORD];
pPos(playerid ,pos[X] ,pos[Y] ,...);
several is offline   Reply With Quote
Old 10/11/2017, 05:33 PM   #4450
IstuntmanI
High-roller
 
IstuntmanI's Avatar
 
Join Date: Mar 2009
Location: Romania
Posts: 1,885
Reputation: 370
Default Re: Little coding questions - For general minor queries 5

Quote:
Originally Posted by several View Post
<>
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 Code:
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 Code:
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.
__________________


IstuntmanI 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 04:35 PM
Minor problem Desert Help Archive 4 17/03/2010 07: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 08:47 PM


All times are GMT. The time now is 07:22 AM.


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