[RW]Robi Posted December 26, 2015 Report Share Posted December 26, 2015 (edited) Salut, acesta este un tutorial despre creearea unui system care alege un ID / Jucator random dintre jucatori conectati pe server, deci sa incepem. Quote new jucatorionline = 0; la OnPlayerConnect adaugam: Quote jucatorionline++; la OnPlayerDisconnect adaugam Quote jucatorionline--; creeam o comanda zcmd CMD:randomid(playerid, params[]) { new string[128]; o vom restrictiona, in cazul meu nu stiu ce aveti voi in gm deci...eu adaug o restrictionare if(IsPlayerAdmin(playerid)) { new online = 0 + random(jucatorionline); format(string, sizeof(string) , "ID: %d a fost extras prin systemul random", online); SendClientMessageToAll(-1, string); } return 1; } Edited December 26, 2015 by [RW]Robi Quote Link to comment Share on other sites More sharing options...
Mister Posted January 9, 2016 Report Share Posted January 9, 2016 Este cam simplu, si cred ca ar avea o eroare, daca un player se deconecteaza idul lui ramane liber si ar putea sa cada la comanda, Ar trebui sa faci sa aleaga un numar din MAX_PLAYERS dupa sa verifici daca acel numar este conectat IsPlayerConnected(randomonline) si daca nu e sa se repete functia pana gaseste un id online cea ce ai facut tu nu cred ca este corect 2 Quote __ ____ __ / |/ (_)____/ /____ _____ / /|_/ / / ___/ __/ _ \/ ___/ / / / / (__ ) /_/ __/ / /_/ /_/_/____/\__/\___/_/ SERVICII SCRIPTING DE CALITATE Pagina Scripting pawn Link to comment Share on other sites More sharing options...
HONNOR Posted January 9, 2016 Report Share Posted January 9, 2016 Mister are dreptate, ID-ul acela va ramane liber. Ar trebui sa creezi o functie care sa capteze toti playerii conectati. Quote Link to comment Share on other sites More sharing options...
Voller. Posted January 9, 2016 Report Share Posted January 9, 2016 public ConnectedPlayers() { new Connected; foreach(new i: Player) if(IsPlayerConnected(i)) Connected++; return Connected; } CMD:test(playerid) { if(IsPlayerAdmin(playerid)) { new ROnline = random(ConnectedPlayers()), Str[128]; //--------------------------------------------------------------------------------- format(Str, sizeof(Str) , "ID: %d a fost extras prin system-ul random!", ROnline); SendClientMessageToAll(-1, Str); } else return 0; } //------------------------------------------------------------------------ Ceva de genul! Sper sa mearga! Quote Link to comment Share on other sites More sharing options...
[XSS]MaxXx Posted January 13, 2016 Report Share Posted January 13, 2016 On 09.01.2016 at 16:22, Voller. said: public ConnectedPlayers() { new Connected; foreach(new i: Player) if(IsPlayerConnected(i)) Connected++; return Connected; } CMD:test(playerid) { if(IsPlayerAdmin(playerid)) { new ROnline = random(ConnectedPlayers()), Str[128]; //--------------------------------------------------------------------------------- format(Str, sizeof(Str) , "ID: %d a fost extras prin system-ul random!", ROnline); SendClientMessageToAll(-1, Str); } else return 0; } //------------------------------------------------------------------------ Ceva de genul! Sper sa mearga! Merge si nu prea. Chestia aia returneaza nr-ul de jucatori conectati. Daca tu ai 10 jucatori in momentul acela, va fi extras un id de la 1 la 10 chiar daca poate, sunt jucatori conectati peste ID 10 sau exista jucatori neconectati cu un ID mai mic de 10. stock _GetRandomPlayer() { new _players[MAX_PLAYERS], i, l, x = GetPlayerPoolSize(); for(l = 0; l < x; l++) if(IsPlayerConnected(l)) _players[++i] = l; return _players[random(i)]; } This should do the trick. 1 Quote Link to comment Share on other sites More sharing options...
Voller. Posted January 14, 2016 Report Share Posted January 14, 2016 20 hours ago, [XSS]MaxXx said: Merge si nu prea. Chestia aia returneaza nr-ul de jucatori conectati. Daca tu ai 10 jucatori in momentul acela, va fi extras un id de la 1 la 10 chiar daca poate, sunt jucatori conectati peste ID 10 sau exista jucatori neconectati cu un ID mai mic de 10. stock _GetRandomPlayer() { new _players[MAX_PLAYERS], i, l, x = GetPlayerPoolSize(); for(l = 0; l < x; l++) if(IsPlayerConnected(l)) _players[++i] = l; return _players[random(i)]; } This should do the trick. Ok, boss! ;) Quote Link to comment Share on other sites More sharing options...
Ping_gooty Posted February 16, 2016 Report Share Posted February 16, 2016 Scuze de bump, dar nu m-am putut abtine sa nu postez varianta mea forward Chose_RandomPlayer(); public Choose_RandomPlayer() { for(new i , L = GetPlayerPoolSize() ; i < L ; i++) { if(IsPlayerConnected(i)) break; if(i == MAX_PLAYERS - 1) { alesul = -1; return; } } new posibil_ales= -1; while(!IsPlayerConnected(posibil_ales)) { posibil_ales = random(MAX_PLAYERS); } alesul = posibil_ales; printf("L-am ales pe %d",alesul); } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.