SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 24/12/2017, 09:40 AM   #711
xMoBi
Big Clucker
 
Join Date: Jul 2017
Location: Australia (visit) - Pakistan (original)
Posts: 99
Reputation: 26
Default Re: Today I learned - Share your newly found knowledge!

Quote:
Originally Posted by iAmir View Post
Today I Learned that I can set ExtraID for streamer items like area , objects , checkpoint and etc
and use it when I want to find them instead of setting a variable and make huge loop to find it

Example :

Code:
CreateHouse(h) { // Let's say this is where the house is created.

         House[h][iAreaID]= CreateDynamicSphere(blah, blah, blah, somevalue, somevalue);
	Streamer_SetIntData(STREAMER_TYPE_AREA, House[h][iAreaID], E_STREAMER_EXTRA_ID, h);
}
And then instead of making a loop in House variable and check for areaid == i matches you can easily do this :

Code:
public OnPlayerEnterDynamicArea(playerid, areaid) {

	new h = Streamer_GetIntData(STREAMER_TYPE_AREA, areaid, E_STREAMER_EXTRA_ID);
	if(0 <= h < MAX_HOUSES) { 
	      // here it is! player is in house h !
	}
}
Thatís lit! I learned from here : http://forum.sa-mp.com/showthread.php?t=611692
this thread is not for this kind of things its about things you learn yourself
xMoBi is offline   Reply With Quote
Old 26/12/2017, 03:05 AM   #712
admantis
High-roller
 
Join Date: Sep 2009
Posts: 2,581
Reputation: 446
Default Re: Today I learned - Share your newly found knowledge!

Quote:
Originally Posted by jlalt View Post
Today learnt how to get the distance between two points ;-;, with / without Z.



which would use
http://wiki.sa-mp.com/wroot/index.php?title=Floatsqroot
and
http://wiki.sa-mp.com/wiki/Floatpower
This also works for 3D spaces (with the Z vector) using the Pythagoras theorem.
admantis is offline   Reply With Quote
Old 28/12/2017, 10:03 PM   #713
mirou123
Huge Clucker
 
Join Date: Jul 2013
Posts: 368
Reputation: 22
Default Re: Today I learned - Share your newly found knowledge!

Quote:
Originally Posted by admantis View Post
This also works for 3D spaces (with the Z vector) using the Pythagoras theorem.
It works in any dimension.
mirou123 is offline   Reply With Quote
Old 29/12/2017, 02:04 PM   #714
GaByM
Big Clucker
 
GaByM's Avatar
 
Join Date: Jan 2014
Location: Romania
Posts: 111
Reputation: 7
Default Re: Today I learned - Share your newly found knowledge!

TIL that using the switch statement slow down compilation time A LOT if used with many cases. I went from compiling my script in 8-15s to 200+
GaByM is offline   Reply With Quote
Old 29/12/2017, 02:23 PM   #715
whadez
Big Clucker
 
whadez's Avatar
 
Join Date: Jun 2014
Location: Hungary
Posts: 120
Reputation: 21
Default Re: Today I learned - Share your newly found knowledge!

Quote:
Originally Posted by GaByM View Post
TIL that using the switch statement slow down compilation time A LOT if used with many cases. I went from compiling my script in 8-15s to 200+
ayylmao xd
__________________
Developing Documentations: Click Here

Reference:
(Laravel, Vue.js) LS:RP MTA [Click Here]
(Laravel) LimeGaming MTA [Click Here]
(Laravel) Blue Lake Roleplay [Click Here]
(Plain PHP) GTA Project Roleplay [Click Here]
(Plain PHP) California Gaming Roleplay [Click Here]

I'm willing to take webdevelopment jobs. Contact me for info.
Discord: whadez#4817
whadez is offline   Reply With Quote
Old 30/12/2017, 08:12 PM   #716
adri1
Banned
 
Join Date: Oct 2010
Posts: 1,938
Reputation: 955
Default Re: Today I learned - Share your newly found knowledge!

Today I learned that all +18yo people that play samp smoke weed
(at least 90% according to my calculations)
adri1 is offline   Reply With Quote
Old 31/12/2017, 09:25 AM   #717
Dutheil
Godfather
 
Dutheil's Avatar
 
