eXot 18 Odesláno: 29. Prosinec, 2014 Share Odesláno: 29. Prosinec, 2014 V prípade ak nepoznáte ani len základy ako vytvoriť klikatelný TextDraw tak v čítaní pokračovať ani nemusíte .. Takže najprv si musíme vytvoriť nejaké TextDrawi public OnGameModeInit() { Textdraw0 = TextDrawCreate(81, 231, "TextDraw ID:0"); TextDrawLetterSize(Textdraw0, 0.35, 1.6); TextDrawTextSize(Textdraw0, 164, 13); TextDrawColor(Textdraw0, -1); TextDrawSetShadow(Textdraw0, 0); TextDrawSetSelectable(Textdraw0, true); Textdraw1 = TextDrawCreate(81, 251, "TextDraw ID:1"); TextDrawLetterSize(Textdraw1, 0.35, 1.6); TextDrawTextSize(Textdraw1, 164, 13); TextDrawColor(Textdraw1, -1); TextDrawSetShadow(Textdraw1, 0); TextDrawSetSelectable(Textdraw1, true); Textdraw2 = TextDrawCreate(81, 271, "TextDraw ID:2"); TextDrawLetterSize(Textdraw2, 0.35, 1.6); TextDrawTextSize(Textdraw2, 164, 13); TextDrawColor(Textdraw2, -1); TextDrawSetShadow(Textdraw2, 0); TextDrawSetSelectable(Textdraw2, true); return true; } Nezabudnite si vytvoriť premenné pre Textdraw0, Textdraw1, Textdraw2 Teraz prejdeme k samotnému publicu OnPlayerClickTextDraw Všetci používame klasickú metódu if(clickedid == Textdraw0) { } else if(clickedid == Textdraw1) { } ... Ale je tu aj rýchlejšia varianta a to pomocou switch() Problém je v tom, že tu sa switch používa troška odlišnejšie ako normálne. Ako na to vám ukážem teraz. public OnPlayerClickTextDraw(playerid, Text:clickedid) { switch(_:clickedid) //Tu si všimnite že sme pridali " _: " { Ďalej by ste asi použili case Textdraw0: { } case Textdraw1: { } .... No tu nastáva ďalšia zmena,miesto dosadenia premennej pre Textdraw musíme dosadiť jeho ID ! Ale ako ho zistím ? Jednoducho, ID sa prideľuje podľa počtu vytvorených Textdrawov (štartovné ID je 0 http://wiki.sa-mp.com/wiki/Starting_IDs ). Takže case budeme používať takto : case 0: //Textdraw0 { } case 1: //Textdraw1 { } case 2: //Textdraw2 { } Aké výhody má použiť túto metódu ? - Je to rýchlejšie - Ak vám niekto ukradne script, a má na servery aj iné Textdrawi, nebude mu fungovať Ďalej, niektorý nevedia že možno zistiť čí si hráč nezrušil výber Textdrawu klávesou ESC, aj s tým vám poradím case 65535: //Tu pozor, ESC má VŽDY ID 65535 ! Je to môj prvý návod tak dúfam že všetkému pochopíte, ak sa vám návod páčil, môžete mi dať Rep+ PS:Návod nieje skopírovaný, túto metódu nenájdete ani na ofiaciálnom fóre. Celý kód tu: new Text:Textdraw0 ,Text:Textdraw1, Text:Textdraw2; public OnGameModeInit() { Textdraw0 = TextDrawCreate(81, 231, "TextDraw ID:0"); TextDrawLetterSize(Textdraw0, 0.35, 1.6); TextDrawTextSize(Textdraw0, 164, 13); TextDrawColor(Textdraw0, -1); TextDrawSetShadow(Textdraw0, 0); TextDrawSetSelectable(Textdraw0, true); Textdraw1 = TextDrawCreate(81, 251, "TextDraw ID:1"); TextDrawLetterSize(Textdraw1, 0.35, 1.6); TextDrawTextSize(Textdraw1, 164, 13); TextDrawColor(Textdraw1, -1); TextDrawSetShadow(Textdraw1, 0); TextDrawSetSelectable(Textdraw1, true); Textdraw2 = TextDrawCreate(81, 271, "TextDraw ID:2"); TextDrawLetterSize(Textdraw2, 0.35, 1.6); TextDrawTextSize(Textdraw2, 164, 13); TextDrawColor(Textdraw2, -1); TextDrawSetShadow(Textdraw2, 0); TextDrawSetSelectable(Textdraw2, true); return true; } public OnPlayerClickTextDraw(playerid, Text:clickedid) { switch(_:clickedid) { case 0: { SendClientMessage(playerid, -1, "Klikol si na Textdraw0"); } case 1: { SendClientMessage(playerid, -1, "Klikol si na Textdraw1"); } case 2: { SendClientMessage(playerid, -1, "Klikol si na Textdraw2"); } case 65535: { SendClientMessage(playerid, -1, "Stlačil si ESC"); } } return true; } 2 Link to comment Share on other sites More sharing options...
Polisek 76 Odesláno: 29. Prosinec, 2014 Share Odesláno: 29. Prosinec, 2014 Už nějakej den uvažuji že ho sem dám Taky (Jsem línej) Tutorial Velice Pěknej 9/10 - Určitě to lidé využíjí Link to comment Share on other sites More sharing options...
Mort 29 Odesláno: 29. Prosinec, 2014 Share Odesláno: 29. Prosinec, 2014 Těch pár milisekund je opravdu zanedbatelných a při jakékoliv změně pořádí textdrawů to můžeš tak akorát celý překopat. Osobně doporučuji tohle nepoužívat a zůstat u if-else (alespoň v tomhle případě) K návodu, dalo by se to vysvětlit lépe, třeba říct proč je tam _: (ikdyž by to fungovalo i bez toho) 6/10 Link to comment Share on other sites More sharing options...
ATomas 286 Odesláno: 29. Prosinec, 2014 Share Odesláno: 29. Prosinec, 2014 Co se tyce optimalizace tak asi nejlepsi reseni. ono cim vice je ifu tim vic je to znat. akorat ma to tu nevyhodu ze se ty icka musi psat "rucne" a musi se davat pozor aby se to neposunulo Link to comment Share on other sites More sharing options...
eXot 18 Odesláno: 29. Prosinec, 2014 Author Share Odesláno: 29. Prosinec, 2014 Je to určené skôr pre módy s veľkým množstvom Textdrawov, Neni to návod pre lenivcov ktorým vadí si troška popísať. Link to comment Share on other sites More sharing options...
LukasB 0 Odesláno: 29. Prosinec, 2014 Share Odesláno: 29. Prosinec, 2014 Good návod 10/10 Link to comment Share on other sites More sharing options...
Polisek 76 Odesláno: 29. Prosinec, 2014 Share Odesláno: 29. Prosinec, 2014 Ale jak psal mort taky bych zůstal u if(clickedid == SkinC1) { } else if(clickedid == SkinC2) { } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now