OnPlayerUpdate - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: OnPlayerUpdate (
/showthread.php?tid=327361)
OnPlayerUpdate -
new121 - 20.03.2012
Would looping through all players checking if they are in a car and getting their car id, then ejecting them from the car if the health is lower then 450 cause lag? would it be better to set a 1 s timer?
Re: OnPlayerUpdate -
ReneG - 20.03.2012
Depends on how many people are on the server.
OnPlayerUpdate gets called 30 times a second, so you do the math.
I would recommend a 1 second timer though.
Re: OnPlayerUpdate -
new121 - 20.03.2012
Alright thanks.
Re: OnPlayerUpdate -
SpiritEvil - 20.03.2012
Try this:
pawn Код:
public OnGameModeInit()
{
SetTimer("PlayersCheck", 1000, true);
return 1;
}
forward PlayersCheck();
public PlayersCheck()
{
for(new i = 0; i <= GetMaxPlayers(); i++)
{
if(IsPlayerConnected(i))
{
if(isPlayerInAnyVehicle(i))
{
new vid, FLoat:vhealth;
vid = GetPlayerVehicleID(i);
GetVehicleHealth(vid, vhealth);
if(vhealth < 450)
{
RemovePlayerFromVehicle(i);
}
}
}
}
}
Re: OnPlayerUpdate -
ReneG - 20.03.2012
Can't believe I didn't think of this, lol. Why don't you just use OnPlayerEnterVehicle and use your code there. No loop is necessary.
EDIT:
Nevermind. Antonio is right.
Re: OnPlayerUpdate -
antonio112 - 20.03.2012
Quote:
Originally Posted by VincentDunn
Can't believe I didn't think of this, lol. Why don't you just use OnPlayerStateChange and use
pawn Код:
if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER) { // You would then add the vehicle health/id code here.
|
What about if the player's in a car with 1000 health and only afterwards, he makes an accident and the vehicles health is lowering under 450 ? That wouldn't work with your solution.
So, a timer is still the best solution. Use
SpiritEvils code.
Re: OnPlayerUpdate -
Micko123 - 04.11.2016
-DELETE-
SORRY GUYS BUT I WROTE ON WRONG THREAD!!!! DAMN!
Re: OnPlayerUpdate -
Vince - 04.11.2016
Much more optimized version without all the redundant checks:
PHP код:
public PlayersCheck()
{
for(new i = 0, j = GetPlayerPoolSize(), Float:vhealth; i <= j; i++)
{
if(GetVehicleHealth(GetPlayerVehicleID(i), vhealth))
{
if(vhealth < 450)
{
RemovePlayerFromVehicle(i);
}
}
}
}
Edit: crap, didn't see the dates. Was looking at date of last post. Oh well.
Re: OnPlayerUpdate -
Micko123 - 04.11.2016
Quote:
Originally Posted by Vince
Much more optimized version without all the redundant checks:
PHP код:
public PlayersCheck()
{
for(new i = 0, j = GetPlayerPoolSize(), Float:vhealth; i <= j; i++)
{
if(GetVehicleHealth(GetPlayerVehicleID(i), vhealth))
{
if(vhealth < 450)
{
RemovePlayerFromVehicle(i);
}
}
}
}
Edit: crap, didn't see the dates. Was looking at date of last post. Oh well.
|
Same happened to me hahahahah
NEXT PERSON THAT IS READING THIS! DO NOT WRITE ANYTHING ON THIS POST!!!!