Join Date: Jul 2014
Location: France
Posts: 5,134
Reputation: 220
Default Re: Today I learned - Share your newly found knowledge!

Quote:
Originally Posted by GaByM View Post
TIL that using the switch statement slow down compilation time A LOT if used with many cases. I went from compiling my script in 8-15s to 200+
https://pastebin.com/jHf6MyU0
Raw : https://pastebin.com/raw/jHf6MyU0

With the latest version of the Zeex's PAWN Compiler.
Code:
Pawn compiler 3.10.4	 	 	Copyright (c) 1997-2006, ITB CompuPhase

[Finished in 0.5s]
__________________
#PrayForFrenchForum
GitHub

Code:
print({1466458484, 543452960, 2037347616, 1952999790, 1797286260, 544694643, 543649646, 1851859053, 1634428192, 1056964608});

Last edited by Dutheil; 31/12/2017 at 10:41 AM.
Dutheil is offline   Reply With Quote
Old 03/01/2018, 06:52 AM   #718
GaByM
Big Clucker
 
GaByM's Avatar
 
Join Date: Jan 2014
Location: Romania
Posts: 111
Reputation: 7
Default Re: Today I learned - Share your newly found knowledge!

Quote:
Originally Posted by Dutheil View Post
https://pastebin.com/jHf6MyU0
Raw : https://pastebin.com/raw/jHf6MyU0

With the latest version of the Zeex's PAWN Compiler.
Code:
Pawn compiler 3.10.4	 	 	Copyright (c) 1997-2006, ITB CompuPhase

[Finished in 0.5s]
Yes, but I did this:

HTML Code:
#include <a_samp>


main()
{
	new b;
	switch(b)
	{
		case 0..20000: {}
		case 20001..115000: {}
		case 115001..200000: {}
		default: {}
	}
}
Which could be so nicely divided by 5000 or 10000, but who would have thought 3 lines of code can take so much to compile?

Last edited by GaByM; 03/01/2018 at 10:11 AM.
GaByM is offline   Reply With Quote
Old 03/01/2018, 07:25 AM   #719
Logic_
High-roller
 
Logic_'s Avatar
 
Join Date: Jun 2015
Location: Oblivion
Posts: 1,485
Reputation: 263
Default Re: Today I learned - Share your newly found knowledge!

Do you even think some one would do that? And if you're doing it, are you actually using it for something useful or it's just an assumption of a code and you compiled it to check something?

Awaiting response.
__________________
Logic_ is offline   Reply With Quote
Old 03/01/2018, 09:52 AM   #720
GaByM
Big Clucker
 
GaByM's Avatar
 
Join Date: Jan 2014
Location: Romania
Posts: 111
Reputation: 7
Default Re: Today I learned - Share your newly found knowledge!

Yes, I use this kind of switch for my fishing system:
Code:
switch(b/10000)
{
	case 0, 1: a = (strcat(s, "some turtles"))*0 + COL_GREY;
	case 2..21: a = (strcat(s, "some fish"))*0 + COL_INFO;
	case 22..39: a = (strcat(s, "a shark"))*0 + COL_BLUE;
	default: a = (strcat(s, "a whale!"))*0 + COL_CYAN;
}
format(str, sizeof(str), "Congratulations! You have caught %s (%i kg). (%i/100 full)", s, b/5000, q);
SCM(playerid, a, str);
Why not an 'if else' block? 2..21 is more readable than (1 < b < 22)

Why do I work with so big numbers in the first place?
'b' means how much volume ocupies the caught fish (since you fish on a boat, your fish fills the boat's boot; every boat has other capacities of storage) measured in cubic centimeters. Why? For reference.

At the moment, I copy other server's economy so I won't place an ad for $50 and eat a burger for $1000.
For example: If a rare fish (a shark) is worth $200,000; on my server, that would be a 200,000cm^3 fish (worth $5,000)
A normal fish (some fish) is worth at least $20,000 and on my server is a 20,000cm^3 fish (worth $500)
GaByM 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
Things you learned from GTA SA Toni Everything and Nothing 212 20/08/2011 07:07 AM
How you learned to script Bam23 Help Archive 9 11/04/2011 10:21 AM
What did u learned today ? rafay Everything and Nothing 170 30/03/2010 04:06 PM


All times are GMT. The time now is 02:43 PM.


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