The online racing simulator
[Solved] Restriction P_Tress Check
Hello, yesterday me and "Dan Taco" have put a code together that calculates the P_Tress in % from your current Horsepower like 104 hp .

P_Tress = (247HP - "Wanted HP") / 2,86

for example
P_Tress = (247HP - 104HP) / 2,86
P_Tress = 50

Anyways my Main Problem is, that P_Tress does not work at all.

On the following code i will get the Message "Bad Boy 2" all the time, no matter what i do.
I have even deleted the whole Restriction code from LFSLapper.lpr while it was disabled with a # infront of every row.
any help would be very appreciated.

CatchEvent OnNewPlayerJoin ( $userName )
IF(GetPlayerVar($userName,"P_Tress") >= 20) THEN
privmsg($userName,"Good Boy 1");
ELSE
privmsg($userName,"Bad Boy 2");
ENDIF
EndCatchEvent

ThanksSmile
#2 - lucaf
You didn't show us the code where you assign the calculated value to P_Tress. But I guess you failed to assign it, and it remains 0? Did you use SetPlayerVar?
Have you tried, which value GetPlayerVar($userName,"P_Tress") returns??
And i see one typo: its 'P_Tres' no 'P_Tress'. This could solve your problem?

@ lucaf: P_Tres (Air_Restriction) is one of the Playervalues you dont have to set first.
This value is retreived from LFS when someone joins the server
so yes ive had a "s" to much in P_Tres.

so heres the 2. Problem i have had.

This Basically works but is not rounded

CatchEvent OnNewPlayerJoin ( $userName )
$userName = GetCurrentPlayerVar("UserName");
IF(GetPlayerVar($userName,"Car") == XRT) THEN
IF(GetPlayerVar($userName,"P_Tres") == 247 - GetUserStoredValue($userName," 1XRT") / 2.86 ) THEN
privmsg($userName,"Good Boy 1");
ELSE
privmsg($userName,"Bad Boy 2");
ENDIF
ENDIF
EndCatchEvent

Ive tried to round it, but got this error:

Incorrect args number in function round

CatchEvent OnNewPlayerJoin ( $userName )
$userName = GetCurrentPlayerVar("UserName");
IF(GetPlayerVar($userName,"Car") == XRT) THEN
IF(GetPlayerVar($userName,"P_Tres") == 247 - round(GetUserStoredValue($userName," 1XRT") / 2.86 )) THEN
privmsg($userName,"Good Boy 1");
ELSE
privmsg($userName,"Bad Boy 2");
ENDIF
ENDIF
EndCatchEvent

to explain:

You can basically buy 5 different XFGS with different HP and Select between them 5 to set as the "Current Car"

and the Value is set with the Horsepower the car has got to weve got to calculate the % in Restriction.
The Round function must contain two variables.
Round($Var,0)


First variable is a variable that need to be rounds. Could be a PlayerVar or everything that contains a numeric value.

The 2nd one rounds the first variable to a specified number of digits behind the comma.
Few examples:

$Number = 1.26456

$RoundedNumber = Round($Number,0);
Output: 1
$RoundedNumber = Round($Number,1);
Output: 1,3
$RoundedNumber = Round($Number,2);
Output: 1,26

Also try the code below. It will turn your Set value into a numeric value. I know its a numeric value but just to be sure.Lapper can go weird sometimes.

IF(GetPlayerVar($userName,"P_Tres") == ToNum(247 - Round(GetUserStoredValue($userName," 1XRT") / 2.86 ),0)) THEN

Incorrect args number in function Round

yet the same
Try now, made a small mistake, played one of the ')' wrong

IF (GetPlayerVar($userName,"P_Tres") == ToNum(Round((247 - GetUserStoredValue($userName," 1XRT") / 2.86 ),0)))
nope, thats exactly what ive tried after your posted it Frown
** Best answer **
I don't know if you problem is already solved, but if it isn't, I might have something that helps you.

