{"action":"created","issue":{"url":"https://api.github.com/repos/crosire/scripthookvdotnet/issues/465","repository_url":"https://api.github.com/repos/crosire/scripthookvdotnet","labels_url":"https://api.github.com/repos/crosire/scripthookvdotnet/issues/465/labels{/name}","comments_url":"https://api.github.com/repos/crosire/scripthookvdotnet/issues/465/comments","events_url":"https://api.github.com/repos/crosire/scripthookvdotnet/issues/465/events","html_url":"https://github.com/crosire/scripthookvdotnet/issues/465","id":155389948,"number":465,"title":"Issue with CreatePed(Model model, Vector3 position, Single heading)","user":{"login":"Buuburn","id":1073602,"avatar_url":"https://avatars.githubusercontent.com/u/1073602?v=3","gravatar_id":"","url":"https://api.github.com/users/Buuburn","html_url":"https://github.com/Buuburn","followers_url":"https://api.github.com/users/Buuburn/followers","following_url":"https://api.github.com/users/Buuburn/following{/other_user}","gists_url":"https://api.github.com/users/Buuburn/gists{/gist_id}","starred_url":"https://api.github.com/users/Buuburn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Buuburn/subscriptions","organizations_url":"https://api.github.com/users/Buuburn/orgs","repos_url":"https://api.github.com/users/Buuburn/repos","events_url":"https://api.github.com/users/Buuburn/events{/privacy}","received_events_url":"https://api.github.com/users/Buuburn/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/crosire/scripthookvdotnet/labels/question","name":"question","color":"cc317c"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2016-05-18T00:04:59Z","updated_at":"2016-05-18T15:38:02Z","closed_at":"2016-05-18T15:38:02Z","body":"When I try to spawn multiple peds this happens:\r\nSystem.InvalidOperationException: Illegal call to 'Script.Wait()' outside main loop!\r\n   at GTA.Script.Wait(Int32 ms)\r\n   at GTA.Model.Request(Int32 timeout)\r\n   at GTA.World.CreatePed(Model model, Vector3 position, Single heading)\r\n\r\n\r\n\r\n But when I use Function.call<Ped>(Hash.CREATE_PED, Etc)  to spawn them it works fine except for a few PedHashes that don't seem to be working. Also using CreateRandomPed() also works.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/crosire/scripthookvdotnet/issues/comments/220066641","html_url":"https://github.com/crosire/scripthookvdotnet/issues/465#issuecomment-220066641","issue_url":"https://api.github.com/repos/crosire/scripthookvdotnet/issues/465","id":220066641,"user":{"login":"crosire","id":2057233,"avatar_url":"https://avatars.githubusercontent.com/u/2057233?v=3","gravatar_id":"","url":"https://api.github.com/users/crosire","html_url":"https://github.com/crosire","followers_url":"https://api.github.com/users/crosire/followers","following_url":"https://api.github.com/users/crosire/following{/other_user}","gists_url":"https://api.github.com/users/crosire/gists{/gist_id}","starred_url":"https://api.github.com/users/crosire/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crosire/subscriptions","organizations_url":"https://api.github.com/users/crosire/orgs","repos_url":"https://api.github.com/users/crosire/repos","events_url":"https://api.github.com/users/crosire/events{/privacy}","received_events_url":"https://api.github.com/users/crosire/received_events","type":"User","site_admin":false},"created_at":"2016-05-18T15:38:02Z","updated_at":"2016-05-18T15:38:02Z","body":"It's not about the natives in this case. The constructor is actually called on the thread for native scheduling. The problem is the ```Script.Wait``` function. That one works by pausing the script main loop, which only works if actually inside that said main loop. Since ```World.CreatePed``` internally relies on ```Script.Wait``` to make sure the ped model is loaded into memory before creating it (or else the ped won't spawn), the same restrictions apply here too. That's why you can only call it in one of those three events, which are executed in the script main loop."}}