Hendrickson Posted October 26, 2011 Share Posted October 26, 2011 HI, Is there a way to globally add an item to everyones inventory? For example if I want to give all users a bonus Halloween item. Is there an easy way to do this? Quote Link to comment Share on other sites More sharing options...
Spudinski Posted October 26, 2011 Share Posted October 26, 2011 MCCodes already have this feature in the admin panel, "Give item to users". It's a loop of INSERT queries if I'm not mistaken. Quote Link to comment Share on other sites More sharing options...
Hendrickson Posted October 26, 2011 Author Share Posted October 26, 2011 (edited) I think that only adds to one person inventory doesn't it? I would liek to add an items to everyone's. What would the mysl query for that be? Edited October 26, 2011 by Hendrickson Quote Link to comment Share on other sites More sharing options...
chicka Posted October 26, 2011 Share Posted October 26, 2011 I think that only adds to one person inventory doesn't it? I would liek to add an items to everyone's. What would the mysl query for that be? With Mccodes V2 there is a mass give items. You should be able to give to everyone.. It should look something like this staff_items.php?action=massitemgive Quote Link to comment Share on other sites More sharing options...
Hendrickson Posted October 26, 2011 Author Share Posted October 26, 2011 Its seems the old owner removed this from the smenu.php If I try the link I get the following error. Error: This script requires an action. Looking at the staff_items.php I can only see give item that is coded there :( Quote Link to comment Share on other sites More sharing options...
chicka Posted October 26, 2011 Share Posted October 26, 2011 (edited) Open up staff_items.php under switch($_GET['action']) { add case 'massitemgive': mass_give_item(); break; case 'massitemgivesub': mass_give_item_sub(); break; At the bottom of the page before $h->endpage(); ?> add function mass_give_item() { global $db,$ir,$c; print "<h3>Giving Item To All Users</h3> <form action='staff_items.php?action=massitemgivesub' method='post'> Item: ".item_dropdown($c,'item')."<br /> Quantity: <input type='text' name='qty' value='1' /><br /> <input type='submit' value='Mass Send' /></form>"; } function mass_give_item_sub() { global $db,$ir,$c; $q=mysql_query("SELECT * FROM users WHERE fedjail=0",$c); while($r=mysql_fetch_array($q)) { $db->query("INSERT INTO inventory VALUES('',{$_POST['item']},{$r['userid']},{$_POST['qty']})",$c) or die(mysql_error()); event_add($r['userid'],"All users were given an item $itemname, Click <a href='inventory.php'>Here</a> to check.",$c); print "Item Sent To {$r['username']}</br>"; } print "<br /><font color=blue>Mass item sending complete!</br></font>"; stafflog_add("Gave {$_POST['qty']} of item ID {$_POST['item']} to all users"); } You'll have to add the link if its not there already but that should do it. Edited October 26, 2011 by chicka Quote Link to comment Share on other sites More sharing options...
Uridium Posted October 26, 2011 Share Posted October 26, 2011 Nicely helped out chicka :) thank you Quote Link to comment Share on other sites More sharing options...
rulerofzu Posted October 26, 2011 Share Posted October 26, 2011 Why are you selecting the entire users table when you only need the userid Why not use the item_add function Also dont you think it would be good to give your players an event letting them know they got something. Quote Link to comment Share on other sites More sharing options...
Hendrickson Posted October 26, 2011 Author Share Posted October 26, 2011 Works fine tested thanks. yes there is an event: event_add($r['userid'],"All users were given an item $itemname, Click <a href='inventory.php'>Here</a> to check.",$c); Quote Link to comment Share on other sites More sharing options...
chicka Posted October 26, 2011 Share Posted October 26, 2011 I'm glad it worked out for ya.. Quote Link to comment Share on other sites More sharing options...
Hendrickson Posted October 27, 2011 Author Share Posted October 27, 2011 Just to complicate things, how would you make it that it only gave the item to active players say in the last week? Quote Link to comment Share on other sites More sharing options...
gurpreet Posted October 27, 2011 Share Posted October 27, 2011 Add laston in your select query, then do something like this: $week = time() - (60*60*24*7); if($r['laston'] < $week) { } else { the code for giving items and such goes here } $h->endpage(); Something like that, there may be a better way to do it but that should work fine. Quote Link to comment Share on other sites More sharing options...
chicka Posted October 28, 2011 Share Posted October 28, 2011 when i'm not so busy, at some point today i'll do it for you. Quote Link to comment Share on other sites More sharing options...
rulerofzu Posted October 28, 2011 Share Posted October 28, 2011 Add laston in your select query, then do something like this: $week = time() - (60*60*24*7); if($r['laston'] < $week) { } else { the code for giving items and such goes here } $h->endpage(); Something like that, there may be a better way to do it but that should work fine. Indeed just put it in the actual query your check for players that have been on in the last 7 days. No need for the if... Quote Link to comment Share on other sites More sharing options...
Hendrickson Posted October 28, 2011 Author Share Posted October 28, 2011 Sorry I'm noob and hwo do I just put it in the query? Quote Link to comment Share on other sites More sharing options...
gurpreet Posted October 29, 2011 Share Posted October 29, 2011 Indeed just put it in the actual query your check for players that have been on in the last 7 days. No need for the if... Ah ok, so just something like this? I think I got it backwards lol: $week = time() - (60*60*24*7); if($r['laston'] > $week) { query here } Sorry I'm noob and hwo do I just put it in the query? function mass_give_item_sub() { global $db,$ir,$c; $q=mysql_query("SELECT * FROM users WHERE fedjail=0",$c); while($r=mysql_fetch_array($q)) { $week = time() - (60*60*24*7); if($r['laston'] > $week) { $db->query("INSERT INTO inventory VALUES('',{$_POST['item']},{$r['userid']},{$_POST['qty']})",$c) or die(mysql_error()); event_add($r['userid'],"All users were given an item $itemname, Click <a href='inventory.php'>Here</a> to check.",$c); print "Item Sent To {$r['username']}</br>"; } print "<font color=blue>Mass item sending complete!</br></font>"; stafflog_add("Gave {$_POST['qty']} of item ID {$_POST['item']} to all users"); } } That should work. Quote Link to comment Share on other sites More sharing options...
rulerofzu Posted October 30, 2011 Share Posted October 30, 2011 No actually IN the sql query select laston, userid from users where laston > unix_timestamp()-60*60*168 && fedjail=0; 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.