Hôm nay nhân dịp có người hỏi về code nông trại nên lục lại. Code này cũng hơn 1 năm rồi, nay đưa ra cho anh em tham khảo. Nông trại trên ego thì làm mem chơi cho vui thôi chứ code không thể chặt chẽ quá được. Sau đây là hướng dẫn:
Đầu tiên, vào thông tin người dùng tạo một shoutbox. Shoutbox này chính là một ô đất trong nông trại. Và lấy ID của Shoutbox này, tôi gọi là A.
Code ô 1:
{% if message_list=="" or message_list==null %} <img src="/files/154586/bare_landx.png"/><br/>Cấp 2<br/>200$ {% if api.r.get("uid")==api.user_id %} <br/><form action="main.php?id=ch_topic_h&uid=73261&uuid=[user_id]&back_url=%2Fuser_info.php%3Fuid%3D[user_id]%26view%3Dcharacter" style="display:inline" method="post"><input type="hidden" name="text" value="bare_land"/><input type="submit" class="nobutton" value="Mua"/></form> {%endif%} {%else%} {{message_list}} {%endif%}
Code ô 2:
{# Tính thời gian trồng cây #} {% set time,date=message_date|split(" ")[1],message_date|split(" ")[0] %} {% set s,m,h,d,mo,y=time|split(":")[2],time|split(":")[1],time|split(":")[0],date|split("-")[2],date|split("-")[1],date|split("-")[0] %} {% set htg=post.published_at|date_modify("- "~y~" years - "~(mo-1)~" months - "~(d-1)~" days - "~h~" hours - "~m~" minutes - "~s~" seconds")|date("H:i:s d/m/Y") %} {% set atime,adate=htg|split(" ")[0],htg|split(" ")[1] %} {% set as,am,ah,ad,amo,ay=atime|split(":")[2],atime|split(":")[1],atime|split(":")[0],adate|split("/")[0],adate|split("/")[1],adate|split("/")[2] %} {% if ad < 2 and amo < 2 and ay < 1 %} {% set ktg = as+am*60+ah*3600 %} {% set tl=10800-ktg %} {% else %} {% set ktg = 999999 %} {% endif %} {# Ô đất trống #} {% if message=="bare_land" %} {% if api.r.get("uid")==api.user_id %}{# chính chủ #} <a href="/main.php?f=2786531&farm_id=73261&p=1" title="Trồng cây"> <img src="/files/154586/{{message}}.png" alt="Ô 1"/> </a><br/>{% if api.r.get("farm_id")=="73261"%}Đã thu!{%else%}Đất trống!{%endif%} {%else%} {# Khách cmnr #} <img src="/files/154586/{{message}}.png" alt="Ô 1"/> {%endif%} {% endif %} {# Hiện ô đất, tên cây #} {% if ktg < 10800 and message!="bare_land" %} {% if message=="eggplant" %}<img src="/files/154586/growing.png"/><br/>Cà tím {% endif %} {% if message=="lettuce" %}<img src="/files/154586/growing.png"/><br/>Rau diếp {% endif %} {% if message=="hay" %}<img src="/files/154586/growing.png"/><br/>Cỏ {% endif %} {% if message=="peppers" %}<img src="/files/154586/growing.png"/><br/>Ớt {% endif %} {% if message=="tomato" %}<img src="/files/154586/growing.png"/><br/>Cà chua {% endif %} {# Thời gian còn lại #} {% autoescape false %}{{ '<br/><font color="blue">[</font><font color="yellow">'~(tl//3600)~'h'~((tl-(tl//3600)*3600)//60)~'</font><font color="blue">]</font>'}} {% endautoescape %} {% endif %} {# Thu hoạch #} {% if (message=="eggplant" or message=="lettuce" or message=="hay" or message=="peppers" or message=="tomato") and (ktg >= 10800) and (ktg < 21600) %} {% if api.r.get("uid")==api.user_id %}{# Chính cmn chủ #} <form action="main.php?id=ch_topic_h&uid=73261&uuid=[user_id]&back_url=%2Fmain.php%3Ff%3D2800396" style="display:inline" method="post"> <input type="hidden" name="text" value="bare_land"/> <input type="image" src="/files/154586/{{message}}.png" alt="Thu" width="32" height="32" class="nobutton"/> </form><br/>Đã chín {%else%} {# Khách cmn rồi #} <img src="/files/154586/{{message}}.png" alt="Thu" width="32" height="32"/><br/>Đã chín {%endif%} {%endif%} {# Cây chết :v #} {%if ktg > 21600 and message!="bare_land" %} {% if api.r.get("uid")==api.user_id %}{# Chính cmn chủ #} <a href="/main.php?f=2786531&farm_id=73261&p=1" title="Trồng cây"> <img src="/files/154586/{{message}}.png" alt="Ô 1"/> </a> {%else%}{# Khách #} <img src="/files/154586/{{message}}.png" alt="Ô 1"/> {%endif%} <br/>Đã chết {% endif %}
Các bạn nhớ thay 73261 thành uid chat box dùng làm nông trại, 2786531 thành id trang mua cây trồng, 2800396 thành id trang thu hoạch.
Code trang mua cây trồng:
<form action="main.php?id=ch_topic_h&uid={{api.r.get("farm_id")}}&uuid=[user_id]&back_url=%2Fuser_info.php%3Fuid%3D[user_id]%26view%3Dcharacter" method="post"><input type="radio" name="text" value="eggplant"/>Cà tím<br/><input type="radio" name="text" value="hay"/>Cỏ khô<br/><input type="radio" name="text" value="lettuce"/>Rau diếp<br/><input type="radio" name="text" value="peppers"/>Ớt<br/><input type="radio" name="text" value="tomato"/>Cà chua<br/><input type="submit" value="Trồng"/></form>
Code trang thu hoạch: phần thưởng khối
<span>%points%<span> <style type="text/css">body{display:none!important}</style> <script type="text/javascript">window.location.replace("http://sharecode.wap.mu/user_info.php?uid=[user_id]&view=character&farm_id=73261");</script> <meta http-equiv="refresh" content="0,url=/user_info.php?uid=[user_id]&view=character&farm_id=73261"/>
Thay 73261 thành ID shuotbox.
CHÚ Ý:
- Giá mở đất và trồng cây là giá của Shoutbox
- Level của Shuotbox là level có thể mở ô đất
- Với mỗi ô đất phải làm 1 trang trồng cây và thu hoạch khác nhau tùy theo giá mở ô đất và số tiền thu hoạch được.
- Nhớ thay các ID như hướng dẫn.
Chúc các bạn thành công!
Code bởi MrKen - admin phonho.net