Mcfarlin Posted November 21, 2009 Posted November 21, 2009 was wondering if it can be done, and if so how? basically the querry and the event_add in the same line of code. that way no matter what when one ran the other would as well. Quote
Danny696 Posted November 21, 2009 Posted November 21, 2009 do you mean 1) $db->query("some query"); event_add("blahh"); 2) $db->query("event_add('blahh')); ??? Quote
Mcfarlin Posted November 21, 2009 Author Posted November 21, 2009 Okay i was trying to help a friend who is using a mod from here. find random items while playing. (changed to crystals) problem is that of those random events where the crystal was found, an event was sent to the user. but no crystal. then other times it works fine with the event and the crystal being credited. just wondered if the querry and the event_add could be combined, then there would be no way this could happen. as is is now. [mysql]$db->query("UPDATE users SET crystals=crystals+$rand2 WHERE userid=$userid"); event_add($ir['userid'],"While playing the game you found a crystal, consider it a gift for playing.");[/mysql] and i think your meaning i could use? [mysql]$db->query("UPDATE users SET crystals=crystals+$rand2 WHERE userid=$userid"), event_add($ir['userid'], "While playing bla bla.");[/mysql] Quote
Arek Posted November 21, 2009 Posted November 21, 2009 Hi Both statements should run together no need to "join" them. Is it possible that $rand2 gave a random number of 0? Quote
Danny696 Posted November 21, 2009 Posted November 21, 2009 $randcrys = rand(1,3); //make sure its not 0 ;) $addcrys = sprintf("UPDATE `users` SET `crystals`=`crystals`+%u WHERE `userid`=%u", abs((@intval) $randcrys), $userid); $db->query($addcrys); event_add($userid, 'While playing '.$set['game_name'].', you found '.number_format($randcrys).', consider it a gift for playing.'); Would work. Quote
Mcfarlin Posted November 21, 2009 Author Posted November 21, 2009 RE: Hi Both statements should run together no need to "join" them. Is it possible that $rand2 gave a random number of 0? No it will never equal 0. [mysql]$rand1=(int) rand(1,200); $rand2=(int) rand(10,50); if($rand1 == 100) { $db->query("UPDATE users SET crystals=crystals+$rand2 WHERE userid=$userid"); event_add($ir['userid'],"While playing the game you found a crate of rations, consider it a gift for playing."); } [/mysql] it will always be 10-50 can they be joined together? Quote
Mcfarlin Posted November 21, 2009 Author Posted November 21, 2009 $randcrys = rand(1,3); //make sure its not 0 ;) $addcrys = sprintf("UPDATE `users` SET `crystals`=`crystals`+%u WHERE `userid`=%u", abs((@intval) $randcrys), $userid); $db->query($addcrys); event_add($userid, 'While playing '.$set['game_name'].', you found '.number_format($randcrys).', consider it a gift for playing.'); Would work. this wont work like the mod was intended. i dont see anything in this to make it a random event, wouldnt this just give out 1-3 crystals every time they go to that page? its in the header so....wont be trying to use that. lol and it still has them as two separate lines they are not joined. thx anyhow danny i did lean something from this post. but thats a lot more secure than the one we are using now, never though about it. was just trying to make the damn thing work first. Quote
Danny696 Posted November 21, 2009 Posted November 21, 2009 just a quick thingy, you can use $db->event_add, this will also insert the event into a non-existant table called event_log. so you can check the non-existant event logs X( Quote
Mcfarlin Posted November 21, 2009 Author Posted November 21, 2009 just a quick thingy, you can use $db->event_add, this will also insert the event into a non-existant table called event_log. so you can check the non-existant event logs X(ha ha ha wait that was a non-existant giggle so you didnt see that. Quote
Danny696 Posted November 22, 2009 Posted November 22, 2009 Lol, the mcc database, is stupid, the easy insert, its eaiser just to do the damn query, thats why you never see it used. Quote
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.