I've tested this piece of code:


<?php 
Privmsg 
("^7DEBUG: " ToNumRound( (247 130 2.86 ),) ) );
?>

Which is nearly the same as you had, except that I put in '130' instead of 'GetUserStoredValue($userName," 1XRT")'
The DEBUG message then said: 202
This is the correct answer as 130 / 2.86 = 45.45454545454545 = rounded to zero decimals: 45
Then 247-45 = 202

So the round function is working correctly, when using a static number, which makes me think that the problem is related to the GetUserStoredValue.
Then I tried this:


<?php 
$userName 
GetCurrentPlayerVar"UserName" );
Privmsg ("^7DEBUG: " ToNumRound( (247 GetUserStoredValue($userName," 1XRT") / 2.86 ),) ) );
?>

Still no error about the round function, but I wasn't getting the value '1XRT' either.
After having a close look, I noticed you have a space before 1XRT, so I tried this:


<?php 
$userName 
GetCurrentPlayerVar"UserName" );
Privmsg ("^7DEBUG: " ToNumRound( (247 GetUserStoredValue($userName,"1XRT") / 2.86 ),) ) );
?>

Now the DEBUG messages said again: 202

Since I had a problem with numbers being retrieved, while working on the cross-server chat script, I think it would be a good idea to replace GetUserStoredValue with GetUserStoredNum, as that will make sure a number is retrieved from the database.
Hopefully this will help you, otherwise I will be happy to give any assistance.
He was getting the " XRT1" value without problems :/

ive tried it yesterday without the Round function and it showed me perfectlySmile



yet round() gives an error, even on this code:

Privmsg ("^7DEBUG: " . ToNum( Round( (247 - GetUserStoredValue($userName," 1XRT") / 2.86 ),0 ) ) );



EDIT: Nope, my problem typed !Test instead of !test Thumbs up

anyways ill get on coding and see what happensSmile

cheers alot Yisc
So its finally working!Smile

To explain:
So basically you can buy up to 5 cars each car (XRT,XFG etc) and have to Select one you want to use.
When you bought a Car (different Horsepower available), the HP will be set to " 1XRT".
The Car will be set to the next available Spot. (One_SXRT to Fifth_SXRT)

" One_SXRT" = One is for the first Spot, the "S" in the "SXRT" is for "Current Selected Car" 1 = True; 0 = False
" 1XRT" = XRT on the first Spot, Set with the Horsepower (depends on what you bought)


This code should work to all Restrictions in Percent for the XRT only!
(247 - 186) / 2.874 =
21,22478
=21 % Restriction for 186HP
. ToNum( Round( ((247 - GetUserStoredValue($userName," 1XRT")) / 2.874 ),0 ) ) );

However heres the code:

CatchEvent OnNewPlayerJoin ( $userName )
IF(GetPlayerVar($userName,"Car") == XRT) THEN
IF (GetUserStoredValue($userName," One_SXRT") == 1) THEN
IF(GetPlayerVar($userName,"P_Tres") == ToNum( Round( ((247 - GetUserStoredValue($userName," 1XRT")) / 2.874 ),0 ) ) ) THEN
privmsg($userName,"you entered the Track with a XRT ".GetUserStoredValue($userName," 1XRT"));
ELSE
privmsg($userName,"To Enter the Track use " . ToNum( Round( ((247 - GetUserStoredValue($userName," 1XRT")) / 2.874 ),0 ) ));
privmsg($userName,"% of Restriction. Current HP of your Car selected: " . GetUserStoredValue($userName," 1XRT"));
cmdLFS("/spec ".$userName);
ENDIF
ENDIF
EndCatchEvent

Glad it's working for you now and a nice system you made there.
Good luck with future coding within the Lapper environment and feel free to ask help/directions if you need to.
This thread is closed

FGED GREDG RDFGDR GSFDG