SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 22/10/2019, 09:18 PM   #1
Vizi10
Huge Clucker
 
Join Date: May 2017
Location: Iran
Posts: 311
Reputation: 8
Default Server freezed with foreach

When i respawn all vehicles with foreach loop server has been crashed/freezed.
Why?

pawn Code:
foreach(new i : Vehicle)
{
    SetVehicleToRespawn(i);
}
//This code is in the server timer. For example, when clock is 12:00 pm, this code is used and respawns the vehicles.
Vizi10 is online now   Reply With Quote
Old 23/10/2019, 04:55 AM   #2
SiaReyes
Gangsta
 
SiaReyes's Avatar
 
Join Date: Mar 2019
Location: Coordinates X,Y,Z
Posts: 622
Reputation: 57
Default Re: Server freezed with foreach

Try this

https://forum.sa-mp.com/showpost.php...57&postcount=4
SiaReyes is offline   Reply With Quote
Old 26/10/2019, 11:45 PM   #3
MP2
Godfather
 
MP2's Avatar
 
Join Date: Jan 2011
Location: England
Posts: 6,234
Reputation: 1001
Default Re: Server freezed with foreach

It’s possible that respawning the vehicle inside the iterator loop removes it from the iterator and breaks the loop. You would then need to use Iter_SafeRemove (I think that is the function name) to remove the vehicle from the iterator before respawning it.

As easier option would just be to use a normal for() loop as stated above.
__________________
Owner and developer of Mike's Cops and Robbers.

Click here to visit our site and find out more. Click here to view trailers.
Enter referral code SAMPFORUM after registering for a $5000 starting bonus!
MP2 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
Connected and logged in to the server, and freezed! StevenLV Scripting Help 0 05/06/2019 12:40 PM
Players gone AFK when freezed TokicMajstor Scripting Help 5 26/04/2019 06:17 PM
Server Freezed Venice Server Support 3 18/09/2014 10:18 PM
GTA-freezed yellow Client Support 1 01/09/2013 05:50 AM


All times are GMT. The time now is 01:45 PM.


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